Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package firstetestmod;
- import java.util.Random;
- import net.minecraft.block.Block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.client.Minecraft;
- 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.util.IIcon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.World;
- import cpw.mods.fml.relauncher.Side;
- import cpw.mods.fml.relauncher.SideOnly;
- public class CombinerMachine extends BlockContainer{
- private final Random maceratorRand = new Random();
- private static boolean hasPower;
- private final boolean hasPower2;
- private static boolean keepMaceratorInventory;
- @SideOnly(Side.CLIENT)
- private IIcon CombinerMachineIconTop;
- private IIcon CombinerMachineIconFront;
- public CombinerMachine(boolean isActive) {
- super(Material.rock);
- this.hasPower2 = isActive;
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconRegister){
- this.blockIcon = iconRegister.registerIcon("test:CombinerMachine");
- this.CombinerMachineIconTop = iconRegister.registerIcon(this.hasPower2 ? "test:CombinerMachinetopActive" : "test:CombinerMachinetop");
- this.CombinerMachineIconFront = iconRegister.registerIcon(this.hasPower2 ? "test:CombinerMachinefrontActive" : "test:CombinerMachinefrontInactive");
- }
- @SideOnly(Side.CLIENT)
- /**
- * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
- */
- public IIcon getIcon(int side, int meta) {
- if (side == 1 ) {
- return this.CombinerMachineIconTop;
- } else if ((side == 5 && meta == 3) || (side == 3 && meta == 0) || (side == 2 && meta == 2) || (side == 4 && meta == 1)) {
- return this.CombinerMachineIconFront;
- }// else {
- // return this.blockIcon;
- // }
- return this.blockIcon;
- }
- /**
- * Returns the ID of the items to drop on destruction.
- * @return
- */
- public Block getBlockDropped(int par1, Random par2Random, int par3)
- {
- return firsttestmodmain.CombinerMachine;
- }
- public TileEntity createNewTileEntity(World world, int p_149915_2_) {
- return null;
- }
- /**
- * 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 world, int x, int y, int z)
- {
- if (!world.isRemote)
- {
- Block direction = world.getBlock(x, y, z - 1);
- Block direction1 = world.getBlock(x, y, z + 1);
- Block direction2 = world.getBlock(x - 1, y, z);
- Block direction3 = world.getBlock(x + 1, y, z);
- byte b0 = 3;
- if (direction.func_149730_j() && !direction.func_149730_j())
- {
- b0 = 3;
- }
- if (direction1.func_149730_j() && !direction1.func_149730_j())
- {
- b0 = 2;
- }
- if (direction2.func_149730_j() && !direction2.func_149730_j())
- {
- b0 = 5;
- }
- if (direction3.func_149730_j() && !direction3.func_149730_j())
- {
- b0 = 4;
- }
- world.setBlockMetadataWithNotify(x, y, z, b0, 2);
- }
- }
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
- {
- player.openGui(firsttestmodmain.instance, firsttestmodmain.guiIdCombinerMachine, 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, firsttestmodmain.CombinerMachineActive);
- }
- else
- {
- par1World.setBlock(par2, par3, par4, firsttestmodmain.CombinerMachine);
- }
- 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.
- */
- public TileEntity createNewTileEntity(World par1World)
- {
- return new TileEntityCombinerMachine();
- }
- /**
- * Called when the block is placed in the world.
- */
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack itemstack)
- {
- int l = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
- world.setBlockMetadataWithNotify(x, y, z, l, 2);
- world.setBlockMetadataWithNotify(x, y, z, l, 2);
- world.setBlockMetadataWithNotify(x, y, z, l, 2);
- world.setBlockMetadataWithNotify(x, y, z, l, 2);
- if (itemstack.hasDisplayName())
- {
- ((TileEntityCombinerMachine) world.getTileEntity(x, y, z)).CombinerMachineName(itemstack.getDisplayName());
- }
- }
- /**
- * ejects contained items into the world, and notifies neighbours of an update, as appropriate
- */
- public void breakBlock(World world, int x, int y, int z, Block block, int meta)
- {
- if (!keepMaceratorInventory)
- {
- TileEntityCombinerMachine TileEntityCombinerMachine = (TileEntityCombinerMachine)world.getTileEntity( x, y, z);
- if (TileEntityCombinerMachine != null)
- {
- for (int j1 = 0; j1 < TileEntityCombinerMachine.getSizeInventory(); ++j1)
- {
- ItemStack itemstack = TileEntityCombinerMachine.getStackInSlot(j1);
- 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 k1 = this.maceratorRand.nextInt(21) + 10;
- if (k1 > itemstack.stackSize)
- {
- k1 = itemstack.stackSize;
- }
- itemstack.stackSize -= k1;
- EntityItem entityitem = new EntityItem(world, (double) ((float) x + f), (double) ((float) y + f1), (double) ((float) z + f2), new ItemStack(itemstack.getItem(), k1, 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);
- world.spawnEntityInWorld(entityitem);
- }
- }
- }
- world.func_147453_f(x, y, z, block);
- }
- }
- super.breakBlock(world, x, y, z, block, meta);
- }
- /**
- * 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));
- }
- @SideOnly(Side.CLIENT)
- public void randomDisplayTick(World world, int x, int y, int z, Random random) {
- if (this.hasPower2) {
- int direction = world.getBlockMetadata(x, y, z);
- float xx = (float) x + 0.5F, yy = (float) y + random.nextFloat() * 6.0F / 16.0F, zz = (float) z + 0.5F, xx2 = random.nextFloat() * 0.3F - 0.2F, zz2 = 0.5F;
- if (direction == 4) {
- world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- } else if (direction == 5) {
- world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- } else if (direction == 3) {
- world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- } else if (direction == 2) {
- world.spawnParticle("smoke", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- world.spawnParticle("flame", (double) (xx - zz2), (double) yy, (double) (zz + xx2), 0.0F, 0.0F, 0.0F);
- }
- }
- }
- @SideOnly(Side.CLIENT)
- /**
- * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
- */
- public Block getBlockPicked(World par1World, int par2, int par3, int par4)
- {
- return firsttestmodmain.CombinerMachine;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement