Advertisement
Guest User

BlockReactor

a guest
Feb 10th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.30 KB | None | 0 0
  1. package net.minecraft.src;
  2.  
  3. import java.util.Random;
  4.  
  5. public class BlockReactor extends BlockContainer
  6. {
  7.     {
  8.    
  9.     this.setCreativeTab(CreativeTabs.tabBlock);
  10.     }
  11.    
  12.     /**
  13.      * Is the random generator used by furnace to drop the inventory contents in random directions.
  14.      */
  15.     private Random reactorRand = new Random();
  16.  
  17.     /** True if this is an active furnace, false if idle */
  18.     private final boolean isActive;
  19.  
  20.     /**
  21.      * This flag is used to prevent the furnace inventory to be dropped upon block removal, is used internally when the
  22.      * furnace block changes from idle to active and vice-versa.
  23.      */
  24.     private static boolean keepReactorInventory = false;
  25.  
  26.     protected BlockReactor(int par1, boolean par2)
  27.     {
  28.         super(par1, Material.rock);
  29.         this.isActive = par2;
  30.         this.blockIndexInTexture = 188;
  31.     }
  32.  
  33.     /**
  34.      * Returns the ID of the items to drop on destruction.
  35.      */
  36.     public int idDropped(int par1, Random par2Random, int par3)
  37.     {
  38.         return mod_NuculerMain.ReactorIdle.blockID;
  39.     }
  40.  
  41.     /**
  42.      * Called whenever the block is added into the world. Args: world, x, y, z
  43.      */
  44.     public void onBlockAdded(World par1World, int par2, int par3, int par4)
  45.     {
  46.         super.onBlockAdded(par1World, par2, par3, par4);
  47.         this.setDefaultDirection(par1World, par2, par3, par4);
  48.     }
  49.  
  50.     /**
  51.      * set a blocks direction
  52.      */
  53.     private void setDefaultDirection(World par1World, int par2, int par3, int par4)
  54.     {
  55.         if (!par1World.isRemote)
  56.         {
  57.             int var5 = par1World.getBlockId(par2, par3, par4 - 1);
  58.             int var6 = par1World.getBlockId(par2, par3, par4 + 1);
  59.             int var7 = par1World.getBlockId(par2 - 1, par3, par4);
  60.             int var8 = par1World.getBlockId(par2 + 1, par3, par4);
  61.             byte var9 = 3;
  62.  
  63.             if (Block.opaqueCubeLookup[var5] && !Block.opaqueCubeLookup[var6])
  64.             {
  65.                 var9 = 3;
  66.             }
  67.  
  68.             if (Block.opaqueCubeLookup[var6] && !Block.opaqueCubeLookup[var5])
  69.             {
  70.                 var9 = 2;
  71.             }
  72.  
  73.             if (Block.opaqueCubeLookup[var7] && !Block.opaqueCubeLookup[var8])
  74.             {
  75.                 var9 = 5;
  76.             }
  77.  
  78.             if (Block.opaqueCubeLookup[var8] && !Block.opaqueCubeLookup[var7])
  79.             {
  80.                 var9 = 4;
  81.             }
  82.  
  83.             par1World.setBlockMetadataWithNotify(par2, par3, par4, var9);
  84.         }
  85.     }
  86.  
  87.     /**
  88.      * Retrieves the block texture to use based on the display side. Args: iBlockAccess, x, y, z, side
  89.      */
  90.     public int getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
  91.     {
  92.         if (par5 == 1)
  93.         {
  94.             return mod_NuculerMain.RSide;
  95.         }
  96.         else if (par5 == 0)
  97.         {
  98.             return mod_NuculerMain.RSide;
  99.         }
  100.         else
  101.         {
  102.             int var6 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
  103.             return par5 != var6 ? this.blockIndexInTexture : (this.isActive ? mod_NuculerMain.RFrontActive : this.blockIndexInTexture + 2);
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * A randomly called display update to be able to add particles or other items for display
  109.      */
  110.     public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
  111.     {
  112.         if (this.isActive)
  113.         {
  114.             int var6 = par1World.getBlockMetadata(par2, par3, par4);
  115.             float var7 = (float)par2 + 0.5F;
  116.             float var8 = (float)par3 + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
  117.             float var9 = (float)par4 + 0.5F;
  118.             float var10 = 0.52F;
  119.             float var11 = par5Random.nextFloat() * 0.6F - 0.3F;
  120.  
  121.             if (var6 == 4)
  122.             {
  123.                 par1World.spawnParticle("smoke", (double)(var7 - var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
  124.                 par1World.spawnParticle("flame", (double)(var7 - var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
  125.             }
  126.             else if (var6 == 5)
  127.             {
  128.                 par1World.spawnParticle("smoke", (double)(var7 + var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
  129.                 par1World.spawnParticle("flame", (double)(var7 + var10), (double)var8, (double)(var9 + var11), 0.0D, 0.0D, 0.0D);
  130.             }
  131.             else if (var6 == 2)
  132.             {
  133.                 par1World.spawnParticle("smoke", (double)(var7 + var11), (double)var8, (double)(var9 - var10), 0.0D, 0.0D, 0.0D);
  134.                 par1World.spawnParticle("flame", (double)(var7 + var11), (double)var8, (double)(var9 - var10), 0.0D, 0.0D, 0.0D);
  135.             }
  136.             else if (var6 == 3)
  137.             {
  138.                 par1World.spawnParticle("smoke", (double)(var7 + var11), (double)var8, (double)(var9 + var10), 0.0D, 0.0D, 0.0D);
  139.                 par1World.spawnParticle("flame", (double)(var7 + var11), (double)var8, (double)(var9 + var10), 0.0D, 0.0D, 0.0D);
  140.             }
  141.         }
  142.     }
  143.  
  144.     /**
  145.      * Returns the block texture based on the side being looked at.  Args: side
  146.      */
  147.     public int getBlockTextureFromSide(int par1)
  148.     {
  149.         return par1 == 1 ? this.blockIndexInTexture : (par1 == 0 ? this.blockIndexInTexture : (par1 == 3 ? this.blockIndexInTexture + 1 : this.blockIndexInTexture));
  150.     }
  151.  
  152.     /**
  153.      * Called upon block activation (right click on the block.)
  154.      */
  155.     public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
  156.     {
  157.         if (par1World.isRemote)
  158.         {
  159.             return true;
  160.         }
  161.         else
  162.         {
  163.             TileEntityReactor var10 = (TileEntityReactor)par1World.getBlockTileEntity(par2, par3, par4);
  164.  
  165.             if (var10 != null)
  166.             {
  167.                 ModLoader.openGUI(par5EntityPlayer, new GuiReactor(par5EntityPlayer.inventory, var10));
  168.             }
  169.  
  170.             return true;
  171.         }
  172.     }
  173.  
  174.     /**
  175.      * Update which block ID the furnace is using depending on whether or not it is burning
  176.      */
  177.     public static void updateReactorBlockState(boolean par0, World par1World, int par2, int par3, int par4)
  178.     {
  179.         int var5 = par1World.getBlockMetadata(par2, par3, par4);
  180.         TileEntity var6 = par1World.getBlockTileEntity(par2, par3, par4);
  181.         keepReactorInventory = true;
  182.  
  183.         if (par0)
  184.         {
  185.             par1World.setBlockWithNotify(par2, par3, par4, mod_NuculerMain.ReactorActive.blockID);
  186.         }
  187.         else
  188.         {
  189.             par1World.setBlockWithNotify(par2, par3, par4, mod_NuculerMain.ReactorIdle.blockID);
  190.         }
  191.  
  192.         keepReactorInventory = false;
  193.         par1World.setBlockMetadataWithNotify(par2, par3, par4, var5);
  194.  
  195.         if (var6 != null)
  196.         {
  197.             var6.validate();
  198.             par1World.setBlockTileEntity(par2, par3, par4, var6);
  199.         }
  200.     }
  201.  
  202.     /**
  203.      * Returns a new instance of a block's tile entity class. Called on placing the block.
  204.      */
  205.     public TileEntity createNewTileEntity(World par1World)
  206.     {
  207.         return new TileEntityReactor();
  208.     }
  209.  
  210.     /**
  211.      * Called when the block is placed in the world.
  212.      */
  213.     public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
  214.     {
  215.         int var6 = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  216.  
  217.         if (var6 == 0)
  218.         {
  219.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 2);
  220.         }
  221.  
  222.         if (var6 == 1)
  223.         {
  224.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 5);
  225.         }
  226.  
  227.         if (var6 == 2)
  228.         {
  229.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 3);
  230.         }
  231.  
  232.         if (var6 == 3)
  233.         {
  234.             par1World.setBlockMetadataWithNotify(par2, par3, par4, 4);
  235.         }
  236.     }
  237.  
  238.     /**
  239.      * ejects contained items into the world, and notifies neighbours of an update, as appropriate
  240.      */
  241.     public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
  242.     {
  243.         if (!keepReactorInventory)
  244.         {
  245.             TileEntityReactor var7 = (TileEntityReactor)par1World.getBlockTileEntity(par2, par3, par4);
  246.  
  247.             if (var7 != null)
  248.             {
  249.                 for (int var8 = 0; var8 < var7.getSizeInventory(); ++var8)
  250.                 {
  251.                     ItemStack var9 = var7.getStackInSlot(var8);
  252.  
  253.                     if (var9 != null)
  254.                     {
  255.                         float var10 = this.reactorRand.nextFloat() * 0.8F + 0.1F;
  256.                         float var11 = this.reactorRand.nextFloat() * 0.8F + 0.1F;
  257.                         float var12 = this.reactorRand.nextFloat() * 0.8F + 0.1F;
  258.  
  259.                         while (var9.stackSize > 0)
  260.                         {
  261.                             int var13 = this.reactorRand.nextInt(21) + 10;
  262.  
  263.                             if (var13 > var9.stackSize)
  264.                             {
  265.                                 var13 = var9.stackSize;
  266.                             }
  267.  
  268.                             var9.stackSize -= var13;
  269.                             EntityItem var14 = new EntityItem(par1World, (double)((float)par2 + var10), (double)((float)par3 + var11), (double)((float)par4 + var12), new ItemStack(var9.itemID, var13, var9.getItemDamage()));
  270.  
  271.                             if (var9.hasTagCompound())
  272.                             {
  273.                                 var14.getEntityItem().setTagCompound((NBTTagCompound)var9.getTagCompound().copy());
  274.                             }
  275.  
  276.                             float var15 = 0.05F;
  277.                             var14.motionX = (double)((float)this.reactorRand.nextGaussian() * var15);
  278.                             var14.motionY = (double)((float)this.reactorRand.nextGaussian() * var15 + 0.2F);
  279.                             var14.motionZ = (double)((float)this.reactorRand.nextGaussian() * var15);
  280.                             par1World.spawnEntityInWorld(var14);
  281.                            
  282.                            
  283.                         }
  284.                     }
  285.                 }
  286.             }
  287.         }
  288.  
  289.         super.breakBlock(par1World, par2, par3, par4, par5, par6);
  290.     }
  291. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement