Search in sources :

Example 1 with PotionEffect

use of net.minecraft.potion.PotionEffect in project MinecraftForge by MinecraftForge.

the class PotionCurativeItemDebug method preInit.

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent evt) {
    Item medicine = new Medicine().setRegistryName(MOD_ID, "medicine");
    GameRegistry.register(medicine);
    Potion incurablePotion = new IncurablePotion().setRegistryName(MOD_ID, "incurable_potion");
    GameRegistry.register(incurablePotion);
    // Register PotionType that can be cured with medicine
    PotionEffect curable = new PotionEffect(incurablePotion, 1200);
    curable.setCurativeItems(Collections.singletonList(new ItemStack(medicine)));
    GameRegistry.register(new PotionType(curable).setRegistryName(MOD_ID, "curable_potion_type"));
    // Register PotionType that can't be cured
    GameRegistry.register(new PotionType(new PotionEffect(incurablePotion, 1200)).setRegistryName(MOD_ID, "incurable_potion_type"));
}
Also used : Item(net.minecraft.item.Item) Potion(net.minecraft.potion.Potion) PotionEffect(net.minecraft.potion.PotionEffect) PotionType(net.minecraft.potion.PotionType) ItemStack(net.minecraft.item.ItemStack)

Example 2 with PotionEffect

use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.

the class BrewUtils method serialize.

public static NBTTagCompound serialize(Collection<Object> collection) {
    List<BrewEffect> brewEffects = new ArrayList<>();
    List<PotionEffect> potionEffects = new ArrayList<>();
    for (Object brew : collection) {
        if (brew instanceof BrewEffect) {
            brewEffects.add((BrewEffect) brew);
        } else if (brew instanceof PotionEffect) {
            potionEffects.add((PotionEffect) brew);
        }
    }
    NBTTagCompound compound = new NBTTagCompound();
    appendPotions(compound, mixPotions(potionEffects));
    appendBrews(compound, mixBrews(brewEffects));
    return compound;
}
Also used : BrewEffect(com.witchworks.api.item.BrewEffect) PotionEffect(net.minecraft.potion.PotionEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 3 with PotionEffect

use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.

the class BrewUtils method appendPotions.

public static void appendPotions(NBTTagCompound tag, Collection<PotionEffect> effects) {
    NBTTagList tagList = tag.getTagList("CustomPotionEffects", 9);
    for (PotionEffect potioneffect : effects) {
        tagList.appendTag(potioneffect.writeCustomPotionEffectToNBT(new NBTTagCompound()));
    }
    tag.setTag("CustomPotionEffects", tagList);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) PotionEffect(net.minecraft.potion.PotionEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 4 with PotionEffect

use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.

the class BrewUtils method addPotionTooltip.

@SideOnly(Side.CLIENT)
public static void addPotionTooltip(ItemStack itemIn, List<String> tooltip, float durationFactor) {
    List<PotionEffect> list = PotionUtils.getEffectsFromStack(itemIn);
    List<Tuple<String, AttributeModifier>> attributes = Lists.newArrayList();
    if (list.isEmpty()) {
        String empty = I18n.format("effect.none").trim();
        tooltip.add(TextFormatting.GRAY + empty);
    } else {
        for (PotionEffect effect : list) {
            StringBuilder string = new StringBuilder();
            string.append(I18n.format(effect.getEffectName()).trim());
            Potion potion = effect.getPotion();
            Map<IAttribute, AttributeModifier> map = potion.getAttributeModifierMap();
            if (!map.isEmpty()) {
                for (Map.Entry<IAttribute, AttributeModifier> entry : map.entrySet()) {
                    AttributeModifier attribute = entry.getValue();
                    attribute = new AttributeModifier(attribute.getName(), potion.getAttributeModifierAmount(effect.getAmplifier(), attribute), attribute.getOperation());
                    attributes.add(new Tuple<>(entry.getKey().getName(), attribute));
                }
            }
            if (effect.getAmplifier() > 0) {
                string.append(" ").append(RomanNumber.getRoman(effect.getAmplifier()));
            }
            if (effect.getDuration() > 20) {
                string.append(" (").append(Potion.getPotionDurationString(effect, durationFactor)).append(")");
            }
            if (potion.isBadEffect()) {
                tooltip.add(TextFormatting.DARK_RED + string.toString());
            } else {
                tooltip.add(TextFormatting.DARK_BLUE + string.toString());
            }
        }
    }
    if (!attributes.isEmpty()) {
        tooltip.add("");
        tooltip.add(TextFormatting.DARK_PURPLE + I18n.format("potion.whenDrank"));
        for (Tuple<String, AttributeModifier> tuple : attributes) {
            AttributeModifier modifier = tuple.getSecond();
            double amount = modifier.getAmount();
            double newAmount;
            if (modifier.getOperation() != 1 && modifier.getOperation() != 2) {
                newAmount = modifier.getAmount();
            } else {
                newAmount = modifier.getAmount() * 100.0D;
            }
            if (amount > 0.0D) {
                tooltip.add(TextFormatting.BLUE + I18n.format("attribute.modifier.plus." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + (String) tuple.getFirst())));
            } else if (amount < 0.0D) {
                newAmount = newAmount * -1.0D;
                tooltip.add(TextFormatting.RED + I18n.format("attribute.modifier.take." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(newAmount), I18n.format("attribute.name." + (String) tuple.getFirst())));
            }
        }
    }
}
Also used : PotionEffect(net.minecraft.potion.PotionEffect) Potion(net.minecraft.potion.Potion) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) Tuple(net.minecraft.util.Tuple) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with PotionEffect

use of net.minecraft.potion.PotionEffect in project Witchworks by Um-Mitternacht.

the class BrewSimpleModifier method apply.

@Override
public boolean apply(List<Object> brews, Object current) {
    if (current instanceof PotionEffect) {
        PotionEffect effect = (PotionEffect) current;
        if (effect.getDuration() < 9600) {
            int hue = MathHelper.clamp(effect.getDuration() + duration, 0, 9600);
            effect.combine(new PotionEffect(effect.getPotion(), hue, effect.getAmplifier()));
        }
        if (effect.getAmplifier() < 3) {
            int hue = MathHelper.clamp(effect.getAmplifier() + amplifier, 0, 3);
            effect.combine(new PotionEffect(effect.getPotion(), effect.getDuration(), hue));
        }
    } else if (current instanceof BrewEffect) {
        BrewEffect effect = (BrewEffect) current;
        if (effect.getDuration() < 9600) {
            int hue = MathHelper.clamp(effect.getDuration() + duration, 0, 9600);
            effect.setDuration(hue);
        }
        if (effect.getAmplifier() < 3) {
            int hue = MathHelper.clamp(effect.getAmplifier() + amplifier, 0, 3);
            effect.setAmplifier(hue);
        }
    }
    return true;
}
Also used : BrewEffect(com.witchworks.api.item.BrewEffect) PotionEffect(net.minecraft.potion.PotionEffect)

Aggregations

PotionEffect (net.minecraft.potion.PotionEffect)367 EntityLivingBase (net.minecraft.entity.EntityLivingBase)115 EntityPlayer (net.minecraft.entity.player.EntityPlayer)89 ItemStack (net.minecraft.item.ItemStack)62 BlockPos (net.minecraft.util.math.BlockPos)48 Entity (net.minecraft.entity.Entity)36 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)35 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)34 World (net.minecraft.world.World)26 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)24 Potion (net.minecraft.potion.Potion)21 IBlockState (net.minecraft.block.state.IBlockState)20 ArrayList (java.util.ArrayList)19 WorldServer (net.minecraft.world.WorldServer)19 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)17 List (java.util.List)14 Random (java.util.Random)14 NBTTagList (net.minecraft.nbt.NBTTagList)14 TileEntity (net.minecraft.tileentity.TileEntity)13 SPacketEntityEffect (net.minecraft.network.play.server.SPacketEntityEffect)9