Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This file is created by MajorSquirrel on 24/02/2016 at 13:51, licensed under MIT License (MIT).
- *
- * Copyright (c) 2015 MajorSquirrel
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
- package net.theviolentsquirrels.questsystem.block;
- import net.minecraft.block.BlockContainer;
- import net.minecraft.block.material.Material;
- import net.minecraft.block.properties.PropertyEnum;
- import net.minecraft.block.state.BlockState;
- import net.minecraft.block.state.IBlockState;
- import net.minecraft.client.resources.model.ModelBakery;
- import net.minecraft.client.resources.model.ModelResourceLocation;
- import net.minecraft.item.Item;
- import net.minecraft.tileentity.TileEntity;
- import net.minecraft.util.IStringSerializable;
- import net.minecraft.world.World;
- import net.theviolentsquirrels.questsystem.Main;
- import net.theviolentsquirrels.questsystem.Reference;
- import net.theviolentsquirrels.questsystem.utility.CustomStrings;
- public class BlockBarrel extends BlockContainer {
- public static final PropertyEnum TYPE = PropertyEnum.create("type", EnumType.class);
- public BlockBarrel(String unlocalizedName) {
- super (Material.wood);
- this.setUnlocalizedName(unlocalizedName);
- this.setCreativeTab(Main.tab);
- this.setHardness(2.0f);
- this.setResistance(10.0f);
- this.setHarvestLevel("axe", 0);
- this.setDefaultState(this.blockState.getBaseState().withProperty(TYPE, EnumType.ZERO));
- }
- /**
- * Returns a new instance of a block's tile entity class. Called on placing the block.
- *
- * @param worldIn
- * @param meta
- */
- @Override
- public TileEntity createNewTileEntity(World worldIn, int meta) {
- return (null);
- }
- /**
- * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
- */
- @Override
- public int getRenderType() {
- return (3);
- }
- @Override
- protected BlockState createBlockState() {
- return (new BlockState(this, TYPE));
- }
- /**
- * Convert the given metadata into a BlockState for this Block
- *
- * @param meta
- */
- @Override
- public IBlockState getStateFromMeta(int meta) {
- return (this.getDefaultState().withProperty(TYPE, EnumType.byMetadata(meta)));
- }
- /**
- * Convert the BlockState into the correct metadata value
- *
- * @param state
- */
- @Override
- public int getMetaFromState(IBlockState state) {
- return (((EnumType) state.getValue(TYPE)).getMetadata());
- }
- public void registerItemVariants() {
- String unlocalizedName, resourceString;
- unlocalizedName = CustomStrings.substringUnlocalizedName(this.getUnlocalizedName());
- resourceString = Reference.MODID + ':' + unlocalizedName;
- ModelBakery.registerItemVariants(Item.getItemFromBlock(this),
- new ModelResourceLocation(resourceString, "inventory"));
- }
- public enum EnumType implements IStringSerializable {
- ZERO(0, "zero"),
- ONE(1, "one"),
- TWO(2, "two");
- private final int meta;
- private final String name;
- private static final EnumType[] META_LOOKUP = new EnumType[values().length];
- static {
- for (EnumType type : values())
- META_LOOKUP[type.getMetadata()] = type;
- }
- EnumType(int meta, String name) {
- this.meta = meta;
- this.name = name;
- }
- @Override
- public String getName() {
- return (this.name);
- }
- public int getMetadata() {
- return (this.meta);
- }
- public static EnumType byMetadata(int meta) {
- if (meta < 0 || meta >= META_LOOKUP.length) meta = 0;
- return (META_LOOKUP[meta]);
- }
- @Override
- public String toString() {
- return (this.getName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement