Search in sources :

Example 1 with IBrew

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

the class BrewUtils method createBrew.

public static ItemStack createBrew(Item item, BrewEffect... effects) {
    ItemStack stack = new ItemStack(item);
    NBTTagList list = addBrewData(stack);
    for (BrewEffect effect : effects) {
        NBTTagCompound tag = new NBTTagCompound();
        IBrew brew = effect.getBrew();
        tag.setInteger(BREW_ID, BrewRegistry.getBrewId(brew));
        tag.setInteger(BREW_AMPLIFIER, effect.getAmplifier());
        tag.setInteger(BREW_DURATION, effect.getDuration());
        list.appendTag(tag);
    }
    return stack;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) BrewEffect(com.witchworks.api.item.BrewEffect) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) IBrew(com.witchworks.api.item.IBrew)

Example 2 with IBrew

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

the class BrewStorageHandler method addEntityBrewEffect.

/**
	 * Add a BrewEffect to the entity.
	 *
	 * @param entity The entity
	 * @param effect The effect
	 */
public static void addEntityBrewEffect(EntityLivingBase entity, BrewEffect effect) {
    Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
    if (optional.isPresent()) {
        Map<IBrew, BrewEffect> effectMap = optional.get().getBrews();
        BrewEffect out = effectMap.get(effect.getBrew());
        if (out == null || effect.getDuration() > out.getDuration()) {
            effectMap.put(effect.getBrew(), effect);
        }
        optional.get().setBrews(effectMap);
    }
}
Also used : BrewEffect(com.witchworks.api.item.BrewEffect) IBrew(com.witchworks.api.item.IBrew)

Example 3 with IBrew

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

the class BrewHUD method renderOverlay.

@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
    if (!BREW_HUD.hide && event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(Minecraft.getMinecraft().player);
        if (optional.isPresent()) {
            ScaledResolution res = event.getResolution();
            int x = res.getScaledWidth() - BREW_HUD.x;
            int yOffset = BREW_HUD.y;
            Minecraft mc = Minecraft.getMinecraft();
            Set<IBrew> client = optional.get().getClient();
            if (client == null)
                return;
            Iterator<IBrew> renders = client.iterator();
            GlStateManager.pushMatrix();
            while (renders.hasNext()) {
                renders.next().renderHUD(x, yOffset, mc);
                yOffset += 22;
            }
            GlStateManager.popMatrix();
        }
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) Minecraft(net.minecraft.client.Minecraft) IBrew(com.witchworks.api.item.IBrew) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IBrew

use of com.witchworks.api.item.IBrew 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 5 with IBrew

use of com.witchworks.api.item.IBrew 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)

Aggregations

IBrew (com.witchworks.api.item.IBrew)9 BrewEffect (com.witchworks.api.item.BrewEffect)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 IBrewStorage (com.witchworks.common.core.capability.potion.IBrewStorage)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 PotionMessage (com.witchworks.common.core.net.PotionMessage)1 HashMap (java.util.HashMap)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1