diff options
| author | Lance5057 <Lance5057@gmail.com> | 2015-07-09 02:25:10 -0500 |
|---|---|---|
| committer | Lance5057 <Lance5057@gmail.com> | 2015-07-09 02:25:10 -0500 |
| commit | e913b331003a724f6be8675ca886f7d5ca112348 (patch) | |
| tree | 05b2b6af6d2795bea9b8dee9cbdb49b37733d1ff /src/main/java/gmail/Lance5057/blocks/FinishingAnvil.java | |
| parent | b4040374ce7af8b219b0273c92ed48aaf84fb32b (diff) | |
Revert "Revert "Worked on the Finishing Anvil""
This reverts commit b4040374ce7af8b219b0273c92ed48aaf84fb32b.
Diffstat (limited to 'src/main/java/gmail/Lance5057/blocks/FinishingAnvil.java')
| -rw-r--r-- | src/main/java/gmail/Lance5057/blocks/FinishingAnvil.java | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/src/main/java/gmail/Lance5057/blocks/FinishingAnvil.java b/src/main/java/gmail/Lance5057/blocks/FinishingAnvil.java new file mode 100644 index 0000000..ac4dcf3 --- /dev/null +++ b/src/main/java/gmail/Lance5057/blocks/FinishingAnvil.java @@ -0,0 +1,150 @@ +package gmail.Lance5057.blocks; + +import static net.minecraftforge.common.util.ForgeDirection.EAST; +import static net.minecraftforge.common.util.ForgeDirection.NORTH; +import static net.minecraftforge.common.util.ForgeDirection.SOUTH; +import static net.minecraftforge.common.util.ForgeDirection.WEST; +import gmail.Lance5057.TinkersDefense; +import gmail.Lance5057.tileentities.TileEntity_FinishingAnvil; + +import java.util.Random; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.world.World; + +public class FinishingAnvil extends BlockContainer { + public FinishingAnvil() { + super(Material.iron); + this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); + } + + @Override + public void onBlockAdded(World world, int i, int j, int k) + { + super.onBlockAdded(world, i, j, k); + world.markBlockForUpdate(i, j, k); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, + EntityPlayer player, int metadata, float what, float these, float are) { + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity == null || player.isSneaking()) { + return false; + } + //code to open gui explained later + player.openGui(TinkersDefense.instance, TinkersDefense.GUI_ANVIL_INV, player.worldObj, x, y, z); + return true; + } + + @Override + public void breakBlock(World world, int x, int y, int z, Block par5, int par6) { + dropItems(world, x, y, z); + super.breakBlock(world, x, y, z, par5, par6); + } + + private void dropItems(World world, int x, int y, int z){ + Random rand = new Random(); + + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (!(tileEntity instanceof IInventory)) { + return; + } + IInventory inventory = (IInventory) tileEntity; + + for (int i = 0; i < inventory.getSizeInventory(); i++) { + ItemStack item = inventory.getStackInSlot(i); + + if (item != null && item.stackSize > 0) { + float rx = rand.nextFloat() * 0.8F + 0.1F; + float ry = rand.nextFloat() * 0.8F + 0.1F; + float rz = rand.nextFloat() * 0.8F + 0.1F; + + EntityItem entityItem = new EntityItem(world, + x + rx, y + ry, z + rz, + new ItemStack(item.getItem(), item.stackSize, item.getItemDamage())); + + if (item.hasTagCompound()) { + entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy()); + } + + float factor = 0.05F; + entityItem.motionX = rand.nextGaussian() * factor; + entityItem.motionY = rand.nextGaussian() * factor + 0.2F; + entityItem.motionZ = rand.nextGaussian() * factor; + world.spawnEntityInWorld(entityItem); + item.stackSize = 0; + } + } +} + + //You don't want the normal render type, or it wont render properly. + @Override + public int getRenderType() { + return -1; + } + + //It's not an opaque cube, so you need this. + @Override + public boolean isOpaqueCube() { + return false; + } + + //It's not a normal block, so you need this too. + public boolean renderAsNormalBlock() { + return false; + } + + //This is the icon to use for showing the block in your hand. + @SideOnly(Side.CLIENT) + @Override + public void registerBlockIcons(IIconRegister icon) { + this.blockIcon = icon.registerIcon("tinkersdefense:WIP"); + } + + @Override + public TileEntity createNewTileEntity(World w, int md) { + TileEntity_FinishingAnvil te = new TileEntity_FinishingAnvil(); + return te; + } + + @Override + public int onBlockPlaced(World p_149660_1_, int p_149660_2_, int p_149660_3_, int p_149660_4_, int p_149660_5_, float p_149660_6_, float p_149660_7_, float p_149660_8_, int p_149660_9_) + { + int j1 = p_149660_9_; + + if ((p_149660_9_ == 0 || p_149660_5_ == 2) && p_149660_1_.isSideSolid(p_149660_2_, p_149660_3_, p_149660_4_ + 1, NORTH)) + { + j1 = 1; + } + + if ((j1 == 0 || p_149660_5_ == 3) && p_149660_1_.isSideSolid(p_149660_2_, p_149660_3_, p_149660_4_ - 1, SOUTH)) + { + j1 = 2; + } + + if ((j1 == 0 || p_149660_5_ == 4) && p_149660_1_.isSideSolid(p_149660_2_ + 1, p_149660_3_, p_149660_4_, WEST)) + { + j1 = 3; + } + + if ((j1 == 0 || p_149660_5_ == 5) && p_149660_1_.isSideSolid(p_149660_2_ - 1, p_149660_3_, p_149660_4_, EAST)) + { + j1 = 4; + } + + return j1; + } +} |
