Search in sources :

Example 16 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project RPG-Hud by KurodaAkira.

the class HudElementStatusEffectsVanilla method drawElement.

@Override
public void drawElement(DrawableHelper gui, MatrixStack ms, float na, float partialTicks, int scaledWidth, int scaledHeight) {
    float scale = getScale();
    ms.scale(scale, scale, scale);
    Collection<StatusEffectInstance> collection = this.mc.player.getStatusEffects();
    if (!collection.isEmpty()) {
        RenderSystem.enableBlend();
        int i = 0;
        int j = 0;
        StatusEffectSpriteManager potionspriteuploader = this.mc.getStatusEffectSpriteManager();
        bind(HandledScreen.BACKGROUND_TEXTURE);
        for (StatusEffectInstance effectinstance : Ordering.natural().reverse().sortedCopy(collection)) {
            StatusEffect effect = effectinstance.getEffectType();
            // Rebind in case previous renderHUDEffect changed texture
            bind(HandledScreen.BACKGROUND_TEXTURE);
            if (effectinstance.shouldShowIcon()) {
                int k = getPosX(scaledWidth);
                int l = getPosY(scaledHeight);
                if (this.mc.isDemo()) {
                    l += 15;
                }
                if (effect.isBeneficial()) {
                    ++i;
                    if (rpgHud.settings.getBoolValue(Settings.status_vertical)) {
                        k -= 25;
                        l += 25 * (i - 1);
                    } else {
                        k -= 25 * i;
                    }
                } else {
                    ++j;
                    if (rpgHud.settings.getBoolValue(Settings.status_vertical)) {
                        k -= 50;
                        l += 25 * (j - 1);
                    } else {
                        k -= 25 * j;
                        l += 25;
                    }
                }
                RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
                float f = 1.0F;
                if (effectinstance.isAmbient()) {
                    // Background Beacon
                    gui.drawTexture(ms, k, l, 165, 166, 24, 24);
                } else {
                    // Background Regular
                    gui.drawTexture(ms, k, l, 141, 166, 24, 24);
                    if (effectinstance.getDuration() <= 200) {
                        int i1 = 10 - effectinstance.getDuration() / 20;
                        f = MathHelper.clamp((float) effectinstance.getDuration() / 10.0F / 5.0F * 0.5F, 0.0F, 0.5F) + MathHelper.cos((float) effectinstance.getDuration() * (float) Math.PI / 5.0F) * MathHelper.clamp((float) i1 / 10.0F * 0.25F, 0.0F, 0.25F);
                    }
                }
                Sprite textureatlassprite = potionspriteuploader.getSprite(effect);
                bind(textureatlassprite.getAtlas().getId());
                RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, f);
                DrawableHelper.drawSprite(ms, k + 3, l + 3, gui.getZOffset(), 18, 18, textureatlassprite);
                // Main
                if (rpgHud.settings.getBoolValue(Settings.status_time) && !effectinstance.isAmbient()) {
                    int duration = effectinstance.getDuration() / 20;
                    String s = "*:**";
                    if (duration < 600)
                        s = String.valueOf(duration / 60 + ":" + (duration % 60 < 10 ? "0" + (duration % 60) : (duration % 60)));
                    k -= mc.textRenderer.getWidth(s) / 2;
                    this.drawStringWithBackground(ms, s, k + 12, l + 14, -1, 0);
                }
            }
        }
    }
    scale = getInvertedScale();
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Sprite(net.minecraft.client.texture.Sprite) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) StatusEffectSpriteManager(net.minecraft.client.texture.StatusEffectSpriteManager)

Example 17 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project WMITAF by ShaksterNano.

the class ModNameUtil method getFirstEffectId.

/**
 * Gets the {@link Identifier} of the first effect on a potion.
 *
 * @param stack The ItemStack to get the Identifier of.
 * @return An {@link Optional} that describes the Identifier of the first effect.
 */
private static Optional<Identifier> getFirstEffectId(ItemStack stack) {
    List<StatusEffectInstance> effectInstances = PotionUtil.getPotionEffects(stack);
    for (StatusEffectInstance effectInstance : effectInstances) {
        StatusEffect effect = effectInstance.getEffectType();
        Identifier effectId = Registry.STATUS_EFFECT.getId(effect);
        if (effectId != null) {
            // Don't make potion types from mods with vanilla effects seem like they're from vanilla, for example a breakable potion from Extra Alchemy with the vanilla night vision effect.
            if (effectId.getNamespace().equals(Identifier.DEFAULT_NAMESPACE)) {
                return Optional.of(Registry.ITEM.getId(stack.getItem()));
            } else {
                return Optional.of(effectId);
            }
        }
    }
    return Optional.empty();
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Identifier(net.minecraft.util.Identifier) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance)

Example 18 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project Culinaire by DawnTeamMC.

the class TeaBottleItem method finishUsing.

@Override
public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
    PlayerEntity playerEntity = user instanceof PlayerEntity ? (PlayerEntity) user : null;
    if (user instanceof ServerPlayerEntity) {
        ServerPlayerEntity serverPlayerEntity = (ServerPlayerEntity) user;
        Criteria.CONSUME_ITEM.trigger(serverPlayerEntity, stack);
        serverPlayerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
    }
    if (!world.isClient) {
        List<TeaType> teaTypes = TeaHelper.getTeaTypesByCompound(stack.getTag());
        if (!teaTypes.isEmpty()) {
            for (TeaType teaType : teaTypes) {
                StatusEffect effect = teaType.getFlavor().getEffect();
                if (effect != null) {
                    if (effect.isInstant()) {
                        effect.applyInstantEffect(user, user, user, teaType.getStrength().getPotency(), 1.0D);
                    } else {
                        user.addStatusEffect(new StatusEffectInstance(effect, teaType.getStrength().getPotency() * 400));
                    }
                }
                if (teaType.getFlavor() == TeaType.Flavor.GLOOPY) {
                    Items.CHORUS_FRUIT.finishUsing(stack, world, user);
                }
            }
        }
    }
    if (playerEntity != null) {
        playerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
        if (!playerEntity.abilities.creativeMode) {
            stack.decrement(1);
        }
    }
    if (playerEntity == null || !playerEntity.abilities.creativeMode) {
        if (stack.isEmpty()) {
            return new ItemStack(Items.GLASS_BOTTLE);
        }
        if (playerEntity != null) {
            playerEntity.inventory.insertStack(new ItemStack(Items.GLASS_BOTTLE));
        }
    }
    return stack;
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) TeaType(com.hugman.culinaire.objects.item.tea.TeaType) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 19 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project Illager-Expansion by OhDricky.

the class AlchemistEntity method cancelEffect.

private void cancelEffect(final AreaEffectCloudEntity areaEffectCloudEntity, final LivingEntity entity) {
    final Potion potion = areaEffectCloudEntity.getPotion();
    final StatusEffectInstance statusEffectInstance = potion.getEffects().get(0);
    final StatusEffect statusEffect = statusEffectInstance.getEffectType();
    entity.removeStatusEffect(statusEffect);
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) Potion(net.minecraft.potion.Potion) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance)

Example 20 with StatusEffect

use of net.minecraft.entity.effect.StatusEffect in project Meteor-Tweaks by Declipsonator.

the class PotionTimerMixin method render.

@Override
public void render(HudRenderer renderer) {
    double x = box.getX();
    double y = box.getY();
    if (isInEditor()) {
        renderer.text("Potion Timers 0:00", x, y, color);
        return;
    }
    int i = 0;
    for (StatusEffectInstance statusEffectInstance : mc.player.getStatusEffects()) {
        StatusEffect statusEffect = statusEffectInstance.getEffectType();
        if (potions.get().contains(statusEffect) && whiteBlackNoRacismBecauseImBetterThanYouSetting.get() == MixinReferences.whiteBlackNoRacismBecauseImBetterThanYou.Blacklist)
            continue;
        else if (!potions.get().contains(statusEffectInstance.getEffectType()) && whiteBlackNoRacismBecauseImBetterThanYouSetting.get() == MixinReferences.whiteBlackNoRacismBecauseImBetterThanYou.Whitelist)
            continue;
        int c = statusEffect.getColor();
        color.r = Color.toRGBAR(c);
        color.g = Color.toRGBAG(c);
        color.b = Color.toRGBAB(c);
        String text = getString(statusEffectInstance);
        renderer.text(text, x + box.alignX(renderer.textWidth(text)), y, color);
        color.r = color.g = color.b = 255;
        y += renderer.textHeight();
        if (i > 0)
            y += 2;
        i++;
    }
}
Also used : StatusEffect(net.minecraft.entity.effect.StatusEffect) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance)

Aggregations

StatusEffect (net.minecraft.entity.effect.StatusEffect)37 StatusEffectInstance (net.minecraft.entity.effect.StatusEffectInstance)18 Identifier (net.minecraft.util.Identifier)9 ArrayList (java.util.ArrayList)6 Sprite (net.minecraft.client.texture.Sprite)4 StatusEffectSpriteManager (net.minecraft.client.texture.StatusEffectSpriteManager)4 ItemStack (net.minecraft.item.ItemStack)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 NbtList (net.minecraft.nbt.NbtList)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 TextRenderer (net.minecraft.client.font.TextRenderer)2 InGameHud (net.minecraft.client.gui.hud.InGameHud)2 LivingEntity (net.minecraft.entity.LivingEntity)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ArmorMaterial (net.minecraft.item.ArmorMaterial)2 NbtElement (net.minecraft.nbt.NbtElement)2 NbtString (net.minecraft.nbt.NbtString)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 SettingsManager (carpet.settings.SettingsManager)1