Search in sources :

Example 6 with BrewEffect

use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.

the class ItemBrew method addInformation.

@SideOnly(Side.CLIENT)
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
    if (NBTHelper.hasTag(stack, BrewUtils.BREW_DESC)) {
        tooltip.add(TextFormatting.ITALIC + I18n.format(NBTHelper.getString(stack, BrewUtils.BREW_DESC)));
    }
    if (GuiScreen.isShiftKeyDown()) {
        tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + I18n.format("tooltip.brew.data"));
        List<BrewEffect> brewsFromStack = BrewUtils.getBrewsFromStack(stack);
        for (BrewEffect effect : brewsFromStack) {
            if (effect == null)
                break;
            IBrew brew = effect.getBrew();
            String info = " - " + TextFormatting.ITALIC + I18n.format(brew.getName()).replace(" Brew", "") + " ";
            info += RomanNumber.getRoman(effect.getAmplifier() + 1) + " ";
            info += "(" + StringUtils.ticksToElapsedTime(effect.getDuration()) + ")";
            tooltip.add(TextFormatting.DARK_AQUA + info);
        }
        if (brewsFromStack.isEmpty()) {
            tooltip.add("---");
        } else
            tooltip.add("");
        BrewUtils.addPotionTooltip(stack, tooltip, 1.0F);
    } else {
        tooltip.add(TextFormatting.DARK_GRAY + "" + TextFormatting.ITALIC + I18n.format("tooltip.shift_for_info"));
    }
}
Also used : BrewEffect(com.witchworks.api.item.BrewEffect) IBrew(com.witchworks.api.item.IBrew) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 7 with BrewEffect

use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.

the class BrewUtils method getBrewsFromStack.

public static List<BrewEffect> getBrewsFromStack(ItemStack stack) {
    List<BrewEffect> effects = new ArrayList<>();
    NBTTagList list = NBTHelper.getNBT(stack, BREW_DATA);
    for (int i = 0, size = list.tagCount(); i < size; i++) {
        NBTTagCompound tag = list.getCompoundTagAt(i);
        IBrew brew = BrewRegistry.getBrewById(tag.getInteger(BREW_ID));
        int duration = tag.getInteger(BREW_DURATION);
        int amplifier = tag.getInteger(BREW_AMPLIFIER);
        effects.add(new BrewEffect(brew, duration, amplifier));
    }
    return effects;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) BrewEffect(com.witchworks.api.item.BrewEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBrew(com.witchworks.api.item.IBrew)

Example 8 with BrewEffect

use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.

the class BrewUtils method mixBrews.

public static Collection<BrewEffect> mixBrews(Collection<BrewEffect> effects) {
    List<BrewEffect> list = new ArrayList<>();
    for (BrewEffect effect : effects) {
        effects.stream().filter(added -> effect != added && effect.getBrew() == added.getBrew()).forEach(added -> {
            effect.combine(added);
            list.add(added);
        });
    }
    effects.removeAll(list);
    return effects;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) RomanNumber(com.witchworks.api.helper.RomanNumber) java.util(java.util) AttributeModifier(net.minecraft.entity.ai.attributes.AttributeModifier) Item(net.minecraft.item.Item) TextFormatting(net.minecraft.util.text.TextFormatting) Tuple(net.minecraft.util.Tuple) BrewEffect(com.witchworks.api.item.BrewEffect) I18n(net.minecraft.client.resources.I18n) ItemStack(net.minecraft.item.ItemStack) PotionEffect(net.minecraft.potion.PotionEffect) NBTTagList(net.minecraft.nbt.NBTTagList) Lists(com.google.common.collect.Lists) BrewRegistry(com.witchworks.api.BrewRegistry) Side(net.minecraftforge.fml.relauncher.Side) IBrew(com.witchworks.api.item.IBrew) NBTHelper(com.witchworks.api.item.NBTHelper) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IAttribute(net.minecraft.entity.ai.attributes.IAttribute) Potion(net.minecraft.potion.Potion) PotionUtils(net.minecraft.potion.PotionUtils) BrewEffect(com.witchworks.api.item.BrewEffect)

Example 9 with BrewEffect

use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.

the class BrewUtils method appendBrews.

public static void appendBrews(NBTTagCompound tag, Collection<BrewEffect> effects) {
    NBTTagList list = new NBTTagList();
    tag.setTag(BREW_DATA, list);
    for (BrewEffect effect : effects) {
        NBTTagCompound compound = new NBTTagCompound();
        IBrew brew = effect.getBrew();
        compound.setInteger(BREW_ID, BrewRegistry.getBrewId(brew));
        compound.setInteger(BREW_AMPLIFIER, effect.getAmplifier());
        compound.setInteger(BREW_DURATION, effect.getDuration());
        list.appendTag(compound);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) BrewEffect(com.witchworks.api.item.BrewEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBrew(com.witchworks.api.item.IBrew)

Example 10 with BrewEffect

use of com.witchworks.api.item.BrewEffect in project Witchworks by Um-Mitternacht.

the class BrewEvents method onUpdate.

@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
    final EntityLivingBase entity = event.getEntityLiving();
    if (entity == null)
        return;
    Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
    if (optional.isPresent()) {
        IBrewStorage storage = optional.get();
        Map<IBrew, BrewEffect> brews = storage.getBrews();
        if (brews.isEmpty())
            return;
        Map<IBrew, BrewEffect> updated = new HashMap<>();
        for (IBrew brew : brews.keySet()) {
            BrewEffect effect = brews.get(brew);
            if (effect.isInstant() || effect.getDuration() <= 0) {
                effect.end(entity.world, entity.getPosition(), entity);
            } else {
                effect.update(entity.world, entity.getPosition(), entity);
                updated.put(effect.getBrew(), effect);
            }
        }
        storage.setBrews(updated);
        if (entity instanceof EntityPlayer) {
            PacketHandler.sendTo((EntityPlayerMP) entity, new PotionMessage(updated.keySet(), entity.getUniqueID()));
        }
    }
}
Also used : BrewEffect(com.witchworks.api.item.BrewEffect) HashMap(java.util.HashMap) IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PotionMessage(com.witchworks.common.core.net.PotionMessage) IBrew(com.witchworks.api.item.IBrew) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

BrewEffect (com.witchworks.api.item.BrewEffect)10 IBrew (com.witchworks.api.item.IBrew)7 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 NBTTagList (net.minecraft.nbt.NBTTagList)4 PotionEffect (net.minecraft.potion.PotionEffect)3 ItemStack (net.minecraft.item.ItemStack)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 Lists (com.google.common.collect.Lists)1 BrewRegistry (com.witchworks.api.BrewRegistry)1 RomanNumber (com.witchworks.api.helper.RomanNumber)1 NBTHelper (com.witchworks.api.item.NBTHelper)1 IBrewStorage (com.witchworks.common.core.capability.potion.IBrewStorage)1 PotionMessage (com.witchworks.common.core.net.PotionMessage)1 java.util (java.util)1 HashMap (java.util.HashMap)1 I18n (net.minecraft.client.resources.I18n)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 AttributeModifier (net.minecraft.entity.ai.attributes.AttributeModifier)1 IAttribute (net.minecraft.entity.ai.attributes.IAttribute)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1