Search in sources :

Example 1 with IBrewStorage

use of com.witchworks.common.core.capability.potion.IBrewStorage 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 IBrewStorage

use of com.witchworks.common.core.capability.potion.IBrewStorage in project Witchworks by Um-Mitternacht.

the class BrewEvents method onPlayerClone.

@SuppressWarnings("ConstantConditions")
@SubscribeEvent
public void onPlayerClone(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
    final EntityPlayer oldPlayer = event.getOriginal();
    final EntityPlayer newPlayer = event.getEntityPlayer();
    if (event.isWasDeath() && oldPlayer.hasCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null) && newPlayer.hasCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null)) {
        final IBrewStorage oldCap = oldPlayer.getCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null);
        final IBrewStorage newCap = oldPlayer.getCapability(BrewStorageProvider.BREW_STORAGE_CAPABILITY, null);
        newCap.setBrews(oldCap.getBrews());
    }
}
Also used : IBrewStorage(com.witchworks.common.core.capability.potion.IBrewStorage) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with IBrewStorage

use of com.witchworks.common.core.capability.potion.IBrewStorage 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 4 with IBrewStorage

use of com.witchworks.common.core.capability.potion.IBrewStorage 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)

Aggregations

IBrewStorage (com.witchworks.common.core.capability.potion.IBrewStorage)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 IBrew (com.witchworks.api.item.IBrew)2 PotionMessage (com.witchworks.common.core.net.PotionMessage)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 BrewEffect (com.witchworks.api.item.BrewEffect)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 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1