Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.limplungs.limpcraft.blocks.machines;
- import java.util.Random;
- import com.limplungs.limpcraft.Construct;
- import com.limplungs.limpcraft.LimpCraft2;
- import com.limplungs.limpcraft.help.Reference;
- import com.limplungs.limpcraft.tileentities.TileEntityCarbonCondenser;
- 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.Minecraft;
- import net.minecraft.client.renderer.texture.IIconRegister;
- import net.minecraft.creativetab.CreativeTabs;
- import net.minecraft.entity.EntityLivingBase;
- import net.minecraft.entity.item.EntityItem;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.IIcon;
- import net.minecraft.util.MathHelper;
- import net.minecraft.world.IBlockAccess;
- import net.minecraft.world.World;
- public class CarbonCondenser extends BlockContainer
- {
- @SideOnly(Side.CLIENT)
- private IIcon sideImport;
- @SideOnly(Side.CLIENT)
- private IIcon sideExport;
- @SideOnly(Side.CLIENT)
- private IIcon sideFront;
- private static boolean isBurning = false;
- private boolean isActive = false;
- public CarbonCondenser(String name, boolean active)
- {
- super(Material.iron);
- this.setBlockName(name);
- this.setBlockTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5));
- this.setCreativeTab(CreativeTabs.tabDecorations);
- this.setStepSound(Block.soundTypePiston);
- this.isOpaqueCube();
- // Mining
- this.setHardness(4f);
- this.setResistance(6f);
- this.setHarvestLevel("pickaxe", 0);
- // stuff
- this.isActive = active;
- }
- @SideOnly(Side.CLIENT)
- public void registerBlockIcons(IIconRegister iconregister)
- {
- this.blockIcon = iconregister.registerIcon(Reference.MODID + ":" + "machineLimpium");
- this.sideImport = iconregister.registerIcon(Reference.MODID + ":" + "machineLimpiumImport");
- this.sideExport = iconregister.registerIcon(Reference.MODID + ":" + "machineLimpiumExport");
- this.sideFront = iconregister.registerIcon(this.isActive ? Reference.MODID + ":" + "machineCarbonCondenserActive" : Reference.MODID + ":" + "machineCarbonCondenser");
- }
- @Override
- public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int face, float hitX, float hitY, float hitZ)
- {
- if (!world.isRemote)
- {
- player.openGui(LimpCraft2.INSTANCE, 0, world, x, y, z);
- ((TileEntityCarbonCondenser) world.getTileEntity(x, y, z)).meta = world.getBlockMetadata(x, y, z);
- Minecraft.getMinecraft().renderGlobal.markBlockForRenderUpdate(x, y, z);
- world.markBlockForUpdate(x, y, z);
- }
- return true;
- }
- @Override
- @SideOnly(Side.CLIENT)
- public IIcon getIcon(IBlockAccess block, int x, int y, int z, int side)
- {
- if (side == block.getBlockMetadata(x, y, z))
- {
- return this.sideFront;
- }
- if (side != block.getBlockMetadata(x, y, z))
- {
- if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).top)
- {
- if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sTop == 0)
- {
- return this.blockIcon;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sTop == 1)
- {
- return this.sideImport;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sTop == 2)
- {
- return this.sideExport;
- }
- }
- if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).left)
- {
- if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sLeft == 0)
- {
- return this.blockIcon;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sLeft == 1)
- {
- return this.sideImport;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sLeft == 2)
- {
- return this.sideExport;
- }
- }
- if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).back)
- {
- if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBack == 0)
- {
- return this.blockIcon;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBack == 1)
- {
- return this.sideImport;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBack == 2)
- {
- return this.sideExport;
- }
- }
- if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).right)
- {
- if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sRight == 0)
- {
- return this.blockIcon;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sRight == 1)
- {
- return this.sideImport;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sRight == 2)
- {
- return this.sideExport;
- }
- }
- if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).bot)
- {
- if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBot == 0)
- {
- return this.blockIcon;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBot == 1)
- {
- return this.sideImport;
- }
- else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBot == 2)
- {
- return this.sideExport;
- }
- }
- }
- return this.blockIcon;
- }
- @Override
- public IIcon getIcon(int side, int meta)
- {
- // Sets inventory icons
- if (side == 3 && meta == 0)
- {
- return this.sideFront;
- }
- else
- {
- return this.blockIcon;
- }
- }
- @Override
- public TileEntity createNewTileEntity(World world, int i)
- {
- return new TileEntityCarbonCondenser();
- }
- public Item getItemDropped(int par1, Random random, int par3)
- {
- return Item.getItemFromBlock(Construct.machineCarbonCondenser);
- }
- public Item getItem(World world, int par2, int par3, int par4)
- {
- return Item.getItemFromBlock(Construct.machineCarbonCondenser);
- }
- @SideOnly(Side.CLIENT)
- public void onBlockAdded(World world, int x, int y, int z)
- {
- super.onBlockAdded(world, x, y, z);
- func_149930_e(world, x, y, z);
- }
- private void func_149930_e(World world, int x, int y, int z)
- {
- if (!world.isRemote)
- {
- Block block = world.getBlock(x, y, z - 1);
- Block block1 = world.getBlock(x, y, z + 1);
- Block block2 = world.getBlock(x - 1, y, z);
- Block block3 = world.getBlock(x + 1, y, z);
- 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;
- }
- world.setBlockMetadataWithNotify(x, y, z, b0, 2);
- }
- }
- public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack p_149689_6_)
- {
- int l = MathHelper.floor_double((double) (entity.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);
- }
- }
- public static void updateBlockState(boolean bool, World world, int x, int y, int z)
- {
- int l = world.getBlockMetadata(x, y, z);
- TileEntity tileentity = world.getTileEntity(x, y, z);
- isBurning = true;
- if (bool)
- {
- world.setBlock(x, y, z, Construct.machineCarbonCondenserActive);
- }
- else
- {
- world.setBlock(x, y, z, Construct.machineCarbonCondenser);
- }
- isBurning = false;
- world.setBlockMetadataWithNotify(x, y, z, l, 2);
- if (tileentity != null)
- {
- tileentity.validate();
- world.setTileEntity(x, y, z, (TileEntityCarbonCondenser) tileentity);
- }
- }
- public void breakBlock(World world, int x, int y, int z, Block block, int meta)
- {
- if (!isBurning)
- {
- TileEntityCarbonCondenser te = (TileEntityCarbonCondenser) world.getTileEntity(x, y, z);
- if (te != null && te instanceof IInventory)
- {
- IInventory inventory = (IInventory) te;
- for (int i = 0; i < inventory.getSizeInventory(); i++)
- {
- ItemStack stack = inventory.getStackInSlotOnClosing(i);
- if (stack != null)
- {
- float spawnx = x + world.rand.nextFloat();
- float spawny = y + world.rand.nextFloat();
- float spawnz = z + world.rand.nextFloat();
- EntityItem drop = new EntityItem(world, spawnx, spawny, spawnz, stack);
- float m = 0.05F;
- drop.motionX = (-.5F + world.rand.nextFloat()) * m;
- drop.motionY = (4F + world.rand.nextFloat()) * m;
- drop.motionZ = (-.5F + world.rand.nextFloat()) * m;
- world.spawnEntityInWorld(drop);
- }
- }
- world.func_147453_f(x, y, z, Construct.machineCarbonCondenser);
- }
- }
- super.breakBlock(world, x, y, z, block, meta);
- }
- @SideOnly(Side.CLIENT)
- public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
- {
- if (isActive)
- {
- int l = p_149734_1_.getBlockMetadata(p_149734_2_, p_149734_3_, p_149734_4_);
- float f = (float) p_149734_2_ + 0.5F;
- float f1 = (float) p_149734_3_ + 0.0F + p_149734_5_.nextFloat() * 6.0F / 16.0F;
- float f2 = (float) p_149734_4_ + 0.5F;
- float f3 = 0.52F;
- float f4 = p_149734_5_.nextFloat() * 0.6F - 0.3F;
- if (l == 4)
- {
- p_149734_1_.spawnParticle("smoke", (double) (f - f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
- p_149734_1_.spawnParticle("flame", (double) (f - f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
- }
- else if (l == 5)
- {
- p_149734_1_.spawnParticle("smoke", (double) (f + f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
- p_149734_1_.spawnParticle("flame", (double) (f + f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
- }
- else if (l == 2)
- {
- p_149734_1_.spawnParticle("smoke", (double) (f + f4), (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
- p_149734_1_.spawnParticle("flame", (double) (f + f4), (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
- }
- else if (l == 3)
- {
- p_149734_1_.spawnParticle("smoke", (double) (f + f4), (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
- p_149734_1_.spawnParticle("flame", (double) (f + f4), (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement