Advertisement
Nuparu00

BlockSmallRock

Apr 28th, 2018
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package com.nuparu.sevendaystomine.block;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.nuparu.sevendaystomine.SevenDaysToMine;
  6. import com.nuparu.sevendaystomine.init.Items;
  7.  
  8. import net.minecraft.block.material.Material;
  9. import net.minecraft.block.properties.IProperty;
  10. import net.minecraft.block.properties.PropertyEnum;
  11. import net.minecraft.block.state.BlockStateContainer;
  12. import net.minecraft.block.state.IBlockState;
  13. import net.minecraft.creativetab.CreativeTabs;
  14. import net.minecraft.item.Item;
  15. import net.minecraft.item.ItemStack;
  16. import net.minecraft.util.IStringSerializable;
  17. import net.minecraft.util.NonNullList;
  18. import net.minecraft.util.math.BlockPos;
  19. import net.minecraft.world.World;
  20. import net.minecraftforge.fml.relauncher.Side;
  21. import net.minecraftforge.fml.relauncher.SideOnly;
  22.  
  23. public class BlockSmallRock extends BlockPickable {
  24.  
  25.     public static final PropertyEnum<EnumType> VARIANT = PropertyEnum.<EnumType>create("variant",
  26.             BlockSmallRock.EnumType.class);
  27.  
  28.     public BlockSmallRock() {
  29.         super(Material.ROCK);
  30.         this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, EnumType.STONE));
  31.         this.setCreativeTab(SevenDaysToMine.TAB_BUILDING);
  32.     }
  33.  
  34.     public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  35.         return Items.SMALL_STONE;
  36.     }
  37.  
  38.     @Override
  39.     public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
  40.         return new ItemStack(Items.SMALL_STONE);
  41.     }
  42.  
  43.     @SideOnly(Side.CLIENT)
  44.     public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list) {
  45.         for (EnumType enumtype : EnumType.values()) {
  46.             list.add(new ItemStack(this, 1, enumtype.getMetadata()));
  47.         }
  48.     }
  49.  
  50.     public IBlockState getStateFromMeta(int meta) {
  51.         return this.getDefaultState().withProperty(VARIANT, EnumType.byMetadata(meta));
  52.     }
  53.  
  54.     public int getMetaFromState(IBlockState state) {
  55.         return ((EnumType) state.getValue(VARIANT)).getMetadata();
  56.     }
  57.  
  58.     protected BlockStateContainer createBlockState() {
  59.         return new BlockStateContainer(this, new IProperty[] { VARIANT });
  60.     }
  61.  
  62.     public static enum EnumType implements IStringSerializable {
  63.         STONE("stone",0), GRANITE("granite",1), DIORITE("diorite",2), ANDESITE("andesite",3);
  64.        
  65.         private static final BlockSmallRock.EnumType[] META_LOOKUP = new BlockSmallRock.EnumType[values().length];
  66.        
  67.         private final String name;
  68.         private final int metadata;
  69.  
  70.         EnumType(String name, int meta) {
  71.             this.name = name;
  72.             this.metadata = meta;
  73.         }
  74.  
  75.         @Override
  76.         public String getName() {
  77.             return name;
  78.         }
  79.        
  80.         public int getMetadata() {
  81.             return metadata;
  82.         }
  83.        
  84.         public static BlockSmallRock.EnumType byMetadata(int meta)
  85.         {
  86.             if (meta < 0 || meta >= META_LOOKUP.length)
  87.             {
  88.                 meta = 0;
  89.             }
  90.  
  91.             return META_LOOKUP[meta];
  92.         }
  93.        
  94.         static
  95.         {
  96.             for (BlockSmallRock.EnumType enumtype : values())
  97.             {
  98.                 META_LOOKUP[enumtype.getMetadata()] = enumtype;
  99.             }
  100.         }
  101.     }
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement