Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.59 KB | None | 0 0
  1. package com.limplungs.limpcraft.blocks.machines;
  2.  
  3. import java.util.Random;
  4. import com.limplungs.limpcraft.Construct;
  5. import com.limplungs.limpcraft.LimpCraft2;
  6. import com.limplungs.limpcraft.help.Reference;
  7. import com.limplungs.limpcraft.tileentities.TileEntityCarbonCondenser;
  8. import cpw.mods.fml.relauncher.Side;
  9. import cpw.mods.fml.relauncher.SideOnly;
  10. import net.minecraft.block.Block;
  11. import net.minecraft.block.BlockContainer;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.client.Minecraft;
  14. import net.minecraft.client.renderer.texture.IIconRegister;
  15. import net.minecraft.creativetab.CreativeTabs;
  16. import net.minecraft.entity.EntityLivingBase;
  17. import net.minecraft.entity.item.EntityItem;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.inventory.IInventory;
  20. import net.minecraft.item.Item;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.tileentity.TileEntity;
  23. import net.minecraft.util.IIcon;
  24. import net.minecraft.util.MathHelper;
  25. import net.minecraft.world.IBlockAccess;
  26. import net.minecraft.world.World;
  27.  
  28. public class CarbonCondenser extends BlockContainer
  29. {
  30.  
  31.     @SideOnly(Side.CLIENT)
  32.     private IIcon sideImport;
  33.     @SideOnly(Side.CLIENT)
  34.     private IIcon sideExport;
  35.     @SideOnly(Side.CLIENT)
  36.     private IIcon sideFront;
  37.  
  38.     private static boolean isBurning = false;
  39.     private boolean isActive = false;
  40.  
  41.     public CarbonCondenser(String name, boolean active)
  42.     {
  43.         super(Material.iron);
  44.         this.setBlockName(name);
  45.         this.setBlockTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5));
  46.         this.setCreativeTab(CreativeTabs.tabDecorations);
  47.         this.setStepSound(Block.soundTypePiston);
  48.         this.isOpaqueCube();
  49.  
  50.         // Mining
  51.         this.setHardness(4f);
  52.         this.setResistance(6f);
  53.         this.setHarvestLevel("pickaxe", 0);
  54.  
  55.         // stuff
  56.         this.isActive = active;
  57.     }
  58.  
  59.     @SideOnly(Side.CLIENT)
  60.     public void registerBlockIcons(IIconRegister iconregister)
  61.     {
  62.         this.blockIcon = iconregister.registerIcon(Reference.MODID + ":" + "machineLimpium");
  63.         this.sideImport = iconregister.registerIcon(Reference.MODID + ":" + "machineLimpiumImport");
  64.         this.sideExport = iconregister.registerIcon(Reference.MODID + ":" + "machineLimpiumExport");
  65.         this.sideFront = iconregister.registerIcon(this.isActive ? Reference.MODID + ":" + "machineCarbonCondenserActive" : Reference.MODID + ":" + "machineCarbonCondenser");
  66.     }
  67.  
  68.  
  69.     @Override
  70.     public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int face, float hitX, float hitY, float hitZ)
  71.     {
  72.         if (!world.isRemote)
  73.         {
  74.             player.openGui(LimpCraft2.INSTANCE, 0, world, x, y, z);
  75.  
  76.             ((TileEntityCarbonCondenser) world.getTileEntity(x, y, z)).meta = world.getBlockMetadata(x, y, z);
  77.            
  78.             Minecraft.getMinecraft().renderGlobal.markBlockForRenderUpdate(x, y, z);
  79.             world.markBlockForUpdate(x, y, z);
  80.         }
  81.         return true;
  82.     }
  83.    
  84.     @Override
  85.     @SideOnly(Side.CLIENT)
  86.     public IIcon getIcon(IBlockAccess block, int x, int y, int z, int side)
  87.     {
  88.        
  89.         if (side == block.getBlockMetadata(x, y, z))
  90.         {
  91.             return this.sideFront;
  92.         }
  93.         if (side != block.getBlockMetadata(x, y, z))
  94.         {
  95.             if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).top)
  96.             {
  97.                 if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sTop == 0)
  98.                 {
  99.                     return this.blockIcon;
  100.                 }
  101.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sTop == 1)
  102.                 {
  103.                     return this.sideImport;
  104.                 }
  105.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sTop == 2)
  106.                 {
  107.                     return this.sideExport;
  108.                 }
  109.             }
  110.             if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).left)
  111.             {
  112.                 if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sLeft == 0)
  113.                 {
  114.                     return this.blockIcon;
  115.                 }
  116.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sLeft == 1)
  117.                 {
  118.                     return this.sideImport;
  119.                 }
  120.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sLeft == 2)
  121.                 {
  122.                     return this.sideExport;
  123.                 }
  124.             }
  125.             if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).back)
  126.             {
  127.                 if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBack == 0)
  128.                 {
  129.                     return this.blockIcon;
  130.                 }
  131.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBack == 1)
  132.                 {
  133.                     return this.sideImport;
  134.                 }
  135.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBack == 2)
  136.                 {
  137.                     return this.sideExport;
  138.                 }
  139.             }
  140.             if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).right)
  141.             {
  142.                 if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sRight == 0)
  143.                 {
  144.                     return this.blockIcon;
  145.                 }
  146.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sRight == 1)
  147.                 {
  148.                     return this.sideImport;
  149.                 }
  150.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sRight == 2)
  151.                 {
  152.                     return this.sideExport;
  153.                 }
  154.             }
  155.             if (side == ((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).bot)
  156.             {
  157.                 if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBot == 0)
  158.                 {
  159.                     return this.blockIcon;
  160.                 }
  161.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBot == 1)
  162.                 {
  163.                     return this.sideImport;
  164.                 }
  165.                 else if (((TileEntityCarbonCondenser) block.getTileEntity(x, y, z)).sBot == 2)
  166.                 {
  167.                     return this.sideExport;
  168.                 }
  169.             }
  170.         }
  171.  
  172.         return this.blockIcon;
  173.     }
  174.  
  175.     @Override
  176.     public IIcon getIcon(int side, int meta)
  177.     {
  178.         // Sets inventory icons
  179.         if (side == 3 && meta == 0)
  180.         {
  181.             return this.sideFront;
  182.         }
  183.         else
  184.         {
  185.             return this.blockIcon;
  186.         }
  187.     }
  188.  
  189.     @Override
  190.     public TileEntity createNewTileEntity(World world, int i)
  191.     {
  192.         return new TileEntityCarbonCondenser();
  193.     }
  194.  
  195.     public Item getItemDropped(int par1, Random random, int par3)
  196.     {
  197.         return Item.getItemFromBlock(Construct.machineCarbonCondenser);
  198.     }
  199.  
  200.     public Item getItem(World world, int par2, int par3, int par4)
  201.     {
  202.         return Item.getItemFromBlock(Construct.machineCarbonCondenser);
  203.     }
  204.  
  205.     @SideOnly(Side.CLIENT)
  206.     public void onBlockAdded(World world, int x, int y, int z)
  207.     {
  208.         super.onBlockAdded(world, x, y, z);
  209.         func_149930_e(world, x, y, z);
  210.     }
  211.  
  212.     private void func_149930_e(World world, int x, int y, int z)
  213.     {
  214.         if (!world.isRemote)
  215.         {
  216.             Block block = world.getBlock(x, y, z - 1);
  217.             Block block1 = world.getBlock(x, y, z + 1);
  218.             Block block2 = world.getBlock(x - 1, y, z);
  219.             Block block3 = world.getBlock(x + 1, y, z);
  220.             byte b0 = 3;
  221.  
  222.             if (block.func_149730_j() && !block1.func_149730_j())
  223.             {
  224.                 b0 = 3;
  225.             }
  226.  
  227.             if (block1.func_149730_j() && !block.func_149730_j())
  228.             {
  229.                 b0 = 2;
  230.             }
  231.  
  232.             if (block2.func_149730_j() && !block3.func_149730_j())
  233.             {
  234.                 b0 = 5;
  235.             }
  236.  
  237.             if (block3.func_149730_j() && !block2.func_149730_j())
  238.             {
  239.                 b0 = 4;
  240.             }
  241.  
  242.             world.setBlockMetadataWithNotify(x, y, z, b0, 2);
  243.         }
  244.     }
  245.  
  246.     public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack p_149689_6_)
  247.     {
  248.         int l = MathHelper.floor_double((double) (entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  249.  
  250.         if (l == 0)
  251.         {
  252.             world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  253.         }
  254.  
  255.         if (l == 1)
  256.         {
  257.             world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  258.         }
  259.  
  260.         if (l == 2)
  261.         {
  262.             world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  263.         }
  264.  
  265.         if (l == 3)
  266.         {
  267.             world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  268.         }
  269.  
  270.     }
  271.  
  272.     public static void updateBlockState(boolean bool, World world, int x, int y, int z)
  273.     {
  274.         int l = world.getBlockMetadata(x, y, z);
  275.  
  276.         TileEntity tileentity = world.getTileEntity(x, y, z);
  277.         isBurning = true;
  278.  
  279.         if (bool)
  280.         {
  281.             world.setBlock(x, y, z, Construct.machineCarbonCondenserActive);
  282.         }
  283.         else
  284.         {
  285.             world.setBlock(x, y, z, Construct.machineCarbonCondenser);
  286.         }
  287.  
  288.         isBurning = false;
  289.         world.setBlockMetadataWithNotify(x, y, z, l, 2);
  290.  
  291.         if (tileentity != null)
  292.         {
  293.             tileentity.validate();
  294.             world.setTileEntity(x, y, z, (TileEntityCarbonCondenser) tileentity);
  295.         }
  296.     }
  297.  
  298.     public void breakBlock(World world, int x, int y, int z, Block block, int meta)
  299.     {
  300.         if (!isBurning)
  301.         {
  302.  
  303.             TileEntityCarbonCondenser te = (TileEntityCarbonCondenser) world.getTileEntity(x, y, z);
  304.             if (te != null && te instanceof IInventory)
  305.             {
  306.                 IInventory inventory = (IInventory) te;
  307.  
  308.                 for (int i = 0; i < inventory.getSizeInventory(); i++)
  309.                 {
  310.                     ItemStack stack = inventory.getStackInSlotOnClosing(i);
  311.  
  312.                     if (stack != null)
  313.                     {
  314.                         float spawnx = x + world.rand.nextFloat();
  315.                         float spawny = y + world.rand.nextFloat();
  316.                         float spawnz = z + world.rand.nextFloat();
  317.  
  318.                         EntityItem drop = new EntityItem(world, spawnx, spawny, spawnz, stack);
  319.  
  320.                         float m = 0.05F;
  321.  
  322.                         drop.motionX = (-.5F + world.rand.nextFloat()) * m;
  323.                         drop.motionY = (4F + world.rand.nextFloat()) * m;
  324.                         drop.motionZ = (-.5F + world.rand.nextFloat()) * m;
  325.  
  326.                         world.spawnEntityInWorld(drop);
  327.                     }
  328.                 }
  329.  
  330.                 world.func_147453_f(x, y, z, Construct.machineCarbonCondenser);
  331.             }
  332.         }
  333.  
  334.         super.breakBlock(world, x, y, z, block, meta);
  335.     }
  336.  
  337.     @SideOnly(Side.CLIENT)
  338.     public void randomDisplayTick(World p_149734_1_, int p_149734_2_, int p_149734_3_, int p_149734_4_, Random p_149734_5_)
  339.     {
  340.         if (isActive)
  341.         {
  342.             int l = p_149734_1_.getBlockMetadata(p_149734_2_, p_149734_3_, p_149734_4_);
  343.             float f = (float) p_149734_2_ + 0.5F;
  344.             float f1 = (float) p_149734_3_ + 0.0F + p_149734_5_.nextFloat() * 6.0F / 16.0F;
  345.             float f2 = (float) p_149734_4_ + 0.5F;
  346.             float f3 = 0.52F;
  347.             float f4 = p_149734_5_.nextFloat() * 0.6F - 0.3F;
  348.  
  349.             if (l == 4)
  350.             {
  351.                 p_149734_1_.spawnParticle("smoke", (double) (f - f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  352.                 p_149734_1_.spawnParticle("flame", (double) (f - f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  353.             }
  354.             else if (l == 5)
  355.             {
  356.                 p_149734_1_.spawnParticle("smoke", (double) (f + f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  357.                 p_149734_1_.spawnParticle("flame", (double) (f + f3), (double) f1, (double) (f2 + f4), 0.0D, 0.0D, 0.0D);
  358.             }
  359.             else if (l == 2)
  360.             {
  361.                 p_149734_1_.spawnParticle("smoke", (double) (f + f4), (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
  362.                 p_149734_1_.spawnParticle("flame", (double) (f + f4), (double) f1, (double) (f2 - f3), 0.0D, 0.0D, 0.0D);
  363.             }
  364.             else if (l == 3)
  365.             {
  366.                 p_149734_1_.spawnParticle("smoke", (double) (f + f4), (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
  367.                 p_149734_1_.spawnParticle("flame", (double) (f + f4), (double) f1, (double) (f2 + f3), 0.0D, 0.0D, 0.0D);
  368.             }
  369.         }
  370.     }
  371. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement