Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mods.GeoActivity.common.blocks.Machines;
- import java.util.Random;
- import mods.GeoActivity.common.geoactivity;
- import mods.GeoActivity.common.blocks.Machines.CR.CRTileE;
- import mods.GeoActivity.core.GuiIDs;
- 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.entity.EntityLiving;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.Container;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.ItemStack;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.Icon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- import net.minecraftforge.common.ForgeDirection;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class CoalRefiner extends BlockContainer
- {
- /**
- * Is the random generator used by furnace to drop the inventory contents in random directions.
- */
- private Random furnaceRand = new Random();
- /** True if this is an active furnace, false if idle */
- private final boolean isActive;
- /**
- * This flag is used to prevent the furnace inventory to be dropped upon block removal, is used internally when the
- * furnace block changes from idle to active and vice-versa.
- */
- private static boolean keepFurnaceInventory = false;
- @SideOnly(Side.CLIENT)
- private Icon crIconTop;
- @SideOnly(Side.CLIENT)
- private Icon crIconFront;
- public CoalRefiner(int par1, Material material, boolean par2)
- {
- super(par1, material);
- this.isActive = par2;
- }
- /**
- * Returns the ID of the items to drop on destruction.
- */
- @Override
- public int idDropped(int par1, Random par2Random, int par3)
- {
- return geoactivity.coalrefineridle.blockID;
- }
- /**
- * 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.setDefaultDirection(par1World, par2, par3, par4);
- }
- @SideOnly(Side.CLIENT)
- @Override
- public Icon getIcon(int side, int meta)
- {
- if(side == meta)
- return this.crIconFront;
- switch(side)
- {
- case 0:
- return this.crIconTop; //bottom
- case 1:
- return this.crIconTop; //top
- default:
- return this.blockIcon; //sides
- //case 2 & 4 - front sides
- //case 3 & 5 - other sides
- }
- }
- @SideOnly(Side.CLIENT)
- @Override
- public void registerIcons(IconRegister par1IconRegister)
- {
- this.blockIcon = par1IconRegister.registerIcon("GeoActivity:CR_side");
- this.crIconFront = par1IconRegister.registerIcon(this.isActive ? "GeoActivity:CR_frontA" : "GeoActivity:CR_frontI");
- this.crIconTop = par1IconRegister.registerIcon("GeoActivity:CR_top");
- }
- /**
- * set a blocks direction
- */
- private void setDefaultDirection(World par1World, int par2, int par3, int par4)
- {
- if (!par1World.isRemote)
- {
- int l = par1World.getBlockId(par2, par3, par4 - 1);
- int i1 = par1World.getBlockId(par2, par3, par4 + 1);
- int j1 = par1World.getBlockId(par2 - 1, par3, par4);
- int k1 = par1World.getBlockId(par2 + 1, par3, par4);
- byte b0 = 3;
- if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])
- {
- b0 = 3;
- }
- if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])
- {
- b0 = 2;
- }
- if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])
- {
- b0 = 5;
- }
- if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])
- {
- b0 = 4;
- }
- par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);
- }
- }
- @Override
- public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
- {
- if (par1World.isRemote)
- {
- return true;
- }
- else
- {
- CRTileE tile_entity = (CRTileE)par1World.getBlockTileEntity(par2, par3, par4);
- if (tile_entity == null || par5EntityPlayer.isSneaking())
- {
- return false;
- }
- par5EntityPlayer.openGui(geoactivity.instance, GuiIDs.CR, par1World, par2, par3, par4);
- return true;
- }
- }
- public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
- {
- int var5 = par1World.getBlockMetadata(par2, par3, par4);
- TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
- keepFurnaceInventory = true;
- if (par0)
- {
- par1World.setBlock(par2, par3, par4, geoactivity.coalrefineractive.blockID);
- }
- else
- {
- par1World.setBlock(par2, par3, par4, geoactivity.coalrefineridle.blockID);
- }
- keepFurnaceInventory = false;
- par1World.setBlockMetadataWithNotify(par2, par3, par4, var5, 2);
- if (tileentity != null)
- {
- tileentity.validate();
- par1World.setBlockTileEntity(par2, par3, par4, tileentity);
- }
- }
- @SideOnly(Side.CLIENT)
- /**
- * A randomly called display update to be able to add particles or other items for display
- */
- public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
- {
- if (this.isActive)
- {
- int l = par1World.getBlockMetadata(par2, par3, par4);
- float f = (float)par2 + 0.5F;
- float f1 = (float)par3 + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
- float f2 = (float)par4 + 0.5F;
- float f3 = 0.52F;
- float f4 = par5Random.nextFloat() * 0.6F - 0.3F;
- if (l == 4)
- {
- par1World.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
- par1World.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
- }
- else if (l == 5)
- {
- par1World.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
- par1World.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
- }
- else if (l == 2)
- {
- par1World.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
- par1World.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
- }
- else if (l == 3)
- {
- par1World.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
- par1World.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
- }
- }
- }
- public TileEntity createNewTileEntity(World par1World)
- {
- return new CRTileE();
- }
- public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack)
- {
- int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if (var6 == 0)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
- }
- if (var6 == 1)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
- }
- if (var6 == 2)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
- }
- if (var6 == 3)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
- }
- if (par6ItemStack.hasDisplayName())
- {
- ((CRTileE)par1World.getBlockTileEntity(par2, par3, par4)).func_94129_a(par6ItemStack.getDisplayName());
- }
- }
- public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
- {
- if (!keepFurnaceInventory)
- {
- CRTileE var7 = (CRTileE) par1World.getBlockTileEntity(par2, par3, par4);
- if (var7 != null)
- {
- for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8)
- {
- ItemStack var9 = var7.getStackInSlot(var8);
- if (var9 != null)
- {
- float var10 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
- float var11 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
- float var12 = this.furnaceRand.nextFloat() * 0.8F + 0.1F;
- while (var9.stackSize > 0)
- {
- int var13 = this.furnaceRand.nextInt(21) + 10;
- if (var13 > var9.stackSize)
- {
- var13 = var9.stackSize;
- }
- var9.stackSize -= var13;
- EntityItem var14 = new EntityItem(par1World, (double)((float)par2 + var10), (double)((float)par3 + var11), (double)((float)par4 + var12), new ItemStack(var9.itemID, var13, var9.getItemDamage()));
- if (var9.hasTagCompound())
- {
- var14.getEntityItem().setTagCompound((NBTTagCompound)var9.getTagCompound().copy());
- }
- float var15 = 0.05F;
- var14.motionX = (double)((float)this.furnaceRand.nextGaussian() * var15);
- var14.motionY = (double)((float)this.furnaceRand.nextGaussian() * var15 + 0.2F);
- var14.motionZ = (double)((float)this.furnaceRand.nextGaussian() * var15);
- par1World.spawnEntityInWorld(var14);
- }
- }
- }
- }
- }
- super.breakBlock(par1World, par2, par3, par4, par5, par6);
- }
- public boolean hasComparatorInputOverride()
- {
- return true;
- }
- public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
- {
- return Container.calcRedstoneFromInventory((IInventory)par1World.getBlockTileEntity(par2, par3, par4));
- }
- @SideOnly(Side.CLIENT)
- public int idPicked(World par1World, int par2, int par3, int par4)
- {
- return Block.furnaceIdle.blockID;
- }
- }
Advertisement
Advertisement
Advertisement
RAW Paste Data
Copied
Advertisement