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

83 lines
2.7 KiB
Java
Raw Normal View History

2017-02-13 23:17:08 +01:00
/*
* This file ("ItemCrystalShard.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.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
2019-05-02 09:10:29 +02:00
public class ItemCrystalShard extends ItemBase implements IColorProvidingItem {
2017-02-13 23:17:08 +01:00
public ItemCrystalShard() {
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
public String getDescriptionId(ItemStack stack) {
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length
? StringUtil.BUGGED_ITEM_NAME
: this.getDescriptionId() + "_" + 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) {
return stack.getItemDamage() >= BlockCrystal.ALL_CRYSTALS.length
? EnumRarity.COMMON
: BlockCrystal.ALL_CRYSTALS[stack.getItemDamage()].rarity;
2017-02-13 23:17:08 +01:00
}
@Override
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.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
2021-02-26 22:15:48 +01:00
@OnlyIn(Dist.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
}
};
}
2021-02-26 22:15:48 +01:00
}