ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockCrystal.java

101 lines
3.3 KiB
Java
Raw Normal View History

2015-11-09 18:05:52 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("BlockCrystal.java") is part of the Actually Additions mod for Minecraft.
2015-11-09 18:05:52 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-11-09 18:05:52 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2015-11-09 18:05:52 +01:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.blocks;
2015-11-09 18:05:52 +01:00
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
2016-01-05 04:47:35 +01:00
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;
2015-11-09 18:05:52 +01:00
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
2015-11-09 18:05:52 +01:00
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
2016-11-19 21:11:17 +01:00
import net.minecraft.util.NonNullList;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2015-11-09 18:05:52 +01:00
import java.util.List;
public class BlockCrystal extends BlockBase{
2015-11-09 18:05:52 +01:00
2016-06-17 23:50:38 +02:00
public static final TheCrystals[] ALL_CRYSTALS = TheCrystals.values();
private static final PropertyInteger META = PropertyInteger.create("meta", 0, ALL_CRYSTALS.length-1);
2015-11-09 18:05:52 +01:00
private final boolean isEmpowered;
public BlockCrystal(String name, boolean isEmpowered){
2016-04-20 21:39:03 +02:00
super(Material.ROCK, name);
this.isEmpowered = isEmpowered;
2015-11-09 18:05:52 +01:00
this.setHardness(1.5F);
this.setResistance(10.0F);
this.setHarvestLevel("pickaxe", 1);
}
@Override
public int damageDropped(IBlockState state){
return this.getMetaFromState(state);
2015-11-09 18:05:52 +01:00
}
@Override
2015-11-09 18:05:52 +01:00
@SideOnly(Side.CLIENT)
2016-11-19 21:11:17 +01:00
public void getSubBlocks(Item item, CreativeTabs tab, NonNullList list){
2016-06-17 23:50:38 +02:00
for(int j = 0; j < ALL_CRYSTALS.length; j++){
2015-11-09 18:05:52 +01:00
list.add(new ItemStack(item, 1, j));
}
}
@Override
2016-04-20 21:39:03 +02:00
protected ItemBlockBase getItemBlock(){
return new TheItemBlock(this);
}
2016-02-01 17:49:55 +01:00
@Override
protected void registerRendering(){
2016-06-17 23:50:38 +02:00
for(int i = 0; i < ALL_CRYSTALS.length; i++){
ActuallyAdditions.proxy.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), META.getName()+"="+i);
2016-02-01 17:49:55 +01:00
}
}
2015-11-09 18:05:52 +01:00
@Override
2015-12-19 10:30:39 +01:00
public EnumRarity getRarity(ItemStack stack){
2016-06-17 23:50:38 +02:00
return stack.getItemDamage() >= ALL_CRYSTALS.length ? EnumRarity.COMMON : ALL_CRYSTALS[stack.getItemDamage()].rarity;
2015-11-09 18:05:52 +01:00
}
@Override
2016-02-01 17:49:55 +01:00
protected PropertyInteger getMetaProperty(){
return META;
}
2015-11-09 18:05:52 +01:00
public static class TheItemBlock extends ItemBlockBase{
public TheItemBlock(Block block){
super(block);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
public String getUnlocalizedName(ItemStack stack){
2016-06-17 23:50:38 +02:00
return stack.getItemDamage() >= ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getUnlocalizedName()+ALL_CRYSTALS[stack.getItemDamage()].name;
2015-11-09 18:05:52 +01:00
}
@Override
public boolean hasEffect(ItemStack stack){
return this.block instanceof BlockCrystal && ((BlockCrystal)this.block).isEmpowered;
}
2015-11-09 18:05:52 +01:00
}
}