Search in sources :

Example 6 with IBrew

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

the class BrewUtils method addBrewEffect.

public static ItemStack addBrewEffect(ItemStack stack, BrewEffect effect) {
    NBTTagList list = addBrewData(stack);
    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) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IBrew(com.witchworks.api.item.IBrew)

Example 7 with IBrew

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

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

Example 9 with IBrew

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

the class PotionMessage method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(target.getMostSignificantBits());
    buf.writeLong(target.getLeastSignificantBits());
    buf.writeInt(client.size());
    for (IBrew brew : client) {
        buf.writeInt(BrewRegistry.getBrewId(brew));
    }
}
Also used : 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