Advertisement
Battledamaged10

My BlockMonitor Code

Aug 13th, 2015
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.45 KB | None | 0 0
  1. package com.battledamaged10.btech.blocks;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.block.properties.IProperty;
  6. import net.minecraft.block.properties.PropertyDirection;
  7. import net.minecraft.block.properties.PropertyInteger;
  8. import net.minecraft.block.state.BlockState;
  9. import net.minecraft.block.state.IBlockState;
  10. import net.minecraft.entity.EntityLivingBase;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.item.ItemDye;
  13. import net.minecraft.item.ItemStack;
  14. import net.minecraft.tileentity.TileEntity;
  15. import net.minecraft.util.BlockPos;
  16. import net.minecraft.util.EnumFacing;
  17. import net.minecraft.world.IBlockAccess;
  18. import net.minecraft.world.World;
  19.  
  20. public class BlockMonitor extends Block{
  21.  
  22.     public static final PropertyInteger COLOR = PropertyInteger.create("color", 0, 15);
  23.     public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);
  24.    
  25.     public BlockMonitor(Material materialIn) {
  26.         super(materialIn);
  27.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(COLOR, Integer.valueOf(0)));
  28.     }
  29.    
  30.     @Override
  31.     public boolean isOpaqueCube()
  32.     {
  33.         return false;
  34.     }
  35.  
  36.     @Override
  37.     public boolean isFullCube()
  38.     {
  39.         return false;
  40.     }
  41.    
  42.     @Override
  43.     public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ){
  44.         ItemStack currentItem = player.getCurrentEquippedItem();
  45.         if (currentItem != null){
  46.             if (currentItem.getItem() instanceof ItemDye){
  47.                 world.setBlockState(pos, state.withProperty(COLOR, 15 - currentItem.getItemDamage()));
  48.                 currentItem.stackSize--;
  49.                 return true;
  50.             }
  51.         }
  52.         return false;
  53.     }
  54.    
  55.     @Override
  56.     public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
  57.     {
  58.         IBlockState state = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer);
  59.         state = state.withProperty(FACING, placer.getHorizontalFacing());
  60.         return state.withProperty(COLOR, Integer.valueOf(0));
  61.     }
  62.  
  63.     @Override
  64.     public int getMetaFromState(IBlockState state)
  65.     {
  66.         return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex();
  67.     }
  68.  
  69.     @Override
  70.     protected BlockState createBlockState()
  71.     {
  72.         return new BlockState(this, new IProperty[] { FACING, COLOR });
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement