Skip to content

Commit

Permalink
Add Yang Glyph Notification (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthegreat1 authored Mar 18, 2024
1 parent 969fa4f commit 8dc3119
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1117,10 +1117,13 @@ public static class Slayer {

public static class EndermanSlayer {
@SerialEntry
public boolean highlightNukekubiHeads = true;
public boolean enableYangGlyphsNotification = true;

@SerialEntry
public boolean highlightBeacons = true;

@SerialEntry
public boolean highlightNukekubiHeads = true;
}

public static class VampireSlayer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
.name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer"))
.collapsed(true)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads"))
.binding(defaults.slayer.endermanSlayer.highlightNukekubiHeads,
() -> config.slayer.endermanSlayer.highlightNukekubiHeads,
newValue -> config.slayer.endermanSlayer.highlightNukekubiHeads = newValue)
.name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer.enableYangGlyphsNotification"))
.binding(defaults.slayer.endermanSlayer.enableYangGlyphsNotification,
() -> config.slayer.endermanSlayer.enableYangGlyphsNotification,
newValue -> config.slayer.endermanSlayer.enableYangGlyphsNotification = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
Expand All @@ -35,6 +35,13 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.slayer.endermanSlayer.highlightBeacons = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads"))
.binding(defaults.slayer.endermanSlayer.highlightNukekubiHeads,
() -> config.slayer.endermanSlayer.highlightNukekubiHeads,
newValue -> config.slayer.endermanSlayer.highlightNukekubiHeads = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.build())

//Vampire Slayer
Expand Down
47 changes: 39 additions & 8 deletions src/main/java/de/hysky/skyblocker/mixin/DataTrackerMixin.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,50 @@
package de.hysky.skyblocker.mixin;

import com.llamalad7.mixinextras.sugar.Local;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.mixin.accessor.EndermanEntityAccessor;
import de.hysky.skyblocker.skyblock.entity.MobGlow;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import de.hysky.skyblocker.utils.Utils;
import net.minecraft.entity.data.DataTracker;
import java.util.Optional;

@Mixin(DataTracker.class)
public class DataTrackerMixin {
public abstract class DataTrackerMixin {
@Shadow
@Final
private Entity trackedEntity;

@SuppressWarnings("ConstantValue")
@Inject(method = "writeUpdatedEntries", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/data/DataTracker;copyToFrom(Lnet/minecraft/entity/data/DataTracker$Entry;Lnet/minecraft/entity/data/DataTracker$SerializedEntry;)V"))
private <T> void skyblocker$onWriteUpdatedEntries(CallbackInfo ci, @Local DataTracker.Entry<T> entry, @Local DataTracker.SerializedEntry<T> serializedEntry) {
if (Utils.isInTheEnd() && SkyblockerConfigManager.get().slayer.endermanSlayer.enableYangGlyphsNotification && entry.getData() == EndermanEntityAccessor.getCARRIED_BLOCK() && entry.get() instanceof Optional<?> value && value.isPresent() && value.get() instanceof BlockState state && state.isOf(Blocks.BEACON) && ((Optional<?>) serializedEntry.value()).isEmpty()) {
MinecraftClient client = MinecraftClient.getInstance();
if (MobGlow.getArmorStands(trackedEntity).stream().anyMatch(armorStand -> armorStand.getName().getString().contains(client.getSession().getUsername()))) {
client.inGameHud.setTitleTicks(5, 20, 10);
client.inGameHud.setTitle(Text.literal("Yang Glyph!").formatted(Formatting.RED));
client.player.playSound(SoundEvents.BLOCK_NOTE_BLOCK_PLING.value(), 100f, 0.1f);
}
}
}

@Inject(method = "copyToFrom", at = @At(value = "NEW", target = "Ljava/lang/IllegalStateException;", shift = At.Shift.BEFORE), cancellable = true)
public void skyblocker$ignoreInvalidDataExceptions(CallbackInfo ci) {
//These exceptions cause annoying small lag spikes for some reason
if (Utils.isOnHypixel()) ci.cancel();
}
@SuppressWarnings({"MixinAnnotationTarget", "UnresolvedMixinReference"})
@Inject(method = "copyToFrom", at = @At(value = "NEW", target = "Ljava/lang/IllegalStateException;"), cancellable = true)
public void skyblocker$ignoreInvalidDataExceptions(CallbackInfo ci) {
//These exceptions cause annoying small lag spikes for some reason
if (Utils.isOnHypixel()) ci.cancel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package de.hysky.skyblocker.mixin.accessor;

import net.minecraft.block.BlockState;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.mob.EndermanEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Optional;

@Mixin(EndermanEntity.class)
public interface EndermanEntityAccessor {
@Accessor
static TrackedData<Optional<BlockState>> getCARRIED_BLOCK() {
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private static void onMessage(Text text, boolean overlay) {
private static void render(WorldRenderContext context) {
if (Utils.isInTheEnd() && SkyblockerConfigManager.get().slayer.endermanSlayer.highlightBeacons) {
for (BlockPos pos : beaconPositions) {
RenderHelper.renderFilled(context, pos, RED_COLOR_COMPONENTS, 0.5f, false);
RenderHelper.renderFilled(context, pos, RED_COLOR_COMPONENTS, 0.5f, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static boolean shouldMobGlow(Entity entity) {

// Regular Mobs
if (!(entity instanceof ArmorStandEntity)) {
List<ArmorStandEntity> armorStands = getArmorStands(entity.getWorld(), box);
List<ArmorStandEntity> armorStands = getArmorStands(entity);

if (!armorStands.isEmpty() && armorStands.get(0).getName().getString().contains("✯"))
return SkyblockerConfigManager.get().locations.dungeons.starredMobGlow;
Expand Down Expand Up @@ -79,7 +79,11 @@ public static boolean shouldMobGlow(Entity entity) {
return false;
}

private static List<ArmorStandEntity> getArmorStands(World world, Box box) {
public static List<ArmorStandEntity> getArmorStands(Entity entity) {
return getArmorStands(entity.getWorld(), entity.getBoundingBox());
}

public static List<ArmorStandEntity> getArmorStands(World world, Box box) {
return world.getEntitiesByClass(ArmorStandEntity.class, box.expand(0, 2, 0), EntityPredicates.NOT_MOUNTED);
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,10 @@
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.amethyst": "Amethyst",
"text.autoconfig.skyblocker.option.messages.chatRules.screen.ruleScreen.sounds.anvil": "Break",
"text.autoconfig.skyblocker.category.slayer": "Slayers",
"text.autoconfig.skyblocker.option.slayer.endermanSlayer": "[Beta] Enderman Slayer",
"text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads": "Nukekubi Head Highlighting",
"text.autoconfig.skyblocker.option.slayer.endermanSlayer": "Enderman Slayer",
"text.autoconfig.skyblocker.option.slayer.endermanSlayer.enableYangGlyphsNotification": "Enable Yang Glyphs notification",
"text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightBeacons": "Beacon Highlighting",
"text.autoconfig.skyblocker.option.slayer.endermanSlayer.highlightNukekubiHeads": "Nukekubi Head Highlighting",
"text.autoconfig.skyblocker.option.slayer.vampireSlayer": "Vampire Slayer",
"text.autoconfig.skyblocker.option.slayer.vampireSlayer.enableEffigyWaypoints": "Enable Effigy Waypoints",
"text.autoconfig.skyblocker.option.slayer.vampireSlayer.compactEffigyWaypoints": "Compact Effigy Waypoints",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"YggdrasilServicesKeyInfoMixin",
"accessor.BeaconBlockEntityRendererInvoker",
"accessor.DrawContextInvoker",
"accessor.EndermanEntityAccessor",
"accessor.FrustumInvoker",
"accessor.HandledScreenAccessor",
"accessor.ItemStackAccessor",
Expand Down

0 comments on commit 8dc3119

Please sign in to comment.