Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package simcraft.machines.workshop;
- import static net.minecraftforge.common.ForgeDirection.DOWN;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.List;
- 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.IconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLiving;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.InventoryLargeChest;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.tileentity.TileEntityChest;
- import net.minecraft.util.Icon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import simcraft.core.RegBlocks;
- import simcraft.core.SimCraft;
- public class blockIronWorkBench extends BlockContainer
- {
- @SideOnly(Side.CLIENT)
- private static Icon icon;
- private Class BlockIronWorkBenchClass;
- public Random random;
- public blockIronWorkBench(int var1, Class var2)
- {
- super(var1, Material.iron);
- this.BlockIronWorkBenchClass = var2;
- this.random = new Random();
- this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
- this.setHardness(2.0F);
- this.setResistance(5F);
- this.setUnlocalizedName("Iron Work Bench");
- this.setCreativeTab(RegBlocks.tabWorkShop);
- }
- @SideOnly(Side.CLIENT)
- public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List) //Adds the metadata blocks to the creative inventory
- {
- for (int var4 = 0; var4 < 1; ++var4)
- {
- par3List.add(new ItemStack(par1, 1, var4));
- }
- }
- public boolean isOpaqueCube()
- {
- return false;
- }
- public boolean renderAsNormalBlock()
- {
- return false;
- }
- public int getRenderType()
- {
- return SimCraft.BlockIronWorkBenchID;
- }
- public int quantityDropped(Random random)
- {
- return 1;
- }
- /**
- * Returns the TileEntity used by this block.
- */
- public TileEntity createNewTileEntity(World var1)
- {
- try
- {
- return (TileEntity)this.BlockIronWorkBenchClass.newInstance();
- }
- catch (Exception var2)
- {
- throw new RuntimeException(var2);
- }
- }
- /**
- * Returns the ID of the items to drop on destruction.
- */
- public int idDropped(int var1, Random var2, int var3)
- {
- return RegBlocks.BlockIronWorkBench.blockID;
- }
- /**
- * Called when the block is placed in the world.
- */
- public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
- {
- int var6 = par1World.getBlockId(par2, par3, par4 - 1);
- int var7 = par1World.getBlockId(par2, par3, par4 + 1);
- int var8 = par1World.getBlockId(par2 - 1, par3, par4);
- int var9 = par1World.getBlockId(par2 + 1, par3, par4);
- byte var10 = 0;
- int var11 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if (var11 == 0)
- {
- var10 = 2;
- }
- if (var11 == 1)
- {
- var10 = 5;
- }
- if (var11 == 2)
- {
- var10 = 3;
- }
- if (var11 == 3)
- {
- var10 = 4;
- }
- if (var6 != this.blockID && var7 != this.blockID && var8 != this.blockID && var9 != this.blockID)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, var10, 3);
- }
- else
- {
- if ((var6 == this.blockID || var7 == this.blockID) && (var10 == 4 || var10 == 5))
- {
- if (var6 == this.blockID)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4 - 1, var10, 3);
- }
- else
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4 + 1, var10, 3);
- }
- par1World.setBlockMetadataWithNotify(par2, par3, par4, var10, 3);
- }
- if ((var8 == this.blockID || var9 == this.blockID) && (var10 == 2 || var10 == 3))
- {
- if (var8 == this.blockID)
- {
- par1World.setBlockMetadataWithNotify(par2 - 1, par3, par4, var10, 3);
- }
- else
- {
- par1World.setBlockMetadataWithNotify(par2 + 1, par3, par4, var10, 3);
- }
- par1World.setBlockMetadataWithNotify(par2, par3, par4, var10, 3);
- }
- }
- }
- /**
- * Called whenever the block is added into the world. Args: world, x, y, z
- */
- public void onBlockAdded(World par1World, int par2, int par3, int par4)
- {
- super.onBlockAdded(par1World, par2, par3, par4);
- this.unifyAdjacentModel(par1World, par2, par3, par4);
- int var5 = par1World.getBlockId(par2, par3, par4 - 1);
- int var6 = par1World.getBlockId(par2, par3, par4 + 1);
- int var7 = par1World.getBlockId(par2 - 1, par3, par4);
- int var8 = par1World.getBlockId(par2 + 1, par3, par4);
- if (var5 == this.blockID)
- {
- this.unifyAdjacentModel(par1World, par2, par3, par4 - 1);
- }
- if (var6 == this.blockID)
- {
- this.unifyAdjacentModel(par1World, par2, par3, par4 + 1);
- }
- if (var7 == this.blockID)
- {
- this.unifyAdjacentModel(par1World, par2 - 1, par3, par4);
- }
- if (var8 == this.blockID)
- {
- this.unifyAdjacentModel(par1World, par2 + 1, par3, par4);
- }
- }
- /**
- * Turns the adjacent chests to a double chest.
- */
- public void unifyAdjacentModel(World par1World, int par2, int par3, int par4)
- {
- if (!par1World.isRemote)
- {
- int var5 = par1World.getBlockId(par2, par3, par4 - 1);
- int var6 = par1World.getBlockId(par2, par3, par4 + 1);
- int var7 = par1World.getBlockId(par2 - 1, par3, par4);
- int var8 = par1World.getBlockId(par2 + 1, par3, par4);
- boolean var9 = true;
- int var10;
- int var11;
- boolean var12;
- byte var13;
- int var14;
- if (var5 != this.blockID && var6 != this.blockID)
- {
- if (var7 != this.blockID && var8 != this.blockID)
- {
- var13 = 3;
- if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6])
- {
- var13 = 3;
- }
- if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5])
- {
- var13 = 2;
- }
- if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8])
- {
- var13 = 5;
- }
- if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7])
- {
- var13 = 4;
- }
- }
- else
- {
- var10 = par1World.getBlockId(var7 == this.blockID ? par2 - 1 : par2 + 1, par3, par4 - 1);
- var11 = par1World.getBlockId(var7 == this.blockID ? par2 - 1 : par2 + 1, par3, par4 + 1);
- var13 = 3;
- var12 = true;
- if (var7 == this.blockID)
- {
- var14 = par1World.getBlockMetadata(par2 - 1, par3, par4);
- }
- else
- {
- var14 = par1World.getBlockMetadata(par2 + 1, par3, par4);
- }
- if (var14 == 2)
- {
- var13 = 2;
- }
- if ((Block.opaqueCubeLookup[var5] || Block.opaqueCubeLookup[var10]) && !Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var11])
- {
- var13 = 3;
- }
- if ((Block.opaqueCubeLookup[var6] || Block.opaqueCubeLookup[var11]) && !Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var10])
- {
- var13 = 2;
- }
- }
- }
- else
- {
- var10 = par1World.getBlockId(par2 - 1, par3, var5 == this.blockID ? par4 - 1 : par4 + 1);
- var11 = par1World.getBlockId(par2 + 1, par3, var5 == this.blockID ? par4 - 1 : par4 + 1);
- var13 = 5;
- var12 = true;
- if (var5 == this.blockID)
- {
- var14 = par1World.getBlockMetadata(par2, par3, par4 - 1);
- }
- else
- {
- var14 = par1World.getBlockMetadata(par2, par3, par4 + 1);
- }
- if (var14 == 4)
- {
- var13 = 4;
- }
- if ((Block.opaqueCubeLookup[var7] || Block.opaqueCubeLookup[var10]) && !Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var11])
- {
- var13 = 5;
- }
- if ((Block.opaqueCubeLookup[var8] || Block.opaqueCubeLookup[var11]) && !Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var10])
- {
- var13 = 4;
- }
- }
- par1World.setBlockMetadataWithNotify(par2, par3, par4, var13, 3);
- }
- }
- /**
- * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
- */
- public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
- {
- int var5 = 0;
- if (par1World.getBlockId(par2 - 1, par3, par4) == this.blockID)
- {
- ++var5;
- }
- if (par1World.getBlockId(par2 + 1, par3, par4) == this.blockID)
- {
- ++var5;
- }
- if (par1World.getBlockId(par2, par3, par4 - 1) == this.blockID)
- {
- ++var5;
- }
- if (par1World.getBlockId(par2, par3, par4 + 1) == this.blockID)
- {
- ++var5;
- }
- return var5 > 1 ? false : (this.isThereANeighborIronBench(par1World, par2 - 1, par3, par4) ? false : (this.isThereANeighborIronBench(par1World, par2 + 1, par3, par4) ? false : (this.isThereANeighborIronBench(par1World, par2, par3, par4 - 1) ? false : !this.isThereANeighborIronBench(par1World, par2, par3, par4 + 1))));
- }
- /**
- * Checks the neighbor blocks to see if there is a chest there. Args: world, x, y, z
- */
- private boolean isThereANeighborIronBench(World par1World, int par2, int par3, int par4)
- {
- return par1World.getBlockId(par2, par3, par4) != this.blockID ? false : (par1World.getBlockId(par2 - 1, par3, par4) == this.blockID ? true : (par1World.getBlockId(par2 + 1, par3, par4) == this.blockID ? true : (par1World.getBlockId(par2, par3, par4 - 1) == this.blockID ? true : par1World.getBlockId(par2, par3, par4 + 1) == this.blockID)));
- }
- /**
- * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
- * their own) Args: x, y, z, neighbor blockID
- */
- public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
- {
- super.onNeighborBlockChange(par1World, par2, par3, par4, par5);
- TileEntityIronWorkBench var6 = (TileEntityIronWorkBench)par1World.getBlockTileEntity(par2, par3, par4);
- if (var6 != null)
- {
- var6.updateContainingBlockInfo();
- }
- }
- /**
- * Called whenever the block is removed.
- */
- public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
- {
- TileEntityIronWorkBench var5 = (TileEntityIronWorkBench)par1World.getBlockTileEntity(par2, par3, par4);
- if (var5 != null)
- {
- for (int var6 = 0; var6 < var5.getSizeInventory(); ++var6)
- {
- ItemStack var7 = var5.getStackInSlot(var6);
- if (var7 != null)
- {
- float var8 = this.random.nextFloat() * 0.8F + 0.1F;
- float var9 = this.random.nextFloat() * 0.8F + 0.1F;
- EntityItem var12;
- for (float var10 = this.random.nextFloat() * 0.8F + 0.1F; var7.stackSize > 0; par1World.spawnEntityInWorld(var12))
- {
- int var11 = this.random.nextInt(21) + 10;
- if (var11 > var7.stackSize)
- {
- var11 = var7.stackSize;
- }
- var7.stackSize -= var11;
- var12 = new EntityItem(par1World, (double)((float)par2 + var8), (double)((float)par3 + var9), (double)((float)par4 + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
- float var13 = 0.05F;
- var12.motionX = (double)((float)this.random.nextGaussian() * var13);
- var12.motionY = (double)((float)this.random.nextGaussian() * var13 + 0.2F);
- var12.motionZ = (double)((float)this.random.nextGaussian() * var13);
- if (var7.hasTagCompound())
- {
- var12.getEntityItem().setTagCompound((NBTTagCompound)var7.getTagCompound().copy());
- }
- }
- }
- }
- }
- super.breakBlock(par1World, par2, par3, par4, par5, par6);
- }
- /**
- * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
- * block.
- */
- public static boolean isHoldingTop(EntityPlayer player)
- {
- return player.inventory.getCurrentItem() != null &&
- player.inventory.getCurrentItem().itemID == RegBlocks.BlockIronWorkBenchAddon.blockID;
- }
- public static boolean isHoldingTop1(EntityPlayer player)
- {
- return player.inventory.getCurrentItem() != null &&
- player.inventory.getCurrentItem().itemID == RegBlocks.BlockIronPressAddon.blockID;
- }
- /**
- * Called upon block activation (left or right click on the block.). The three integers represent x,y,z of the
- * block.
- */
- public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
- {
- if (SimCraft.globalFunctions.isSimulating() && isHoldingTop(par5EntityPlayer))
- {
- return false;
- }
- if (SimCraft.globalFunctions.isSimulating() && isHoldingTop1(par5EntityPlayer))
- {
- return false;
- }
- if (SimCraft.globalFunctions.isSimulating())
- {
- if (par5EntityPlayer.isSneaking())
- {
- return false;
- }
- else
- {
- Object var6 = (TileEntityIronWorkBench)par1World.getBlockTileEntity(par2, par3, par4);
- par5EntityPlayer.openGui(SimCraft.instance, 3, par1World, par2, par3, par4);
- return true;
- }
- }
- return true;
- }
- @SideOnly(Side.CLIENT)
- public Icon getIcon(int par1, int par2)
- {
- return this.icon;
- }
- @SideOnly(Side.CLIENT)
- /**
- * When this method is called, your block should register all the icons it needs with the given IconRegister. This
- * is the only chance you get to register icons.
- */
- public void registerIcons(IconRegister par1IconRegister)
- {
- this.icon = par1IconRegister.registerIcon(SimCraft.modid + ":" + "IronWorkBench_Single");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment