Skip to content

Commit

Permalink
updates to latest
Browse files Browse the repository at this point in the history
  • Loading branch information
westernat committed Jan 8, 2024
1 parent 6805753 commit abaf99d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
13 changes: 11 additions & 2 deletions src/main/java/org/mesdag/advjs/mixin/ServerBossBarMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import net.minecraft.entity.boss.ServerBossBar;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralTextContent;
import net.minecraft.text.TextContent;
import net.minecraft.text.TranslatableTextContent;
import org.mesdag.advjs.trigger.custom.CriteriaTriggers;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -15,7 +18,13 @@ public abstract class ServerBossBarMixin {
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V", shift = At.Shift.AFTER))
private void advJS$trigger(ServerPlayerEntity serverPlayer, CallbackInfo ci) {
ServerBossBar self = (ServerBossBar) (Object) this;
// TODO displayName
CriteriaTriggers.BOSS_EVENT.trigger(serverPlayer, self.shouldDarkenSky(), self.hasDragonMusic(), self.shouldThickenFog());
TextContent contents = self.getName().getContent();
String key = "";
if (contents instanceof TranslatableTextContent translatableContents) {
key = translatableContents.getKey();
} else if (contents instanceof LiteralTextContent literalContents) {
key = literalContents.string();
}
CriteriaTriggers.BOSS_EVENT.trigger(serverPlayer, self.shouldDarkenSky(), self.hasDragonMusic(), self.shouldThickenFog(), key);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
Expand All @@ -22,11 +21,12 @@ public class BossEventConditions extends AbstractCriterion<BossEventConditions.C
boolean darkenScreen = jsonObject.has("darken_screen") && jsonObject.get("darken_screen").getAsBoolean();
boolean playBossMusic = jsonObject.has("play_boss_music") && jsonObject.get("play_boss_music").getAsBoolean();
boolean createWorldFog = jsonObject.has("create_world_fog") && jsonObject.get("create_world_fog").getAsBoolean();
return new Conditions(composite, darkenScreen, playBossMusic, createWorldFog);
String key = jsonObject.has("key") ? jsonObject.get("key").getAsString() : "";
return new Conditions(composite, darkenScreen, playBossMusic, createWorldFog, key);
}

public void trigger(ServerPlayerEntity serverPlayer, boolean darkenScreen, boolean playBossMusic, boolean createWorldFog) {
this.trigger(serverPlayer, instance -> instance.matches(darkenScreen, playBossMusic, createWorldFog));
public void trigger(ServerPlayerEntity serverPlayer, boolean darkenScreen, boolean playBossMusic, boolean createWorldFog, String key) {
this.trigger(serverPlayer, instance -> instance.matches(darkenScreen, playBossMusic, createWorldFog, key));
}

@Override
Expand All @@ -37,13 +37,14 @@ public void trigger(ServerPlayerEntity serverPlayer, boolean darkenScreen, boole
public static Conditions bossEvent(Consumer<Builder> consumer) {
Builder builder = new Builder();
consumer.accept(builder);
return new Conditions(builder.player, builder.darkenScreen, builder.playBossMusic, builder.createWorldFog);
return new Conditions(builder.player, builder.darkenScreen, builder.playBossMusic, builder.createWorldFog, builder.key);
}

public static class Builder extends AbstractTriggerBuilder {
boolean darkenScreen = false;
boolean playBossMusic = false;
boolean createWorldFog = false;
String key = "";

@Info("Check darken screen.")
public void setDarkenScreen(boolean darkenScreen) {
Expand All @@ -59,22 +60,37 @@ public void setPlayBossMusic(boolean playBossMusic) {
public void setCreateWorldFog(boolean createWorldFog) {
this.createWorldFog = createWorldFog;
}

@Info("""
Match 'translation key' or 'literal text' of boss bar.
If set to "", it will not check key. Defaults to "".
""")
public void setKey(String key) {
this.key = key;
}
}

public static class Conditions extends AbstractCriterionConditions {
private final boolean darkenScreen;
private final boolean playBossMusic;
private final boolean createWorldFog;
private final String key;

public Conditions(LootContextPredicate composite, boolean darkenScreen, boolean playBossMusic, boolean createWorldFog) {
public Conditions(LootContextPredicate composite, boolean darkenScreen, boolean playBossMusic, boolean createWorldFog, String key) {
super(ID, composite);
this.darkenScreen = darkenScreen;
this.playBossMusic = playBossMusic;
this.createWorldFog = createWorldFog;
this.key = key;
}

public boolean matches(boolean darkenScreen, boolean playBossMusic, boolean createWorldFog) {
return this.darkenScreen == darkenScreen && this.playBossMusic && playBossMusic && this.createWorldFog == createWorldFog;
public boolean matches(boolean darkenScreen, boolean playBossMusic, boolean createWorldFog, String key) {
if (!this.key.equals("") && !this.key.equals(key)) {
return false;
} else {
return this.darkenScreen == darkenScreen && this.playBossMusic && playBossMusic && this.createWorldFog == createWorldFog;
}
}
}
}

0 comments on commit abaf99d

Please sign in to comment.