grossik

Untitled

Nov 17th, 2016
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.98 KB | None | 0 0
  1. package cz.grossik.farmcraft2.pan;
  2.  
  3. import java.util.Random;
  4.  
  5. import javax.annotation.Nullable;
  6.  
  7. import cz.grossik.farmcraft2.Main;
  8. import cz.grossik.farmcraft2.crushing.TileEntityCrushing;
  9. import cz.grossik.farmcraft2.handler.BlockHandler;
  10. import cz.grossik.farmcraft2.handler.FC2_GuiHandler;
  11. import cz.grossik.farmcraft2.handler.ItemHandler;
  12. import net.minecraft.block.BlockContainer;
  13. import net.minecraft.block.material.Material;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.entity.EntityLivingBase;
  16. import net.minecraft.entity.item.EntityItem;
  17. import net.minecraft.entity.player.EntityPlayer;
  18. import net.minecraft.inventory.Container;
  19. import net.minecraft.inventory.InventoryHelper;
  20. import net.minecraft.inventory.Slot;
  21. import net.minecraft.item.ItemStack;
  22. import net.minecraft.tileentity.TileEntity;
  23. import net.minecraft.util.EnumBlockRenderType;
  24. import net.minecraft.util.EnumFacing;
  25. import net.minecraft.util.EnumHand;
  26. import net.minecraft.util.EnumParticleTypes;
  27. import net.minecraft.util.math.BlockPos;
  28. import net.minecraft.world.EnumSkyBlock;
  29. import net.minecraft.world.IBlockAccess;
  30. import net.minecraft.world.World;
  31. import net.minecraftforge.common.util.FakePlayer;
  32. import net.minecraftforge.fml.relauncher.Side;
  33. import net.minecraftforge.fml.relauncher.SideOnly;
  34.  
  35. public class BlockPan extends BlockContainer
  36. {
  37. private static boolean keepInventory;
  38.  
  39. public BlockPan()
  40. {
  41. super(Material.ROCK);
  42. setUnlocalizedName("pan");
  43. setCreativeTab(Main.FarmCraft2Tab);
  44. setHardness(2f);
  45. setResistance(10f);
  46. }
  47.  
  48. public TileEntity createNewTileEntity(World worldIn, int meta)
  49. {
  50. return new TileEntityPan();
  51. }
  52.  
  53. @SuppressWarnings("deprecation")
  54. @Override
  55. public boolean isOpaqueCube(IBlockState state)
  56. {
  57. return false;
  58. }
  59.  
  60. public static void setState(boolean active, World worldIn, BlockPos pos)
  61. {
  62. IBlockState iblockstate = worldIn.getBlockState(pos);
  63. TileEntity tileentity = worldIn.getTileEntity(pos);
  64. keepInventory = true;
  65.  
  66. if (active)
  67. {
  68. worldIn.setBlockState(pos, BlockHandler.Pan.getDefaultState(), 3);
  69. worldIn.setBlockState(pos, BlockHandler.Pan.getDefaultState(), 3);
  70. }
  71. else
  72. {
  73. worldIn.setBlockState(pos, BlockHandler.Pan.getDefaultState(), 3);
  74. worldIn.setBlockState(pos, BlockHandler.Pan.getDefaultState(), 3);
  75. }
  76.  
  77. keepInventory = false;
  78.  
  79. if (tileentity != null)
  80. {
  81. tileentity.validate();
  82. worldIn.setTileEntity(pos, tileentity);
  83. }
  84. }
  85.  
  86. public EnumBlockRenderType getRenderType(IBlockState state)
  87. {
  88. return EnumBlockRenderType.MODEL;
  89. }
  90.  
  91. public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
  92. {
  93. TileEntityPan te = (TileEntityPan) world.getTileEntity(pos);
  94. return te == null || !te.isBurning() ? 0 : 14;
  95. }
  96.  
  97. public boolean isPassable(IBlockAccess worldIn, BlockPos pos)
  98. {
  99. return true;
  100. }
  101.  
  102. public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
  103. {
  104. TileEntityPan te = (TileEntityPan) world.getTileEntity(pos);
  105. Container container = te.createContainer(player.inventory, player);
  106. Slot slot = (Slot)container.inventorySlots.get(0);
  107. Slot slot2 = (Slot)container.inventorySlots.get(2);
  108.  
  109. ItemStack is_p = slot.getStack();
  110.  
  111. if(heldItem != null && heldItem.getItem().equals(ItemHandler.DfPancakes) && !te.isBurning() && is_p == null)
  112. {
  113. ItemStack is = heldItem.splitStack(1);
  114. slot.putStack(is);
  115. } else if(heldItem == null && te.Check() == true){
  116. ItemStack is_2 = slot2.getStack();
  117.  
  118. EntityItem entityitem = new EntityItem(world, player.posX, player.posY - 1.0D, player.posZ, is_2.copy());
  119. if (!(player instanceof FakePlayer))
  120. entityitem.onCollideWithPlayer(player);
  121.  
  122. } else {
  123. if(!world.isRemote){
  124. player.openGui(Main.MODID, FC2_GuiHandler.PANGUI, world, pos.getX(), pos.getY(), pos.getZ());
  125. }
  126. }
  127.  
  128. return true;
  129. }
  130.  
  131. private void spawnParticle(World world, BlockPos pos, Random rand, boolean isFire)
  132. {
  133. double x = pos.getX() + 0.5F + (rand.nextFloat() * 0.6F -0.3F);
  134. double y = pos.getY() + 0.15F;
  135. double z = pos.getZ() + 0.5F + (rand.nextFloat() * -0.6F - -0.3F);
  136. EnumParticleTypes type;
  137. if(isFire)
  138. type = EnumParticleTypes.FLAME;
  139. else
  140. type = EnumParticleTypes.SMOKE_NORMAL;
  141. world.spawnParticle(type, x, y, z, 0, 0, 0, new int[0]);
  142. }
  143.  
  144. public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  145. {
  146. if (stack.hasDisplayName())
  147. {
  148. TileEntity tileentity = worldIn.getTileEntity(pos);
  149.  
  150. if (tileentity instanceof TileEntityCrushing)
  151. {
  152. ((TileEntityPan)tileentity).setCustomInventoryName(stack.getDisplayName());
  153. }
  154. }
  155. }
  156.  
  157. @SideOnly(Side.CLIENT)
  158. public void randomDisplayTick(IBlockState state, World worldIn, BlockPos pos, Random rand)
  159. {
  160. worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
  161. worldIn.checkLightFor(EnumSkyBlock.BLOCK, pos);
  162.  
  163. boolean cooking = ((TileEntityPan) worldIn.getTileEntity(pos)).isBurning();
  164. if(cooking)
  165. {
  166. for(int i = 0; i < rand.nextInt(10); i++)
  167. {
  168. spawnParticle(worldIn, pos, rand, true);
  169. }
  170. for(int i = 1; i < rand.nextInt(10); i++)
  171. {
  172. spawnParticle(worldIn, pos, rand, false);
  173. }
  174. }
  175. }
  176.  
  177. public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
  178. {
  179. if (!keepInventory)
  180. {
  181. TileEntity tileentity = worldIn.getTileEntity(pos);
  182.  
  183. if (tileentity instanceof TileEntityPan)
  184. {
  185. InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityPan)tileentity);
  186. worldIn.updateComparatorOutputLevel(pos, this);
  187. }
  188. }
  189.  
  190. super.breakBlock(worldIn, pos, state);
  191. }
  192.  
  193. public boolean hasComparatorInputOverride(IBlockState state)
  194. {
  195. return true;
  196. }
  197.  
  198. public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
  199. {
  200. return Container.calcRedstone(worldIn.getTileEntity(pos));
  201. }
  202.  
  203. public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
  204. {
  205. return new ItemStack(BlockHandler.Pan);
  206. }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment