Advertisement
Guest User

Untitled

a guest
Feb 24th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.40 KB | None | 0 0
  1. /*
  2.  *  This file is created by MajorSquirrel on 24/02/2016 at 13:51, licensed under MIT License (MIT).
  3.  *
  4.  *  Copyright (c) 2015 MajorSquirrel
  5.  *
  6.  *  Permission is hereby granted, free of charge, to any person obtaining a copy
  7.  *  of this software and associated documentation files (the "Software"), to deal
  8.  *  in the Software without restriction, including without limitation the rights
  9.  *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.  *  copies of the Software, and to permit persons to whom the Software is
  11.  *  furnished to do so, subject to the following conditions:
  12.  * 
  13.  *  The above copyright notice and this permission notice shall be included in all
  14.  *  copies or substantial portions of the Software.
  15.  * 
  16.  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.  *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22.  *  SOFTWARE.
  23.  */
  24.  
  25. package net.theviolentsquirrels.questsystem.block;
  26.  
  27. import net.minecraft.block.BlockContainer;
  28. import net.minecraft.block.material.Material;
  29. import net.minecraft.block.properties.PropertyEnum;
  30. import net.minecraft.block.state.BlockState;
  31. import net.minecraft.block.state.IBlockState;
  32. import net.minecraft.client.resources.model.ModelBakery;
  33. import net.minecraft.client.resources.model.ModelResourceLocation;
  34. import net.minecraft.item.Item;
  35. import net.minecraft.tileentity.TileEntity;
  36. import net.minecraft.util.IStringSerializable;
  37. import net.minecraft.world.World;
  38. import net.theviolentsquirrels.questsystem.Main;
  39. import net.theviolentsquirrels.questsystem.Reference;
  40. import net.theviolentsquirrels.questsystem.utility.CustomStrings;
  41.  
  42. public class                            BlockBarrel extends BlockContainer {
  43.     public static final PropertyEnum    TYPE = PropertyEnum.create("type", EnumType.class);
  44.  
  45.     public                              BlockBarrel(String unlocalizedName) {
  46.         super (Material.wood);
  47.         this.setUnlocalizedName(unlocalizedName);
  48.         this.setCreativeTab(Main.tab);
  49.         this.setHardness(2.0f);
  50.         this.setResistance(10.0f);
  51.         this.setHarvestLevel("axe", 0);
  52.         this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.ZERO));
  53.     }
  54.  
  55.     /**
  56.      * Returns a new instance of a block's tile entity class. Called on placing the block.
  57.      *
  58.      * @param                           worldIn
  59.      * @param                           meta
  60.      */
  61.     @Override
  62.     public TileEntity                   createNewTileEntity(World worldIn, int meta) {
  63.         return (null);
  64.     }
  65.  
  66.     /**
  67.      * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
  68.      */
  69.     @Override
  70.     public int                          getRenderType() {
  71.         return (3);
  72.     }
  73.  
  74.     @Override
  75.     protected BlockState                createBlockState() {
  76.         return (new BlockState(this, TYPE));
  77.     }
  78.  
  79.     /**
  80.      * Convert the given metadata into a BlockState for this Block
  81.      *
  82.      * @param                           meta
  83.      */
  84.     @Override
  85.     public IBlockState                  getStateFromMeta(int meta) {
  86.         return (this.getDefaultState().withProperty(TYPE, EnumType.byMetadata(meta)));
  87.     }
  88.  
  89.     /**
  90.      * Convert the BlockState into the correct metadata value
  91.      *
  92.      * @param                           state
  93.      */
  94.     @Override
  95.     public int                          getMetaFromState(IBlockState state) {
  96.         return (((EnumType) state.getValue(TYPE)).getMetadata());
  97.     }
  98.  
  99.     public void                         registerItemVariants() {
  100.         String                          unlocalizedName, resourceString;
  101.  
  102.         unlocalizedName = CustomStrings.substringUnlocalizedName(this.getUnlocalizedName());
  103.         resourceString = Reference.MODID + ':' + unlocalizedName;
  104.         ModelBakery.registerItemVariants(Item.getItemFromBlock(this),
  105.                 new ModelResourceLocation(resourceString, "inventory"));
  106.     }
  107.  
  108.     public enum                         EnumType implements IStringSerializable {
  109.         ZERO(0, "zero"),
  110.         ONE(1, "one"),
  111.         TWO(2, "two");
  112.  
  113.         private final int               meta;
  114.         private final String            name;
  115.         private static final EnumType[] META_LOOKUP = new EnumType[values().length];
  116.  
  117.         static {
  118.             for (EnumType type : values())
  119.                 META_LOOKUP[type.getMetadata()] = type;
  120.         }
  121.  
  122.         EnumType(int meta, String name) {
  123.             this.meta = meta;
  124.             this.name = name;
  125.         }
  126.  
  127.         @Override
  128.         public String                   getName() {
  129.             return (this.name);
  130.         }
  131.  
  132.         public int                      getMetadata() {
  133.             return (this.meta);
  134.         }
  135.  
  136.         public static EnumType          byMetadata(int meta) {
  137.             if (meta < 0 || meta >= META_LOOKUP.length) meta = 0;
  138.             return (META_LOOKUP[meta]);
  139.         }
  140.  
  141.         @Override
  142.         public String                   toString() {
  143.             return (this.getName());
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement