Search in sources :

Example 1 with BrewEffect

use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.

the class BrewMessage method toBytes.

@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(target.getMostSignificantBits());
    buf.writeLong(target.getLeastSignificantBits());
    buf.writeInt(effects.size());
    for (BrewEffect effect : effects.values()) {
        buf.writeInt(BrewRegistry.getBrewId(effect.getBrew()));
        buf.writeInt(effect.getDuration());
        buf.writeInt(effect.getAmplifier());
    }
}
Also used : BrewEffect(com.bewitchment.common.brew.BrewEffect)

Example 2 with BrewEffect

use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.

the class EntityBrew method doSplash.

private void doSplash() {
    AxisAlignedBB axisalignedbb = this.getEntityBoundingBox().expand(4.0D, 2.0D, 4.0D);
    List<EntityLivingBase> list = this.world.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb);
    if (!list.isEmpty()) {
        Tuple<List<BrewEffect>, List<PotionEffect>> tuple = BrewUtils.deSerialize(NBTHelper.fixNBT(getBrew()));
        for (EntityLivingBase entity : list) {
            double distance = this.getDistanceSq(entity);
            if (distance < 16.0D) {
                for (BrewEffect effect : tuple.getFirst()) {
                    BrewStorageHandler.addEntityBrewEffect(entity, effect.copy());
                }
                for (PotionEffect potioneffect : tuple.getSecond()) {
                    entity.addPotionEffect(new PotionEffect(potioneffect));
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BrewEffect(com.bewitchment.common.brew.BrewEffect) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) List(java.util.List)

Example 3 with BrewEffect

use of com.bewitchment.common.brew.BrewEffect in project Bewitchment by Um-Mitternacht.

the class BrewSimpleModifier method apply.

@Override
public boolean apply(List<Object> brews, Object current) {
    if (current instanceof PotionEffect) {
        PotionEffect effect = (PotionEffect) current;
        if (effect.getDuration() < 9600) {
            int hue = MathHelper.clamp(effect.getDuration() + duration, 0, 9600);
            effect.combine(new PotionEffect(effect.getPotion(), hue, effect.getAmplifier()));
        }
        if (effect.getAmplifier() < 3) {
            int hue = MathHelper.clamp(effect.getAmplifier() + amplifier, 0, 3);
            effect.combine(new PotionEffect(effect.getPotion(), effect.getDuration(), hue));
        }
    } else if (current instanceof BrewEffect) {
        BrewEffect effect = (BrewEffect) current;
        if (effect.getDuration() < 9600) {
            int hue = MathHelper.clamp(effect.getDuration() + duration, 0, 9600);
            effect.setDuration(hue);
        }
        if (effect.getAmplifier() < 3) {
            int hue = MathHelper.clamp(effect.getAmplifier() + amplifier, 0, 3);
            effect.setAmplifier(hue);
        }
    }
    return true;
}
Also used : BrewEffect(com.bewitchment.common.brew.BrewEffect) PotionEffect(net.minecraft.potion.PotionEffect)

Example 4 with BrewEffect

use of com.bewitchment.common.brew.BrewEffect 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 5 with BrewEffect

use of com.bewitchment.common.brew.BrewEffect 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)

Aggregations

BrewEffect (com.bewitchment.common.brew.BrewEffect)8 IBrewStorage (com.bewitchment.api.capability.IBrewStorage)3 IBrew (com.bewitchment.api.cauldron.brew.IBrew)3 PotionEffect (net.minecraft.potion.PotionEffect)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 BrewSimpleModifier (com.bewitchment.api.recipe.BrewSimpleModifier)1 HashMap (java.util.HashMap)1 List (java.util.List)1 UUID (java.util.UUID)1 Minecraft (net.minecraft.client.Minecraft)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 FluidStack (net.minecraftforge.fluids.FluidStack)1