diff --git a/assets/tinker/lang/en_US.xml b/assets/tinker/lang/en_US.xml
index 5bcc8e3b..2fcbee2a 100644
--- a/assets/tinker/lang/en_US.xml
+++ b/assets/tinker/lang/en_US.xml
@@ -154,6 +154,7 @@
Drawbridge
Igniter
+ Landmine
Block of Cobalt
Block of Ardite
@@ -303,6 +304,10 @@
%1$s will be a stepping stone for our revolution!
%1$s thought swimming in hot liquids was a good idea
+ %1$s watched their legs get blown off
+ %1$s was doomed to fall by Landmine
+ %1$s took a ride on a firework
+
Wooden
Stone
Iron
diff --git a/assets/tinker/textures/blocks/Landmine.png b/assets/tinker/textures/blocks/Landmine.png
new file mode 100644
index 00000000..7859155d
Binary files /dev/null and b/assets/tinker/textures/blocks/Landmine.png differ
diff --git a/assets/tinker/textures/gui/landmine.png b/assets/tinker/textures/gui/landmine.png
new file mode 100644
index 00000000..1e881185
Binary files /dev/null and b/assets/tinker/textures/gui/landmine.png differ
diff --git a/tconstruct/TConstruct.java b/tconstruct/TConstruct.java
index e1d14638..15ef184a 100644
--- a/tconstruct/TConstruct.java
+++ b/tconstruct/TConstruct.java
@@ -4,6 +4,8 @@ import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import tconstruct.common.TContent;
import tconstruct.common.TProxyCommon;
+import tconstruct.landmine.logic.behavior.Behavior;
+import tconstruct.landmine.logic.behavior.stackCombo.SpecialStackHandler;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.crafting.Detailing;
import tconstruct.library.crafting.LiquidCasting;
@@ -124,6 +126,8 @@ public class TConstruct
@EventHandler
public void postInit (FMLPostInitializationEvent evt)
{
+ Behavior.registerBuiltInBehaviors();
+ SpecialStackHandler.registerBuiltInStackHandlers();
content.modIntegration();
content.createEntities();
/*SkillRegistry.registerSkill("Wall Building", new WallBuilding());
diff --git a/tconstruct/client/TProxyClient.java b/tconstruct/client/TProxyClient.java
index 6946ef79..69b3639c 100644
--- a/tconstruct/client/TProxyClient.java
+++ b/tconstruct/client/TProxyClient.java
@@ -137,6 +137,10 @@ import tconstruct.entity.SlimeClone;
import tconstruct.entity.projectile.ArrowEntity;
import tconstruct.entity.projectile.DaggerEntity;
import tconstruct.entity.projectile.LaunchedPotion;
+import tconstruct.landmine.client.gui.GuiLandmine;
+import tconstruct.landmine.client.render.RenderLandmine;
+import tconstruct.landmine.inventory.ContainerLandmine;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.client.ToolGuiElement;
@@ -183,7 +187,10 @@ public class TProxyClient extends TProxyCommon
return new GlowstoneAggregatorGui(player.inventory, (GlowstoneAggregator) world.getBlockTileEntity(x, y, z), world, x, y, z);
if (ID == drawbridgeGui)
return new DrawbridgeGui(player.inventory, (DrawbridgeLogic) world.getBlockTileEntity(x, y, z), world, x, y, z);
-
+ if (ID == landmineGui){
+ return new GuiLandmine(new ContainerLandmine(player, (TileEntityLandmine) world.getBlockTileEntity(x, y, z)));
+ }
+
if (ID == manualGuiID)
{
ItemStack stack = player.getCurrentEquippedItem();
@@ -360,6 +367,7 @@ public class TProxyClient extends TProxyCommon
RenderingRegistry.registerBlockHandler(new DryingRackRender());
RenderingRegistry.registerBlockHandler(new PaneRender());
RenderingRegistry.registerBlockHandler(new PaneConnectedRender());
+ RenderingRegistry.registerBlockHandler(new RenderLandmine());
//RenderingRegistry.registerBlockHandler(new BrickRender());
//RenderingRegistry.registerBlockHandler(new BallRepeaterRender());
diff --git a/tconstruct/common/TContent.java b/tconstruct/common/TContent.java
index 45f631c6..dc818e59 100644
--- a/tconstruct/common/TContent.java
+++ b/tconstruct/common/TContent.java
@@ -10,6 +10,7 @@ import net.minecraft.block.BlockDispenser;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialLiquid;
+import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -150,6 +151,9 @@ import tconstruct.items.tools.Rapier;
import tconstruct.items.tools.Scythe;
import tconstruct.items.tools.Shortbow;
import tconstruct.items.tools.Shovel;
+import tconstruct.landmine.block.BlockLandmine;
+import tconstruct.landmine.item.ItemBlockLandmine;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
import tconstruct.library.TConstructRegistry;
import tconstruct.library.client.TConstructClientRegistry;
import tconstruct.library.crafting.Detailing;
@@ -539,6 +543,11 @@ public class TContent implements IFuelHandler
GameRegistry.registerBlock(redstoneMachine, RedstoneMachineItem.class, "Redstone.Machine");
GameRegistry.registerTileEntity(DrawbridgeLogic.class, "Drawbridge");
GameRegistry.registerTileEntity(FirestarterLogic.class, "Firestarter");
+
+ //Landmine
+ landmine = new BlockLandmine(PHConstruct.landmine).setHardness(0.5F).setResistance(0F).setStepSound(Block.soundMetalFootstep).setCreativeTab(CreativeTabs.tabRedstone).setUnlocalizedName("landmine");
+ GameRegistry.registerBlock(landmine, ItemBlockLandmine.class, "Redstone.Landmine");
+ GameRegistry.registerTileEntity(TileEntityLandmine.class, "Landmine");
dryingRack = new DryingRack(PHConstruct.dryingRack).setUnlocalizedName("Armor.DryingRack");
GameRegistry.registerBlock(dryingRack, "Armor.DryingRack");
diff --git a/tconstruct/common/TProxyCommon.java b/tconstruct/common/TProxyCommon.java
index f70cd481..d7a6873e 100644
--- a/tconstruct/common/TProxyCommon.java
+++ b/tconstruct/common/TProxyCommon.java
@@ -5,6 +5,8 @@ import tconstruct.entity.MiniGardy;
import tconstruct.inventory.ArmorExtendedContainer;
import tconstruct.inventory.KnapsackContainer;
import tconstruct.inventory.MiniGardyContainer;
+import tconstruct.landmine.inventory.ContainerLandmine;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
import tconstruct.library.blocks.InventoryLogic;
import tconstruct.util.player.TPlayerStats;
import net.minecraft.entity.Entity;
@@ -29,7 +31,8 @@ public class TProxyCommon implements IGuiHandler
public static int smelteryGuiID = 7;
public static int glowstoneAggregatorGui = 8;
public static int drawbridgeGui = 9;
-
+ public static int landmineGui = 10;
+
public static int inventoryGui = 100;
public static int armorGuiID = 101;
public static int knapsackGuiID = 102;
@@ -41,6 +44,11 @@ public class TProxyCommon implements IGuiHandler
@Override
public Object getServerGuiElement (int ID, EntityPlayer player, World world, int x, int y, int z)
{
+
+ if (ID == landmineGui){
+ return new ContainerLandmine(player, (TileEntityLandmine)world.getBlockTileEntity(x, y, z));
+ }
+
if (ID < 0)
return null;
diff --git a/tconstruct/landmine/Helper.java b/tconstruct/landmine/Helper.java
new file mode 100644
index 00000000..cdd13f7d
--- /dev/null
+++ b/tconstruct/landmine/Helper.java
@@ -0,0 +1,72 @@
+package tconstruct.landmine;
+
+import net.minecraft.block.Block;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.client.renderer.Tessellator;
+import net.minecraftforge.common.ForgeDirection;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class Helper {
+
+ public static ForgeDirection convertMetaToForgeOrientation(int metadata){
+ switch(metadata){
+ case 6:
+ return ForgeDirection.DOWN;
+ case 7:
+ return ForgeDirection.UP;
+ case 1:
+ return ForgeDirection.WEST;
+ case 3:
+ return ForgeDirection.NORTH;
+ case 2:
+ return ForgeDirection.EAST;
+ case 4:
+ return ForgeDirection.SOUTH;
+ case 5:
+ return ForgeDirection.DOWN;
+ case 0:
+ return ForgeDirection.UP;
+ }
+
+ return ForgeDirection.UNKNOWN;
+ }
+
+ public static void renderInventoryCube(Block block, int metadata, int modelID, RenderBlocks renderer){
+ Tessellator tessellator = Tessellator.instance;
+
+ tessellator.startDrawingQuads();
+ tessellator.setNormal(0.0F, 1.0F, 0.0F);
+ renderer.renderFaceYPos(block, 0, 0, 0, renderer.getBlockIconFromSideAndMetadata(block, 1, metadata));
+ tessellator.draw();
+
+ tessellator.startDrawingQuads();
+ tessellator.setNormal(0.0F, -1.0F, 0.0F);
+ renderer.renderFaceYNeg(block, 0, 0, 0, renderer.getBlockIconFromSideAndMetadata(block, 0, metadata));
+ tessellator.draw();
+
+ tessellator.startDrawingQuads();
+ tessellator.setNormal(1.0F, 0.0F, 0.0F);
+ renderer.renderFaceXPos(block, 0, 0, 0, renderer.getBlockIconFromSideAndMetadata(block, 2, metadata));
+ tessellator.draw();
+
+ tessellator.startDrawingQuads();
+ tessellator.setNormal(-1.0F, 0.0F, 0.0F);
+ renderer.renderFaceXNeg(block, 0, 0, 0, renderer.getBlockIconFromSideAndMetadata(block, 3, metadata));
+ tessellator.draw();
+
+ tessellator.startDrawingQuads();
+ tessellator.setNormal(0.0F, 0.0F, 1.0F);
+ renderer.renderFaceZPos(block, 0, 0, 0, renderer.getBlockIconFromSideAndMetadata(block, 4, metadata));
+ tessellator.draw();
+
+ tessellator.startDrawingQuads();
+ tessellator.setNormal(0.0F, 0.0F, -1.0F);
+ renderer.renderFaceZNeg(block, 0, 0, 0, renderer.getBlockIconFromSideAndMetadata(block, 5, metadata));
+ tessellator.draw();
+ }
+
+}
diff --git a/tconstruct/landmine/block/BlockLandmine.java b/tconstruct/landmine/block/BlockLandmine.java
new file mode 100644
index 00000000..9a231974
--- /dev/null
+++ b/tconstruct/landmine/block/BlockLandmine.java
@@ -0,0 +1,529 @@
+package tconstruct.landmine.block;
+
+import static net.minecraftforge.common.ForgeDirection.DOWN;
+import static net.minecraftforge.common.ForgeDirection.EAST;
+import static net.minecraftforge.common.ForgeDirection.NORTH;
+import static net.minecraftforge.common.ForgeDirection.SOUTH;
+import static net.minecraftforge.common.ForgeDirection.UP;
+import static net.minecraftforge.common.ForgeDirection.WEST;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.BlockContainer;
+import net.minecraft.block.EnumMobType;
+import net.minecraft.block.material.Material;
+import net.minecraft.client.renderer.texture.IconRegister;
+import net.minecraft.creativetab.CreativeTabs;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.entity.item.EntityTNTPrimed;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.util.Icon;
+import net.minecraft.util.MathHelper;
+import net.minecraft.world.Explosion;
+import net.minecraft.world.IBlockAccess;
+import net.minecraft.world.World;
+import net.minecraftforge.common.ForgeDirection;
+import tconstruct.TConstruct;
+import tconstruct.common.TProxyCommon;
+import tconstruct.landmine.Helper;
+import tconstruct.landmine.client.render.RenderLandmine;
+import tconstruct.landmine.logic.LandmineExplodeLogic;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BlockLandmine extends BlockContainer {
+
+ // Should explode when broken instead of dropping items(may not actually work
+ boolean explodeOnBroken = false;
+
+ public BlockLandmine(int par1) {
+ super(par1, Material.tnt);
+ this.setTickRandomly(true);
+ this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F - 0.0625F, 0.0625F, 1.0F - 0.0625F);
+ }
+
+ @Override
+ public int getLightValue(IBlockAccess world, int x, int y, int z) {
+ if (world.getBlockTileEntity(x, y, z) instanceof TileEntityLandmine) {
+ TileEntityLandmine te = (TileEntityLandmine) world.getBlockTileEntity(x, y, z);
+
+ if (te != null) {
+ if (te.getStackInSlot(3) != null) {
+ return lightValue[te.getStackInSlot(3).itemID];
+ }
+ }
+ }
+ return super.getLightValue(world, x, y, z);
+ }
+
+ @Override
+ public int tickRate(World par1World) {
+ return 20;
+ }
+
+ @Override
+ public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) {
+ TileEntityLandmine te = (TileEntityLandmine) par1IBlockAccess.getBlockTileEntity(par2, par3, par4);
+
+ ItemStack camo = te.getStackInSlot(3);
+ if (camo != null && camo.itemID < blocksList.length) {
+ return Block.blocksList[camo.itemID].getIcon(par5, camo.getItemDamage());
+ } else {
+ return this.getIcon(par5, par1IBlockAccess.getBlockMetadata(par2, par3, par4));
+ }
+ }
+
+ @Override
+ public boolean isOpaqueCube() {
+ return false;
+ }
+
+ @Override
+ public boolean renderAsNormalBlock() {
+ return false;
+ }
+
+ @Override
+ public int getRenderType() {
+ return RenderLandmine.model;
+ }
+
+ @Override
+ public void onBlockClicked(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer) {
+ super.onBlockClicked(par1World, par2, par3, par4, par5EntityPlayer);
+
+ if(this.explodeOnBroken){
+ checkExplosion(par1World, par2, par3, par4, true);
+ }
+ }
+
+ @Override
+ public void registerIcons(IconRegister par1IconRegister) {
+ this.blockIcon = par1IconRegister.registerIcon("tinker:Landmine");
+ }
+
+ @Override
+ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) {
+ par5EntityPlayer.openGui(TConstruct.instance, TProxyCommon.landmineGui, par1World, par2, par3, par4);
+ return true;
+ }
+
+ @Override
+ public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6) {
+ TileEntityLandmine tileentity = (TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4);
+
+ int metadata = par1World.getBlockMetadata(par2, par3, par4);
+
+ if (tileentity != null && (!explodeOnBroken || !hasItems(par1World, par2, par3, par4)) && par6 != 193 && !tileentity.isExploding) {
+ int id = this.blockID;
+ if (id > 0) {
+ ItemStack is = new ItemStack(id, 1, damageDropped(tileentity.triggerType));
+ if(tileentity.isInvNameLocalized()){
+ is.setItemName(tileentity.getInvName());
+ }
+ dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(id, 1, damageDropped(tileentity.triggerType)));
+ }
+
+ for (int j1 = 0; j1 < tileentity.getSizeInventory(); ++j1) {
+ ItemStack itemstack = tileentity.getStackInSlot(j1);
+
+ if (itemstack != null) {
+ while (itemstack.stackSize > 0) {
+
+ int ss = itemstack.stackSize;
+ itemstack.stackSize -= ss;
+ EntityItem entityitem = new EntityItem(par1World, (double) ((float) par2), (double) ((float) par3), (double) ((float) par4), new ItemStack(itemstack.itemID, ss, itemstack.getItemDamage()));
+
+ if (itemstack.hasTagCompound()) {
+ entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
+ }
+
+ float f3 = 0.05F;
+ entityitem.motionX = (double) (f3);
+ entityitem.motionY = (double) (f3 + 0.2F);
+ entityitem.motionZ = (double) (f3);
+ par1World.spawnEntityInWorld(entityitem);
+ }
+ }
+ }
+
+ par1World.func_96440_m(par2, par3, par4, par5);
+ } else if (explodeOnBroken) {
+ checkExplosion(par1World, par2, par3, par4, true);
+ }
+
+ super.breakBlock(par1World, par2, par3, par4, par5, par6);
+ }
+
+ @Override
+ public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) {
+ par3List.add(new ItemStack(par1, 1, 0));
+ par3List.add(new ItemStack(par1, 1, 1));
+ par3List.add(new ItemStack(par1, 1, 2));
+ par3List.add(new ItemStack(par1, 1, 3));
+ }
+
+ @Override
+ public boolean getBlocksMovement(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
+ return true;
+ }
+
+ @Override
+ public boolean canPlaceBlockOnSide(World par1World, int par2, int par3, int par4, int par5) {
+ ForgeDirection dir = ForgeDirection.getOrientation(par5);
+ return (dir == DOWN && par1World.isBlockSolidOnSide(par2, par3 + 1, par4, DOWN)) || (dir == UP && par1World.isBlockSolidOnSide(par2, par3 - 1, par4, UP)) || (dir == NORTH && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH)) || (dir == SOUTH && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH)) || (dir == WEST && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST)) || (dir == EAST && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST));
+ }
+
+ @Override
+ public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) {
+ return par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST) || par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST) || par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH) || par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH) || par1World.isBlockSolidOnSide(par2, par3 - 1, par4, UP) || par1World.isBlockSolidOnSide(par2, par3 + 1, par4, DOWN);
+ }
+
+ @Override
+ public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9) {
+ int j1 = par9 & 8;
+ int k1 = par9 & 7;
+ byte b0 = -1;
+
+ if (par5 == 0 && par1World.isBlockSolidOnSide(par2, par3 + 1, par4, DOWN)) {
+ b0 = 0;
+ }
+
+ if (par5 == 1 && par1World.isBlockSolidOnSide(par2, par3 - 1, par4, UP)) {
+ b0 = 5;
+ }
+
+ if (par5 == 2 && par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH)) {
+ b0 = 4;
+ }
+
+ if (par5 == 3 && par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH)) {
+ b0 = 3;
+ }
+
+ if (par5 == 4 && par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST)) {
+ b0 = 2;
+ }
+
+ if (par5 == 5 && par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST)) {
+ b0 = 1;
+ }
+
+ return b0 + j1;
+ }
+
+ @Override
+ public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) {
+ int l = par1World.getBlockMetadata(par2, par3, par4);
+ int i1 = l & 7;
+ int j1 = l & 8;
+
+ if (i1 == invertMetadata(1)) {
+ if ((MathHelper.floor_double((double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 1) == 0) {
+ par1World.setBlockMetadataWithNotify(par2, par3, par4, 5 | j1, 2);
+ } else {
+ par1World.setBlockMetadataWithNotify(par2, par3, par4, 6 | j1, 2);
+ }
+ } else if (i1 == invertMetadata(0)) {
+ if ((MathHelper.floor_double((double) (par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 1) == 0) {
+ par1World.setBlockMetadataWithNotify(par2, par3, par4, 7 | j1, 2);
+ } else {
+ par1World.setBlockMetadataWithNotify(par2, par3, par4, 0 | j1, 2);
+ }
+ }
+
+ if (par6ItemStack.hasDisplayName()) {
+ ((TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4)).setGuiDisplayName(par6ItemStack.getDisplayName());
+ }
+ }
+
+ public static int invertMetadata(int par0) {
+ switch (par0) {
+ case 0:
+ return 0;
+ case 1:
+ return 5;
+ case 2:
+ return 4;
+ case 3:
+ return 3;
+ case 4:
+ return 2;
+ case 5:
+ return 1;
+ default:
+ return -1;
+ }
+ }
+
+ @Override
+ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) {
+ checkPlacement(par1World, par2, par3, par4, par5);
+
+ checkExplosion(par1World, par2, par3, par4, false);
+ }
+
+ public void checkPlacement(World par1World, int par2, int par3, int par4, int par5) {
+ if (this.checkIfAttachedToBlock(par1World, par2, par3, par4)) {
+ int i1 = par1World.getBlockMetadata(par2, par3, par4) & 7;
+ boolean flag = false;
+
+ if (!par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST) && i1 == 1) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST) && i1 == 2) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH) && i1 == 3) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH) && i1 == 4) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2, par3 - 1, par4, UP) && i1 == 5) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2, par3 - 1, par4, UP) && i1 == 6) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2, par3 + 1, par4, DOWN) && i1 == 0) {
+ flag = true;
+ }
+
+ if (!par1World.isBlockSolidOnSide(par2, par3 + 1, par4, DOWN) && i1 == 7) {
+ flag = true;
+ }
+
+ if (flag) {
+ this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
+ par1World.setBlockToAir(par2, par3, par4);
+ }
+ }
+ }
+
+ private boolean checkIfAttachedToBlock(World par1World, int par2, int par3, int par4) {
+ if (!this.canPlaceBlockAt(par1World, par2, par3, par4)) {
+ this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
+ par1World.setBlockToAir(par2, par3, par4);
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ @Override
+ public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) {
+ if (!par1World.isRemote) {
+ checkExplosion(par1World, par2, par3, par4, false);
+ }
+ }
+
+ public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) {
+ if (!par1World.isRemote) {
+ this.checkExplosion(par1World, par2, par3, par4, false);
+ }
+ }
+
+ public void checkExplosion(World par1World, int par2, int par3, int par4, boolean skipCheck) {
+ if (skipCheck || getMineState(par1World, par2, par3, par4) > 0) {
+ if (hasItems(par1World, par2, par3, par4)) {
+ TileEntityLandmine te = (TileEntityLandmine)par1World.getBlockTileEntity(par2, par3, par4);
+ if(te.soundcountything <= 0){
+ par1World.playSoundEffect((double) par2 + 0.5D, (double) par3 + 0.1D, (double) par4 + 0.5D, "random.click", 0.3F, 0.6F);
+ te.setSoundPlayed();
+ }
+ new LandmineExplodeLogic(par1World, par2, par3, par4, getMineTriggerer(par1World, par2, par3, par4)).explode();
+ }
+ }
+ }
+
+ @Override
+ public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) {
+ return null;
+ }
+
+ private boolean hasItems(World par1World, int par2, int par3, int par4) {
+ TileEntityLandmine te = (TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4);
+ if (te != null && te.getStackInSlot(0) != null || te.getStackInSlot(1) != null || te.getStackInSlot(2) != null) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ protected int getMineState(World par1World, int par2, int par3, int par4) {
+ EnumMobType triggerMobType;
+
+ TileEntityLandmine te = (TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4);
+
+ // Change to return 1 if you want the landmine to blow up when the block
+ // holding it is broken
+ if (te == null) {
+ return 0;
+ }
+ switch (te.triggerType) {
+ case 0:
+ triggerMobType = EnumMobType.everything;
+ break;
+ case 1:
+ triggerMobType = EnumMobType.mobs;
+ break;
+ case 2:
+ triggerMobType = EnumMobType.players;
+ break;
+ default:
+ triggerMobType = null;
+ break;
+ }
+
+ if (triggerMobType != null) {
+ List list = null;
+
+ if (triggerMobType == EnumMobType.everything) {
+ list = par1World.getEntitiesWithinAABBExcludingEntity((Entity) null, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
+ }
+
+ if (triggerMobType == EnumMobType.mobs) {
+ list = par1World.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
+ }
+
+ if (triggerMobType == EnumMobType.players) {
+ list = par1World.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
+ }
+
+ if (list != null && !list.isEmpty()) {
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ Entity entity = (Entity) iterator.next();
+
+ if (!entity.doesEntityNotTriggerPressurePlate()) {
+ return 1;
+ }
+ }
+ }
+ }
+
+ return par1World.isBlockIndirectlyGettingPowered(par2, par3, par4) ? 1 : 0;
+ }
+
+ public Entity getMineTriggerer(World par1World, int par2, int par3, int par4) {
+
+ EnumMobType triggerMobType;
+
+ TileEntityLandmine te = (TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4);
+
+ // Change to return 1 if you want the landmine to blow up when the
+ // block holding it is broken
+ if (te == null) {
+ return null;
+ }
+ switch (te.triggerType) {
+ case 0:
+ triggerMobType = EnumMobType.everything;
+ break;
+ case 1:
+ triggerMobType = EnumMobType.mobs;
+ break;
+ case 2:
+ triggerMobType = EnumMobType.players;
+ break;
+ default:
+ triggerMobType = null;
+ break;
+ }
+
+ if (triggerMobType != null) {
+ List list = null;
+
+ if (triggerMobType == EnumMobType.everything) {
+ list = par1World.getEntitiesWithinAABBExcludingEntity((Entity) null, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
+ }
+
+ if (triggerMobType == EnumMobType.mobs) {
+ list = par1World.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
+ }
+
+ if (triggerMobType == EnumMobType.players) {
+ list = par1World.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getAABBPool().getAABB(par2 + 0D, par3 + 0D, par4 + 0D, par2 + 1D, par3 + 1D, par4 + 1D));
+ }
+
+ if (list != null && !list.isEmpty()) {
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ Entity entity = (Entity) iterator.next();
+
+ if (!entity.doesEntityNotTriggerPressurePlate()) {
+ return entity;
+ }
+ }
+ }
+ }
+
+ return new EntityTNTPrimed(par1World, par2, par3, par4, (EntityLivingBase) null);
+ }
+
+ @Override
+ public boolean canDropFromExplosion(Explosion par1Explosion) {
+ return false;
+ }
+
+ @Override
+ public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) {
+ int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
+ int i1 = l & 7;
+ boolean flag = (l & 8) > 0;
+
+ ForgeDirection dir = Helper.convertMetaToForgeOrientation(i1);
+ switch (dir) {
+ case DOWN:
+ this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 1.0F - 0.0625F, 0.0625F, 1.0F - 0.0625F);
+ break;
+ case UP:
+ this.setBlockBounds(0.0625F, 1.0F - 0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F, 1.0F - 0.0625F);
+ break;
+ case NORTH:
+ this.setBlockBounds(0.0625F, 0.0625F, 0.0F, 1.0F - 0.0625F, 1.0F - 0.0625F, 0.0625F);
+ break;
+ case SOUTH:
+ this.setBlockBounds(0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F, 1.0F);
+ break;
+ case EAST:
+ this.setBlockBounds(1.0F - 0.0625F, 0.0625F, 0.0625F, 1.0F, 1.0F - 0.0625F, 1.0F - 0.0625F);
+ break;
+ case WEST:
+ this.setBlockBounds(0.0F, 0.0625F, 0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F);
+ break;
+ }
+ }
+
+ @Override
+ public int idDropped(int par1, Random par2Random, int par3) {
+ return 0;
+ }
+
+ @Override
+ public TileEntity createNewTileEntity(World world) {
+ return new TileEntityLandmine();
+ }
+}
diff --git a/tconstruct/landmine/client/gui/GuiLandmine.java b/tconstruct/landmine/client/gui/GuiLandmine.java
new file mode 100644
index 00000000..b6d8be12
--- /dev/null
+++ b/tconstruct/landmine/client/gui/GuiLandmine.java
@@ -0,0 +1,74 @@
+package tconstruct.landmine.client.gui;
+
+import java.util.List;
+
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.inventory.GuiContainer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.ResourceLocation;
+import net.minecraft.util.StatCollector;
+
+import org.lwjgl.opengl.GL11;
+
+import tconstruct.landmine.inventory.ContainerLandmine;
+import tconstruct.landmine.logic.behavior.Behavior;
+
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class GuiLandmine extends GuiContainer {
+
+ ContainerLandmine container;
+
+ ResourceLocation background = new ResourceLocation("tinker:textures/gui/landmine.png");
+
+ public GuiLandmine(ContainerLandmine par1Container) {
+ super(par1Container);
+ container = par1Container;
+ }
+
+ @Override
+ protected void drawItemStackTooltip(ItemStack par1ItemStack, int par2, int par3) {
+ List list = par1ItemStack.getTooltip(this.mc.thePlayer, this.mc.gameSettings.advancedItemTooltips);
+
+ Behavior b = Behavior.getBehaviorFromStack(par1ItemStack);
+ if(b != null){
+ b.getInformation(par1ItemStack, list);
+ }
+
+ for (int k = 0; k < list.size(); ++k) {
+ if (k == 0) {
+ list.set(k, "\u00a7" + Integer.toHexString(par1ItemStack.getRarity().rarityColor) + (String) list.get(k));
+ } else {
+ list.set(k, EnumChatFormatting.GRAY + (String) list.get(k));
+ }
+ }
+
+ FontRenderer font = par1ItemStack.getItem().getFontRenderer(par1ItemStack);
+ drawHoveringText(list, par2, par3, (font == null ? fontRenderer : font));
+ }
+
+ @Override
+ protected void drawGuiContainerForegroundLayer(int i, int j) {
+ if (container.te != null) {
+ fontRenderer.drawString(container.te.getInvName(), 8, 5, 4210752);
+ } else {
+ fontRenderer.drawString("Landmine", 8, 5, 4210752);
+ }
+ fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 3, 4210752);
+ }
+
+ @Override
+ protected void drawGuiContainerBackgroundLayer(float f, int i, int j) {
+ GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
+ mc.renderEngine.func_110577_a(background);
+ int x = (width - xSize) / 2;
+ int y = (height - ySize) / 2;
+ this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
+ }
+
+}
diff --git a/tconstruct/landmine/client/render/RenderLandmine.java b/tconstruct/landmine/client/render/RenderLandmine.java
new file mode 100644
index 00000000..48e3c2ac
--- /dev/null
+++ b/tconstruct/landmine/client/render/RenderLandmine.java
@@ -0,0 +1,87 @@
+package tconstruct.landmine.client.render;
+
+import net.minecraft.block.Block;
+import net.minecraft.client.renderer.RenderBlocks;
+import net.minecraft.world.IBlockAccess;
+import net.minecraftforge.common.ForgeDirection;
+
+import org.lwjgl.opengl.GL11;
+
+import tconstruct.landmine.Helper;
+import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
+import cpw.mods.fml.client.registry.RenderingRegistry;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class RenderLandmine implements ISimpleBlockRenderingHandler {
+
+ public static int model = RenderingRegistry.getNextAvailableRenderId();
+
+ @Override
+ public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
+ GL11.glPushMatrix();
+ GL11.glTranslatef(-0.5F, 0F, -0.5F);
+
+ renderer.setRenderBounds(0.0625F, 0.0F, 0.0625F, 1.0F - 0.0625F, 0.0625F, 1.0F - 0.0625F);
+ Helper.renderInventoryCube(block, metadata, modelID, renderer);
+
+ GL11.glPopMatrix();
+ }
+
+ @Override
+ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
+ if(modelId == getRenderId()){
+ renderBasedOnSide(world, x, y, z, block, modelId, renderer);
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ public void renderBasedOnSide(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer){
+ int l = world.getBlockMetadata(x, y, z);
+ int i1 = l & 7;
+ boolean flag = (l & 8) > 0;
+
+ ForgeDirection dir = Helper.convertMetaToForgeOrientation(i1);
+
+ //System.out.println(i1 + " for " + dir);
+
+ switch(dir){
+ case DOWN:
+ renderer.setRenderBounds(0.0625F, 0.0F, 0.0625F, 1.0F - 0.0625F, 0.0625F, 1.0F - 0.0625F);
+ break;
+ case UP:
+ renderer.setRenderBounds(0.0625F, 1.0F - 0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F, 1.0F - 0.0625F);
+ break;
+ case NORTH:
+ renderer.setRenderBounds(0.0625F, 0.0625F, 0.0F, 1.0F - 0.0625F, 1.0F - 0.0625F, 0.0625F);
+ break;
+ case SOUTH:
+ renderer.setRenderBounds(0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F, 1.0F);
+ break;
+ case EAST:
+ renderer.setRenderBounds(1.0F - 0.0625F, 0.0625F, 0.0625F, 1.0F, 1.0F - 0.0625F, 1.0F - 0.0625F);
+ break;
+ case WEST:
+ renderer.setRenderBounds(0.0F, 0.0625F, 0.0625F, 0.0625F, 1.0F - 0.0625F, 1.0F - 0.0625F);
+ break;
+ }
+
+ renderer.renderStandardBlock(block, x, y, z);
+ }
+
+ @Override
+ public boolean shouldRender3DInInventory() {
+ return true;
+ }
+
+ @Override
+ public int getRenderId() {
+ return model;
+ }
+
+}
diff --git a/tconstruct/landmine/damageSource/DamageSourceLandmine.java b/tconstruct/landmine/damageSource/DamageSourceLandmine.java
new file mode 100644
index 00000000..2e1da52d
--- /dev/null
+++ b/tconstruct/landmine/damageSource/DamageSourceLandmine.java
@@ -0,0 +1,19 @@
+package tconstruct.landmine.damageSource;
+
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.util.ChatMessageComponent;
+import net.minecraft.util.DamageSource;
+import net.minecraft.util.StatCollector;
+
+public class DamageSourceLandmine extends DamageSource{
+
+ public DamageSourceLandmine(String s) {
+ super(s);
+ this.setDamageBypassesArmor();
+ }
+
+ public ChatMessageComponent getDeathMessage(EntityLivingBase par1EntityLivingBase){
+ return super.getDeathMessage(par1EntityLivingBase);
+ }
+
+}
diff --git a/tconstruct/landmine/inventory/ContainerLandmine.java b/tconstruct/landmine/inventory/ContainerLandmine.java
new file mode 100644
index 00000000..d420a9f6
--- /dev/null
+++ b/tconstruct/landmine/inventory/ContainerLandmine.java
@@ -0,0 +1,402 @@
+package tconstruct.landmine.inventory;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import tconstruct.landmine.tileentity.TileEntityLandmine;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.InventoryPlayer;
+import net.minecraft.inventory.Container;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.FurnaceRecipes;
+import net.minecraft.tileentity.TileEntityFurnace;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class ContainerLandmine extends Container {
+
+ public TileEntityLandmine te;
+ public EntityPlayer entityPlayer;
+ private int field_94536_g;
+ private int field_94535_f = -1;
+ private final Set field_94537_h = new HashSet();
+
+ public ContainerLandmine(EntityPlayer player, TileEntityLandmine te) {
+ this.te = te;
+ this.entityPlayer = player;
+ addInventorySlots(te);
+ bindPlayerInventory(player.inventory);
+ }
+
+ public void addInventorySlots(TileEntityLandmine inv) {
+ addSlotToContainer(new SlotBehavedOnly(inv, 0, 35, 53));
+ addSlotToContainer(new SlotBehavedOnly(inv, 1, 80, 53));
+ addSlotToContainer(new SlotBehavedOnly(inv, 2, 125, 53));
+ addSlotToContainer(new SlotOpaqueBlocksOnly(inv, 3, 80, 21));
+ }
+
+ public void bindPlayerInventory(InventoryPlayer inventory) {
+ for (int i = 0; i < 3; i++) {
+ for (int j = 0; j < 9; j++) {
+ addSlotToContainer(new Slot(inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
+ }
+ }
+
+ for (int i = 0; i < 9; i++) {
+ addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142));
+ }
+ }
+
+ @Override
+ public boolean canInteractWith(EntityPlayer entityplayer) {
+ return te.isUseableByPlayer(entityplayer);
+ }
+
+ @Override
+ public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
+ // This code actually works perfectly, but does not respect the global
+ // TileEntity stack limit, shift clicking ability disabled.
+ /*
+ * ItemStack itemstack = null; Slot slot = (Slot)
+ * this.inventorySlots.get(par2);
+ *
+ * if (slot != null && slot.getHasStack()) { ItemStack itemstack1 =
+ * slot.getStack(); itemstack = itemstack1.copy();
+ *
+ * if (par2 == 2) { if (!this.mergeItemStack(itemstack1, 3, 39, true)) {
+ * return null; }
+ *
+ * slot.onSlotChange(itemstack1, itemstack); } else if (par2 != 1 &&
+ * par2 != 0) { if (!this.mergeItemStack(itemstack1, 0, 1, false)) { if
+ * (!this.mergeItemStack(itemstack1, 1, 2, false)) { if
+ * (!this.mergeItemStack(itemstack1, 30, 39, false)) { return null; }
+ * else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1,
+ * 3, 30, false)) { return null; } } } } else if
+ * (!this.mergeItemStack(itemstack1, 3, 39, false)) { return null; }
+ *
+ * if (itemstack1.stackSize == 0) { slot.putStack((ItemStack) null); }
+ * else { slot.onSlotChanged(); }
+ *
+ * if (itemstack1.stackSize == itemstack.stackSize) { return null; }
+ *
+ * slot.onPickupFromSlot(par1EntityPlayer, itemstack1); }
+ *
+ * return itemstack;
+ */
+ return null;
+ }
+
+ /* Disabled for another(less buggy and sticky) system */
+ @Override
+ public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
+ ItemStack itemstack = null;
+ InventoryPlayer inventoryplayer = par4EntityPlayer.inventory;
+ int l;
+ ItemStack itemstack1;
+
+ if (par3 == 5) {
+ int i1 = this.field_94536_g;
+ this.field_94536_g = func_94532_c(par2);
+
+ if ((i1 != 1 || this.field_94536_g != 2) && i1 != this.field_94536_g) {
+ this.func_94533_d();
+ } else if (inventoryplayer.getItemStack() == null) {
+ this.func_94533_d();
+ } else if (this.field_94536_g == 0) {
+ this.field_94535_f = func_94529_b(par2);
+
+ if (func_94528_d(this.field_94535_f)) {
+ this.field_94536_g = 1;
+ this.field_94537_h.clear();
+ } else {
+ this.func_94533_d();
+ }
+ } else if (this.field_94536_g == 1) {
+ Slot slot = (Slot) this.inventorySlots.get(par1);
+
+ if (slot != null && func_94527_a(slot, inventoryplayer.getItemStack(), true) && slot.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize > this.field_94537_h.size() && this.canDragIntoSlot(slot)) {
+ this.field_94537_h.add(slot);
+ }
+ } else if (this.field_94536_g == 2) {
+ if (!this.field_94537_h.isEmpty()) {
+ itemstack1 = inventoryplayer.getItemStack().copy();
+ l = inventoryplayer.getItemStack().stackSize;
+ Iterator iterator = this.field_94537_h.iterator();
+
+ while (iterator.hasNext()) {
+ Slot slot1 = (Slot) iterator.next();
+
+ if (slot1 != null && func_94527_a(slot1, inventoryplayer.getItemStack(), true) && slot1.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize >= this.field_94537_h.size() && this.canDragIntoSlot(slot1)) {
+ ItemStack itemstack2 = itemstack1.copy();
+ int j1 = slot1.getHasStack() ? slot1.getStack().stackSize : 0;
+ func_94525_a(this.field_94537_h, this.field_94535_f, itemstack2, j1);
+
+ if (itemstack2.stackSize > itemstack2.getMaxStackSize()) {
+ itemstack2.stackSize = itemstack2.getMaxStackSize();
+ }
+
+ if (itemstack2.stackSize > slot1.getSlotStackLimit()) {
+ itemstack2.stackSize = slot1.getSlotStackLimit();
+ }
+
+ l -= itemstack2.stackSize - j1;
+ slot1.putStack(itemstack2);
+ }
+ }
+
+ itemstack1.stackSize = l;
+
+ if (itemstack1.stackSize <= 0) {
+ itemstack1 = null;
+ }
+
+ inventoryplayer.setItemStack(itemstack1);
+ }
+
+ this.func_94533_d();
+ } else {
+ this.func_94533_d();
+ }
+ } else if (this.field_94536_g != 0) {
+ this.func_94533_d();
+ } else {
+ Slot slot2;
+ int k1;
+ ItemStack itemstack3;
+
+ if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) {
+ if (par1 == -999) {
+ if (inventoryplayer.getItemStack() != null && par1 == -999) {
+ if (par2 == 0) {
+ par4EntityPlayer.dropPlayerItem(inventoryplayer.getItemStack());
+ inventoryplayer.setItemStack((ItemStack) null);
+ }
+
+ if (par2 == 1) {
+ par4EntityPlayer.dropPlayerItem(inventoryplayer.getItemStack().splitStack(1));
+
+ if (inventoryplayer.getItemStack().stackSize == 0) {
+ inventoryplayer.setItemStack((ItemStack) null);
+ }
+ }
+ }
+ } else if (par3 == 1) {
+ if (par1 < 0) {
+ return null;
+ }
+
+ slot2 = (Slot) this.inventorySlots.get(par1);
+
+ if (slot2 != null && slot2.canTakeStack(par4EntityPlayer)) {
+ itemstack1 = this.transferStackInSlot(par4EntityPlayer, par1);
+
+ if (itemstack1 != null) {
+ l = itemstack1.itemID;
+ itemstack = itemstack1.copy();
+
+ if (slot2 != null && slot2.getStack() != null && slot2.getStack().itemID == l) {
+ this.retrySlotClick(par1, par2, true, par4EntityPlayer);
+ }
+ }
+ }
+ } else {
+ if (par1 < 0) {
+ return null;
+ }
+
+ slot2 = (Slot) this.inventorySlots.get(par1);
+
+ boolean shouldDoStuff = true;
+
+ if ((!(slot2 instanceof SlotBehavedOnly))) {
+ shouldDoStuff = false;
+ }
+
+ if (slot2 != null) {
+ itemstack1 = slot2.getStack();
+ ItemStack itemstack4 = inventoryplayer.getItemStack();
+
+ if (itemstack1 != null) {
+ itemstack = itemstack1.copy();
+ }
+
+ if (itemstack1 == null) {
+ if (itemstack4 != null && slot2.isItemValid(itemstack4)) {
+ k1 = par2 == 0 ? itemstack4.stackSize : 1;
+
+ if (k1 > slot2.getSlotStackLimit()) {
+ k1 = slot2.getSlotStackLimit();
+ }
+
+ if (itemstack4.stackSize >= k1) {
+ slot2.putStack(itemstack4.splitStack(k1));
+ }
+
+ if (itemstack4.stackSize == 0) {
+ inventoryplayer.setItemStack((ItemStack) null);
+ }
+ } else if (shouldDoStuff && slot2 instanceof SlotBehavedOnly && itemstack4 != null && slot2.isItemValid(new ItemStack(itemstack4.itemID, 1, itemstack4.getItemDamage()))) {
+ k1 = par2 == 0 ? 1 : 1;
+
+ if (k1 > slot2.getSlotStackLimit()) {
+ k1 = slot2.getSlotStackLimit();
+ }
+
+ if (itemstack4.stackSize >= k1) {
+ slot2.putStack(itemstack4.splitStack(k1));
+ }
+
+ if (itemstack4.stackSize == 0) {
+ inventoryplayer.setItemStack((ItemStack) null);
+ }
+ }
+ } else if (slot2.canTakeStack(par4EntityPlayer)) {
+ if (itemstack4 == null) {
+ k1 = par2 == 0 ? itemstack1.stackSize : (itemstack1.stackSize + 1) / 2;
+ itemstack3 = slot2.decrStackSize(k1);
+ inventoryplayer.setItemStack(itemstack3);
+
+ if (itemstack1.stackSize == 0) {
+ slot2.putStack((ItemStack) null);
+ }
+
+ slot2.onPickupFromSlot(par4EntityPlayer, inventoryplayer.getItemStack());
+ } else if (slot2.isItemValid(itemstack4)) {
+ if (itemstack1.itemID == itemstack4.itemID && itemstack1.getItemDamage() == itemstack4.getItemDamage() && ItemStack.areItemStackTagsEqual(itemstack1, itemstack4)) {
+ k1 = par2 == 0 ? itemstack4.stackSize : 1;
+
+ if (k1 > slot2.getSlotStackLimit() - itemstack1.stackSize) {
+ k1 = slot2.getSlotStackLimit() - itemstack1.stackSize;
+ }
+
+ if (k1 > itemstack4.getMaxStackSize() - itemstack1.stackSize) {
+ k1 = itemstack4.getMaxStackSize() - itemstack1.stackSize;
+ }
+
+ itemstack4.splitStack(k1);
+
+ if (itemstack4.stackSize == 0) {
+ inventoryplayer.setItemStack((ItemStack) null);
+ }
+
+ itemstack1.stackSize += k1;
+ } else if (itemstack4.stackSize <= slot2.getSlotStackLimit()) {
+ slot2.putStack(itemstack4);
+ inventoryplayer.setItemStack(itemstack1);
+ }
+ } else if (itemstack1.itemID == itemstack4.itemID && itemstack4.getMaxStackSize() > 1 && (!itemstack1.getHasSubtypes() || itemstack1.getItemDamage() == itemstack4.getItemDamage()) && ItemStack.areItemStackTagsEqual(itemstack1, itemstack4)) {
+ k1 = itemstack1.stackSize;
+
+ if (k1 > 0 && k1 + itemstack4.stackSize <= itemstack4.getMaxStackSize()) {
+ itemstack4.stackSize += k1;
+ itemstack1 = slot2.decrStackSize(k1);
+
+ if (itemstack1.stackSize == 0) {
+ slot2.putStack((ItemStack) null);
+ }
+
+ slot2.onPickupFromSlot(par4EntityPlayer, inventoryplayer.getItemStack());
+ }
+ }
+ }
+
+ slot2.onSlotChanged();
+ }
+ }
+ } else if (par3 == 2 && par2 >= 0 && par2 < 9) {
+ slot2 = (Slot) this.inventorySlots.get(par1);
+
+ if (slot2.canTakeStack(par4EntityPlayer)) {
+ itemstack1 = inventoryplayer.getStackInSlot(par2);
+ boolean flag = itemstack1 == null || slot2.inventory == inventoryplayer && slot2.isItemValid(itemstack1);
+ k1 = -1;
+
+ if (!flag) {
+ k1 = inventoryplayer.getFirstEmptyStack();
+ flag |= k1 > -1;
+ }
+
+ if (slot2.getHasStack() && flag) {
+ itemstack3 = slot2.getStack();
+ inventoryplayer.setInventorySlotContents(par2, itemstack3.copy());
+
+ if ((slot2.inventory != inventoryplayer || !slot2.isItemValid(itemstack1)) && itemstack1 != null) {
+ if (k1 > -1) {
+ inventoryplayer.addItemStackToInventory(itemstack1);
+ slot2.decrStackSize(itemstack3.stackSize);
+ slot2.putStack((ItemStack) null);
+ slot2.onPickupFromSlot(par4EntityPlayer, itemstack3);
+ }
+ } else {
+ slot2.decrStackSize(itemstack3.stackSize);
+ slot2.putStack(itemstack1);
+ slot2.onPickupFromSlot(par4EntityPlayer, itemstack3);
+ }
+ } else if (!slot2.getHasStack() && itemstack1 != null && slot2.isItemValid(itemstack1)) {
+ inventoryplayer.setInventorySlotContents(par2, (ItemStack) null);
+ slot2.putStack(itemstack1);
+ }
+ }
+ } else if (par3 == 3 && par4EntityPlayer.capabilities.isCreativeMode && inventoryplayer.getItemStack() == null && par1 >= 0) {
+ slot2 = (Slot) this.inventorySlots.get(par1);
+
+ if (slot2 != null && slot2.getHasStack()) {
+ itemstack1 = slot2.getStack().copy();
+ itemstack1.stackSize = itemstack1.getMaxStackSize();
+ inventoryplayer.setItemStack(itemstack1);
+ }
+ } else if (par3 == 4 && inventoryplayer.getItemStack() == null && par1 >= 0) {
+ slot2 = (Slot) this.inventorySlots.get(par1);
+
+ if (slot2 != null && slot2.getHasStack() && slot2.canTakeStack(par4EntityPlayer)) {
+ itemstack1 = slot2.decrStackSize(par2 == 0 ? 1 : slot2.getStack().stackSize);
+ slot2.onPickupFromSlot(par4EntityPlayer, itemstack1);
+ par4EntityPlayer.dropPlayerItem(itemstack1);
+ }
+ } else if (par3 == 6 && par1 >= 0) {
+ slot2 = (Slot) this.inventorySlots.get(par1);
+ itemstack1 = inventoryplayer.getItemStack();
+
+ if (itemstack1 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(par4EntityPlayer))) {
+ l = par2 == 0 ? 0 : this.inventorySlots.size() - 1;
+ k1 = par2 == 0 ? 1 : -1;
+
+ for (int l1 = 0; l1 < 2; ++l1) {
+ for (int i2 = l; i2 >= 0 && i2 < this.inventorySlots.size() && itemstack1.stackSize < itemstack1.getMaxStackSize(); i2 += k1) {
+ Slot slot3 = (Slot) this.inventorySlots.get(i2);
+
+ if (slot3.getHasStack() && func_94527_a(slot3, itemstack1, true) && slot3.canTakeStack(par4EntityPlayer) && this.func_94530_a(itemstack1, slot3) && (l1 != 0 || slot3.getStack().stackSize != slot3.getStack().getMaxStackSize())) {
+ int j2 = Math.min(itemstack1.getMaxStackSize() - itemstack1.stackSize, slot3.getStack().stackSize);
+ ItemStack itemstack5 = slot3.decrStackSize(j2);
+ itemstack1.stackSize += j2;
+
+ if (itemstack5.stackSize <= 0) {
+ slot3.putStack((ItemStack) null);
+ }
+
+ slot3.onPickupFromSlot(par4EntityPlayer, itemstack5);
+ }
+ }
+ }
+ }
+
+ this.detectAndSendChanges();
+ }
+ }
+
+ return itemstack;
+ }
+
+ @Override
+ public boolean canDragIntoSlot(Slot par1Slot) {
+ return false;
+ }
+
+}
diff --git a/tconstruct/landmine/inventory/SlotBehavedOnly.java b/tconstruct/landmine/inventory/SlotBehavedOnly.java
new file mode 100644
index 00000000..e3fd30e2
--- /dev/null
+++ b/tconstruct/landmine/inventory/SlotBehavedOnly.java
@@ -0,0 +1,41 @@
+package tconstruct.landmine.inventory;
+
+import tconstruct.landmine.logic.behavior.Behavior;
+import net.minecraft.block.Block;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+
+public class SlotBehavedOnly extends Slot{
+
+ public SlotBehavedOnly(IInventory par1iInventory, int par2, int par3, int par4) {
+ super(par1iInventory, par2, par3, par4);
+ }
+
+ @Override
+ public boolean isItemValid(ItemStack par1ItemStack){
+ Behavior b = Behavior.getBehaviorFromStack(par1ItemStack);
+
+ if(b == null){
+ return false;
+ }
+
+ int stackL = b.getStackLimit(par1ItemStack);
+
+ if(b != null && this.inventory.getStackInSlot(this.slotNumber) != null && !this.inventory.getStackInSlot(this.slotNumber).isItemEqual(par1ItemStack)){
+ ItemStack is = this.inventory.getStackInSlot(this.slotNumber);
+ if(is.stackSize + par1ItemStack.stackSize <= stackL){
+ return true;
+ }
+ }else{
+ return par1ItemStack.stackSize <= stackL;
+ }
+
+ return false;
+ //return b != null;
+ }
+
+ public int getSlotStackLimit(ItemStack par1ItemStack){
+ return Behavior.getBehaviorFromStack(par1ItemStack) != null ? Behavior.getBehaviorFromStack(par1ItemStack).getStackLimit(par1ItemStack) : 1;
+ }
+}
diff --git a/tconstruct/landmine/inventory/SlotBlocksOnly.java b/tconstruct/landmine/inventory/SlotBlocksOnly.java
new file mode 100644
index 00000000..ee3eb9bc
--- /dev/null
+++ b/tconstruct/landmine/inventory/SlotBlocksOnly.java
@@ -0,0 +1,28 @@
+package tconstruct.landmine.inventory;
+
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class SlotBlocksOnly extends Slot {
+
+ public SlotBlocksOnly(IInventory par1iInventory, int par2, int par3, int par4) {
+ super(par1iInventory, par2, par3, par4);
+ }
+
+ public boolean isItemValid(ItemStack par1ItemStack) {
+ return par1ItemStack.getItem() instanceof ItemBlock;
+ }
+
+ @Override
+ public int getSlotStackLimit(){
+ return 1;
+ }
+
+}
diff --git a/tconstruct/landmine/inventory/SlotOpaqueBlocksOnly.java b/tconstruct/landmine/inventory/SlotOpaqueBlocksOnly.java
new file mode 100644
index 00000000..1dbfdbce
--- /dev/null
+++ b/tconstruct/landmine/inventory/SlotOpaqueBlocksOnly.java
@@ -0,0 +1,32 @@
+package tconstruct.landmine.inventory;
+
+import net.minecraft.block.Block;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class SlotOpaqueBlocksOnly extends SlotBlocksOnly {
+
+ public SlotOpaqueBlocksOnly(IInventory par1iInventory, int par2, int par3, int par4) {
+ super(par1iInventory, par2, par3, par4);
+ }
+
+ public boolean isItemValid(ItemStack par1ItemStack) {
+ if (super.isItemValid(par1ItemStack)) {
+ Block b = Block.blocksList[par1ItemStack.itemID];
+ return b.isOpaqueCube() && b.renderAsNormalBlock();
+ }
+
+ return false;
+ }
+
+ @Override
+ public int getSlotStackLimit() {
+ return 1;
+ }
+
+}
diff --git a/tconstruct/landmine/item/ItemBlockLandmine.java b/tconstruct/landmine/item/ItemBlockLandmine.java
new file mode 100644
index 00000000..f7817797
--- /dev/null
+++ b/tconstruct/landmine/item/ItemBlockLandmine.java
@@ -0,0 +1,78 @@
+package tconstruct.landmine.item;
+
+import java.util.List;
+import java.util.Random;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import tconstruct.common.TContent;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class ItemBlockLandmine extends ItemBlock{
+
+ public ItemBlockLandmine(int par1) {
+ super(par1);
+ }
+
+ @Override
+ public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
+ String interaction = null;
+
+ switch(par1ItemStack.getItemDamage()){
+ case 0:
+ interaction = "everything";
+ break;
+ case 1:
+ interaction = "mobs, players and redstone";
+ break;
+ case 2:
+ interaction = "players and redstone";
+ break;
+ default:
+ interaction = "redstone only";
+ break;
+ }
+
+ par3List.add("Interacts with: " + interaction);
+ }
+
+ @Override
+ public int getMetadata(int par1){
+ return 0;
+ }
+
+ @Override
+ public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
+ if (!world.setBlock(x, y, z, TContent.landmine.blockID, metadata, 3)) {
+ return false;
+ }
+
+ if (world.getBlockId(x, y, z) == TContent.landmine.blockID) {
+ TContent.landmine.onBlockPlacedBy(world, x, y, z, player, stack);
+
+ TileEntityLandmine te = (TileEntityLandmine) world.getBlockTileEntity(x, y, z);
+ if(te == null){
+ te = (TileEntityLandmine) TContent.landmine.createTileEntity(world, metadata);
+ }
+
+ te.triggerType = stack.getItemDamage();
+ world.setBlockTileEntity(x, y, z, te);
+
+ TContent.landmine.onPostBlockPlaced(world, x, y, z, metadata);
+ }
+
+ return true;
+ }
+
+ public static Random getRandom(){
+ return itemRand;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/LandmineExplodeLogic.java b/tconstruct/landmine/logic/LandmineExplodeLogic.java
new file mode 100644
index 00000000..6649b088
--- /dev/null
+++ b/tconstruct/landmine/logic/LandmineExplodeLogic.java
@@ -0,0 +1,192 @@
+package tconstruct.landmine.logic;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import tconstruct.landmine.logic.behavior.Behavior;
+import tconstruct.landmine.logic.behavior.stackCombo.SpecialStackHandler;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+/**
+ * This logic is designed only for blocks having TileEntityLandmine as their tileEntity(otherwise ClassCastException will be awarded)
+ * @author fuj1n
+ *
+ */
+public class LandmineExplodeLogic {
+
+ private final World worldObj;
+ private final Entity triggerer;
+ private final TileEntityLandmine tileEntity;
+ private final int x, y, z;
+
+ public LandmineExplodeLogic(World par1World, int par2, int par3, int par4, Entity entity){
+ worldObj = par1World;
+ this.tileEntity = (TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4);
+ this.x = par2;
+ this.y = par3;
+ this.z = par4;
+ this.triggerer = entity;
+ }
+
+ public void explode(){
+ if(triggerer == null){
+ return;
+ }
+
+ boolean preventExplode = false;
+ boolean isOffensive = true;
+ boolean cancelDefault = false;
+
+ ArrayList stacks = new ArrayList();
+ boolean hasExploded = false;
+
+ if(tileEntity == null){
+ return;
+ }
+
+ tileEntity.isExploding = true;
+
+ for(int i = 0; i < tileEntity.getSizeTriggerInventory(); i++){
+ ItemStack currentStack = tileEntity.getStackInSlot(i);
+ Behavior b = Behavior.getBehaviorFromStack(currentStack);
+ if (b != null) {
+
+ if(b.doesBehaviorPreventRemovalOfBlock(currentStack)){
+ preventExplode = true;
+ }
+
+ if(!b.isBehaviorExchangableWithOffensive(currentStack)){
+ isOffensive = false;
+ }
+
+ if(b.overridesDefault()){
+ cancelDefault = true;
+ }
+
+ if (!stacks.isEmpty() && Behavior.arrayContainsEqualStack(stacks, currentStack) && b.effectStacks()) {
+ stacks.get(Behavior.arrayIndexOfStack(stacks, currentStack)).stackSize += currentStack.stackSize;
+ } else {
+ stacks.add(currentStack);
+ }
+ }
+ }
+
+ LandmineSpecialStackLogic specialStacks = new LandmineSpecialStackLogic(worldObj, x, y, z, triggerer, isOffensive, stacks);
+ specialStacks.handleSpecialStacks();
+
+ Iterator i1 = stacks.iterator();
+ while(i1.hasNext()){
+ ItemStack currentStack = i1.next();
+ Behavior b = Behavior.getBehaviorFromStack(currentStack);
+ if(b != null){
+ if (isOffensive || !b.isOffensive(currentStack)) {
+ b.executeLogic(worldObj, x, y, z, currentStack, triggerer, !preventExplode);
+ if (b.shouldItemBeRemoved(currentStack, !preventExplode)) {
+ if (b.effectStacks()) {
+ for (int i = 0; i < tileEntity.getSizeTriggerInventory(); i++) {
+ if (tileEntity.getStackInSlot(i) != null) {
+ if (tileEntity.getStackInSlot(i).isItemEqual(currentStack)) {
+ tileEntity.setInventorySlotContents(i, null);
+ }
+ }
+ }
+ } else {
+ boolean hasRemoved = false;
+
+ for (int i = 0; i < tileEntity.getSizeTriggerInventory() && !hasRemoved; i++) {
+ if (tileEntity.getStackInSlot(i) != null) {
+ if (tileEntity.getStackInSlot(i).isItemEqual(currentStack)) {
+ tileEntity.setInventorySlotContents(i, null);
+ hasRemoved = true;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ Behavior defBeh = Behavior.getDefaulBehavior();
+ if(defBeh != null && isOffensive && !cancelDefault){
+ defBeh.executeLogic(worldObj, x, y, z, null, triggerer, !preventExplode);
+ }
+
+ if(hasExploded || defBeh != null && !preventExplode){
+ worldObj.removeBlockTileEntity(x, y, z);
+ worldObj.setBlockToAir(x, y, z);
+ }else{
+ tileEntity.isExploding = false;
+ }
+
+ }
+
+ //Legacy explode logic
+ /*public void explode(){
+ if(triggerer == null){
+ return;
+ }
+
+ boolean preventRemoval = false;
+
+ ItemStack stackEffect = null;
+ boolean hasExploded = false;
+
+ if(tileEntity == null){
+ return;
+ }
+
+ tileEntity.isExploding = true;
+
+ for(int i = 0; i < tileEntity.getSizeInventory() - 1; i++){
+ ItemStack currentItemStack = tileEntity.getStackInSlot(i);
+ if(currentItemStack != null){
+ Behavior b = Behavior.getBehaviorFromStack(stackEffect);
+ if(Behavior.getBehaviorFromStack(currentItemStack).doesBehaviorPreventRemovalOfBlock(currentItemStack)){
+ preventRemoval = true;
+ }
+ if(stackEffect != null && (b != null && b.effectStacks()) && currentItemStack.isItemEqual(stackEffect)){
+ stackEffect.stackSize += currentItemStack.stackSize;
+ }else if(stackEffect == null){
+ stackEffect = currentItemStack;
+ stackEffect.stackSize = currentItemStack.stackSize;
+ }else{
+ Behavior beh = Behavior.getBehaviorFromStack(stackEffect);
+ ItemStack currentStackEffect = stackEffect;
+ stackEffect = currentItemStack;
+ stackEffect.stackSize = currentItemStack.stackSize;
+ if(beh != null){
+ hasExploded = true;
+ tileEntity.setInventorySlotContents(i, null);
+ beh.executeLogic(worldObj, x, y, z, currentStackEffect, triggerer);
+ }
+ }
+ }
+ }
+
+ Behavior beh = Behavior.getBehaviorFromStack(stackEffect);
+ ItemStack currentStackEffect = stackEffect;
+ stackEffect = null;
+ if(beh != null){
+ hasExploded = true;
+ beh.executeLogic(worldObj, x, y, z, currentStackEffect, triggerer);
+ }
+
+ Behavior defBeh = Behavior.getDefaulBehavior();
+ if(defBeh != null){
+ defBeh.executeLogic(worldObj, x, y, z, null, triggerer);
+ }
+
+ if(hasExploded || defBeh != null){
+ worldObj.removeBlockTileEntity(x, y, z);
+ worldObj.setBlockToAir(x, y, z);
+ }else{
+ tileEntity.isExploding = false;
+ }
+ }*/
+
+}
diff --git a/tconstruct/landmine/logic/LandmineSpecialStackLogic.java b/tconstruct/landmine/logic/LandmineSpecialStackLogic.java
new file mode 100644
index 00000000..0356b929
--- /dev/null
+++ b/tconstruct/landmine/logic/LandmineSpecialStackLogic.java
@@ -0,0 +1,44 @@
+package tconstruct.landmine.logic;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import tconstruct.landmine.logic.behavior.stackCombo.SpecialStackHandler;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+public class LandmineSpecialStackLogic {
+
+ private final World worldObj;
+ private final Entity triggerer;
+ private final TileEntityLandmine tileEntity;
+ private final int x, y, z;
+ private final boolean isOffensive;
+ private final ArrayList stackEffects;
+
+ public LandmineSpecialStackLogic(World par1World, int par2, int par3, int par4, Entity entity, boolean mayHurtPlayer, ArrayList items){
+ worldObj = par1World;
+ this.tileEntity = (TileEntityLandmine) par1World.getBlockTileEntity(par2, par3, par4);
+ this.x = par2;
+ this.y = par3;
+ this.z = par4;
+ this.triggerer = entity;
+ this.isOffensive = mayHurtPlayer;
+ this.stackEffects = items;
+ }
+
+ public void handleSpecialStacks(){
+ Iterator i1 = SpecialStackHandler.handlers.iterator();
+
+ while(i1.hasNext()){
+ SpecialStackHandler h = i1.next();
+ if(isOffensive || !h.isOffensive(stackEffects)){
+ h.checkStack(worldObj, x, y, z, triggerer, stackEffects);
+ }
+ }
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/Behavior.java b/tconstruct/landmine/logic/behavior/Behavior.java
new file mode 100644
index 00000000..b188f1f6
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/Behavior.java
@@ -0,0 +1,186 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import tconstruct.landmine.Helper;
+
+import net.minecraft.block.Block;
+import net.minecraft.block.ITileEntityProvider;
+import net.minecraft.entity.Entity;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemBlock;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.world.World;
+import net.minecraftforge.common.ForgeDirection;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public abstract class Behavior {
+
+ public static HashMap behaviorsListItems = new HashMap();
+ public static HashMap behaviorsListBlocks = new HashMap();
+ protected static Behavior defaultBehavior;
+
+ public static Behavior dummy = new BehaviorDummy();
+ public static Behavior utilityMode = new BehaviorPreventExplode();
+ public static Behavior explosive = new BehaviorExplosive();
+ public static Behavior firework = new BehaviorFirework();
+ public static Behavior blockThrow = new BehaviorBlockThrow();
+ public static Behavior potion = new BehaviorPotion();
+ public static Behavior fireball = new BehaviorFirecharge();
+ public static Behavior spawn = new BehaviorSpawnEgg();
+ public static Behavior shoot = new BehaviorProjectile();
+ public static Behavior shear = new BehaviorShears();
+
+ public static void registerBuiltInBehaviors(){
+ defaultBehavior = new BehaviorDefault();
+
+ addBehavior(new ItemStack(Item.stick), dummy);
+ addBehavior(new ItemStack(Item.redstone), utilityMode);
+ addBehavior(new ItemStack(Block.torchWood), blockThrow);
+ addBehavior(new ItemStack(Item.gunpowder), explosive);
+ addBehavior(new ItemStack(Block.tnt), explosive);
+ addBehavior(new ItemStack(Item.firework), firework);
+ addBehavior(new ItemStack(Item.potion), potion);
+ addBehavior(new ItemStack(Item.fireballCharge), fireball);
+ addBehavior(new ItemStack(Item.monsterPlacer), spawn);
+ addBehavior(new ItemStack(Item.arrow), shoot);
+ addBehavior(new ItemStack(Item.snowball), shoot);
+ addBehavior(new ItemStack(Item.enderPearl), shoot);
+ addBehavior(new ItemStack(Item.shears), shear);
+
+ //Make sure the part below this comment is executed last(to avoid conflicts)
+ for(int i = 1; i < Block.blocksList.length; i++){
+ if(Block.blocksList[i] != null && Block.blocksList[i].isOpaqueCube() && Block.blocksList[i].renderAsNormalBlock() && !(Block.blocksList[i] instanceof ITileEntityProvider) && !behaviorsListBlocks.containsKey(new ItemStack(Block.blocksList[i]))){
+ addBehavior(new ItemStack(Block.blocksList[i]), blockThrow);
+ }
+ }
+ }
+
+ public static Behavior getBehaviorFromStack(ItemStack par1ItemStack){
+ if(par1ItemStack == null){
+ return null;
+ }
+
+ if(par1ItemStack.getItem() instanceof ItemBlock){
+ if(!behaviorsListBlocks.isEmpty()){
+ return behaviorsListBlocks.get(par1ItemStack.itemID);
+ }else{
+ return null;
+ }
+ }else{
+ if(!behaviorsListItems.isEmpty()){
+ return behaviorsListItems.get(par1ItemStack.itemID);
+ }else{
+ return null;
+ }
+ }
+ }
+
+ public static Behavior getDefaulBehavior(){
+ return defaultBehavior;
+ }
+
+ public static void addBehavior(ItemStack par1ItemStack, Behavior par2Behavior){
+ if(par1ItemStack.getItem() instanceof ItemBlock){
+ if(!behaviorsListBlocks.containsKey(par1ItemStack.itemID)){
+ behaviorsListBlocks.put(par1ItemStack.itemID, par2Behavior);
+ }
+ }else{
+ if(!behaviorsListItems.containsKey(par1ItemStack.itemID)){
+ behaviorsListItems.put(par1ItemStack.itemID, par2Behavior);
+ }
+ }
+ }
+
+ public abstract void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved);
+
+ public int getStackLimit(ItemStack par1ItemStack){
+ return 1;
+ }
+
+ public void getInformation(ItemStack par1ItemStack, List par2List){}
+
+ //Will return false if the effect does not stack among the slots
+ public boolean effectStacks(){
+ return true;
+ }
+
+ public EnumFacing getFacing(World par1World, int par2, int par3, int par4){
+ ForgeDirection dir = Helper.convertMetaToForgeOrientation(par1World.getBlockMetadata(par2, par3, par4));
+
+ switch(dir){
+ case DOWN:
+ return EnumFacing.UP;
+ case UP:
+ return EnumFacing.DOWN;
+ case WEST:
+ return EnumFacing.WEST;
+ case EAST:
+ return EnumFacing.EAST;
+ case SOUTH:
+ return EnumFacing.NORTH;
+ case NORTH:
+ return EnumFacing.SOUTH;
+ default:
+ return EnumFacing.UP;
+ }
+ }
+
+ public boolean doesBehaviorPreventRemovalOfBlock(ItemStack par1ItemStack){
+ return false;
+ }
+
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+
+ public boolean isBehaviorExchangableWithOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+
+ public boolean shouldItemBeRemoved(ItemStack par1ItemStack, boolean willBlockGetRemoved){
+ return true;
+ }
+
+ public static final int arrayIndexOfStack(ArrayList stacks, ItemStack item){
+ Iterator i1 = stacks.iterator();
+
+ int index = 0;
+
+ while(i1.hasNext()){
+ ItemStack stack = i1.next();
+ if(stack.isItemEqual(item)){
+ return index;
+ }
+ index++;
+ }
+
+ return -1;
+ }
+
+ public static final boolean arrayContainsEqualStack(ArrayList stacks, ItemStack item){
+ Iterator i1 = stacks.iterator();
+
+ while(i1.hasNext()){
+ ItemStack stack = i1.next();
+ if(stack.isItemEqual(item)){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean overridesDefault(){
+ return false;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorBlockThrow.java b/tconstruct/landmine/logic/behavior/BehaviorBlockThrow.java
new file mode 100644
index 00000000..7fb31950
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorBlockThrow.java
@@ -0,0 +1,80 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.List;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.item.EntityFallingSand;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorBlockThrow extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ for(int i = 0; i < par5ItemStack.stackSize; i++){
+ int direction = par1World.rand.nextInt(8);
+ double speed = 2D * Math.random() + 0.01D;
+ double upVecReduction = 0.25D;
+ double randomnessFactor = 0.5D;
+ double vec0 = 0, vec1 = par1World.rand.nextDouble() * upVecReduction, vec2 = 0;
+ switch (direction) {
+ case 0:
+ vec0 = speed + par1World.rand.nextDouble() * randomnessFactor;
+ //vec2 = par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 1:
+ vec0 = -speed + par1World.rand.nextDouble() * randomnessFactor;
+ //vec2 = par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 2:
+ vec2 = speed + par1World.rand.nextDouble() * randomnessFactor;
+ //vec0 = par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 3:
+ vec2 = -speed + par1World.rand.nextDouble() * randomnessFactor;
+ //vec0 = par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 4:
+ vec0 = speed + par1World.rand.nextDouble() * randomnessFactor;
+ vec2 = speed + par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 5:
+ vec0 = speed + par1World.rand.nextDouble() * randomnessFactor;
+ vec2 = -speed + par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 6:
+ vec0 = -speed + par1World.rand.nextDouble() * randomnessFactor;
+ vec2 = speed + par1World.rand.nextDouble() * randomnessFactor;
+ break;
+ case 7:
+ vec0 = -speed;
+ vec2 = -speed;
+ break;
+ default:
+ vec0 = speed;
+ break;
+ }
+
+ EntityFallingSand entityfallingsand = new EntityFallingSand(par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 2F), (double) ((float) par4 + 0.5F), par5ItemStack.itemID, par5ItemStack.getItemDamage());
+ entityfallingsand.preventEntitySpawning = false;
+ entityfallingsand.fallTime = 2;
+ entityfallingsand.setVelocity(vec0, vec1, vec2);
+ par1World.spawnEntityInWorld(entityfallingsand);
+ }
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+
+ @Override
+ public int getStackLimit(ItemStack par1ItemStack){
+ return 64;
+ }
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorDefault.java b/tconstruct/landmine/logic/behavior/BehaviorDefault.java
new file mode 100644
index 00000000..39839742
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorDefault.java
@@ -0,0 +1,17 @@
+package tconstruct.landmine.logic.behavior;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+import tconstruct.landmine.damageSource.DamageSourceLandmine;
+
+public class BehaviorDefault extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ if(triggerer != null){
+ triggerer.attackEntityFrom(new DamageSourceLandmine("Landmine"), 5F);
+ }
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorDummy.java b/tconstruct/landmine/logic/behavior/BehaviorDummy.java
new file mode 100644
index 00000000..5f2724b2
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorDummy.java
@@ -0,0 +1,18 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.List;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorDummy extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {}
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorExplosive.java b/tconstruct/landmine/logic/behavior/BehaviorExplosive.java
new file mode 100644
index 00000000..db4c7a6a
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorExplosive.java
@@ -0,0 +1,55 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.List;
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityTNTPrimed;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorExplosive extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ float explodeStrenght = 0;
+ if(par5ItemStack.itemID == Block.tnt.blockID){
+ explodeStrenght = 4.0F * par5ItemStack.stackSize;
+ }else if(par5ItemStack.itemID == Item.gunpowder.itemID){
+ explodeStrenght = 0.8F * par5ItemStack.stackSize;
+ }
+
+ par1World.createExplosion(new EntityTNTPrimed(par1World, par2, par3, par4, (EntityLivingBase) null), par2, par3, par4, explodeStrenght, true);
+ }
+
+ @Override
+ public void getInformation(ItemStack par1ItemStack, List par2List){
+ String str = "UNDEFINED";
+ if(par1ItemStack.itemID == Block.tnt.blockID){
+ str = "medium";
+ }else if(par1ItemStack.itemID == Item.gunpowder.itemID){
+ str = "small";
+ }
+
+ //par2List.add("This item explodes with " + str + " power when the landmine is triggered.");
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+
+ @Override
+ //Change this to false to greatly decrease the maximum potential of explosions but at the same time, make them launch the player much higher(I mean the explosions with 2 or more TNT
+ public boolean effectStacks(){
+ return true;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorFirecharge.java b/tconstruct/landmine/logic/behavior/BehaviorFirecharge.java
new file mode 100644
index 00000000..7f9f0a18
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorFirecharge.java
@@ -0,0 +1,54 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.List;
+import java.util.Random;
+
+import tconstruct.landmine.item.ItemBlockLandmine;
+
+
+import net.minecraft.block.Block;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.projectile.EntitySmallFireball;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.DamageSource;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorFirecharge extends Behavior {
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ EnumFacing face = getFacing(par1World, par2, par3, par4);
+
+ for (int n = 0; n < par5ItemStack.stackSize; n++) {
+ triggerer.attackEntityFrom(DamageSource.generic, 9F);
+ triggerer.setFire(4);
+ double d0 = par2 + (double) ((float) face.getFrontOffsetX() * 0.3F);
+ double d1 = par3 + (double) ((float) face.getFrontOffsetX() * 0.3F);
+ double d2 = par4 + (double) ((float) face.getFrontOffsetZ() * 0.3F);
+ Random random = par1World.rand;
+ double d3 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetX();
+ double d4 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetY();
+ double d5 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetZ();
+ par1World.spawnEntityInWorld(new EntitySmallFireball(par1World, d0, d1, d2, d3, d4, d5));
+
+ for (int i = par2 - 2; i <= (par2 + 2); i++) {
+ for (int j = par4 - 2; j <= (par4 + 2); j++) {
+ if ((par1World.getBlockId(i, par3, j) == 0 || (Block.blocksList[par1World.getBlockId(i, par3, j)] != null && Block.blocksList[par1World.getBlockId(i, par3, j)].isBlockReplaceable(par1World, i, par3, j))) && ItemBlockLandmine.getRandom().nextInt(5) == 0 && Block.fire.canPlaceBlockAt(par1World, i, par3, j)) {
+ par1World.setBlock(i, par3, j, Block.fire.blockID);
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorFirework.java b/tconstruct/landmine/logic/behavior/BehaviorFirework.java
new file mode 100644
index 00000000..ad043508
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorFirework.java
@@ -0,0 +1,51 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.List;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityFireworkRocket;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorFirework extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ for (int i = 0; i < par5ItemStack.stackSize; i++) {
+ EntityFireworkRocket entityfireworkrocket = new EntityFireworkRocket(par1World, (double) par2, (double) par3, (double) par4, par5ItemStack);
+ par1World.spawnEntityInWorld(entityfireworkrocket);
+
+ boolean shouldRun = true;
+ if (triggerer instanceof EntityPlayer) {
+ EntityPlayer player = (EntityPlayer) triggerer;
+ if (player.capabilities.isCreativeMode) {
+ // Remove the bellow comment to make the player in creative
+ // mode not get launched
+ // shouldRun = false;
+ }
+ }
+
+ if (shouldRun) {
+ triggerer.mountEntity(entityfireworkrocket);
+ }
+ }
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return false;
+ }
+
+ @Override
+ public boolean overridesDefault(){
+ return true;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorPotion.java b/tconstruct/landmine/logic/behavior/BehaviorPotion.java
new file mode 100644
index 00000000..3247bbb0
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorPotion.java
@@ -0,0 +1,61 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.Iterator;
+import java.util.List;
+
+import tconstruct.landmine.item.ItemBlockLandmine;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.projectile.EntityPotion;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemPotion;
+import net.minecraft.item.ItemStack;
+import net.minecraft.potion.PotionEffect;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorPotion extends Behavior {
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ if (ItemPotion.isSplash(par5ItemStack.getItemDamage())) {
+ par1World.playSoundAtEntity(triggerer, "random.bow", 0.5F, 0.4F / (ItemBlockLandmine.getRandom().nextFloat() * 0.4F + 0.8F));
+
+ if (!par1World.isRemote) {
+ if (triggerer instanceof EntityLivingBase) {
+ par1World.spawnEntityInWorld(new EntityPotion(par1World, (EntityLivingBase) triggerer, par5ItemStack));
+ } else {
+ par1World.spawnEntityInWorld(new EntityPotion(par1World, par2, par3, par4, par5ItemStack));
+ }
+ }
+ }else{
+ if(triggerer instanceof EntityPlayer){
+ Item.potion.onEaten(par5ItemStack, par1World, (EntityPlayer)triggerer);
+ }else if(triggerer instanceof EntityLivingBase){
+ if (!par1World.isRemote) {
+ List list = Item.potion.getEffects(par5ItemStack);
+
+ if (list != null) {
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ PotionEffect potioneffect = (PotionEffect) iterator.next();
+ ((EntityLivingBase)triggerer).addPotionEffect(new PotionEffect(potioneffect));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return false;
+ }
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorPreventExplode.java b/tconstruct/landmine/logic/behavior/BehaviorPreventExplode.java
new file mode 100644
index 00000000..ba0b06c7
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorPreventExplode.java
@@ -0,0 +1,32 @@
+package tconstruct.landmine.logic.behavior;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.world.World;
+
+public class BehaviorPreventExplode extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {}
+
+ @Override
+ public boolean isBehaviorExchangableWithOffensive(ItemStack par1ItemStack){
+ return false;
+ }
+
+ @Override
+ public boolean doesBehaviorPreventRemovalOfBlock(ItemStack par1ItemStack){
+ return true;
+ }
+
+ @Override
+ public boolean shouldItemBeRemoved(ItemStack par1ItemStack, boolean willBlockBeRemoved){
+ return false;
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return false;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorProjectile.java b/tconstruct/landmine/logic/behavior/BehaviorProjectile.java
new file mode 100644
index 00000000..a02d4515
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorProjectile.java
@@ -0,0 +1,58 @@
+package tconstruct.landmine.logic.behavior;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.IProjectile;
+import net.minecraft.entity.item.EntityEnderPearl;
+import net.minecraft.entity.projectile.EntityArrow;
+import net.minecraft.entity.projectile.EntitySnowball;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorProjectile extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ IProjectile entity = null;
+
+ EnumFacing enumfacing = getFacing(par1World, par2, par3, par4);
+
+ if(par5ItemStack.itemID == Item.arrow.itemID){
+ entity = new EntityArrow(par1World, par2, par3, par4);
+ ((EntityArrow)entity).canBePickedUp = 1;
+ }else if(par5ItemStack.itemID == Item.snowball.itemID){
+ entity = new EntitySnowball(par1World, par2, par3, par4);
+ }else if(par5ItemStack.itemID == Item.enderPearl.itemID){
+ if(triggerer instanceof EntityLivingBase){
+ entity = new EntityEnderPearl(par1World, (EntityLivingBase)triggerer);
+ ((EntityEnderPearl)entity).setPosition(par2, par3, par4);
+ }else{
+ entity = new EntityEnderPearl(par1World, par2, par3, par4);
+ }
+ }
+
+ if(entity == null){
+ return;
+ }
+
+ entity.setThrowableHeading((double)enumfacing.getFrontOffsetX(), (double)((float)enumfacing.getFrontOffsetY() + 0.1F), (double)enumfacing.getFrontOffsetZ(), 1.1F, 6.0F);
+ par1World.spawnEntityInWorld((Entity)entity);
+ par1World.playAuxSFX(1002, par2, par3, par4, 0);
+ }
+
+
+ //Projectiles: snowballs, arrows
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorShears.java b/tconstruct/landmine/logic/behavior/BehaviorShears.java
new file mode 100644
index 00000000..b241d3f3
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorShears.java
@@ -0,0 +1,94 @@
+package tconstruct.landmine.logic.behavior;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import tconstruct.landmine.item.ItemBlockLandmine;
+
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.enchantment.EnchantmentHelper;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.AxisAlignedBB;
+import net.minecraft.world.World;
+import net.minecraftforge.common.IShearable;
+
+//TODO Add a block that is similar to landmine, but only triggers by redstone, does not hurt the player, and does not disappear when used(also does not do anything that can deal damage)
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorShears extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ Random rand = ItemBlockLandmine.getRandom();
+
+ List sheeps = par1World.getEntitiesWithinAABB(IShearable.class, AxisAlignedBB.getAABBPool().getAABB(par2 - 2, par3 - 2, par4 - 2, par2 + 2, par3 + 2, par4 + 2));
+
+ if(sheeps != null && !sheeps.isEmpty()){
+ Iterator i1 = sheeps.iterator();
+ IShearable sheep;
+ while (i1.hasNext()) {
+ sheep = i1.next();
+ if (sheep.isShearable(par5ItemStack, par1World, par2, par3, par4)) {
+ if (rand.nextInt(2) == 0) {
+ ArrayList drops = sheep.onSheared(par5ItemStack, par1World, par2, par3, par4, EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, par5ItemStack));
+ if (sheep instanceof EntityLivingBase) {
+ par5ItemStack.damageItem(1, (EntityLivingBase) sheep);
+ }
+ Iterator i2 = drops.iterator();
+ while (i2.hasNext()) {
+ if (sheep instanceof Entity) {
+ Entity ent = (Entity) sheep;
+ dropItem(par1World, (int) ent.posX, (int) ent.posY, (int) ent.posZ, i2.next());
+ } else {
+ dropItem(par1World, par2, par3, par4, i2.next());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if(willBlockBeRemoved){
+ dropItem(par1World, par2, par3, par4, par5ItemStack);
+ }
+ }
+
+ protected void dropItem(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack) {
+ if (!par1World.isRemote && par1World.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
+ float f = 0.7F;
+ double d0 = (double) (par1World.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
+ double d1 = (double) (par1World.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
+ double d2 = (double) (par1World.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
+ EntityItem entityitem = new EntityItem(par1World, (double) par2 + d0, (double) par3 + d1, (double) par4 + d2, par5ItemStack);
+ entityitem.delayBeforeCanPickup = 10;
+ par1World.spawnEntityInWorld(entityitem);
+ }
+ }
+
+ //Shear some sheep around a small area
+
+ @Override
+ public boolean shouldItemBeRemoved(ItemStack par1ItemStack, boolean willBlockBeRemoved){
+ return willBlockBeRemoved;
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return false;
+ }
+
+ @Override
+ public boolean effectStacks(){
+ return false;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/BehaviorSpawnEgg.java b/tconstruct/landmine/logic/behavior/BehaviorSpawnEgg.java
new file mode 100644
index 00000000..5b438acb
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/BehaviorSpawnEgg.java
@@ -0,0 +1,43 @@
+package tconstruct.landmine.logic.behavior;
+
+import net.minecraft.block.BlockDispenser;
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLiving;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.item.ItemMonsterPlacer;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.world.World;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class BehaviorSpawnEgg extends Behavior{
+
+ @Override
+ public void executeLogic(World par1World, int par2, int par3, int par4, ItemStack par5ItemStack, Entity triggerer, boolean willBlockBeRemoved) {
+ EnumFacing enumfacing = getFacing(par1World, par2, par3, par4);
+ double d0 = par2 + Math.random() + (double)enumfacing.getFrontOffsetX();
+ double d1 = (double)((float)par3 + 0.2F);
+ double d2 = par4 + Math.random() + (double)enumfacing.getFrontOffsetZ();
+ Entity entity = ItemMonsterPlacer.spawnCreature(par1World, par5ItemStack.getItemDamage(), d0, d1, d2);
+
+ if (entity instanceof EntityLivingBase && par5ItemStack.hasDisplayName())
+ {
+ ((EntityLiving)entity).setCustomNameTag(par5ItemStack.getDisplayName());
+ }
+ }
+
+ @Override
+ public boolean effectStacks(){
+ return false;
+ }
+
+ @Override
+ public boolean isOffensive(ItemStack par1ItemStack){
+ return true;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/stackCombo/SpecialStackHandler.java b/tconstruct/landmine/logic/behavior/stackCombo/SpecialStackHandler.java
new file mode 100644
index 00000000..97b1eaa8
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/stackCombo/SpecialStackHandler.java
@@ -0,0 +1,94 @@
+package tconstruct.landmine.logic.behavior.stackCombo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import tconstruct.landmine.Helper;
+import tconstruct.landmine.logic.behavior.Behavior;
+import tconstruct.landmine.tileentity.TileEntityLandmine;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.world.World;
+import net.minecraftforge.common.ForgeDirection;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public abstract class SpecialStackHandler {
+
+ public static ArrayList handlers = new ArrayList();
+
+ public static void registerBuiltInStackHandlers(){
+ addSpecialBehavior(new SpecialStackHandlerRocketFireball());
+ }
+
+ public static void addSpecialBehavior(SpecialStackHandler handler){
+ if(!handlers.contains(handler)){
+ handlers.add(handler);
+ }
+ }
+
+ public abstract void checkStack(World par1World, int par2, int par3, int par4, Entity triggerer, ArrayList stacks);
+
+ public EnumFacing getFacing(World par1World, int par2, int par3, int par4){
+ ForgeDirection dir = Helper.convertMetaToForgeOrientation(par1World.getBlockMetadata(par2, par3, par4));
+
+ switch(dir){
+ case DOWN:
+ return EnumFacing.UP;
+ case UP:
+ return EnumFacing.DOWN;
+ case WEST:
+ return EnumFacing.WEST;
+ case EAST:
+ return EnumFacing.EAST;
+ case SOUTH:
+ return EnumFacing.NORTH;
+ case NORTH:
+ return EnumFacing.SOUTH;
+ default:
+ return EnumFacing.UP;
+ }
+ }
+
+ public final void removeItemFromInventory(World par1World, int x, int y, int z, ItemStack item){
+ if(item == null || item.stackSize <= 0){
+ return;
+ }
+
+ TileEntityLandmine tileEntity = (TileEntityLandmine) par1World.getBlockTileEntity(x, y, z);
+
+ while(item.stackSize > 0){
+ boolean hasRemovedThisIteration = false;
+ for(int i = 0; i < tileEntity.getSizeTriggerInventory(); i++){
+ if(!hasRemovedThisIteration && tileEntity.getStackInSlot(i) != null){
+ if(tileEntity.getStackInSlot(i).isItemEqual(item)){
+ tileEntity.decrStackSize(i, 1);
+ item.stackSize--;
+ }
+ }
+
+ if(!hasRemovedThisIteration && i == tileEntity.getSizeTriggerInventory() - 1){
+ item.stackSize--;
+ }
+ }
+ }
+ }
+
+ public static final int arrayIndexOfStack(ArrayList stacks, ItemStack item){
+ return Behavior.arrayIndexOfStack(stacks, item);
+ }
+
+ public static final boolean arrayContainsEqualStack(ArrayList stacks, ItemStack item){
+ return Behavior.arrayContainsEqualStack(stacks, item);
+ }
+
+ public boolean isOffensive(ArrayList par1ArrayList){
+ return true;
+ }
+
+}
diff --git a/tconstruct/landmine/logic/behavior/stackCombo/SpecialStackHandlerRocketFireball.java b/tconstruct/landmine/logic/behavior/stackCombo/SpecialStackHandlerRocketFireball.java
new file mode 100644
index 00000000..6f2c7c41
--- /dev/null
+++ b/tconstruct/landmine/logic/behavior/stackCombo/SpecialStackHandlerRocketFireball.java
@@ -0,0 +1,63 @@
+package tconstruct.landmine.logic.behavior.stackCombo;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import net.minecraft.entity.Entity;
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.projectile.EntityFireball;
+import net.minecraft.entity.projectile.EntityLargeFireball;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.EnumFacing;
+import net.minecraft.world.World;
+
+public class SpecialStackHandlerRocketFireball extends SpecialStackHandler{
+
+ @Override
+ public void checkStack(World par1World, int par2, int par3, int par4, Entity triggerer, ArrayList stacks) {
+ if (stacks.isEmpty()) {
+ return;
+ }
+
+ if (this.arrayContainsEqualStack(stacks, new ItemStack(Item.firework)) && this.arrayContainsEqualStack(stacks, new ItemStack(Item.fireballCharge))) {
+ int index0 = this.arrayIndexOfStack(stacks, new ItemStack(Item.firework));
+ int index1 = this.arrayIndexOfStack(stacks, new ItemStack(Item.fireballCharge));
+ EnumFacing face = getFacing(par1World, par2, par3, par4);
+
+ while (stacks.get(index0).stackSize > 0 && stacks.get(index1).stackSize > 0) {
+ double d0 = par2 + (double) ((float) face.getFrontOffsetX() * 0.3F);
+ double d1 = par3 + (double) ((float) face.getFrontOffsetX() * 0.3F);
+ double d2 = par4 + (double) ((float) face.getFrontOffsetZ() * 0.3F);
+ Random random = par1World.rand;
+ double d3 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetX();
+ double d4 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetY();
+ double d5 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetZ();
+ EntityFireball fireball = new EntityLargeFireball(par1World, d0, d1, d2, d3, d4, d5);
+ par1World.spawnEntityInWorld(fireball);
+
+ if (triggerer instanceof EntityLivingBase) {
+ boolean shouldRun = true;
+ if (triggerer instanceof EntityPlayer) {
+ EntityPlayer player = (EntityPlayer) triggerer;
+ if (player.capabilities.isCreativeMode) {
+ // Remove the bellow comment to make the player in
+ // creative mode not get launched
+ // shouldRun = false;
+ }
+ }
+
+ if (shouldRun) {
+ triggerer.mountEntity(fireball);
+ }
+ }
+
+ this.removeItemFromInventory(par1World, par2, par3, par4, new ItemStack(Item.firework, 1));
+ stacks.get(index0).stackSize--;
+ this.removeItemFromInventory(par1World, par2, par3, par4, new ItemStack(Item.fireballCharge, 1));
+ stacks.get(index1).stackSize--;
+ }
+ }
+ }
+}
diff --git a/tconstruct/landmine/tileentity/TileEntityLandmine.java b/tconstruct/landmine/tileentity/TileEntityLandmine.java
new file mode 100644
index 00000000..bff2fd33
--- /dev/null
+++ b/tconstruct/landmine/tileentity/TileEntityLandmine.java
@@ -0,0 +1,219 @@
+package tconstruct.landmine.tileentity;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.ItemStack;
+import net.minecraft.item.crafting.FurnaceRecipes;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.nbt.NBTTagList;
+import net.minecraft.network.INetworkManager;
+import net.minecraft.network.packet.Packet;
+import net.minecraft.network.packet.Packet132TileEntityData;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.tileentity.TileEntityFurnace;
+
+/**
+ *
+ * @author fuj1n
+ *
+ */
+public class TileEntityLandmine extends TileEntity implements IInventory{
+
+ private ItemStack[] inventory = new ItemStack[getSizeInventory()];
+ private String containerName;
+
+ public int soundcountythingmax = 10;
+ public int soundcountything = 0;
+
+ private boolean shouldUpdateLogic = true;
+
+ public int triggerType;
+ public boolean isExploding = false;
+
+
+ public int getSizeTriggerInventory(){
+ return 3;
+ }
+
+ @Override
+ public int getSizeInventory() {
+ return 4;
+ }
+
+ @Override
+ public void writeToNBT(NBTTagCompound par1NBTTagCompound) {
+ super.writeToNBT(par1NBTTagCompound);
+ NBTTagList nbttaglist = new NBTTagList();
+
+ for (int i = 0; i < this.inventory.length; ++i) {
+ if (this.inventory[i] != null) {
+ NBTTagCompound nbttagcompound1 = new NBTTagCompound();
+ nbttagcompound1.setByte("Slot", (byte) i);
+ this.inventory[i].writeToNBT(nbttagcompound1);
+ nbttaglist.appendTag(nbttagcompound1);
+ }
+ }
+
+ par1NBTTagCompound.setTag("Items", nbttaglist);
+
+ par1NBTTagCompound.setInteger("triggerType", triggerType);
+
+ if (this.isInvNameLocalized()) {
+ par1NBTTagCompound.setString("CustomName", this.containerName);
+ }
+ }
+
+ @Override
+ public void readFromNBT(NBTTagCompound par1NBTTagCompound) {
+ super.readFromNBT(par1NBTTagCompound);
+ NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
+ this.inventory = new ItemStack[this.getSizeInventory()];
+
+ for (int i = 0; i < nbttaglist.tagCount(); ++i) {
+ NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
+ byte b0 = nbttagcompound1.getByte("Slot");
+
+ if (b0 >= 0 && b0 < this.inventory.length) {
+ this.inventory[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
+ }
+ }
+
+ triggerType = par1NBTTagCompound.getInteger("triggerType");
+
+ if (par1NBTTagCompound.hasKey("CustomName")) {
+ this.containerName = par1NBTTagCompound.getString("CustomName");
+ }
+ }
+
+ @Override
+ public Packet getDescriptionPacket(){
+ NBTTagCompound nbt = new NBTTagCompound();
+ writeToNBT(nbt);
+ return new Packet132TileEntityData(xCoord, yCoord, zCoord, 0, nbt);
+ }
+
+ @Override
+ public void onDataPacket(INetworkManager net, Packet132TileEntityData packet){
+ readFromNBT(packet.customParam1);
+ }
+
+ @Override
+ public ItemStack getStackInSlot(int i) {
+ if(i < inventory.length){
+ return inventory[i];
+ }else{
+ return null;
+ }
+ }
+
+ @Override
+ public ItemStack decrStackSize(int par1, int par2) {
+ if (par1 < inventory.length) {
+ if (inventory[par1] != null) {
+ ItemStack itemstack;
+
+ if (inventory[par1].stackSize <= par2) {
+ itemstack = inventory[par1];
+ inventory[par1] = null;
+ return itemstack;
+ } else {
+ itemstack = inventory[par1].splitStack(par2);
+
+ if (inventory[par1].stackSize == 0) {
+ inventory[par1] = null;
+ }
+
+ return itemstack;
+ }
+ } else {
+ return null;
+ }
+ }else{
+ return null;
+ }
+ }
+
+ @Override
+ public ItemStack getStackInSlotOnClosing(int i) {
+ if (i < inventory.length && this.inventory[i] != null) {
+ ItemStack itemstack = this.inventory[i];
+ this.inventory[i] = null;
+ return itemstack;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public void setInventorySlotContents(int i, ItemStack itemstack) {
+ if(i < inventory.length){
+ inventory[i] = itemstack;
+ }
+ }
+
+ @Override
+ public String getInvName() {
+ return this.isInvNameLocalized() ? this.containerName : "Landmine";
+ }
+
+ @Override
+ public boolean isInvNameLocalized() {
+ return containerName != null && containerName.length() > 0;
+ }
+
+ @Override
+ public int getInventoryStackLimit() {
+ return 64;
+ }
+
+ public void setGuiDisplayName(String par1Str){
+ this.containerName = par1Str;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) {
+ return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : par1EntityPlayer.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
+ }
+
+ @Override
+ public void openChest() {}
+
+ @Override
+ public void closeChest() {}
+
+ @Override
+ public void onInventoryChanged() {
+ super.onInventoryChanged();
+ this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
+ }
+
+ @Override
+ public boolean isItemValidForSlot(int i, ItemStack itemstack) {
+ //Should automatic camo insertion be allowed.
+ if(i == 3){
+ return false;
+ }else{
+ //Here for mDiyo to decide if he wants automation for insertion/extraction of the items to be an option.
+ //Would be useful for building automated mine laying machines.
+ return false;
+ }
+ }
+
+ public void setSoundPlayed(){
+ soundcountythingmax = 35;
+ soundcountything = soundcountythingmax;
+ }
+
+ @Override
+ public void updateEntity(){
+ if(shouldUpdateLogic){
+ worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
+ shouldUpdateLogic = false;
+ }
+ if(soundcountything > 0){
+ soundcountything--;
+ }
+ }
+
+}