Java Code Examples for net.minecraft.potion.PotionEffect#readCustomPotionEffectFromNBT()

The following examples show how to use net.minecraft.potion.PotionEffect#readCustomPotionEffectFromNBT() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerPotionCreator.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SuppressWarnings ("unchecked")
@Override
public void handleInputPacket(PacketCustom packet) {
    ItemStack potion = potionInv.getStackInSlot(0);
    if (potion == null) {
        return;
    }

    boolean add = packet.readBoolean();
    Potion effect = Potion.getPotionById(packet.readUByte());

    NBTTagList effects = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
    NBTTagList newEffects = new NBTTagList();
    for (int i = 0; i < effects.tagCount(); i++) {
        NBTTagCompound tag = effects.getCompoundTagAt(i);
        PotionEffect e = PotionEffect.readCustomPotionEffectFromNBT(tag);
        if (e.getPotion() != effect) {
            newEffects.appendTag(tag);
        }
    }
    if (add) {
        newEffects.appendTag(new PotionEffect(effect, packet.readInt(), packet.readUByte()).writeCustomPotionEffectToNBT(new NBTTagCompound()));
    }
    potion.getTagCompound().setTag("CustomPotionEffects", newEffects);
}
 
Example 2
Source File: LingeringPotion.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@Override
public List<PotionEffect> getEffects(ItemStack stack) {
	if (stack.hasTagCompound() && stack.getTagCompound().hasKey("CustomPotionEffects", 9)) {
		List<PotionEffect> list = new ArrayList<PotionEffect>();
		NBTTagList nbttaglist = stack.getTagCompound().getTagList("CustomPotionEffects", 10);

		for (int i = 0; i < nbttaglist.tagCount(); i++) {
			NBTTagCompound nbt = nbttaglist.getCompoundTagAt(i);
			PotionEffect potioneffect = PotionEffect.readCustomPotionEffectFromNBT(nbt);
			if (potioneffect != null)
				list.add(potioneffect);
		}

		return list;
	} else
		return getEffects(stack.getItemDamage());
}
 
Example 3
Source File: ContainerPotionCreator.java    From NotEnoughItems with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void handleInputPacket(PacketCustom packet) {
    ItemStack potion = potionInv.getStackInSlot(0);
    if (potion == null)
        return;

    boolean add = packet.readBoolean();
    int effectID = packet.readUByte();

    NBTTagList effects = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
    NBTTagList newEffects = new NBTTagList();
    for(int i = 0; i < effects.tagCount(); i++) {
        NBTTagCompound tag = effects.getCompoundTagAt(i);
        PotionEffect e = PotionEffect.readCustomPotionEffectFromNBT(tag);
        if(e.getPotionID() != effectID)
            newEffects.appendTag(tag);
    }
    if(add)
        newEffects.appendTag(new PotionEffect(effectID, packet.readInt(), packet.readUByte()).writeCustomPotionEffectToNBT(new NBTTagCompound()));
    potion.getTagCompound().setTag("CustomPotionEffects", newEffects);
}
 
Example 4
Source File: GuiPotionCreator.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private PotionEffect getEffect(Potion potion) {
    ItemStack potionStack = container.potionInv.getStackInSlot(0);
    if (!potionStack.isEmpty() && potionStack.hasTagCompound() && potionStack.getTagCompound().hasKey("CustomPotionEffects")) {
        NBTTagList potionTagList = potionStack.getTagCompound().getTagList("CustomPotionEffects", 10);
        for (int i = 0; i < potionTagList.tagCount(); i++) {
            PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(potionTagList.getCompoundTagAt(i));
            if (effect.getPotion() == potion) {
                return effect;
            }
        }
    }
    return null;
}
 
Example 5
Source File: TippedArrow.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
public static PotionEffect getEffect(ItemStack stack) {
	if (stack.hasTagCompound() && stack.getTagCompound().hasKey("Potion", Constants.NBT.TAG_COMPOUND)) {
		NBTTagCompound nbt = stack.getTagCompound().getCompoundTag("Potion");
		return PotionEffect.readCustomPotionEffectFromNBT(nbt);
	}
	return null;
}
 
Example 6
Source File: GuiPotionCreator.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private PotionEffect getEffect(int id) {
    ItemStack potion = container.potionInv.getStackInSlot(0);
    if (potion != null && potion.hasTagCompound() && potion.getTagCompound().hasKey("CustomPotionEffects")) {
        NBTTagList potionTagList = potion.getTagCompound().getTagList("CustomPotionEffects", 10);
        for (int i = 0; i < potionTagList.tagCount(); i++) {
            PotionEffect effect = PotionEffect.readCustomPotionEffectFromNBT(potionTagList.getCompoundTagAt(i));
            if (effect.getPotionID() == id)
                return effect;
        }
    }
    return null;
}
 
Example 7
Source File: EntityTippedArrow.java    From Et-Futurum with The Unlicense 4 votes vote down vote up
@Override
public void readEntityFromNBT(NBTTagCompound nbt) {
	super.readEntityFromNBT(nbt);
	if (nbt.hasKey("Effect"))
		effect = PotionEffect.readCustomPotionEffectFromNBT((NBTTagCompound) nbt.getTag("Effect"));
}