Skip to content

Commit

Permalink
Merge pull request #446 from kevinthegreat1/debug
Browse files Browse the repository at this point in the history
Update Debug Mode
  • Loading branch information
AzureAaron authored Dec 15, 2023
2 parents ab3d2e8 + ff69b0e commit 6795c4d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.skyblock.*;
import de.hysky.skyblocker.skyblock.waypoint.MythologicalRitual;
import de.hysky.skyblocker.skyblock.dungeon.*;
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonSecrets;
import de.hysky.skyblocker.skyblock.dungeon.secrets.SecretsTracker;
Expand All @@ -18,11 +17,12 @@
import de.hysky.skyblocker.skyblock.rift.TheRift;
import de.hysky.skyblocker.skyblock.shortcut.Shortcuts;
import de.hysky.skyblocker.skyblock.special.SpecialEffects;
import de.hysky.skyblocker.skyblock.waypoint.Relics;
import de.hysky.skyblocker.skyblock.tabhud.TabHud;
import de.hysky.skyblocker.skyblock.tabhud.screenbuilder.ScreenMaster;
import de.hysky.skyblocker.skyblock.tabhud.util.PlayerListMgr;
import de.hysky.skyblocker.skyblock.waypoint.FairySouls;
import de.hysky.skyblocker.skyblock.waypoint.MythologicalRitual;
import de.hysky.skyblocker.skyblock.waypoint.Relics;
import de.hysky.skyblocker.utils.ApiUtils;
import de.hysky.skyblocker.utils.NEURepoManager;
import de.hysky.skyblocker.utils.Utils;
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/de/hysky/skyblocker/debug/Debug.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
package de.hysky.skyblocker.debug;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.utils.ItemUtils;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.text.Text;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class Debug {
private static final boolean DEBUG_ENABLED = Boolean.parseBoolean(System.getProperty("skyblocker.debug", "false"));

public static boolean debugEnabled() {
return DEBUG_ENABLED || FabricLoader.getInstance().isDevelopmentEnvironment();
}

public static void init() {
if (DEBUG_ENABLED || FabricLoader.getInstance().isDevelopmentEnvironment()) {
ClientCommandRegistrationCallback.EVENT.register(DumpPlayersCommand::register);
if (debugEnabled()) {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("debug")
.then(dumpPlayersCommand())
.then(ItemUtils.dumpHeldItemNbtCommand())
)));
}
}

private static LiteralArgumentBuilder<FabricClientCommandSource> dumpPlayersCommand() {
return literal("dumpPlayers")
.executes(context -> {
context.getSource().getWorld().getPlayers().forEach(player -> context.getSource().sendFeedback(Text.of("'" + player.getName().getString() + "'")));
return Command.SINGLE_SUCCESS;
});
}
}
31 changes: 0 additions & 31 deletions src/main/java/de/hysky/skyblocker/debug/DumpPlayersCommand.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.hysky.skyblocker.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(EntityRenderDispatcher.class)
public class EntityRenderDispatcherMixin {
@ModifyExpressionValue(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;isInvisible()Z", ordinal = 1))
private <E extends Entity> boolean skyblocker$armorStandHitboxVisible(boolean invisible, E entity) {
return (!(entity instanceof ArmorStandEntity) || !Utils.isOnHypixel() || !Debug.debugEnabled()) && invisible;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.hysky.skyblocker.mixin;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.utils.Utils;
import net.minecraft.client.render.entity.LivingEntityRenderer;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.decoration.ArmorStandEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(LivingEntityRenderer.class)
public class LivingEntityRendererMixin {
@ModifyExpressionValue(method = "render(Lnet/minecraft/entity/LivingEntity;FFLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;I)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/entity/LivingEntityRenderer;isVisible(Lnet/minecraft/entity/LivingEntity;)Z"))
private <T extends LivingEntity> boolean skyblocker$armorStandVisible(boolean visible, T entity) {
return entity instanceof ArmorStandEntity && Utils.isOnHypixel() && Debug.debugEnabled() || visible;
}
}
12 changes: 12 additions & 0 deletions src/main/java/de/hysky/skyblocker/utils/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package de.hysky.skyblocker.utils;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
Expand All @@ -18,13 +21,22 @@
import java.util.function.Predicate;
import java.util.regex.Pattern;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class ItemUtils {
public static final String EXTRA_ATTRIBUTES = "ExtraAttributes";
public static final String ID = "id";
public static final String UUID = "uuid";
public static final Pattern NOT_DURABILITY = Pattern.compile("[^0-9 /]");
public static final Predicate<String> FUEL_PREDICATE = line -> line.contains("Fuel: ");

public static LiteralArgumentBuilder<FabricClientCommandSource> dumpHeldItemNbtCommand() {
return literal("dumpHeldItemNbt").executes(context -> {
context.getSource().sendFeedback(Text.literal("[Skyblocker Debug] Held Item Nbt: " + context.getSource().getPlayer().getMainHandStack().writeNbt(new NbtCompound())));
return Command.SINGLE_SUCCESS;
});
}

public static List<Text> getTooltips(ItemStack item) {
MinecraftClient client = MinecraftClient.getInstance();
return client.player == null || item == null ? Collections.emptyList() : item.getTooltip(client.player, TooltipContext.Default.BASIC);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/skyblocker.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"ClientPlayNetworkHandlerMixin",
"DrawContextMixin",
"DyeableItemMixin",
"EntityRenderDispatcherMixin",
"FarmlandBlockMixin",
"GenericContainerScreenHandlerMixin",
"HandledScreenMixin",
Expand All @@ -21,6 +22,7 @@
"ItemMixin",
"ItemStackMixin",
"LeverBlockMixin",
"LivingEntityRendererMixin",
"MinecraftClientMixin",
"PlayerListHudMixin",
"PlayerSkinProviderMixin",
Expand Down

0 comments on commit 6795c4d

Please sign in to comment.