Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. package net.theviolentsquirrels.questsystem.block;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.block.properties.PropertyEnum;
  6. import net.minecraft.block.state.BlockState;
  7. import net.minecraft.block.state.IBlockState;
  8. import net.minecraft.util.IStringSerializable;
  9. import net.theviolentsquirrels.questsystem.Main;
  10.  
  11. public class                            BlockBarrel extends Block {
  12.     public static final PropertyEnum    TYPE = PropertyEnum.create("mode", EnumType.class);
  13.  
  14.     public                              BlockBarrel(String unlocalizedName) {
  15.         super (Material.wood);
  16.         this.setUnlocalizedName(unlocalizedName);
  17.         this.setCreativeTab(Main.tab);
  18.         this.setHardness(2.0f);
  19.         this.setResistance(10.0f);
  20.         this.setHarvestLevel("axe", 0);
  21.         this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.NORMAL));
  22.     }
  23.  
  24.     /**
  25.      * Called throughout the code as a replacement for block instanceof BlockContainer
  26.      * Moving this to the Block base class allows for mods that wish to extend vanilla
  27.      * blocks, and also want to have a tile entity on that block, may.
  28.      * <p/>
  29.      * Return true from this function to specify this block has a tile entity.
  30.      *
  31.      * @param state State of the current block
  32.      * @return True if block has a tile entity, false otherwise
  33.      */
  34.     @Override
  35.     public boolean                      hasTileEntity(IBlockState state) {
  36.         return (false);
  37.     }
  38.  
  39.     /**
  40.      * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
  41.      */
  42.     @Override
  43.     public int                          getRenderType() {
  44.         return (3);
  45.     }
  46.  
  47.     @Override
  48.     protected BlockState                createBlockState() {
  49.         return (new BlockState(this, TYPE));
  50.     }
  51.  
  52.     /**
  53.      * Convert the given metadata into a BlockState for this Block
  54.      *
  55.      * @param                           meta
  56.      */
  57.     @Override
  58.     public IBlockState                  getStateFromMeta(int meta) {
  59.         return (this.getDefaultState().withProperty(TYPE, EnumType.byMetadata(meta)));
  60.     }
  61.  
  62.     /**
  63.      * Convert the BlockState into the correct metadata value
  64.      *
  65.      * @param                           state
  66.      */
  67.     @Override
  68.     public int                          getMetaFromState(IBlockState state) {
  69.         return (((EnumType) state.getValue(TYPE)).getMetadata());
  70.     }
  71.  
  72.     public enum                         EnumType implements IStringSerializable {
  73.         NORMAL(0, "normal"),
  74.         FERMENTED(1, "fermented");
  75.  
  76.         private final int               meta;
  77.         private final String            name;
  78.         private static final EnumType[] META_LOOKUP = new EnumType[values().length];
  79.  
  80.         static {
  81.             for (EnumType type : values())
  82.                 META_LOOKUP[type.getMetadata()] = type;
  83.         }
  84.  
  85.         EnumType(int meta, String name) {
  86.             this.meta = meta;
  87.             this.name = name;
  88.         }
  89.  
  90.         @Override
  91.         public String                   getName() {
  92.             return (this.name);
  93.         }
  94.  
  95.         public int                      getMetadata() {
  96.             return (this.meta);
  97.         }
  98.  
  99.         public static EnumType          byMetadata(int meta) {
  100.             if (meta < 0 || meta >= META_LOOKUP.length) meta = 0;
  101.             return (META_LOOKUP[meta]);
  102.         }
  103.  
  104.         @Override
  105.         public String                   toString() {
  106.             return (this.getName());
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement