Search in sources :

Example 1 with PotionMessage

use of com.witchworks.common.core.net.PotionMessage in project Witchworks by Um-Mitternacht.

the class BrewEvents method onWorldJoin.

@SubscribeEvent
public void onWorldJoin(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityPlayerMP) {
        EntityPlayerMP entity = (EntityPlayerMP) event.getEntity();
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(entity);
        if (optional.isPresent()) {
            PacketHandler.sendTo(entity, new PotionMessage(optional.get().getBrews().keySet(), entity.getUniqueID()));
        }
    }
}
Also used : IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PotionMessage(com.witchworks.common.core.net.PotionMessage) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with PotionMessage

use of com.witchworks.common.core.net.PotionMessage 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

IBrewStorage (com.witchworks.common.core.capability.potion.IBrewStorage)2 PotionMessage (com.witchworks.common.core.net.PotionMessage)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 BrewEffect (com.witchworks.api.item.BrewEffect)1 IBrew (com.witchworks.api.item.IBrew)1 HashMap (java.util.HashMap)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1