Search in sources :

Example 1 with Potion

use of net.minecraft.potion.Potion 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 Potion

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

the class PotionRegistryDebug method preInit.

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
    // test automatic id distribution
    Potion forge = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forge"), false, 0xff00ff);
    // test that ids above 127 work
    Potion forgy = new PotionForge(new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), true, 0x00ff00);
    //TODo: Generic this out in GameRegistry, 'RegistryEntry' base type?
    GameData.getPotionRegistry().register(-1, new ResourceLocation(ForgeVersion.MOD_ID, "forge"), forge);
    GameData.getPotionRegistry().register(200, new ResourceLocation(ForgeVersion.MOD_ID, "forgy"), forgy);
    Random rand = new Random();
    TIntSet taken = new TIntHashSet(100);
    int ra = rand.nextInt(100) + 100;
    taken.add(ra);
    for (int i = 0; i < 20; i++) {
        int r = rand.nextInt(200) + 35;
        while (taken.contains(r)) r = rand.nextInt(200) + 35;
        //r = 32+i;
        taken.add(r);
    // this potions will most likely not have the same IDs between server and client.
    // The forge handshake on connect should fix this.
    //new PotionForge(new ResourceLocation(ForgeModContainer.MOD_ID, "randomPotion" + r), false, 0xff00ff);
    }
}
Also used : Random(java.util.Random) Potion(net.minecraft.potion.Potion) TIntSet(gnu.trove.set.TIntSet) ResourceLocation(net.minecraft.util.ResourceLocation) TIntHashSet(gnu.trove.set.hash.TIntHashSet)

Example 3 with Potion

use of net.minecraft.potion.Potion 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 4 with Potion

use of net.minecraft.potion.Potion in project GregTech by GregTechCE.

the class GTUtility method addPotionTooltip.

/**
 * Adds potion tooltip into given lines list
 *
 * @param potions potion effects to add to tooltip
 * @param lines   description lines
 */
@SideOnly(Side.CLIENT)
public static void addPotionTooltip(Iterable<PotionEffect> potions, List<String> lines) {
    ArrayList<Tuple<String, AttributeModifier>> attributeLines = new ArrayList<>();
    for (PotionEffect potionEffect : potions) {
        String line = I18n.format(potionEffect.getEffectName());
        Potion potion = potionEffect.getPotion();
        Map<IAttribute, AttributeModifier> attributes = potionEffect.getPotion().getAttributeModifierMap();
        if (!attributes.isEmpty()) {
            for (Map.Entry<IAttribute, AttributeModifier> entry : attributes.entrySet()) {
                AttributeModifier modifier = entry.getValue();
                attributeLines.add(new Tuple<>(entry.getKey().getName(), new AttributeModifier(modifier.getName(), potion.getAttributeModifierAmount(potionEffect.getAmplifier(), modifier), modifier.getOperation())));
            }
        }
        if (potionEffect.getAmplifier() > 0) {
            line = line + " " + I18n.format("potion.potency." + potionEffect.getAmplifier());
        }
        if (potionEffect.getDuration() > 20) {
            line = line + " (" + Potion.getPotionDurationString(potionEffect, 1.0f) + ")";
        }
        if (potion.isBadEffect()) {
            lines.add(TextFormatting.RED + line);
        } else {
            lines.add(TextFormatting.BLUE + line);
        }
    }
    if (!attributeLines.isEmpty()) {
        lines.add("");
        lines.add(TextFormatting.DARK_PURPLE + I18n.format("potion.whenDrank"));
        for (Tuple<String, AttributeModifier> tuple : attributeLines) {
            AttributeModifier modifier = tuple.getSecond();
            double d0 = modifier.getAmount();
            double d1;
            if (modifier.getOperation() != 1 && modifier.getOperation() != 2) {
                d1 = modifier.getAmount();
            } else {
                d1 = modifier.getAmount() * 100.0D;
            }
            if (d0 > 0.0D) {
                lines.add(TextFormatting.BLUE + I18n.format("attribute.modifier.plus." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(d1), I18n.format("attribute.name." + tuple.getFirst())));
            } else if (d0 < 0.0D) {
                d1 = d1 * -1.0D;
                lines.add(TextFormatting.RED + I18n.format("attribute.modifier.take." + modifier.getOperation(), ItemStack.DECIMALFORMAT.format(d1), I18n.format("attribute.name." + 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 Potion

use of net.minecraft.potion.Potion in project SpongeCommon by SpongePowered.

the class SpongeParticleHelper method toCachedPacket.

private static ICachedParticleEffect toCachedPacket(SpongeParticleEffect effect) {
    SpongeParticleType type = effect.getType();
    EnumParticleTypes internal = type.getInternalType();
    // Special cases
    if (internal == null) {
        if (type == ParticleTypes.FIREWORKS) {
            final List<FireworkEffect> effects = type.getDefaultOption(ParticleOptions.FIREWORK_EFFECTS).get();
            if (effects.isEmpty()) {
                return EmptyCachedPacket.INSTANCE;
            }
            final net.minecraft.item.ItemStack itemStack = new net.minecraft.item.ItemStack(Items.FIREWORKS);
            FireworkUtils.setFireworkEffects(itemStack, effects);
            final SPacketEntityMetadata packetEntityMetadata = new SPacketEntityMetadata();
            packetEntityMetadata.entityId = CachedFireworkPacket.FIREWORK_ROCKET_ID;
            packetEntityMetadata.dataManagerEntries = new ArrayList<>();
            packetEntityMetadata.dataManagerEntries.add(new EntityDataManager.DataEntry<>(EntityFireworkRocket.FIREWORK_ITEM, itemStack));
            return new CachedFireworkPacket(packetEntityMetadata);
        }
        if (type == ParticleTypes.FERTILIZER) {
            int quantity = effect.getOptionOrDefault(ParticleOptions.QUANTITY).get();
            return new CachedEffectPacket(2005, quantity, false);
        } else if (type == ParticleTypes.SPLASH_POTION) {
            Potion potion = (Potion) effect.getOptionOrDefault(ParticleOptions.POTION_EFFECT_TYPE).get();
            for (PotionType potionType : PotionType.REGISTRY) {
                for (net.minecraft.potion.PotionEffect potionEffect : potionType.getEffects()) {
                    if (potionEffect.getPotion() == potion) {
                        return new CachedEffectPacket(2002, PotionType.REGISTRY.getIDForObject(potionType), false);
                    }
                }
            }
            return EmptyCachedPacket.INSTANCE;
        } else if (type == ParticleTypes.BREAK_BLOCK) {
            int state = getBlockState(effect, type.getDefaultOption(ParticleOptions.BLOCK_STATE));
            if (state == 0) {
                return EmptyCachedPacket.INSTANCE;
            }
            return new CachedEffectPacket(2001, state, false);
        } else if (type == ParticleTypes.MOBSPAWNER_FLAMES) {
            return new CachedEffectPacket(2004, 0, false);
        } else if (type == ParticleTypes.ENDER_TELEPORT) {
            return new CachedEffectPacket(2003, 0, false);
        } else if (type == ParticleTypes.DRAGON_BREATH_ATTACK) {
            return new CachedEffectPacket(2006, 0, false);
        } else if (type == ParticleTypes.FIRE_SMOKE) {
            final Direction direction = effect.getOptionOrDefault(ParticleOptions.DIRECTION).get();
            return new CachedEffectPacket(2000, getDirectionData(direction), false);
        }
        return EmptyCachedPacket.INSTANCE;
    }
    Vector3f offset = effect.getOption(ParticleOptions.OFFSET).map(Vector3d::toFloat).orElse(Vector3f.ZERO);
    int quantity = effect.getOption(ParticleOptions.QUANTITY).orElse(1);
    int[] extra = null;
    // The extra values, normal behavior offsetX, offsetY, offsetZ
    double f0 = 0f;
    double f1 = 0f;
    double f2 = 0f;
    // Depends on behavior
    // Note: If the count > 0 -> speed = 0f else if count = 0 -> speed = 1f
    Optional<BlockState> defaultBlockState;
    if (internal != EnumParticleTypes.ITEM_CRACK && (defaultBlockState = type.getDefaultOption(ParticleOptions.BLOCK_STATE)).isPresent()) {
        int state = getBlockState(effect, defaultBlockState);
        if (state == 0) {
            return EmptyCachedPacket.INSTANCE;
        }
        extra = new int[] { state };
    }
    Optional<ItemStackSnapshot> defaultSnapshot;
    if (extra == null && (defaultSnapshot = type.getDefaultOption(ParticleOptions.ITEM_STACK_SNAPSHOT)).isPresent()) {
        Optional<ItemStackSnapshot> optSnapshot = effect.getOption(ParticleOptions.ITEM_STACK_SNAPSHOT);
        if (optSnapshot.isPresent()) {
            ItemStackSnapshot snapshot = optSnapshot.get();
            extra = new int[] { Item.getIdFromItem((Item) snapshot.getType()), ((SpongeItemStackSnapshot) snapshot).getDamageValue() };
        } else {
            Optional<BlockState> optBlockState = effect.getOption(ParticleOptions.BLOCK_STATE);
            if (optBlockState.isPresent()) {
                BlockState blockState = optBlockState.get();
                Optional<ItemType> optItemType = blockState.getType().getItem();
                if (optItemType.isPresent()) {
                    extra = new int[] { Item.getIdFromItem((Item) optItemType.get()), ((Block) blockState.getType()).getMetaFromState((IBlockState) blockState) };
                } else {
                    return EmptyCachedPacket.INSTANCE;
                }
            } else {
                ItemStackSnapshot snapshot = defaultSnapshot.get();
                extra = new int[] { Item.getIdFromItem((Item) snapshot.getType()), ((SpongeItemStackSnapshot) snapshot).getDamageValue() };
            }
        }
    }
    if (extra == null) {
        extra = new int[0];
    }
    Optional<Double> defaultScale = type.getDefaultOption(ParticleOptions.SCALE);
    Optional<Color> defaultColor;
    Optional<NotePitch> defaultNote;
    Optional<Vector3d> defaultVelocity;
    if (defaultScale.isPresent()) {
        double scale = effect.getOption(ParticleOptions.SCALE).orElse(defaultScale.get());
        // Server formula: sizeServer = (-sizeClient * 2) + 2
        if (internal == EnumParticleTypes.EXPLOSION_LARGE || internal == EnumParticleTypes.SWEEP_ATTACK) {
            scale = (-scale * 2f) + 2f;
        }
        if (scale == 0f) {
            return new CachedParticlePacket(internal, offset, quantity, extra);
        }
        f0 = scale;
    } else if ((defaultColor = type.getDefaultOption(ParticleOptions.COLOR)).isPresent()) {
        Color color = effect.getOption(ParticleOptions.COLOR).orElse(null);
        boolean isSpell = internal == EnumParticleTypes.SPELL_MOB || internal == EnumParticleTypes.SPELL_MOB_AMBIENT;
        if (!isSpell && (color == null || color.equals(defaultColor.get()))) {
            return new CachedParticlePacket(internal, offset, quantity, extra);
        } else if (isSpell && color == null) {
            color = defaultColor.get();
        }
        f0 = color.getRed() / 255f;
        f1 = color.getGreen() / 255f;
        f2 = color.getBlue() / 255f;
        // but we already chose for the color, can't have both
        if (isSpell) {
            f0 = Math.max(f0, 0.001f);
            f2 = Math.max(f0, 0.001f);
        }
        // If the f0 value 0 is, the redstone will set it automatically to red 255
        if (f0 == 0f && internal == EnumParticleTypes.REDSTONE) {
            f0 = 0.00001f;
        }
    } else if ((defaultNote = type.getDefaultOption(ParticleOptions.NOTE)).isPresent()) {
        NotePitch notePitch = effect.getOption(ParticleOptions.NOTE).orElse(defaultNote.get());
        float note = ((SpongeNotePitch) notePitch).getByteId();
        if (note == 0f) {
            return new CachedParticlePacket(internal, offset, quantity, extra);
        }
        f0 = note / 24f;
    } else if ((defaultVelocity = type.getDefaultOption(ParticleOptions.VELOCITY)).isPresent()) {
        Vector3d velocity = effect.getOption(ParticleOptions.VELOCITY).orElse(defaultVelocity.get());
        f0 = velocity.getX();
        f1 = velocity.getY();
        f2 = velocity.getZ();
        Optional<Boolean> slowHorizontalVelocity = type.getDefaultOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY);
        if (slowHorizontalVelocity.isPresent() && effect.getOption(ParticleOptions.SLOW_HORIZONTAL_VELOCITY).orElse(slowHorizontalVelocity.get())) {
            f0 = 0f;
            f2 = 0f;
        }
        // The y value won't work for this effect, if the value isn't 0 the velocity won't work
        if (internal == EnumParticleTypes.WATER_SPLASH) {
            f1 = 0f;
        }
        if (f0 == 0f && f1 == 0f && f2 == 0f) {
            return new CachedParticlePacket(internal, offset, quantity, extra);
        }
    }
    // Is this check necessary?
    if (f0 == 0f && f1 == 0f && f2 == 0f) {
        return new CachedParticlePacket(internal, offset, quantity, extra);
    }
    return new CachedOffsetParticlePacket(internal, new Vector3f(f0, f1, f2), offset, quantity, extra);
}
Also used : ItemType(org.spongepowered.api.item.ItemType) FireworkEffect(org.spongepowered.api.item.FireworkEffect) Direction(org.spongepowered.api.util.Direction) NotePitch(org.spongepowered.api.data.type.NotePitch) SpongeNotePitch(org.spongepowered.common.data.type.SpongeNotePitch) Item(net.minecraft.item.Item) SpongeNotePitch(org.spongepowered.common.data.type.SpongeNotePitch) IBlockState(net.minecraft.block.state.IBlockState) Optional(java.util.Optional) Potion(net.minecraft.potion.Potion) Color(org.spongepowered.api.util.Color) SPacketEntityMetadata(net.minecraft.network.play.server.SPacketEntityMetadata) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) Vector3d(com.flowpowered.math.vector.Vector3d) EnumParticleTypes(net.minecraft.util.EnumParticleTypes) Vector3f(com.flowpowered.math.vector.Vector3f) EntityDataManager(net.minecraft.network.datasync.EntityDataManager) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) SpongeItemStackSnapshot(org.spongepowered.common.item.inventory.SpongeItemStackSnapshot) PotionType(net.minecraft.potion.PotionType)

Aggregations

Potion (net.minecraft.potion.Potion)32 PotionEffect (net.minecraft.potion.PotionEffect)18 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)3 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)3 ItemStack (net.minecraft.item.ItemStack)3 Tuple (net.minecraft.util.Tuple)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 Field (java.lang.reflect.Field)2 Optional (java.util.Optional)2 Minecraft (net.minecraft.client.Minecraft)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 Item (net.minecraft.item.Item)2 PotionType (net.minecraft.potion.PotionType)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 BlockPos (net.minecraft.util.math.BlockPos)2 PotionEffectType (org.spongepowered.api.effect.potion.PotionEffectType)2 AMVector2 (am2.api.math.AMVector2)1 InventoryBaubles (baubles.common.container.InventoryBaubles)1 ChemthrowerEffect_Damage (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Damage)1