Guest User

Untitled

a guest
Aug 8th, 2014
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. package com.jack.jackmod.block;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.jack.jackmod.init.ModBlocks;
  6. import com.jack.jackmod.reference.Reference;
  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.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.nbt.NBTTagCompound;
  17. import net.minecraft.tileentity.TileEntity;
  18. import net.minecraft.util.IIcon;
  19. import net.minecraft.util.MathHelper;
  20. import net.minecraft.world.World;
  21. import com.jack.jackmod.JackMod;
  22. import com.jack.jackmod.tileentity.TileEntityHydrogenSeparator;
  23. import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
  24. import cpw.mods.fml.relauncher.Side;
  25. import cpw.mods.fml.relauncher.SideOnly;
  26.  
  27. public class BlockHydrogenSeparator extends BlockContainer {
  28.  
  29. private final boolean isActive;
  30.  
  31. @SideOnly(Side.CLIENT)
  32. private IIcon iconFront;
  33.  
  34. @SideOnly(Side.CLIENT)
  35. private IIcon iconTop;
  36.  
  37. private static boolean keepInventory;
  38. private Random rand = new Random();
  39.  
  40. public AlabasterOven(boolean isActive) {
  41. super(Material.iron);
  42.  
  43. this.isActive = isActive;
  44. }
  45.  
  46. @SideOnly(Side.CLIENT)
  47. public void registerBlockIcons(IIconRegister iconRegister) {
  48. this.blockIcon = iconRegister.registerIcon(Reference.MOD_ID + ":" + "hydrogenSeparatorSide");
  49. this.iconFront = iconRegister.registerIcon(Reference.MOD_ID + ":" + (this.isActive ? "hydrogenSeparatorFrontActive" : "hydrogenSeparatorFront"));
  50. this.iconTop = iconRegister.registerIcon(Reference.MOD_ID + ":" + "hydrogenSeparator");
  51. }
  52.  
  53. @SideOnly(Side.CLIENT)
  54. public IIcon getIcon(int side, int metadata) {
  55. return metadata == 0 && side == 3 ? this.iconFront : side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side == metadata ? this.iconFront : this.blockIcon));
  56. //return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side != metadata ? this.blockIcon : this.iconFront));
  57. }
  58.  
  59. public Item getItemDropped(int i, Random random, int j) {
  60. return Item.getItemFromBlock(ModBlocks.hydrogenSeparatorIdle);
  61. }
  62.  
  63. public void onBlockAdded(World world, int x, int y, int z) {
  64. super.onBlockAdded(world, x, y, z);
  65. this.setDefaultDirection(world, x, y, z);
  66. }
  67.  
  68. private void setDefaultDirection(World world, int x, int y, int z) {
  69. if(!world.isRemote) {
  70. Block b1 = world.getBlock(x, y, z - 1);
  71. Block b2 = world.getBlock(x, y, z + 1);
  72. Block b3 = world.getBlock(x - 1, y, z);
  73. Block b4 = world.getBlock(x + 1, y, z);
  74.  
  75. byte b0 = 3;
  76.  
  77. if(b1.func_149730_j() && !b2.func_149730_j()) {
  78. b0 = 3;
  79. }
  80.  
  81. if(b2.func_149730_j() && !b1.func_149730_j()) {
  82. b0 = 2;
  83. }
  84.  
  85. if(b3.func_149730_j() && !b4.func_149730_j()) {
  86. b0 = 5;
  87. }
  88.  
  89. if(b4.func_149730_j() && !b3.func_149730_j()) {
  90. b0 = 4;
  91. }
  92.  
  93. world.setBlockMetadataWithNotify(x, y, x, b0, 2);
  94. }
  95.  
  96. }
  97.  
  98. public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
  99. if(!world.isRemote) {
  100. FMLNetworkHandler.openGui(player, JackMod.instance, Reference.GUI_ID_HYDROGEN_SEPARATOR, world, x, y, z);
  101. }
  102. return true;
  103. }
  104.  
  105. @Override
  106. public TileEntity createNewTileEntity(World world, int i) {
  107. return new TileEntityHydrogenSeparator();
  108. }
  109.  
  110. @SideOnly(Side.CLIENT)
  111. public void randomDisplayTick(World world, int x, int y, int z, Random random) {
  112. if(this.isActive) {
  113. int direction = world.getBlockMetadata(x, y, z);
  114.  
  115. float x1 = (float)x + 0.5F;
  116. float y1 = (float)y + random.nextFloat();
  117. float z1 = (float)z + 0.5F;
  118.  
  119. float f = 0.52F;
  120. float f1 = random.nextFloat() * 0.6F - 0.3F;
  121.  
  122. if(direction == 4){
  123. world.spawnParticle("smoke", (double)(x1 - f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
  124. world.spawnParticle("flame", (double)(x1 - f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
  125. }
  126.  
  127. if(direction == 5){
  128. world.spawnParticle("smoke", (double)(x1 + f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
  129. world.spawnParticle("flame", (double)(x1 + f), (double)(y1), (double)(z1 + f1), 0D, 0D, 0D);
  130. }
  131.  
  132. if(direction == 2){
  133. world.spawnParticle("smoke", (double)(x1 + f1), (double)(y1), (double)(z1 - f), 0D, 0D, 0D);
  134. world.spawnParticle("flame", (double)(x1 + f1), (double)(y1), (double)(z1 - f), 0D, 0D, 0D);
  135. }
  136.  
  137. if(direction == 3){
  138. world.spawnParticle("smoke", (double)(x1 + f1), (double)(y1), (double)(z1 + f), 0D, 0D, 0D);
  139. world.spawnParticle("flame", (double)(x1 + f1), (double)(y1), (double)(z1 + f), 0D, 0D, 0D);
  140. }
  141. }
  142. }
  143.  
  144. public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) {
  145. int l = MathHelper.floor_double((double)(entityplayer.rotationYaw * 4.0F / 360.F) + 0.5D) & 3;
  146.  
  147. if(l == 0) {
  148. world.setBlockMetadataWithNotify(x, y, z, 2, 2);
  149. }
  150.  
  151. if(l == 1) {
  152. world.setBlockMetadataWithNotify(x, y, z, 5, 2);
  153. }
  154.  
  155. if(l == 2) {
  156. world.setBlockMetadataWithNotify(x, y, z, 3, 2);
  157. }
  158.  
  159. if(l == 3) {
  160. world.setBlockMetadataWithNotify(x, y, z, 4, 2);
  161. }
  162.  
  163. if(itemstack.hasDisplayName()) {
  164. /*
  165.  
  166. THE ERROR IS HERE V V V V
  167.  
  168. */
  169. ((TileEntity) world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName());
  170. }
  171. }
  172.  
  173. public static void updateHydrogenSeparatorBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) {
  174. int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
  175.  
  176. TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord);
  177. keepInventory = true;
  178.  
  179. if(active) {
  180. worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.hydrogenSeparatorActive);
  181. }else{
  182. worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.hydrogenSeparatorIdle);
  183. }
  184.  
  185. keepInventory = false;
  186.  
  187. worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2);
  188.  
  189. if(tileentity != null) {
  190. tileentity.validate();
  191. worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity);
  192. }
  193. }
  194.  
  195. public void breakBlock(World world, int x, int y, int z, Block oldblock, int oldMetadata) {
  196. if(!keepInventory) {
  197. TileEntityHydrogenSeparator tileentity = (TileEntityHydrogenSeparator) world.getTileEntity(x, y, z);
  198.  
  199. if(tileentity != null) {
  200. for(int i = 0; i < tileentity.getSizeInventory(); i++) {
  201. ItemStack itemstack = tileentity.getStackInSlot(i);
  202.  
  203. if(itemstack != null) {
  204. float f = this.rand.nextFloat() * 0.8F + 0.1F;
  205. float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
  206. float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
  207.  
  208. while(itemstack.stackSize > 0) {
  209. int j = this.rand.nextInt(21) + 10;
  210.  
  211. if(j > itemstack.stackSize) {
  212. j = itemstack.stackSize;
  213. }
  214.  
  215. itemstack.stackSize -= j;
  216.  
  217. EntityItem item = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage()));
  218.  
  219. if(itemstack.hasTagCompound()) {
  220. item.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
  221. }
  222.  
  223. world.spawnEntityInWorld(item);
  224. }
  225. }
  226. }
  227.  
  228. world.func_147453_f(x, y, z, oldblock);
  229. }
  230. }
  231.  
  232. super.breakBlock(world, x, y, z, oldblock, oldMetadata);
  233. }
  234.  
  235. public Item getItem(World world, int x, int y, int z) {
  236. return Item.getItemFromBlock(ModBlocks.hydrogenSeparatorIdle);
  237. }
  238.  
  239. }
Advertisement
Add Comment
Please, Sign In to add comment