Advertisement
Guest User

Untitled

a guest
Feb 16th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.00 KB | None | 0 0
  1. package com.expansion.blocks;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.expansion.tileentity.TileEntityGrinder;
  6.  
  7. import net.minecraft.block.Block;
  8. import net.minecraft.block.BlockContainer;
  9. import net.minecraft.block.BlockFurnace;
  10. import net.minecraft.block.material.Material;
  11. import net.minecraft.block.properties.IProperty;
  12. import net.minecraft.block.properties.PropertyDirection;
  13. import net.minecraft.block.state.BlockState;
  14. import net.minecraft.block.state.IBlockState;
  15. import net.minecraft.entity.EntityLivingBase;
  16. import net.minecraft.entity.player.EntityPlayer;
  17. import net.minecraft.entity.player.InventoryPlayer;
  18. import net.minecraft.init.Blocks;
  19. import net.minecraft.init.Items;
  20. import net.minecraft.inventory.Container;
  21. import net.minecraft.inventory.ContainerFurnace;
  22. import net.minecraft.inventory.IInventory;
  23. import net.minecraft.inventory.InventoryHelper;
  24. import net.minecraft.inventory.SlotFurnaceFuel;
  25. import net.minecraft.item.Item;
  26. import net.minecraft.item.ItemBlock;
  27. import net.minecraft.item.ItemHoe;
  28. import net.minecraft.item.ItemStack;
  29. import net.minecraft.item.ItemSword;
  30. import net.minecraft.item.ItemTool;
  31. import net.minecraft.nbt.NBTTagCompound;
  32. import net.minecraft.nbt.NBTTagList;
  33. import net.minecraft.tileentity.TileEntity;
  34. import net.minecraft.tileentity.TileEntityFurnace;
  35. import net.minecraft.util.BlockPos;
  36. import net.minecraft.util.EnumFacing;
  37. import net.minecraft.util.EnumParticleTypes;
  38. import net.minecraft.util.IChatComponent;
  39. import net.minecraft.util.MathHelper;
  40. import net.minecraft.world.World;
  41. import net.minecraftforge.fml.relauncher.Side;
  42. import net.minecraftforge.fml.relauncher.SideOnly;
  43.  
  44. public class MachineGrinder extends BlockContainer  {
  45.  
  46.    
  47.  
  48.     public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  49.     private final boolean isBurning;
  50.     private static boolean keepInventory;
  51.     private static final String __OBFID = "CL_00000248";
  52.  
  53.     protected MachineGrinder(boolean isBurning)
  54.     {
  55.         super(Material.rock);
  56.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  57.         this.isBurning = isBurning;
  58.     }
  59.  
  60.     public Item getItemDropped(IBlockState state, Random rand, int fortune)
  61.     {
  62.         return Item.getItemFromBlock(BlockList.GrinderOff);
  63.     }
  64.  
  65.     public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  66.     {
  67.         this.setDefaultFacing(worldIn, pos, state);
  68.     }
  69.  
  70.     private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
  71.     {
  72.         if (!worldIn.isRemote)
  73.         {
  74.             Block block = worldIn.getBlockState(pos.north()).getBlock();
  75.             Block block1 = worldIn.getBlockState(pos.south()).getBlock();
  76.             Block block2 = worldIn.getBlockState(pos.west()).getBlock();
  77.             Block block3 = worldIn.getBlockState(pos.east()).getBlock();
  78.             EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  79.  
  80.             if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock())
  81.             {
  82.                 enumfacing = EnumFacing.SOUTH;
  83.             }
  84.             else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock())
  85.             {
  86.                 enumfacing = EnumFacing.NORTH;
  87.             }
  88.             else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock())
  89.             {
  90.                 enumfacing = EnumFacing.EAST;
  91.             }
  92.             else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock())
  93.             {
  94.                 enumfacing = EnumFacing.WEST;
  95.             }
  96.  
  97.             worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
  98.         }
  99.     }
  100.  
  101.     @SideOnly(Side.CLIENT)
  102.     public void randomDisplayTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
  103.     {
  104.         if (this.isBurning)
  105.         {
  106.             EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  107.             double d0 = (double)pos.getX() + 0.5D;
  108.             double d1 = (double)pos.getY() + rand.nextDouble() * 6.0D / 16.0D;
  109.             double d2 = (double)pos.getZ() + 0.5D;
  110.             double d3 = 0.52D;
  111.             double d4 = rand.nextDouble() * 0.6D - 0.3D;
  112.  
  113.             switch (MachineGrinder.SwitchEnumFacing.FACING_LOOKUP[enumfacing.ordinal()])
  114.             {
  115.                 case 1:
  116.                     worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  117.                     worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  118.                     break;
  119.                 case 2:
  120.                     worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  121.                     worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);
  122.                     break;
  123.                 case 3:
  124.                     worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D, new int[0]);
  125.                     worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D, new int[0]);
  126.                     break;
  127.                 case 4:
  128.                     worldIn.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D, new int[0]);
  129.                     worldIn.spawnParticle(EnumParticleTypes.FLAME, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D, new int[0]);
  130.             }
  131.         }
  132.     }
  133.  
  134.     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
  135.     {
  136.         if (worldIn.isRemote)
  137.         {
  138.             return true;
  139.         }
  140.         else
  141.         {
  142.             TileEntity tileentity = worldIn.getTileEntity(pos);
  143.  
  144.             if (tileentity instanceof TileEntityFurnace)
  145.             {
  146.                 playerIn.displayGUIChest((TileEntityFurnace)tileentity);
  147.             }
  148.  
  149.             return true;
  150.         }
  151.     }
  152.  
  153.     public static void setState(boolean active, World worldIn, BlockPos pos)
  154.     {
  155.         IBlockState iblockstate = worldIn.getBlockState(pos);
  156.         TileEntity tileentity = worldIn.getTileEntity(pos);
  157.         keepInventory = true;
  158.  
  159.         if (active)
  160.         {
  161.             worldIn.setBlockState(pos, BlockList.GrinderOn.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  162.             worldIn.setBlockState(pos, BlockList.GrinderOn.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  163.         }
  164.         else
  165.         {
  166.             worldIn.setBlockState(pos, BlockList.GrinderOff.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  167.             worldIn.setBlockState(pos, BlockList.GrinderOff.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  168.         }
  169.  
  170.         keepInventory = false;
  171.  
  172.         if (tileentity != null)
  173.         {
  174.             tileentity.validate();
  175.             worldIn.setTileEntity(pos, tileentity);
  176.         }
  177.     }
  178.  
  179.     public TileEntity createNewTileEntity(World worldIn, int meta)
  180.     {
  181.         return new TileEntityGrinder();
  182.     }
  183.  
  184.     public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  185.     {
  186.         return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  187.     }
  188.  
  189.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  190.     {
  191.         worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  192.  
  193.         if (stack.hasDisplayName())
  194.         {
  195.             TileEntity tileentity = worldIn.getTileEntity(pos);
  196.  
  197.             if (tileentity instanceof TileEntityGrinder)
  198.             {
  199.                 ((TileEntityGrinder)tileentity).setCustomInventoryName(stack.getDisplayName());
  200.             }
  201.         }
  202.     }
  203.  
  204.     public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
  205.     {
  206.         if (!keepInventory)
  207.         {
  208.             TileEntity tileentity = worldIn.getTileEntity(pos);
  209.  
  210.             if (tileentity instanceof TileEntityGrinder)
  211.             {
  212.                 InventoryHelper.dropInventoryItems(worldIn, pos, (TileEntityGrinder)tileentity);
  213.                 worldIn.updateComparatorOutputLevel(pos, this);
  214.             }
  215.         }
  216.  
  217.         super.breakBlock(worldIn, pos, state);
  218.     }
  219.  
  220.     public boolean hasComparatorInputOverride()
  221.     {
  222.         return true;
  223.     }
  224.  
  225.     public int getComparatorInputOverride(World worldIn, BlockPos pos)
  226.     {
  227.         return Container.calcRedstone(worldIn.getTileEntity(pos));
  228.     }
  229.  
  230.     @SideOnly(Side.CLIENT)
  231.     public Item getItem(World worldIn, BlockPos pos)
  232.     {
  233.         return Item.getItemFromBlock(BlockList.GrinderOff);
  234.     }
  235.  
  236.     public int getRenderType()
  237.     {
  238.         return 3;
  239.     }
  240.  
  241.     @SideOnly(Side.CLIENT)
  242.     public IBlockState getStateForEntityRender(IBlockState state)
  243.     {
  244.         return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH);
  245.     }
  246.  
  247.     public IBlockState getStateFromMeta(int meta)
  248.     {
  249.         EnumFacing enumfacing = EnumFacing.getFront(meta);
  250.  
  251.         if (enumfacing.getAxis() == EnumFacing.Axis.Y)
  252.         {
  253.             enumfacing = EnumFacing.NORTH;
  254.         }
  255.  
  256.         return this.getDefaultState().withProperty(FACING, enumfacing);
  257.     }
  258.  
  259.     public int getMetaFromState(IBlockState state)
  260.     {
  261.         return ((EnumFacing)state.getValue(FACING)).getIndex();
  262.     }
  263.  
  264.     protected BlockState createBlockState()
  265.     {
  266.         return new BlockState(this, new IProperty[] {FACING});
  267.     }
  268.  
  269.     @SideOnly(Side.CLIENT)
  270.  
  271.     static final class SwitchEnumFacing
  272.         {
  273.             static final int[] FACING_LOOKUP = new int[EnumFacing.values().length];
  274.             private static final String __OBFID = "CL_00002111";
  275.  
  276.             static
  277.             {
  278.                 try
  279.                 {
  280.                     FACING_LOOKUP[EnumFacing.WEST.ordinal()] = 1;
  281.                 }
  282.                 catch (NoSuchFieldError var4)
  283.                 {
  284.                     ;
  285.                 }
  286.  
  287.                 try
  288.                 {
  289.                     FACING_LOOKUP[EnumFacing.EAST.ordinal()] = 2;
  290.                 }
  291.                 catch (NoSuchFieldError var3)
  292.                 {
  293.                     ;
  294.                 }
  295.  
  296.                 try
  297.                 {
  298.                     FACING_LOOKUP[EnumFacing.NORTH.ordinal()] = 3;
  299.                 }
  300.                 catch (NoSuchFieldError var2)
  301.                 {
  302.                     ;
  303.                 }
  304.  
  305.                 try
  306.                 {
  307.                     FACING_LOOKUP[EnumFacing.SOUTH.ordinal()] = 4;
  308.                 }
  309.                 catch (NoSuchFieldError var1)
  310.                 {
  311.                     ;
  312.                 }
  313.             }
  314.         }
  315.  
  316.    
  317. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement