Skip to content

Commit

Permalink
status effect handling; including cursed status effect icon mixins
Browse files Browse the repository at this point in the history
  • Loading branch information
DaFuqs committed Jan 4, 2025
1 parent c99cc5e commit d5f3d13
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 99 deletions.
31 changes: 31 additions & 0 deletions src/main/java/de/dafuqs/spectrum/helpers/StatusEffectHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.dafuqs.spectrum.helpers;

import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.api.status_effect.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.entity.effect.*;
import net.minecraft.util.*;

public class StatusEffectHelper {

private static final Identifier INCURABLE_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/incurable_effect_backgrounds.png");
private static final Identifier NIGHT_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/night_alchemy_effect_backgrounds.png");
private static final Identifier DIVINITY_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/divinity_effect_backgrounds.png");

public static Identifier getTexture(Identifier texture, StatusEffectInstance effect) {
var type = effect.getEffectType();

if (type == SpectrumStatusEffects.DIVINITY)
return DIVINITY_EFFECT_BACKGROUNDS;

if (Incurable.isIncurable(effect) && type != SpectrumStatusEffects.ETERNAL_SLUMBER && type != SpectrumStatusEffects.FATAL_SLUMBER) {
return INCURABLE_EFFECT_BACKGROUNDS;
}

if (type.isIn(SpectrumStatusEffectTags.NIGHT_ALCHEMY))
return NIGHT_EFFECT_BACKGROUNDS;

return texture;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public Multimap<RegistryEntry<EntityAttribute>, EntityAttributeModifier> getModi
modifiers.put(SpectrumEntityAttributes.MENTAL_PRESENCE, new EntityAttributeModifier(MENTAL_PRESENCE_ATTRIBUTE_ID, -1F, EntityAttributeModifier.Operation.ADD_VALUE));
return modifiers;
}

public static boolean testEffectFor(LivingEntity entity, StatusEffect effect) {
if (effect.isBeneficial())
public static boolean testEffectFor(LivingEntity entity, RegistryEntry<StatusEffect> effect) {
if (effect.value().isBeneficial())
return false;

if (SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.SOPORIFIC, effect))
if (effect.isIn(SpectrumStatusEffectTags.SOPORIFIC))
return false;

var trinkets = TrinketsApi.getTrinketComponent(entity);
Expand All @@ -60,7 +60,7 @@ public static boolean testEffectFor(LivingEntity entity, StatusEffect effect) {
return false;

var component = trinkets.get();
return component.isEquipped(SpectrumItems.AETHER_GRACED_NECTAR_GLOVES) && (effect.getCategory() == StatusEffectCategory.HARMFUL || effect == SpectrumStatusEffects.FRENZY);
return component.isEquipped(SpectrumItems.AETHER_GRACED_NECTAR_GLOVES) && (effect.value().getCategory() == StatusEffectCategory.HARMFUL || effect == SpectrumStatusEffects.FRENZY);
}

public static boolean tryBlockEffect(LivingEntity entity, int cost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static void removeSingleStatusEffect(@NotNull LivingEntity entity, Status

List<StatusEffectInstance> negativeEffects = new ArrayList<>();
for (StatusEffectInstance statusEffectInstance : currentEffects) {
var effect = statusEffectInstance.getEffectType().value();
if (effect.getCategory() == category && !SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.SOPORIFIC, effect) && !SpectrumStatusEffectTags.isIncurable(effect)) {
var effect = statusEffectInstance.getEffectType();
if (effect.value().getCategory() == category && !effect.isIn(SpectrumStatusEffectTags.SOPORIFIC) && !SpectrumStatusEffectTags.isIncurable(effect)) {
negativeEffects.add(statusEffectInstance);
}
}
Expand Down Expand Up @@ -89,8 +89,8 @@ public static void shortenNegativeStatusEffects(@NotNull LivingEntity entity, in
}
}

public static boolean affects(StatusEffect statusEffect) {
return statusEffect.getCategory() == StatusEffectCategory.HARMFUL && !SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.SOPORIFIC, statusEffect) && !SpectrumStatusEffectTags.isIncurable(statusEffect);
public static boolean affects(RegistryEntry<StatusEffect> effect) {
return effect.value().getCategory() == StatusEffectCategory.HARMFUL && !effect.isIn(SpectrumStatusEffectTags.SOPORIFIC) && !SpectrumStatusEffectTags.isIncurable(effect);
}

public static void preventPhantomSpawns(@NotNull ServerPlayerEntity serverPlayerEntity) {
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/de/dafuqs/spectrum/mixin/LivingEntityMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import net.minecraft.item.*;
import net.minecraft.nbt.*;
import net.minecraft.network.packet.s2c.play.*;
import net.minecraft.registry.entry.*;
import net.minecraft.server.network.*;
import net.minecraft.server.world.*;
import net.minecraft.sound.*;
Expand Down Expand Up @@ -76,9 +77,6 @@ public abstract class LivingEntityMixin {
@Shadow
public abstract boolean damage(DamageSource source, float amount);

@Shadow
public abstract boolean removeStatusEffect(StatusEffect type);

@Shadow
public abstract boolean addStatusEffect(StatusEffectInstance effect);

Expand All @@ -87,17 +85,20 @@ public abstract class LivingEntityMixin {

@Shadow
public abstract int getArmor();

@Shadow
public abstract double getAttributeValue(EntityAttribute attribute);

@Shadow public abstract void remove(Entity.RemovalReason reason);

@Shadow
public abstract void travel(Vec3d movementInput);

@Shadow protected ItemStack activeItemStack;


@Shadow
public abstract double getAttributeValue(RegistryEntry<EntityAttribute> attribute);

@Shadow
public abstract boolean removeStatusEffect(RegistryEntry<StatusEffect> effect);

// FabricDefaultAttributeRegistry seems to only allow adding full containers and only single entity types?
@Inject(method = "createLivingAttributes()Lnet/minecraft/entity/attribute/DefaultAttributeContainer$Builder;", require = 1, allow = 1, at = @At("RETURN"))
private static void spectrum$addAttributes(final CallbackInfoReturnable<DefaultAttributeContainer.Builder> cir) {
Expand Down Expand Up @@ -228,8 +229,8 @@ public abstract class LivingEntityMixin {
@ModifyReturnValue(method = "canHaveStatusEffect(Lnet/minecraft/entity/effect/StatusEffectInstance;)Z", at = @At("RETURN"))
private boolean spectrum$canHaveStatusEffect(boolean original, @Local(argsOnly = true) StatusEffectInstance statusEffectInstance) {
var instance = (LivingEntity) (Object) this;

if (original && this.hasStatusEffect(SpectrumStatusEffects.IMMUNITY) && statusEffectInstance.getEffectType().getCategory() == StatusEffectCategory.HARMFUL && !SpectrumStatusEffectTags.isIncurable(statusEffectInstance.getEffectType())) {
if (original && this.hasStatusEffect(SpectrumStatusEffects.IMMUNITY) && statusEffectInstance.getEffectType().value().getCategory() == StatusEffectCategory.HARMFUL && !SpectrumStatusEffectTags.isIncurable(statusEffectInstance.getEffectType())) {
if (Incurable.isIncurable(statusEffectInstance)) {
var immunity = getStatusEffect(SpectrumStatusEffects.IMMUNITY);
var cost = 600 * (statusEffectInstance.getAmplifier() + 1);
Expand Down Expand Up @@ -618,7 +619,7 @@ private float getToughness() {

@Inject(method = "addStatusEffect(Lnet/minecraft/entity/effect/StatusEffectInstance;Lnet/minecraft/entity/Entity;)Z", at = @At(value = "INVOKE", target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;"), cancellable = true)
private void spectrum$addStatusEffect(StatusEffectInstance effect, Entity source, CallbackInfoReturnable<Boolean> cir) {
StatusEffect effectType = effect.getEffectType();
RegistryEntry<StatusEffect> effectType = effect.getEffectType();
if (effectType instanceof StackableStatusEffect) {
if (!SpectrumStatusEffects.effectsAreGettingStacked) {
if (this.canHaveStatusEffect(effect)) {
Expand All @@ -638,7 +639,7 @@ private float getToughness() {
} else {
SpectrumStatusEffects.effectsAreGettingStacked = false;
}
} else if (EffectProlongingStatusEffect.canBeExtended(effectType)) {
} else if (EffectProlongingStatusEffect.canBeExtended(effect.getEffectType())) {
StatusEffectInstance effectProlongingInstance = this.getStatusEffect(SpectrumStatusEffects.EFFECT_PROLONGING);
if (effectProlongingInstance != null) {
((StatusEffectInstanceAccessor) effect).setDuration(EffectProlongingStatusEffect.getExtendedDuration(effect.getDuration(), effectProlongingInstance.getAmplifier()));
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/de/dafuqs/spectrum/mixin/WitherEntityMixin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package de.dafuqs.spectrum.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.injector.*;
import com.llamalad7.mixinextras.sugar.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.entity.*;
import net.minecraft.entity.boss.*;
import net.minecraft.entity.damage.*;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.*;
import net.minecraft.server.world.*;
import net.minecraft.world.*;
import org.spongepowered.asm.mixin.*;
import org.spongepowered.asm.mixin.injection.*;
Expand All @@ -21,11 +22,10 @@ protected WitherEntityMixin(EntityType<? extends LivingEntity> entityType, World
}

@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setCovetedItem()V"),
method = "dropEquipment(Lnet/minecraft/entity/damage/DamageSource;IZ)V", locals = LocalCapture.CAPTURE_FAILSOFT)
private void spawnEntity(DamageSource source, int lootingMultiplier, boolean allowDrops, CallbackInfo ci, ItemEntity itemEntity) {
method = "dropEquipment(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/damage/DamageSource;Z)V", locals = LocalCapture.CAPTURE_FAILSOFT)
private void spawnEntity(ServerWorld world, DamageSource source, boolean causedByPlayer, CallbackInfo ci, ItemEntity itemEntity) {
Entity attackerEntity = source.getAttacker();
if (attackerEntity instanceof LivingEntity livingAttacker) {
World world = attackerEntity.getWorld();
int cloversFavorLevel = SpectrumEnchantmentHelper.getLevel(world.getRegistryManager(), SpectrumEnchantments.CLOVERS_FAVOR, livingAttacker.getMainHandStack());
if (cloversFavorLevel > 0) {
int additionalCount = (int) (cloversFavorLevel / 2.0F + world.random.nextFloat() * cloversFavorLevel);
Expand All @@ -36,10 +36,9 @@ private void spawnEntity(DamageSource source, int lootingMultiplier, boolean all

@ModifyReturnValue(method = "addStatusEffect", at = @At("TAIL"))
private boolean spectrum$allowWitherNaps(boolean original, @Local(argsOnly = true) StatusEffectInstance effect, @Local(argsOnly = true) Entity source) {
if (SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.SOPORIFIC, effect.getEffectType())) {
if (effect.getEffectType().isIn(SpectrumStatusEffectTags.SOPORIFIC)) {
return super.addStatusEffect(effect, source);
}

return original;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package de.dafuqs.spectrum.mixin.client;

import com.llamalad7.mixinextras.sugar.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.api.status_effect.*;
import de.dafuqs.spectrum.registries.*;
import de.dafuqs.spectrum.helpers.*;
import net.minecraft.client.gui.screen.ingame.*;
import net.minecraft.entity.effect.*;
import net.minecraft.util.*;
Expand All @@ -12,37 +10,15 @@

@Mixin(AbstractInventoryScreen.class)
public class AbstractInventoryScreenMixin {

@Unique
private static final Identifier INCURABLE_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/incurable_effect_backgrounds.png");
@Unique
private static final Identifier NIGHT_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/night_alchemy_effect_backgrounds.png");
@Unique
private static final Identifier DIVINITY_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/divinity_effect_backgrounds.png");

@ModifyArg(method = "drawStatusEffectBackgrounds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0))

@ModifyArg(method = "drawStatusEffectBackgrounds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V", ordinal = 0))
public Identifier modifyWideBackground(Identifier texture, @Local StatusEffectInstance effect) {
return getTexture(texture, effect);
return StatusEffectHelper.getTexture(texture, effect);
}

@ModifyArg(method = "drawStatusEffectBackgrounds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1))
@ModifyArg(method = "drawStatusEffectBackgrounds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V", ordinal = 1))
public Identifier modifyBackground(Identifier texture, @Local StatusEffectInstance effect) {
return getTexture(texture, effect);
return StatusEffectHelper.getTexture(texture, effect);
}

private static Identifier getTexture(Identifier texture, StatusEffectInstance effect) {
var type = effect.getEffectType();

if (type == SpectrumStatusEffects.DIVINITY)
return DIVINITY_EFFECT_BACKGROUNDS;

if (Incurable.isIncurable(effect) && type != SpectrumStatusEffects.ETERNAL_SLUMBER && type != SpectrumStatusEffects.FATAL_SLUMBER) {
return INCURABLE_EFFECT_BACKGROUNDS;
}

if (SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.NIGHT_ALCHEMY, type))
return NIGHT_EFFECT_BACKGROUNDS;

return texture;
}
}
37 changes: 7 additions & 30 deletions src/main/java/de/dafuqs/spectrum/mixin/client/InGameHudMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import com.llamalad7.mixinextras.injector.*;
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import com.llamalad7.mixinextras.sugar.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.api.status_effect.*;
import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.registries.*;
import de.dafuqs.spectrum.render.*;
import de.dafuqs.spectrum.status_effects.*;
Expand All @@ -21,12 +20,6 @@
@Mixin(InGameHud.class)
public abstract class InGameHudMixin {

@Unique
private static final Identifier INCURABLE_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/incurable_effect_backgrounds.png");
@Unique
private static final Identifier NIGHT_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/night_alchemy_effect_backgrounds.png");
@Unique
private static final Identifier DIVINITY_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/divinity_effect_backgrounds.png");

@Shadow protected abstract PlayerEntity getCameraPlayer();

Expand Down Expand Up @@ -86,30 +79,14 @@ private static boolean isInDim() {
MinecraftClient client = MinecraftClient.getInstance();
return SpectrumDimensions.DIMENSION_KEY.equals(client.player.getWorld().getRegistryKey());
}

@ModifyArg(method = "renderStatusEffectOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0))
@ModifyArg(method = "renderStatusEffectOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V", ordinal = 0))
private Identifier modifyAmbientEffectBackgrounds(Identifier texture, @Local StatusEffectInstance effect) {
return getTexture(texture, effect);
return StatusEffectHelper.getTexture(texture, effect);
}

@ModifyArg(method = "renderStatusEffectOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1))
@ModifyArg(method = "renderStatusEffectOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawGuiTexture(Lnet/minecraft/util/Identifier;IIII)V", ordinal = 1))
private Identifier modifyEffectBackgrounds(Identifier texture, @Local StatusEffectInstance effect) {
return getTexture(texture, effect);
}

private static Identifier getTexture(Identifier texture, StatusEffectInstance effect) {
var type = effect.getEffectType();

if (type == SpectrumStatusEffects.DIVINITY)
return DIVINITY_EFFECT_BACKGROUNDS;

if (Incurable.isIncurable(effect) && type != SpectrumStatusEffects.ETERNAL_SLUMBER && type != SpectrumStatusEffects.FATAL_SLUMBER) {
return INCURABLE_EFFECT_BACKGROUNDS;
}

if (SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.NIGHT_ALCHEMY, type))
return NIGHT_EFFECT_BACKGROUNDS;

return texture;
return StatusEffectHelper.getTexture(texture, effect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.minecraft.entity.*;
import net.minecraft.entity.effect.*;
import net.minecraft.registry.*;
import net.minecraft.registry.entry.*;
import net.minecraft.registry.tag.*;

public class SpectrumStatusEffectTags {
Expand All @@ -23,13 +24,9 @@ public static void register() {
private static TagKey<StatusEffect> of(String id) {
return TagKey.of(RegistryKeys.STATUS_EFFECT, SpectrumCommon.locate(id));
}

public static boolean isIn(TagKey<StatusEffect> tag, StatusEffect effect) {
return Registries.STATUS_EFFECT.getEntry(effect).isIn(tag);
}

public static boolean isIncurable(StatusEffect statusEffect) {
return isIn(SpectrumStatusEffectTags.INCURABLE, statusEffect);
public static boolean isIncurable(RegistryEntry<StatusEffect> effect) {
return effect.isIn(SpectrumStatusEffectTags.INCURABLE);
}

public static boolean hasEffectWithTag(LivingEntity livingEntity, TagKey<StatusEffect> tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import de.dafuqs.spectrum.api.status_effect.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.entity.effect.*;
import net.minecraft.registry.entry.*;

public class EffectProlongingStatusEffect extends SpectrumStatusEffect implements StackableStatusEffect {

Expand All @@ -11,9 +12,9 @@ public class EffectProlongingStatusEffect extends SpectrumStatusEffect implement
public EffectProlongingStatusEffect(StatusEffectCategory category, int color) {
super(category, color);
}

public static boolean canBeExtended(StatusEffect statusEffect) {
return !SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.NO_DURATION_EXTENSION, statusEffect);
public static boolean canBeExtended(RegistryEntry<StatusEffect> statusEffect) {
return !statusEffect.isIn(SpectrumStatusEffectTags.NO_DURATION_EXTENSION);
}

public static int getExtendedDuration(int originalDuration, int prolongingAmplifier) {
Expand Down

0 comments on commit d5f3d13

Please sign in to comment.