Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BlockForge extends BlockContainer
- {
- private final boolean isActive;
- @SideOnly(Side.CLIENT)
- private Icon iconFront;
- private static boolean keepInventory;
- public BlockForge(int id, boolean isActive)
- {
- super(id, Material.iron);
- this.isActive = isActive;
- }
- @SideOnly(Side.CLIENT)
- public void registerIcons(IconRegister iconRegister)
- {
- this.blockIcon = iconRegister.registerIcon("skyrim:Forge_Side");
- this.iconFront = iconRegister.registerIcon(this.isActive ? "skyrim:Forge_Front_Active" : "skyrim:Forge_Front_Idle");
- }
- @SideOnly(Side.CLIENT)
- public Icon getIcon(int side, int metadata)
- {
- return side == metadata ? this.iconFront : this.blockIcon;
- }
- public int idDropped(int par, Random rand, int par3)
- {
- return SkyrimMain.inactiveForge.blockID;
- }
- public void onBlockAdded(World world, int x, int y, int z)
- {
- super.onBlockAdded(world, x, y, z);
- this.setDefaultDirection(world, x, y, z);
- }
- private void setDefaultDirection(World world, int x, int y, int z)
- {
- if(!world.isRemote)
- {
- int l = world.getBlockId(x, y, z - 1);
- int il = world.getBlockId(x, y, z + 1);
- int jl = world.getBlockId(x - 1, y, z);
- int kl = world.getBlockId(x + 1, y, z);
- byte b0 = 3;
- if(Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[il])
- {
- b0 = 3;
- }
- if(Block.opaqueCubeLookup[il] && !Block.opaqueCubeLookup[l])
- {
- b0 = 2;
- }
- if(Block.opaqueCubeLookup[kl] && !Block.opaqueCubeLookup[jl])
- {
- b0 = 5;
- }
- if(Block.opaqueCubeLookup[jl] && !Block.opaqueCubeLookup[kl])
- {
- b0 = 5;
- }
- world.setBlockMetadataWithNotify(x, y, z, b0, 2);
- }
- }
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
- {
- if(!world.isRemote)
- {
- TileEntityForge tileentityforge = (TileEntityForge)world.getBlockTileEntity(x, y, z);
- if (tileentityforge != null)
- {
- player.openGui(SkyrimMain.instance, 0, world, x, y, z);
- }
- return true;
- }
- else
- {
- return true;
- }
- }
- public TileEntity createNewTileEntity(World world)
- {
- return new TileEntityForge();
- }
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entitylivingbase, ItemStack itemstack)
- {
- int l = MathHelper.floor_double((double)(entitylivingbase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if(l == 0)
- {
- world.setBlockMetadataWithNotify(x, y, z, 2, 2);
- }
- if(l == 1)
- {
- world.setBlockMetadataWithNotify(x, y, z, 5, 2);
- }
- if(l == 2)
- {
- world.setBlockMetadataWithNotify(x, y, z, 3, 2);
- }
- if(l == 3)
- {
- world.setBlockMetadataWithNotify(x, y, z, 4, 2);
- }
- if(itemstack.hasDisplayName())
- {
- ((TileEntityForge)world.getBlockTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
- }
- }
- public static void updateForgeBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord)
- {
- int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
- TileEntity tileentity = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord);
- keepInventory = true;
- if(active)
- {
- worldObj.setBlock(xCoord, yCoord, zCoord, SkyrimMain.activeForge.blockID);
- }
- else
- {
- worldObj.setBlock(xCoord, yCoord, zCoord, SkyrimMain.inactiveForge.blockID);
- }
- keepInventory = false;
- worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);
- if(tileentity != null)
- {
- tileentity.validate();
- worldObj.setBlockTileEntity(xCoord, yCoord, zCoord, tileentity);
- }
- }
- public boolean hasComparatorInputOverride()
- {
- return true;
- }
- public int getComparatorInputOverride(World world, int x, int y, int z, int i)
- {
- return Container.calcRedstoneFromInventory((IInventory)world.getBlockTileEntity(x, y, z));
- }
- public int idPicked(World world, int x, int y, int z)
- {
- return SkyrimMain.inactiveForge.blockID;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment