Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mrpablo2000.machinecraft.blocks;
- import java.util.Random;
- import javax.swing.Icon;
- 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.EntityLivingBase;
- 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.tileentity.TileEntityFurnace;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import com.mrpablo2000.machinecraft.MachineCraftBase;
- import com.mrpablo2000.machinecraft.tileentity.TileEntityMacerator;
- import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class BlockGenerator extends BlockContainer{
- private final Random maceratorRand = new Random();
- private final boolean isActive;
- private static boolean keepMaceratorInventory;
- @SideOnly(Side.CLIENT)
- private IIcon field_149935_N;
- @SideOnly(Side.CLIENT)
- private IIcon field_149936_O;
- public BlockGenerator(boolean isActive) {
- super(Material.rock);
- this.isActive = isActive;
- }
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(int p_149691_1_, int p_149691_2_)
- {
- return p_149691_1_ == 1 ? this.field_149935_N : (p_149691_1_ == 0 ? this.field_149935_N : (p_149691_1_ != p_149691_2_ ? this.blockIcon : this.field_149936_O));
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister p_149651_1_)
- {
- this.blockIcon = p_149651_1_.registerIcon("mcbase:macerator_side");
- this.field_149936_O = p_149651_1_.registerIcon(this.isActive ? "mcbase:macerator_front_active" : "mcbase:macerator_front_idle");
- this.field_149935_N = p_149651_1_.registerIcon("mcbase:macerator_side");
- }
- /**
- * 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);
- }
- /**
- * set a blocks direction
- */
- private void setDefaultDirection(World p_149930_1_, int p_149930_2_, int p_149930_3_, int p_149930_4_)
- {
- if (!p_149930_1_.isRemote)
- {
- Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ - 1);
- Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ + 1);
- Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_, p_149930_4_);
- Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_, p_149930_4_);
- byte b0 = 3;
- if (block.func_149730_j() && !block1.func_149730_j())
- {
- b0 = 3;
- }
- if (block1.func_149730_j() && !block.func_149730_j())
- {
- b0 = 2;
- }
- if (block2.func_149730_j() && !block3.func_149730_j())
- {
- b0 = 5;
- }
- if (block3.func_149730_j() && !block2.func_149730_j())
- {
- b0 = 4;
- }
- p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_, p_149930_4_, b0, 2);
- }
- }
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
- FMLNetworkHandler.openGui(player, MachineCraftBase.instance, 1, world, x, y, z);
- return true;
- }
- /**
- * Update which block ID the furnace is using depending on whether or not it is burning
- */
- public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
- {
- int l = par1World.getBlockMetadata(par2, par3, par4);
- TileEntity tileentity = par1World.getTileEntity(par2, par3, par4);
- keepMaceratorInventory = true;
- if (par0)
- {
- par1World.setBlock(par2, par3, par4, MachineCraftBase.blockGeneratorActive);
- }
- else
- {
- par1World.setBlock(par2, par3, par4, MachineCraftBase.blockGeneratorIdle);
- }
- keepMaceratorInventory = false;
- par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
- if (tileentity != null)
- {
- tileentity.validate();
- par1World.setTileEntity(par2, par3, par4, tileentity);
- }
- }
- /**
- * Returns a new instance of a block's tile entity class. Called on placing the block.
- */
- @Override
- public TileEntity createNewTileEntity(World par1World, int i)
- {
- return new com.mrpablo2000.machinecraft.tileentity.TileEntityMacerator();
- }
- /**
- * Called when the block is placed in the world.
- */
- public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
- {
- int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
- if (l == 0)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
- }
- if (l == 1)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
- }
- if (l == 2)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
- }
- if (l == 3)
- {
- par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
- }
- if (par6ItemStack.hasDisplayName())
- {
- ((TileEntityFurnace)par1World.getTileEntity(par2, par3, par4)).func_145951_a(par6ItemStack.getDisplayName());
- }
- }
- /**
- * ejects contained items into the world, and notifies neighbours of an update, as appropriate
- */
- public void breakBlock(World p_149749_1_, int p_149749_2_, int p_149749_3_, int p_149749_4_, Block p_149749_5_, int p_149749_6_)
- {
- if (!keepMaceratorInventory)
- {
- TileEntityMacerator tileentityfurnace = (TileEntityMacerator)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
- if (tileentityfurnace != null)
- {
- for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
- {
- ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
- if (itemstack != null)
- {
- float f = this.maceratorRand.nextFloat() * 0.8F + 0.1F;
- float f1 = this.maceratorRand.nextFloat() * 0.8F + 0.1F;
- float f2 = this.maceratorRand.nextFloat() * 0.8F + 0.1F;
- while (itemstack.stackSize > 0)
- {
- int j1 = this.maceratorRand.nextInt(21) + 10;
- if (j1 > itemstack.stackSize)
- {
- j1 = itemstack.stackSize;
- }
- itemstack.stackSize -= j1;
- EntityItem entityitem = new EntityItem(p_149749_1_, (double)((float)p_149749_2_ + f), (double)((float)p_149749_3_ + f1), (double)((float)p_149749_4_ + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
- if (itemstack.hasTagCompound())
- {
- entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
- }
- float f3 = 0.05F;
- entityitem.motionX = (double)((float)this.maceratorRand.nextGaussian() * f3);
- entityitem.motionY = (double)((float)this.maceratorRand.nextGaussian() * f3 + 0.2F);
- entityitem.motionZ = (double)((float)this.maceratorRand.nextGaussian() * f3);
- p_149749_1_.spawnEntityInWorld(entityitem);
- }
- }
- }
- p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
- }
- }
- super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
- }
- /**
- * If this returns true, then comparators facing away from this block will use the value from
- * getComparatorInputOverride instead of the actual redstone signal strength.
- */
- public boolean hasComparatorInputOverride()
- {
- return true;
- }
- /**
- * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
- * strength when this block inputs to a comparator.
- */
- public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
- {
- return Container.calcRedstoneFromInventory((IInventory)par1World.getTileEntity(par2, par3, par4));
- }
- }
Add Comment
Please, Sign In to add comment