Search in sources :

Example 6 with IBrew

use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment 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.getRegisteredBrew(tag.getString(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) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBrew(com.bewitchment.api.cauldron.brew.IBrew)

Example 7 with IBrew

use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.

the class BrewHUD method renderOverlay.

@SubscribeEvent
public void renderOverlay(RenderGameOverlayEvent.Post event) {
    if (!ConfigHandler.CLIENT.BREW_HUD.hide && event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(Minecraft.getMinecraft().player);
        if (optional.isPresent()) {
            ScaledResolution res = event.getResolution();
            int xOffset = res.getScaledWidth() - ConfigHandler.CLIENT.BREW_HUD.x;
            int yOffset = ConfigHandler.CLIENT.BREW_HUD.y;
            Minecraft mc = Minecraft.getMinecraft();
            Collection<BrewEffect> effects = optional.get().getBrewEffects();
            if (effects.isEmpty())
                return;
            for (BrewEffect effect : effects) {
                IBrew brew = effect.getBrew();
                if (brew.shouldRender()) {
                    GlStateManager.pushMatrix();
                    GlStateManager.enableBlend();
                    brew.renderHUD(xOffset, yOffset, mc, effect.getAmplifier());
                    if (ConfigHandler.CLIENT.BREW_HUD.orientation) {
                        yOffset += 22;
                    } else {
                        xOffset += 22;
                    }
                    GlStateManager.disableBlend();
                    GlStateManager.popMatrix();
                }
            }
        }
    }
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) BrewEffect(com.bewitchment.common.brew.BrewEffect) IBrewStorage(com.bewitchment.api.capability.IBrewStorage) Minecraft(net.minecraft.client.Minecraft) IBrew(com.bewitchment.api.cauldron.brew.IBrew) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 8 with IBrew

use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.

the class BrewEvents method onUpdate.

@SubscribeEvent
public void onUpdate(LivingEvent.LivingUpdateEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
    if (optional.isPresent()) {
        IBrewStorage storage = optional.get();
        Map<IBrew, BrewEffect> brews = storage.getBrewMap();
        if (brews.isEmpty())
            return;
        boolean update = false;
        if (!entity.world.isRemote && BrewStorageHandler.BREW_REMOVAL.containsKey(entity)) {
            for (IBrew brew : BrewStorageHandler.BREW_REMOVAL.get(entity)) {
                brews.get(brew).end(entity.world, entity.getPosition(), entity);
                brews.remove(brew);
            }
            BrewStorageHandler.BREW_REMOVAL.remove(entity);
            update = true;
        }
        Map<IBrew, BrewEffect> updated = new HashMap<>();
        for (BrewEffect effect : brews.values()) {
            if (effect.getDuration() <= 0) {
                effect.end(entity.world, entity.getPosition(), entity);
                update = true;
            } else {
                effect.update(entity.world, entity.getPosition(), entity);
                updated.put(effect.getBrew(), effect);
            }
        }
        if (!entity.world.isRemote) {
            storage.setBrewMap(updated);
            if (update) {
                storage.syncToNear(entity);
            }
        }
    }
}
Also used : BrewEffect(com.bewitchment.common.brew.BrewEffect) HashMap(java.util.HashMap) IBrewStorage(com.bewitchment.api.capability.IBrewStorage) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IBrew(com.bewitchment.api.cauldron.brew.IBrew) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 9 with IBrew

use of com.bewitchment.api.cauldron.brew.IBrew in project Bewitchment by Um-Mitternacht.

the class BrewMessage method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    target = new UUID(buf.readLong(), buf.readLong());
    int size = buf.readInt();
    effects = new LinkedHashMap<>(size);
    for (int i = 0; i < size; i++) {
        IBrew brew = BrewRegistry.getBrew(buf.readInt());
        effects.put(brew, new BrewEffect(brew, buf.readInt(), buf.readInt()));
    }
}
Also used : BrewEffect(com.bewitchment.common.brew.BrewEffect) UUID(java.util.UUID) IBrew(com.bewitchment.api.cauldron.brew.IBrew)

Aggregations

IBrew (com.bewitchment.api.cauldron.brew.IBrew)9 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)5 NBTTagList (net.minecraft.nbt.NBTTagList)5 BrewEffect (com.bewitchment.common.brew.BrewEffect)3 IBrewStorage (com.bewitchment.api.capability.IBrewStorage)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemStack (net.minecraft.item.ItemStack)1 PotionEffect (net.minecraft.potion.PotionEffect)1 Tuple (net.minecraft.util.Tuple)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1