ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemCrystalShard.java

69 lines
2.4 KiB
Java
Raw Normal View History

2017-02-13 23:17:08 +01:00
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.BlockCrystal;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.IColorProvidingItem;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.renderer.color.IItemColor;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
2019-05-02 09:08:15 +02:00
import net.minecraftforge.common.IRarity;
2017-02-13 23:17:08 +01:00
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
2019-05-02 09:10:29 +02:00
public class ItemCrystalShard extends ItemBase implements IColorProvidingItem {
2017-02-13 23:17:08 +01:00
2019-05-02 09:10:29 +02:00
public ItemCrystalShard(String name) {
2017-02-13 23:17:08 +01:00
super(name);
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@Override
2019-05-02 09:10:29 +02:00
public int getMetadata(int damage) {
2017-02-13 23:17:08 +01:00
return damage;
}
@Override
2019-05-02 09:10:29 +02:00
public String getTranslationKey(ItemStack stack) {
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length ? StringUtil.BUGGED_ITEM_NAME : this.getTranslationKey() + "_" + BlockCrystal.ALL_CRYSTALS[stack.getItemDamage()].name;
2017-02-13 23:17:08 +01:00
}
@Override
2019-05-02 09:08:15 +02:00
public IRarity getForgeRarity(ItemStack stack) {
2017-02-13 23:17:08 +01:00
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length ? EnumRarity.COMMON : BlockCrystal.ALL_CRYSTALS[stack.getItemDamage()].rarity;
}
@Override
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> list) {
if (this.isInCreativeTab(tab)) {
for (int j = 0; j < BlockCrystal.ALL_CRYSTALS.length; j++) {
2017-06-17 00:48:49 +02:00
list.add(new ItemStack(this, 1, j));
}
2017-02-13 23:17:08 +01:00
}
}
@Override
2019-05-02 09:10:29 +02:00
protected void registerRendering() {
for (int i = 0; i < BlockCrystal.ALL_CRYSTALS.length; i++) {
2018-05-10 11:38:58 +02:00
ActuallyAdditions.PROXY.addRenderRegister(new ItemStack(this, 1, i), this.getRegistryName(), "inventory");
2017-02-13 23:17:08 +01:00
}
}
@Override
@SideOnly(Side.CLIENT)
2019-05-02 09:10:29 +02:00
public IItemColor getItemColor() {
2019-02-27 19:53:05 +01:00
return (stack, tintIndex) -> {
int damage = stack.getItemDamage();
2019-05-02 09:10:29 +02:00
if (damage >= 0 && damage < BlockCrystal.ALL_CRYSTALS.length) {
2019-02-27 19:53:05 +01:00
return BlockCrystal.ALL_CRYSTALS[damage].clusterColor;
2019-05-02 09:10:29 +02:00
} else {
2019-02-27 19:53:05 +01:00
return 0;
2017-02-13 23:17:08 +01:00
}
};
}
}