Advertisement
Guest User

Untitled

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