mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-06-27 12:51:42 +02:00
77 lines
2.9 KiB
Java
77 lines
2.9 KiB
Java
package de.ellpeck.naturesaura.items;
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
import de.ellpeck.naturesaura.entities.EntityEffectInhibitor;
|
|
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
|
|
import net.minecraft.client.renderer.color.IItemColor;
|
|
import net.minecraft.creativetab.CreativeTabs;
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
import net.minecraft.item.ItemStack;
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
import net.minecraft.util.*;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.text.translation.I18n;
|
|
import net.minecraft.world.World;
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
public class ItemInhibitingPowder extends ItemImpl implements IColorProvidingItem {
|
|
|
|
public ItemInhibitingPowder() {
|
|
super("inhibiting_powder");
|
|
}
|
|
|
|
@Override
|
|
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
|
|
if (!worldIn.isRemote) {
|
|
ItemStack stack = player.getHeldItem(hand);
|
|
ResourceLocation effect = getEffect(stack);
|
|
EntityEffectInhibitor entity = new EntityEffectInhibitor(worldIn);
|
|
entity.setInhibitedEffect(effect);
|
|
entity.setColor(NaturesAuraAPI.INHIBITED_EFFECTS.get(effect));
|
|
entity.setPosition(pos.getX() + hitX, pos.getY() + hitY + 1, pos.getZ() + hitZ);
|
|
worldIn.spawnEntity(entity);
|
|
stack.shrink(1);
|
|
}
|
|
return EnumActionResult.SUCCESS;
|
|
}
|
|
|
|
@Override
|
|
public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items) {
|
|
if (this.isInCreativeTab(tab)) {
|
|
for (ResourceLocation effect : NaturesAuraAPI.INHIBITED_EFFECTS.keySet()) {
|
|
ItemStack stack = new ItemStack(this);
|
|
setEffect(stack, effect);
|
|
items.add(stack);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getItemStackDisplayName(ItemStack stack) {
|
|
return I18n.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + "." + getEffect(stack) + ".name").trim();
|
|
}
|
|
|
|
public static ResourceLocation getEffect(ItemStack stack) {
|
|
if (!stack.hasTagCompound())
|
|
return null;
|
|
String effect = stack.getTagCompound().getString("effect");
|
|
if (effect.isEmpty())
|
|
return null;
|
|
return new ResourceLocation(effect);
|
|
}
|
|
|
|
public static ItemStack setEffect(ItemStack stack, ResourceLocation effect) {
|
|
if (!stack.hasTagCompound())
|
|
stack.setTagCompound(new NBTTagCompound());
|
|
stack.getTagCompound().setString("effect", effect.toString());
|
|
return stack;
|
|
}
|
|
|
|
@Override
|
|
@SideOnly(Side.CLIENT)
|
|
public IItemColor getItemColor() {
|
|
return (stack, tintIndex) -> NaturesAuraAPI.INHIBITED_EFFECTS.getOrDefault(getEffect(stack), 0xFFFFFF);
|
|
}
|
|
}
|