Search in sources :

Example 1 with IBrewStorage

use of com.bewitchment.api.capability.IBrewStorage in project Bewitchment by Um-Mitternacht.

the class BrewEvents method onPlayerClone.

@SubscribeEvent
public void onPlayerClone(Clone event) {
    if (!event.isWasDeath()) {
        final EntityPlayer oldPlayer = event.getOriginal();
        final EntityPlayer newPlayer = event.getEntityPlayer();
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage(oldPlayer);
        optional.ifPresent(oldStorage -> BrewStorageHandler.getBrewStorage(newPlayer).ifPresent(newStorage -> {
            newStorage.setBrewMap(oldStorage.getBrewMap());
            newStorage.syncToNear(newPlayer);
        }));
    }
}
Also used : BrewEffect(com.bewitchment.common.brew.BrewEffect) Entity(net.minecraft.entity.Entity) com.bewitchment.api.cauldron.brew.special(com.bewitchment.api.cauldron.brew.special) Collection(java.util.Collection) IBrew(com.bewitchment.api.cauldron.brew.IBrew) PlayerEvent(net.minecraftforge.fml.common.gameevent.PlayerEvent) HashMap(java.util.HashMap) Clone(net.minecraftforge.event.entity.player.PlayerEvent.Clone) AttachCapabilitiesEvent(net.minecraftforge.event.AttachCapabilitiesEvent) StartTracking(net.minecraftforge.event.entity.player.PlayerEvent.StartTracking) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BrewStorageHandler(com.bewitchment.common.core.capability.brew.BrewStorageHandler) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Map(java.util.Map) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) IBrewStorage(com.bewitchment.api.capability.IBrewStorage) Optional(java.util.Optional) LibMod(com.bewitchment.common.lib.LibMod) BrewStorageProvider(com.bewitchment.common.core.capability.brew.BrewStorageProvider) net.minecraftforge.event.entity.living(net.minecraftforge.event.entity.living) IBrewStorage(com.bewitchment.api.capability.IBrewStorage) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IBrewStorage

use of com.bewitchment.api.capability.IBrewStorage 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 3 with IBrewStorage

use of com.bewitchment.api.capability.IBrewStorage in project Bewitchment by Um-Mitternacht.

the class BrewEvents method onEntityStartTracking.

@SubscribeEvent
public void onEntityStartTracking(StartTracking event) {
    Entity entity = event.getTarget();
    EntityPlayer player = event.getEntityPlayer();
    if (!entity.world.isRemote && entity != player && entity instanceof EntityLivingBase && player instanceof EntityPlayerMP) {
        Optional<IBrewStorage> optional = BrewStorageHandler.getBrewStorage((EntityLivingBase) entity);
        if (optional.isPresent()) {
            IBrewStorage storage = optional.get();
            storage.syncTo((EntityPlayerMP) event.getEntityPlayer());
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) IBrewStorage(com.bewitchment.api.capability.IBrewStorage) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with IBrewStorage

use of com.bewitchment.api.capability.IBrewStorage 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 5 with IBrewStorage

use of com.bewitchment.api.capability.IBrewStorage in project Bewitchment 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()) {
        IBrewStorage storage = optional.get();
        BrewEffect active = storage.getBrew(effect.getBrew());
        if (active == null || effect.getDuration() > active.getDuration()) {
            storage.addBrew(entity, effect);
        }
    }
}
Also used : BrewEffect(com.bewitchment.common.brew.BrewEffect) IBrewStorage(com.bewitchment.api.capability.IBrewStorage)

Aggregations

IBrewStorage (com.bewitchment.api.capability.IBrewStorage)5 BrewEffect (com.bewitchment.common.brew.BrewEffect)4 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)4 IBrew (com.bewitchment.api.cauldron.brew.IBrew)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)3 HashMap (java.util.HashMap)2 Entity (net.minecraft.entity.Entity)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 com.bewitchment.api.cauldron.brew.special (com.bewitchment.api.cauldron.brew.special)1 BrewStorageHandler (com.bewitchment.common.core.capability.brew.BrewStorageHandler)1 BrewStorageProvider (com.bewitchment.common.core.capability.brew.BrewStorageProvider)1 LibMod (com.bewitchment.common.lib.LibMod)1 Collection (java.util.Collection)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 AttachCapabilitiesEvent (net.minecraftforge.event.AttachCapabilitiesEvent)1