Guest User

Untitled

a guest
Nov 10th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. package com.mrpablo2000.machinecraft.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import javax.swing.Icon;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockContainer;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.client.renderer.texture.IIconRegister;
  11. import net.minecraft.entity.EntityLivingBase;
  12. import net.minecraft.entity.item.EntityItem;
  13. import net.minecraft.entity.player.EntityPlayer;
  14. import net.minecraft.inventory.Container;
  15. import net.minecraft.inventory.IInventory;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.nbt.NBTTagCompound;
  18. import net.minecraft.tileentity.TileEntity;
  19. import net.minecraft.tileentity.TileEntityFurnace;
  20. import net.minecraft.util.IIcon;
  21. import net.minecraft.util.MathHelper;
  22. import net.minecraft.world.World;
  23.  
  24. import com.mrpablo2000.machinecraft.MachineCraftBase;
  25. import com.mrpablo2000.machinecraft.tileentity.TileEntityMacerator;
  26.  
  27. import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
  28. import cpw.mods.fml.relauncher.Side;
  29. import cpw.mods.fml.relauncher.SideOnly;
  30.  
  31. public class BlockGenerator extends BlockContainer{
  32.  
  33. private final Random maceratorRand = new Random();
  34.  
  35. private final boolean isActive;
  36.  
  37. private static boolean keepMaceratorInventory;
  38. @SideOnly(Side.CLIENT)
  39. private IIcon field_149935_N;
  40. @SideOnly(Side.CLIENT)
  41. private IIcon field_149936_O;
  42.  
  43. public BlockGenerator(boolean isActive) {
  44. super(Material.rock);
  45.  
  46. this.isActive = isActive;
  47. }
  48.  
  49. @SideOnly(Side.CLIENT)
  50. public IIcon getIcon(int p_149691_1_, int p_149691_2_)
  51. {
  52. 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));
  53. }
  54.  
  55. @SideOnly(Side.CLIENT)
  56. public void registerBlockIcons(IIconRegister p_149651_1_)
  57. {
  58. this.blockIcon = p_149651_1_.registerIcon("mcbase:macerator_side");
  59. this.field_149936_O = p_149651_1_.registerIcon(this.isActive ? "mcbase:macerator_front_active" : "mcbase:macerator_front_idle");
  60. this.field_149935_N = p_149651_1_.registerIcon("mcbase:macerator_side");
  61. }
  62. /**
  63. * Called whenever the block is added into the world. Args: world, x, y, z
  64. */
  65. public void onBlockAdded(World par1World, int par2, int par3, int par4)
  66. {
  67. super.onBlockAdded(par1World, par2, par3, par4);
  68. this.setDefaultDirection(par1World, par2, par3, par4);
  69. }
  70.  
  71. /**
  72. * set a blocks direction
  73. */
  74. private void setDefaultDirection(World p_149930_1_, int p_149930_2_, int p_149930_3_, int p_149930_4_)
  75. {
  76. if (!p_149930_1_.isRemote)
  77. {
  78. Block block = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ - 1);
  79. Block block1 = p_149930_1_.getBlock(p_149930_2_, p_149930_3_, p_149930_4_ + 1);
  80. Block block2 = p_149930_1_.getBlock(p_149930_2_ - 1, p_149930_3_, p_149930_4_);
  81. Block block3 = p_149930_1_.getBlock(p_149930_2_ + 1, p_149930_3_, p_149930_4_);
  82. byte b0 = 3;
  83.  
  84. if (block.func_149730_j() && !block1.func_149730_j())
  85. {
  86. b0 = 3;
  87. }
  88.  
  89. if (block1.func_149730_j() && !block.func_149730_j())
  90. {
  91. b0 = 2;
  92. }
  93.  
  94. if (block2.func_149730_j() && !block3.func_149730_j())
  95. {
  96. b0 = 5;
  97. }
  98.  
  99. if (block3.func_149730_j() && !block2.func_149730_j())
  100. {
  101. b0 = 4;
  102. }
  103.  
  104. p_149930_1_.setBlockMetadataWithNotify(p_149930_2_, p_149930_3_, p_149930_4_, b0, 2);
  105. }
  106. }
  107.  
  108.  
  109. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
  110.  
  111. FMLNetworkHandler.openGui(player, MachineCraftBase.instance, 1, world, x, y, z);
  112. return true;
  113. }
  114.  
  115. /**
  116. * Update which block ID the furnace is using depending on whether or not it is burning
  117. */
  118. public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
  119. {
  120. int l = par1World.getBlockMetadata(par2, par3, par4);
  121. TileEntity tileentity = par1World.getTileEntity(par2, par3, par4);
  122. keepMaceratorInventory = true;
  123.  
  124. if (par0)
  125. {
  126. par1World.setBlock(par2, par3, par4, MachineCraftBase.blockGeneratorActive);
  127. }
  128. else
  129. {
  130. par1World.setBlock(par2, par3, par4, MachineCraftBase.blockGeneratorIdle);
  131. }
  132.  
  133. keepMaceratorInventory = false;
  134. par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);
  135.  
  136. if (tileentity != null)
  137. {
  138. tileentity.validate();
  139. par1World.setTileEntity(par2, par3, par4, tileentity);
  140. }
  141. }
  142.  
  143. /**
  144. * Returns a new instance of a block's tile entity class. Called on placing the block.
  145. */
  146. @Override
  147. public TileEntity createNewTileEntity(World par1World, int i)
  148. {
  149. return new com.mrpablo2000.machinecraft.tileentity.TileEntityMacerator();
  150. }
  151.  
  152. /**
  153. * Called when the block is placed in the world.
  154. */
  155. public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
  156. {
  157. int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
  158.  
  159. if (l == 0)
  160. {
  161. par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
  162. }
  163.  
  164. if (l == 1)
  165. {
  166. par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
  167. }
  168.  
  169. if (l == 2)
  170. {
  171. par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
  172. }
  173.  
  174. if (l == 3)
  175. {
  176. par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
  177. }
  178.  
  179. if (par6ItemStack.hasDisplayName())
  180. {
  181. ((TileEntityFurnace)par1World.getTileEntity(par2, par3, par4)).func_145951_a(par6ItemStack.getDisplayName());
  182. }
  183. }
  184.  
  185. /**
  186. * ejects contained items into the world, and notifies neighbours of an update, as appropriate
  187. */
  188. 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_)
  189. {
  190. if (!keepMaceratorInventory)
  191. {
  192. TileEntityMacerator tileentityfurnace = (TileEntityMacerator)p_149749_1_.getTileEntity(p_149749_2_, p_149749_3_, p_149749_4_);
  193.  
  194. if (tileentityfurnace != null)
  195. {
  196. for (int i1 = 0; i1 < tileentityfurnace.getSizeInventory(); ++i1)
  197. {
  198. ItemStack itemstack = tileentityfurnace.getStackInSlot(i1);
  199.  
  200. if (itemstack != null)
  201. {
  202. float f = this.maceratorRand.nextFloat() * 0.8F + 0.1F;
  203. float f1 = this.maceratorRand.nextFloat() * 0.8F + 0.1F;
  204. float f2 = this.maceratorRand.nextFloat() * 0.8F + 0.1F;
  205.  
  206. while (itemstack.stackSize > 0)
  207. {
  208. int j1 = this.maceratorRand.nextInt(21) + 10;
  209.  
  210. if (j1 > itemstack.stackSize)
  211. {
  212. j1 = itemstack.stackSize;
  213. }
  214.  
  215. itemstack.stackSize -= j1;
  216. 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()));
  217.  
  218. if (itemstack.hasTagCompound())
  219. {
  220. entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  221. }
  222.  
  223. float f3 = 0.05F;
  224. entityitem.motionX = (double)((float)this.maceratorRand.nextGaussian() * f3);
  225. entityitem.motionY = (double)((float)this.maceratorRand.nextGaussian() * f3 + 0.2F);
  226. entityitem.motionZ = (double)((float)this.maceratorRand.nextGaussian() * f3);
  227. p_149749_1_.spawnEntityInWorld(entityitem);
  228. }
  229. }
  230. }
  231.  
  232. p_149749_1_.func_147453_f(p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_);
  233. }
  234. }
  235.  
  236. super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
  237. }
  238. /**
  239. * If this returns true, then comparators facing away from this block will use the value from
  240. * getComparatorInputOverride instead of the actual redstone signal strength.
  241. */
  242. public boolean hasComparatorInputOverride()
  243. {
  244. return true;
  245. }
  246.  
  247. /**
  248. * If hasComparatorInputOverride returns true, the return value from this is used instead of the redstone signal
  249. * strength when this block inputs to a comparator.
  250. */
  251. public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
  252. {
  253. return Container.calcRedstoneFromInventory((IInventory)par1World.getTileEntity(par2, par3, par4));
  254. }
  255.  
  256. }
Add Comment
Please, Sign In to add comment