Skip to content

Commit

Permalink
Add DebugRender - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymoose7 committed Aug 29, 2024
1 parent fef076a commit 3e14fee
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/main/java/anticope/rejects/MeteorRejectsAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import meteordevelopment.meteorclient.systems.modules.Category;
import meteordevelopment.meteorclient.systems.modules.Modules;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.render.debug.DebugRenderer;
import net.minecraft.item.Items;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -22,6 +23,7 @@ public class MeteorRejectsAddon extends MeteorAddon {
public static final Logger LOG = LoggerFactory.getLogger("Rejects");
public static final Category CATEGORY = new Category("Rejects", Items.BARRIER.getDefaultStack());
public static final HudGroup HUD_GROUP = new HudGroup("Rejects");
public static DebugRenderer DEBUG_RENDERER;

@Override
public void onInitialize() {
Expand Down Expand Up @@ -57,6 +59,7 @@ public void onInitialize() {
modules.add(new Confuse());
modules.add(new CoordLogger());
modules.add(new CustomPackets());
modules.add(new DebugRender());
modules.add(new ExtraElytra());
modules.add(new FullFlight());
modules.add(new GamemodeNotifier());
Expand Down
128 changes: 128 additions & 0 deletions src/main/java/anticope/rejects/mixin/DebugInfoSenderMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
package anticope.rejects.mixin;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.brain.MemoryModuleType;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.ai.goal.GoalSelector;
import net.minecraft.entity.ai.goal.PrioritizedGoal;
import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.entity.mob.BreezeEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.s2c.custom.*;
import net.minecraft.registry.Registry;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.network.DebugInfoSender;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.structure.StructurePiece;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.village.raid.Raid;
import net.minecraft.world.StructureWorldAccess;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import net.minecraft.world.event.listener.GameEventListener;
import org.jetbrains.annotations.Nullable;
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 java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Mixin(DebugInfoSender.class)
public class DebugInfoSenderMixin {

@Shadow
private static void sendToAll(ServerWorld world, CustomPayload payload) {
throw new AssertionError();
}

//TODO: Fix this
@Inject(method = "sendPathfindingData", at = @At("HEAD"))
private static void sendPathfindingData(World world, MobEntity mob, @Nullable Path path, float nodeReachProximity, CallbackInfo ci) {
//sendToAll((ServerWorld) world, new DebugPathCustomPayload(mob.getId(), path, nodeReachProximity));
}

//TODO: Change delay
@Inject(method = "sendNeighborUpdate", at = @At("HEAD"))
private static void sendNeighborUpdate(World world, BlockPos pos, CallbackInfo ci) {
sendToAll((ServerWorld) world, new DebugNeighborsUpdateCustomPayload(world.getTime(), pos));
}

//TODO: fix
@Inject(method = "sendStructureStart", at = @At("HEAD"))
private static void sendStructureStart(StructureWorldAccess world, StructureStart structureStart, CallbackInfo ci) {
List<DebugStructuresCustomPayload.Piece> pieces = new ArrayList<>();
ServerWorld serverWorld = world.toServerWorld();

for (int i = 0; i < structureStart.getChildren().size(); i++) {
StructurePiece piece = structureStart.getChildren().get(i);
pieces.add(new DebugStructuresCustomPayload.Piece(piece.getBoundingBox(), false));
}

sendToAll(serverWorld, new DebugStructuresCustomPayload(serverWorld.getRegistryKey(), structureStart.getBoundingBox(), pieces));
}

@Inject(method = "sendGoalSelector", at = @At("HEAD"))
private static void sendGoalSelector(World world, MobEntity mob, GoalSelector goalSelector, CallbackInfo ci) {
List<DebugGoalSelectorCustomPayload.Goal> goals = ((MobEntityAccessor)mob).getGoalSelector().getGoals().stream().map((goal) ->
new DebugGoalSelectorCustomPayload.Goal(goal.getPriority(), goal.isRunning(), goal.getGoal().toString())).toList();

sendToAll((ServerWorld) world, new DebugGoalSelectorCustomPayload(mob.getId(), mob.getBlockPos(), goals));
}

@Inject(method = "sendRaids", at = @At("HEAD"))
private static void sendRaids(ServerWorld server, Collection<Raid> raids, CallbackInfo ci) {
sendToAll(server, new DebugRaidsCustomPayload(raids.stream().map(Raid::getCenter).toList()));
}

@Inject(method = "sendBrainDebugData", at = @At("HEAD"))
private static void sendBrainDebugData(LivingEntity living, CallbackInfo ci) {

}

/*@Inject(method = "sendBeeDebugData", at = @At("HEAD"))
private static void sendBeeDebugData(BeeEntity bee, CallbackInfo ci) {
sendToAll((ServerWorld) bee.getWorld(), new DebugBeeCustomPayload(new DebugBeeCustomPayload.Bee(bee.getUuid(), bee.getId(), bee.getPos(), bee.getNavigation().getCurrentPath(), bee.getHivePos(), bee.getFlowerPos(), bee.getMoveGoalTicks(), (Set)bee.getGoalSelector().getGoals().stream().map((prioritizedGoal) -> {
return prioritizedGoal.getGoal().toString();
}).collect(Collectors.toSet()), bee.getPossibleHives())));
}*/

@Inject(method = "sendBreezeDebugData", at = @At("HEAD"))
private static void sendBreezeDebugData(BreezeEntity breeze, CallbackInfo ci) {
sendToAll((ServerWorld) breeze.getWorld(), new DebugBreezeCustomPayload(new DebugBreezeCustomPayload.BreezeInfo(breeze.getUuid(), breeze.getId(), breeze.getTarget() == null ? null : breeze.getTarget().getId(), (BlockPos)breeze.getBrain().getOptionalMemory(MemoryModuleType.BREEZE_JUMP_TARGET).orElse((null)))));
}

@Inject(method = "sendGameEvent", at = @At("HEAD"))
private static void sendGameEvent(World world, RegistryEntry<GameEvent> event, Vec3d pos, CallbackInfo ci) {
if (world instanceof ServerWorld serverWorld) {
event.getKey().ifPresent((key) -> {
sendToAll(serverWorld, new DebugGameEventCustomPayload(key, pos));
});
}
}

@Inject(method = "sendGameEventListener", at = @At("HEAD"))
private static void sendGameEventListener(World world, GameEventListener eventListener, CallbackInfo ci) {
if (world instanceof ServerWorld serverWorld) {
sendToAll(serverWorld, new DebugGameEventListenersCustomPayload(eventListener.getPositionSource(), eventListener.getRange()));
}
}

/*
public static void sendBeehiveDebugData(World world, BlockPos pos, BlockState state, BeehiveBlockEntity blockEntity) {
}
*/

//gametest
//poi

}
25 changes: 25 additions & 0 deletions src/main/java/anticope/rejects/mixin/DebugRendererMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package anticope.rejects.mixin;

import anticope.rejects.modules.DebugRender;
import meteordevelopment.meteorclient.systems.modules.Modules;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.debug.DebugRenderer;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(DebugRenderer.class)
public class DebugRendererMixin {

@Inject(method = "render", at = @At("HEAD"))
public void render(MatrixStack matrixStack, VertexConsumerProvider.Immediate immediate, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) {
DebugRender debugRender = Modules.get().get(DebugRender.class);
if (debugRender != null && debugRender.isActive()) {
debugRender.render(matrixStack, immediate, cameraX, cameraY, cameraZ);
}
}


}
12 changes: 12 additions & 0 deletions src/main/java/anticope/rejects/mixin/MobEntityAccessor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package anticope.rejects.mixin;

import net.minecraft.entity.ai.goal.GoalSelector;
import net.minecraft.entity.mob.MobEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(MobEntity.class)
public interface MobEntityAccessor {
@Accessor("goalSelector")
GoalSelector getGoalSelector();
}
48 changes: 48 additions & 0 deletions src/main/java/anticope/rejects/mixin/PathMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package anticope.rejects.mixin;

import net.minecraft.entity.ai.pathing.Path;
import net.minecraft.entity.ai.pathing.PathNode;
import net.minecraft.entity.ai.pathing.TargetPathNode;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.BlockPos;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
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 java.util.List;
import java.util.Set;

@Mixin(Path.class)
public abstract class PathMixin {

@Shadow
@Mutable
@Nullable
private Path.DebugNodeInfo debugNodeInfos;

@Shadow
@Final
private List<PathNode> nodes;

@Shadow
@Final
private BlockPos target;

@Inject(method = {"toBuf"}, at = {@At("HEAD")})
private void toBuf(PacketByteBuf buf, CallbackInfo ci) {
this.debugNodeInfos = new Path.DebugNodeInfo(this.nodes.stream().filter((pathNode) -> {
return !pathNode.visited;
}).toArray((x$0) -> {
return new PathNode[x$0];
}), this.nodes.stream().filter((pathNode) -> {
return pathNode.visited;
}).toArray((x$0) -> {
return new PathNode[x$0];
}), Set.of(new TargetPathNode(this.target.getX(), this.target.getY(), this.target.getZ())));
}
}
60 changes: 60 additions & 0 deletions src/main/java/anticope/rejects/modules/DebugRender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package anticope.rejects.modules;

import anticope.rejects.MeteorRejectsAddon;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Module;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;

import java.util.HashMap;
import java.util.Map;

public class DebugRender extends Module {

private final SettingGroup sgGeneral = settings.getDefaultGroup();

private final Map<Setting<Boolean>, DebugRenderer> renderers = new HashMap<>();

public DebugRender() {
super(MeteorRejectsAddon.CATEGORY, "debug-renders", "Render useful debug information.");

addRenderer("lighting-debug", createRenderer(mc.debugRenderer.lightDebugRenderer::render));
addRenderer("pathfinding-debug", createRenderer(mc.debugRenderer.pathfindingDebugRenderer::render));
addRenderer("neighbor-updates", createRenderer(mc.debugRenderer.neighborUpdateDebugRenderer::render));
addRenderer("structure-outlines", createRenderer(mc.debugRenderer.structureDebugRenderer::render));
addRenderer("mob-goals", createRenderer(mc.debugRenderer.goalSelectorDebugRenderer::render));
addRenderer("raid-center", createRenderer(mc.debugRenderer.raidCenterDebugRenderer::render));
addRenderer("bee-brain", createRenderer(mc.debugRenderer.beeDebugRenderer::render));
addRenderer("breeze-brain", createRenderer(mc.debugRenderer.breezeDebugRenderer::render));
addRenderer("game-event-1", createRenderer(mc.debugRenderer.breezeDebugRenderer::render));
addRenderer("game-event-2", createRenderer(mc.debugRenderer.breezeDebugRenderer::render));
}

private DebugRenderer createRenderer(DebugRenderer debugRenderer) {
return debugRenderer;
}

private void addRenderer(String name, DebugRenderer renderer) {
Setting<Boolean> setting = sgGeneral.add(new BoolSetting.Builder()
.name(name)
.description("add-description-here")
.defaultValue(false)
.build()
);
renderers.put(setting, renderer);
}

public interface DebugRenderer {
void render(MatrixStack matrixStack, VertexConsumerProvider.Immediate immediate, double cameraX, double cameraY, double cameraZ);
}

public void render(MatrixStack matrixStack, VertexConsumerProvider.Immediate immediate, double cameraX, double cameraY, double cameraZ) {
for (Map.Entry<Setting<Boolean>, DebugRenderer> entry : renderers.entrySet()) {
if (entry.getKey().get()) {
entry.getValue().render(matrixStack, immediate, cameraX, cameraY, cameraZ);
}
}
}
}
8 changes: 7 additions & 1 deletion src/main/resources/meteor-rejects.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
"CommandSuggestorMixin",
"CountPlacementModifierAccessor",
"Deadmau5FeatureRendererMixin",
"DebugInfoSenderMixin",
"DebugRendererMixin",
"EntityAccessor",
"GameRendererMixin",
"HandshakeC2SPacketAccessor",
"HeightContextMixin",
"HeightRangePlacementModifierAccessor",
"LivingEntityMixin",
"LivingEntityRendererMixin",
"MobEntityAccessor",
"MultiplayerScreenAccessor",
"MultiplayerScreenMixin",
"PlayerEntityMixin",
Expand All @@ -30,5 +33,8 @@
],
"injectors": {
"defaultRequire": 1
}
},
"mixins": [
"PathMixin"
]
}

0 comments on commit 3e14fee

Please sign in to comment.