ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrystal.java
2018-05-10 05:38:58 -04:00

108 lines
3.6 KiB
Java

/*
* 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
*
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
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.PropertyEnum;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public class BlockCrystal extends BlockBase{
public static final TheCrystals[] ALL_CRYSTALS = TheCrystals.values();
private static final PropertyEnum<TheCrystals> TYPE = PropertyEnum.create("type", TheCrystals.class);
private final boolean isEmpowered;
public BlockCrystal(String name, boolean isEmpowered){
super(Material.ROCK, name);
this.isEmpowered = isEmpowered;
this.setHardness(1.5F);
this.setResistance(10.0F);
this.setHarvestLevel("pickaxe", 1);
}
@Override
public int damageDropped(IBlockState state){
return this.getMetaFromState(state);
}
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> list){
for(int j = 0; j < ALL_CRYSTALS.length; j++){
list.add(new ItemStack(this, 1, j));
}
}
@Override
protected ItemBlockBase getItemBlock(){
return new TheItemBlock(this);
}
@Override
public void registerRendering(){
for(int i = 0; i < ALL_CRYSTALS.length; i++){
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), TYPE.getName()+"="+ALL_CRYSTALS[i].name);
}
}
@Override
public IBlockState getStateFromMeta(int meta){
return this.getDefaultState().withProperty(TYPE, TheCrystals.values()[meta]);
}
@Override
public int getMetaFromState(IBlockState state){
return state.getValue(TYPE).ordinal();
}
@Override
protected BlockStateContainer createBlockState(){
return new BlockStateContainer(this, TYPE);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return stack.getItemDamage() >= ALL_CRYSTALS.length ? EnumRarity.COMMON : ALL_CRYSTALS[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() >= ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+"_"+ALL_CRYSTALS[stack.getItemDamage()].name;
}
@Override
public boolean hasEffect(ItemStack stack){
return this.block instanceof BlockCrystal && ((BlockCrystal)this.block).isEmpowered;
}
}
}