/* * This file ("BlockCrystal.java") is part of the Actually Additions Mod for Minecraft. * It is created and owned by Ellpeck and distributed * under the Actually Additions License to be found at * http://ellpeck.de/actaddlicense/ * View the source code at https://github.com/Ellpeck/ActuallyAdditions * * © 2016 Ellpeck */ package de.ellpeck.actuallyadditions.mod.blocks; import de.ellpeck.actuallyadditions.mod.blocks.base.BlockBase; import de.ellpeck.actuallyadditions.mod.blocks.base.ItemBlockBase; import de.ellpeck.actuallyadditions.mod.items.metalists.TheCrystals; import de.ellpeck.actuallyadditions.mod.util.StringUtil; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.List; public class BlockCrystal extends BlockBase{ public static final TheCrystals[] allCrystals = TheCrystals.values(); private static final PropertyInteger META = PropertyInteger.create("meta", 0, allCrystals.length-1); public BlockCrystal(String name){ super(Material.rock, name); this.setHardness(1.5F); this.setResistance(10.0F); this.setHarvestLevel("pickaxe", 1); } @Override protected PropertyInteger getMetaProperty(){ return META; } @Override public int damageDropped(IBlockState state){ return this.getMetaFromState(state); } @Override @SideOnly(Side.CLIENT) public int getRenderColor(IBlockState state){ int meta = this.getMetaFromState(state); return meta >= allCrystals.length ? super.getRenderColor(state) : allCrystals[meta].color; } @Override @SideOnly(Side.CLIENT) public int colorMultiplier(IBlockAccess world, BlockPos pos, int renderPass){ return this.getRenderColor(world.getBlockState(pos)); } @SuppressWarnings("all") @SideOnly(Side.CLIENT) public void getSubBlocks(Item item, CreativeTabs tab, List list){ for(int j = 0; j < allCrystals.length; j++){ list.add(new ItemStack(item, 1, j)); } } @Override public Class getItemBlock(){ return TheItemBlock.class; } @Override public EnumRarity getRarity(ItemStack stack){ return stack.getItemDamage() >= allCrystals.length ? EnumRarity.COMMON : allCrystals[stack.getItemDamage()].rarity; } public static class TheItemBlock extends ItemBlockBase{ public TheItemBlock(Block block){ super(block); this.setHasSubtypes(true); this.setMaxDamage(0); } @Override public String getUnlocalizedName(ItemStack stack){ return stack.getItemDamage() >= allCrystals.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+allCrystals[stack.getItemDamage()].name; } } }