Skip to content

Commit 2eb375d

Browse files
committed
Effect backgrounds, since Daf wanted more pile of shame work :teehee:
1 parent e2de9fd commit 2eb375d

File tree

11 files changed

+161
-0
lines changed

11 files changed

+161
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package de.dafuqs.spectrum.api.status_effect;
2+
3+
public interface IncurablePacketInject {
4+
5+
boolean getIncurable();
6+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.dafuqs.spectrum.mixin;
2+
3+
import com.llamalad7.mixinextras.sugar.*;
4+
import de.dafuqs.spectrum.api.status_effect.*;
5+
import net.minecraft.entity.effect.*;
6+
import net.minecraft.network.*;
7+
import net.minecraft.network.packet.s2c.play.*;
8+
import org.spongepowered.asm.mixin.*;
9+
import org.spongepowered.asm.mixin.injection.*;
10+
import org.spongepowered.asm.mixin.injection.callback.*;
11+
12+
@Mixin(EntityStatusEffectS2CPacket.class)
13+
public class EntityStatusEffectS2CPacketMixin implements IncurablePacketInject {
14+
15+
@Unique
16+
private boolean incurable;
17+
18+
@Inject(method = "<init>(ILnet/minecraft/entity/effect/StatusEffectInstance;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/network/packet/s2c/play/EntityStatusEffectS2CPacket;flags:B"))
19+
public void initIncurable(int entityId, StatusEffectInstance effect, CallbackInfo ci, @Local byte b) {
20+
this.incurable = Incurable.isIncurable(effect);
21+
}
22+
23+
@Inject(method = "<init>(Lnet/minecraft/network/PacketByteBuf;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;readByte()B", ordinal = 1))
24+
public void initIncurable(PacketByteBuf buf, CallbackInfo ci) {
25+
this.incurable = buf.readBoolean();
26+
}
27+
28+
@Inject(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;writeByte(I)Lio/netty/buffer/ByteBuf;", ordinal = 1))
29+
public void writeIncurable(PacketByteBuf buf, CallbackInfo ci) {
30+
buf.writeBoolean(incurable);
31+
}
32+
33+
@Override
34+
public boolean getIncurable() {
35+
return incurable;
36+
}
37+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package de.dafuqs.spectrum.mixin.client;
2+
3+
import com.llamalad7.mixinextras.sugar.*;
4+
import de.dafuqs.spectrum.*;
5+
import de.dafuqs.spectrum.api.status_effect.*;
6+
import de.dafuqs.spectrum.registries.*;
7+
import net.minecraft.client.gui.screen.ingame.*;
8+
import net.minecraft.entity.effect.*;
9+
import net.minecraft.util.*;
10+
import org.spongepowered.asm.mixin.*;
11+
import org.spongepowered.asm.mixin.injection.*;
12+
13+
@Mixin(AbstractInventoryScreen.class)
14+
public class AbstractInventoryScreenMixin {
15+
16+
@Unique
17+
private static final Identifier INCURABLE_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/incurable_effect_backgrounds.png");
18+
@Unique
19+
private static final Identifier NIGHT_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/night_alchemy_effect_backgrounds.png");
20+
@Unique
21+
private static final Identifier DIVINITY_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/divinity_effect_backgrounds.png");
22+
23+
@ModifyArg(method = "drawStatusEffectBackgrounds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0))
24+
public Identifier modifyWideBackground(Identifier texture, @Local StatusEffectInstance effect) {
25+
return getTexture(texture, effect);
26+
}
27+
28+
@ModifyArg(method = "drawStatusEffectBackgrounds", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1))
29+
public Identifier modifyBackground(Identifier texture, @Local StatusEffectInstance effect) {
30+
return getTexture(texture, effect);
31+
}
32+
33+
private static Identifier getTexture(Identifier texture, StatusEffectInstance effect) {
34+
var type = effect.getEffectType();
35+
36+
if (type == SpectrumStatusEffects.DIVINITY)
37+
return DIVINITY_EFFECT_BACKGROUNDS;
38+
39+
if (Incurable.isIncurable(effect) && type != SpectrumStatusEffects.ETERNAL_SLUMBER && type != SpectrumStatusEffects.FATAL_SLUMBER) {
40+
return INCURABLE_EFFECT_BACKGROUNDS;
41+
}
42+
43+
if (SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.NIGHT_ALCHEMY, type))
44+
return NIGHT_EFFECT_BACKGROUNDS;
45+
46+
return texture;
47+
}
48+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.dafuqs.spectrum.mixin.client;
2+
3+
import com.llamalad7.mixinextras.sugar.*;
4+
import de.dafuqs.spectrum.api.status_effect.*;
5+
import net.minecraft.client.network.*;
6+
import net.minecraft.entity.effect.*;
7+
import net.minecraft.network.packet.s2c.play.*;
8+
import org.spongepowered.asm.mixin.*;
9+
import org.spongepowered.asm.mixin.injection.*;
10+
import org.spongepowered.asm.mixin.injection.callback.*;
11+
12+
@Mixin(ClientPlayNetworkHandler.class)
13+
public class ClientPlayNetworkHandlerMixin {
14+
15+
@Inject(method = "onEntityStatusEffect", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setStatusEffect(Lnet/minecraft/entity/effect/StatusEffectInstance;Lnet/minecraft/entity/Entity;)V"))
16+
public void readAndApplyIncurableFlag(EntityStatusEffectS2CPacket packet, CallbackInfo ci, @Local StatusEffectInstance effect) {
17+
var incurable = ((IncurablePacketInject) packet).getIncurable();
18+
if (incurable) {
19+
((Incurable) effect).spectrum$setIncurable(true);
20+
}
21+
}
22+
}

src/main/java/de/dafuqs/spectrum/mixin/client/InGameHudMixin.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,32 @@
22

33
import com.llamalad7.mixinextras.injector.*;
44
import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
5+
import com.llamalad7.mixinextras.sugar.*;
6+
import de.dafuqs.spectrum.*;
7+
import de.dafuqs.spectrum.api.status_effect.*;
58
import de.dafuqs.spectrum.registries.*;
69
import de.dafuqs.spectrum.render.*;
710
import de.dafuqs.spectrum.status_effects.*;
811
import net.minecraft.client.*;
912
import net.minecraft.client.gui.*;
1013
import net.minecraft.client.gui.hud.*;
14+
import net.minecraft.entity.effect.*;
1115
import net.minecraft.entity.player.*;
16+
import net.minecraft.util.*;
1217
import org.spongepowered.asm.mixin.*;
1318
import org.spongepowered.asm.mixin.injection.*;
1419
import org.spongepowered.asm.mixin.injection.callback.*;
1520

1621
@Mixin(InGameHud.class)
1722
public abstract class InGameHudMixin {
1823

24+
@Unique
25+
private static final Identifier INCURABLE_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/incurable_effect_backgrounds.png");
26+
@Unique
27+
private static final Identifier NIGHT_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/night_alchemy_effect_backgrounds.png");
28+
@Unique
29+
private static final Identifier DIVINITY_EFFECT_BACKGROUNDS = SpectrumCommon.locate("textures/gui/divinity_effect_backgrounds.png");
30+
1931
@Shadow protected abstract PlayerEntity getCameraPlayer();
2032

2133
@Shadow public abstract void render(DrawContext context, float tickDelta);
@@ -75,4 +87,29 @@ private static boolean isInDim() {
7587
return SpectrumDimensions.DIMENSION_KEY.equals(client.player.getWorld().getRegistryKey());
7688
}
7789

90+
@ModifyArg(method = "renderStatusEffectOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 0))
91+
private Identifier modifyAmbientEffectBackgrounds(Identifier texture, @Local StatusEffectInstance effect) {
92+
return getTexture(texture, effect);
93+
}
94+
95+
@ModifyArg(method = "renderStatusEffectOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIIIII)V", ordinal = 1))
96+
private Identifier modifyEffectBackgrounds(Identifier texture, @Local StatusEffectInstance effect) {
97+
return getTexture(texture, effect);
98+
}
99+
100+
private static Identifier getTexture(Identifier texture, StatusEffectInstance effect) {
101+
var type = effect.getEffectType();
102+
103+
if (type == SpectrumStatusEffects.DIVINITY)
104+
return DIVINITY_EFFECT_BACKGROUNDS;
105+
106+
if (Incurable.isIncurable(effect) && type != SpectrumStatusEffects.ETERNAL_SLUMBER && type != SpectrumStatusEffects.FATAL_SLUMBER) {
107+
return INCURABLE_EFFECT_BACKGROUNDS;
108+
}
109+
110+
if (SpectrumStatusEffectTags.isIn(SpectrumStatusEffectTags.NIGHT_ALCHEMY, type))
111+
return NIGHT_EFFECT_BACKGROUNDS;
112+
113+
return texture;
114+
}
78115
}

src/main/java/de/dafuqs/spectrum/registries/SpectrumStatusEffectTags.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ public class SpectrumStatusEffectTags {
1111
public static TagKey<StatusEffect> INCURABLE;
1212
public static TagKey<StatusEffect> NO_DURATION_EXTENSION;
1313
public static TagKey<StatusEffect> SOPORIFIC;
14+
public static TagKey<StatusEffect> NIGHT_ALCHEMY;
1415

1516
public static void register() {
1617
INCURABLE = of("uncurable");
1718
NO_DURATION_EXTENSION = of("no_duration_extension");
1819
SOPORIFIC = of("soporific");
20+
NIGHT_ALCHEMY = of("night_alchemy");
1921
}
2022

2123
private static TagKey<StatusEffect> of(String id) {
1.04 KB
Loading
1.05 KB
Loading
900 Bytes
Loading
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"values": [
3+
"#spectrum:soporific",
4+
"spectrum:calming"
5+
]
6+
}

0 commit comments

Comments
 (0)