TheGoldCrayon

BlockRune

Jun 8th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.43 KB | None | 0 0
  1. package com.TheGoldCrayon.Daemonology.blocks;
  2.  
  3. import java.util.List;
  4.  
  5. import com.TheGoldCrayon.Daemonology.DaemonologyMod;
  6. import com.TheGoldCrayon.Daemonology.handlers.EnumHandler;
  7.  
  8. import net.minecraft.block.Block;
  9. import net.minecraft.block.material.Material;
  10. import net.minecraft.block.properties.IProperty;
  11. import net.minecraft.block.properties.PropertyEnum;
  12. import net.minecraft.block.state.BlockState;
  13. import net.minecraft.block.state.IBlockState;
  14. import net.minecraft.creativetab.CreativeTabs;
  15. import net.minecraft.entity.player.EntityPlayer;
  16. import net.minecraft.init.Blocks;
  17. import net.minecraft.item.Item;
  18. import net.minecraft.item.ItemStack;
  19. import net.minecraft.util.AxisAlignedBB;
  20. import net.minecraft.util.BlockPos;
  21. import net.minecraft.util.EnumWorldBlockLayer;
  22. import net.minecraft.util.MovingObjectPosition;
  23. import net.minecraft.world.World;
  24. import net.minecraftforge.fml.relauncher.Side;
  25. import net.minecraftforge.fml.relauncher.SideOnly;
  26.  
  27. public class BlockRune extends Block implements IMetaBlockName
  28. {
  29.  
  30.     public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumHandler.BlockRuneTypes.class);
  31.    
  32.     public BlockRune(String unlocalizedName)
  33.     {
  34.         super(Material.circuits);
  35.         this.setUnlocalizedName(unlocalizedName);
  36.         this.setCreativeTab(DaemonologyMod.tabDaemonology);
  37.         this.setBlockBounds(0f, 0f, 0f, 1f, 0.05f, 1f);
  38.         this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumHandler.BlockRuneTypes.BLACK));
  39.        
  40.     }
  41.    
  42.     @Override
  43.     public void getSubBlocks(Item item, CreativeTabs tab, List<ItemStack> list)
  44.     {
  45.         list.add(new ItemStack(item, 1, 0));
  46.         list.add(new ItemStack(item, 1, 1));
  47.     }
  48.    
  49.     public boolean isOpaqueCube()
  50.     {
  51.         return false;
  52.     }
  53.  
  54.     public boolean isFullCube()
  55.     {
  56.         return false;
  57.     }
  58.    
  59.     @SideOnly(Side.CLIENT)
  60.     public EnumWorldBlockLayer getBlockLayer()
  61.     {
  62.         return EnumWorldBlockLayer.CUTOUT;
  63.     }
  64.    
  65.     public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
  66.     {
  67.         return null;
  68.     }
  69.    
  70.     public boolean canPlaceBlockAt(World worldIn, BlockPos pos)
  71.     {
  72.         return World.doesBlockHaveSolidTopSurface(worldIn, pos.down()) || worldIn.getBlockState(pos.down()).getBlock() == Blocks.glowstone;
  73.     }
  74.    
  75.     @Override
  76.     protected BlockState createBlockState()
  77.     {
  78.         return new BlockState(this, new IProperty[] { TYPE });
  79.     }
  80.    
  81.     @Override
  82.     public IBlockState getStateFromMeta(int meta)
  83.     {
  84.         if (meta == 0)
  85.         {
  86.             return getDefaultState().withProperty(TYPE, EnumHandler.BlockRuneTypes.BLACK);
  87.         }
  88.         if (meta == 1)
  89.         {
  90.             return getDefaultState().withProperty(TYPE, EnumHandler.BlockRuneTypes.RED);
  91.         }
  92.         return getDefaultState().withProperty(TYPE, EnumHandler.BlockRuneTypes.BLACK);
  93.         }
  94.    
  95.     @Override
  96.     public int getMetaFromState(IBlockState state)
  97.     {
  98.         EnumHandler.BlockRuneTypes type = (EnumHandler.BlockRuneTypes) state.getValue(TYPE);
  99.         return type.getID();
  100.     }
  101.    
  102.     @Override
  103.     public int damageDropped(IBlockState state)
  104.     {
  105.         return this.getMetaFromState(state);
  106.     }
  107.    
  108.     @Override
  109.     public String getSpecialName(ItemStack stack)
  110.     {
  111.         if(stack.getItemDamage() == 0)
  112.         {
  113.             return "black";
  114.         }
  115.         if(stack.getItemDamage() == 1)
  116.         {
  117.             return "red";
  118.         }
  119.         return "black";
  120.     }
  121.    
  122.     @Override
  123.     public ItemStack getPickBlock(MovingObjectPosition target, World world, BlockPos pos, EntityPlayer player)
  124.     {
  125.         return new ItemStack(Item.getItemFromBlock(this), 1, this.getMetaFromState(world.getBlockState(pos)));
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment