Guest User

SauceMaker

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