Guest User

BlockGrinder

a guest
Aug 20th, 2015
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [code]package com.vladan899.blocks.properties;
  2.  
  3. import java.util.Random;
  4.  
  5.  
  6. import com.vladan899.blocks.BlockList;
  7. import com.vladan899.main.Main;
  8. import com.vladan899.tileentity.TileEntitySmasher;
  9.  
  10. import net.minecraft.block.Block;
  11. import net.minecraft.block.BlockContainer;
  12. import net.minecraft.block.material.Material;
  13. import net.minecraft.block.properties.IProperty;
  14. import net.minecraft.block.properties.PropertyDirection;
  15. import net.minecraft.block.state.BlockState;
  16. import net.minecraft.block.state.IBlockState;
  17. import net.minecraft.entity.EntityLivingBase;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.init.Blocks;
  20. import net.minecraft.inventory.Container;
  21. import net.minecraft.item.Item;
  22. import net.minecraft.item.ItemStack;
  23. import net.minecraft.tileentity.TileEntity;
  24. import net.minecraft.tileentity.TileEntityFurnace;
  25. import net.minecraft.util.BlockPos;
  26. import net.minecraft.util.EnumFacing;
  27. import net.minecraft.world.World;
  28. import net.minecraftforge.fml.relauncher.Side;
  29. import net.minecraftforge.fml.relauncher.SideOnly;
  30.  
  31. public class BlockMachineSmasher 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.    
  37.     public BlockMachineSmasher(boolean isBurning ) {
  38.         super(Material.iron);
  39.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH));
  40.         this.isBurning = isBurning;
  41.     }
  42.  
  43.     @Override
  44.     public TileEntity createNewTileEntity(World worldIn, int meta)
  45.     {
  46.         // TODO Auto-generated method stub
  47.         return new TileEntitySmasher();
  48.     }
  49.    
  50.     public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
  51.     {
  52.         if (!world.isRemote)
  53.         {
  54.             playerIn.openGui(Main.instance, BlockList.GuiIDSmasher, world, pos.getX(), pos.getY(), pos.getZ());
  55.         }
  56.         return true;
  57.        
  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, BlockList.SmasherOn.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  69.            
  70.         }
  71.         else
  72.         {
  73.             worldIn.setBlockState(pos, BlockList.SmasherOff.getDefaultState().withProperty(FACING, iblockstate.getValue(FACING)), 3);
  74.         }
  75.  
  76.         keepInventory = false;
  77.  
  78.         if (tileentity != null)
  79.         {
  80.             tileentity.validate();
  81.             worldIn.setTileEntity(pos, tileentity);
  82.         }
  83.     }
  84.    
  85.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
  86.     {
  87.         worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  88.  
  89.         if (stack.hasDisplayName())
  90.         {
  91.             TileEntity tileentity = worldIn.getTileEntity(pos);
  92.  
  93.             if (tileentity instanceof TileEntitySmasher)
  94.             {
  95.                 ((TileEntitySmasher)tileentity).setCustomInventoryName(stack.getDisplayName());
  96.             }
  97.         }
  98.     }
  99.    
  100.     public Item getItemDropped(IBlockState state, Random rand, int fortune)
  101.     {
  102.         return Item.getItemFromBlock(BlockList.SmasherOff);
  103.     }
  104.  
  105.     public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
  106.     {
  107.         this.setDefaultFacing(worldIn, pos, state);
  108.     }
  109.    
  110.     public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  111.     {
  112.         return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  113.     }
  114.    
  115.    
  116.     public boolean hasComparatorInputOverride()
  117.     {
  118.         return true;
  119.     }
  120.  
  121.     public int getComparatorInputOverride(World worldIn, BlockPos pos)
  122.     {
  123.         return Container.calcRedstone(worldIn.getTileEntity(pos));
  124.     }
  125.  
  126.     @SideOnly(Side.CLIENT)
  127.     public Item getItem(World worldIn, BlockPos pos)
  128.     {
  129.         return Item.getItemFromBlock(BlockList.SmasherOff);
  130.     }
  131.  
  132.     private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
  133.     {
  134.         if (!worldIn.isRemote)
  135.         {
  136.             Block block = worldIn.getBlockState(pos.north()).getBlock();
  137.             Block block1 = worldIn.getBlockState(pos.south()).getBlock();
  138.             Block block2 = worldIn.getBlockState(pos.west()).getBlock();
  139.             Block block3 = worldIn.getBlockState(pos.east()).getBlock();
  140.             EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
  141.  
  142.             if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock())
  143.             {
  144.                 enumfacing = EnumFacing.SOUTH;
  145.             }
  146.             else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock())
  147.             {
  148.                 enumfacing = EnumFacing.NORTH;
  149.             }
  150.             else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock())
  151.             {
  152.                 enumfacing = EnumFacing.EAST;
  153.             }
  154.             else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock())
  155.             {
  156.                 enumfacing = EnumFacing.WEST;
  157.             }
  158.  
  159.             worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
  160.         }
  161.     }
  162.    
  163.     public int getRenderType()
  164.     {
  165.         return 3;
  166.     }
  167.    
  168.     public IBlockState getStateFromMeta(int meta)
  169.     {
  170.         EnumFacing enumfacing = EnumFacing.getFront(meta);
  171.  
  172.         if (enumfacing.getAxis() == EnumFacing.Axis.Y)
  173.         {
  174.             enumfacing = EnumFacing.NORTH;
  175.         }
  176.  
  177.         return this.getDefaultState().withProperty(FACING, enumfacing);
  178.     }
  179.    
  180.     public int getMetaFromState(IBlockState state)
  181.     {
  182.         return ((EnumFacing)state.getValue(FACING)).getIndex();
  183.     }
  184.  
  185.     protected BlockState createBlockState()
  186.     {
  187.         return new BlockState(this, new IProperty[] {FACING});
  188.     }
  189.  
  190. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×