Skip to content

Commit

Permalink
DebugRender polish
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymoose7 committed Sep 1, 2024
1 parent 3e14fee commit b05fbe3
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 33 deletions.
137 changes: 113 additions & 24 deletions src/main/java/anticope/rejects/mixin/DebugInfoSenderMixin.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
package anticope.rejects.mixin;

import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BeehiveBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.brain.Activity;
import net.minecraft.entity.ai.brain.Brain;
import net.minecraft.entity.ai.brain.MemoryModuleType;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.ai.brain.task.Task;
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.mob.WardenEntity;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.network.packet.s2c.custom.*;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.tag.StructureTags;
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.util.NameGenerator;
import net.minecraft.util.math.*;
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 net.minecraft.world.gen.structure.Structure;
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.*;
import java.util.stream.Collectors;

// https://modrinth.com/mod/dev-tools-unlocker/versions - for good base
@Mixin(DebugInfoSender.class)
public class DebugInfoSenderMixin {

Expand All @@ -45,13 +52,60 @@ private static void sendToAll(ServerWorld world, CustomPayload payload) {
throw new AssertionError();
}

//TODO: Fix this
@Shadow
private static List<String> listMemories(LivingEntity entity, long currentTime) {
throw new AssertionError();
}

@Inject(method = {"sendChunkWatchingChange"}, at = {@At("HEAD")})
private static void sendChunkWatchingChange(ServerWorld world, ChunkPos pos, CallbackInfo ci) {
sendToAll(world, new DebugWorldgenAttemptCustomPayload(pos.getStartPos().up(100), 1.0F, 1.0F, 1.0F, 1.0F, 1.0F));
}

@Inject(method = {"sendPoiAddition"}, at = {@At("HEAD")})
private static void sendPoiAddition(ServerWorld world, BlockPos pos, CallbackInfo ci) {
world.getPointOfInterestStorage().getType(pos).ifPresent((registryEntry) -> {
sendToAll(world, new DebugPoiAddedCustomPayload(pos, registryEntry.getIdAsString(), world.getPointOfInterestStorage().getFreeTickets(pos)));
});
}

@Inject(method = {"sendPoiRemoval"}, at = {@At("HEAD")})
private static void sendPoiRemoval(ServerWorld world, BlockPos pos, CallbackInfo ci) {
sendToAll(world, new DebugPoiRemovedCustomPayload(pos));
}

@Inject(method = {"sendPointOfInterest"}, at = {@At("HEAD")})
private static void sendPointOfInterest(ServerWorld world, BlockPos pos, CallbackInfo ci) {
sendToAll(world, new DebugPoiTicketCountCustomPayload(pos, world.getPointOfInterestStorage().getFreeTickets(pos)));
}

@Inject(method = {"sendPoi"}, at = {@At("HEAD")})
private static void sendPoi(ServerWorld world, BlockPos pos, CallbackInfo ci) {
Registry<Structure> structureRegistry = world.getRegistryManager().get(RegistryKeys.STRUCTURE);
ChunkSectionPos chunkSectionPos = ChunkSectionPos.from(pos);

for (RegistryEntry<Structure> entry : structureRegistry.iterateEntries(StructureTags.VILLAGE)) {
if (!world.getStructureAccessor().getStructureStarts(chunkSectionPos, entry.value()).isEmpty()) {
return;
}
}

sendToAll(world, new DebugVillageSectionsCustomPayload(Set.of(chunkSectionPos), Set.of()));
}

private static void addPoi(Brain<?> brain, MemoryModuleType<GlobalPos> memoryModuleType, Set<BlockPos> set) {
brain.getOptionalMemory(memoryModuleType)
.map(GlobalPos::pos)
.ifPresent(Objects.requireNonNull(set)::add);
}

@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));
}
if (path != null) {
sendToAll((ServerWorld) world, new DebugPathCustomPayload(mob.getId(), path, nodeReachProximity));
}}

//TODO: Change delay
//TODO: Add 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));
Expand Down Expand Up @@ -85,16 +139,54 @@ private static void sendRaids(ServerWorld server, Collection<Raid> raids, Callba
}

@Inject(method = "sendBrainDebugData", at = @At("HEAD"))
private static void sendBrainDebugData(LivingEntity living, CallbackInfo ci) {
private static void sendBrainDebugData(LivingEntity livingEntity, CallbackInfo ci) {
MobEntity entity = (MobEntity)livingEntity;
ServerWorld serverWorld = (ServerWorld)entity.getWorld();

List<String> gossips = new ArrayList<>();
Set<BlockPos> pois = new HashSet<>();
Set<BlockPos> potentialPois = new HashSet<>();

String profession = "";
String inventory = "";
int xp = 0;
int angerLevel = -1;
boolean wantsGolem = false;

if (entity instanceof WardenEntity wardenEntity) {
angerLevel = wardenEntity.getAnger();
} else if (entity instanceof VillagerEntity villager) {
profession = villager.getVillagerData().getProfession().toString();
xp = villager.getExperience();
inventory = villager.getInventory().toString();
wantsGolem = villager.canSummonGolem(serverWorld.getTime());

villager.getGossip().getEntityReputationAssociatedGossips().forEach((uuid, associatedGossip) -> {
Entity gossipEntity = serverWorld.getEntity(uuid);
if (gossipEntity != null) {
String name = NameGenerator.name(gossipEntity);

associatedGossip.object2IntEntrySet().forEach(entry ->
gossips.add(name + ": " + entry.getKey().asString() + " " + entry.getValue())
);
}
});

Brain<?> brain = villager.getBrain();
addPoi(brain, MemoryModuleType.HOME, pois);
addPoi(brain, MemoryModuleType.JOB_SITE, pois);
addPoi(brain, MemoryModuleType.MEETING_POINT, pois);
addPoi(brain, MemoryModuleType.HIDING_PLACE, pois);
addPoi(brain, MemoryModuleType.POTENTIAL_JOB_SITE, potentialPois);
}

sendToAll(serverWorld, new DebugBrainCustomPayload(new DebugBrainCustomPayload.Brain(entity.getUuid(), entity.getId(), entity.getName().getString(), profession, xp, entity.getHealth(), entity.getMaxHealth(), entity.getPos(), inventory, entity.getNavigation().getCurrentPath(), wantsGolem, angerLevel, entity.getBrain().getPossibleActivities().stream().map(Activity::toString).toList(), entity.getBrain().getRunningTasks().stream().map(Task::getName).toList(), listMemories(entity, serverWorld.getTime()), gossips, pois, potentialPois)));
}

/*@Inject(method = "sendBeeDebugData", at = @At("HEAD"))
@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())));
}*/
sendToAll((ServerWorld) bee.getWorld(), new DebugBeeCustomPayload(new DebugBeeCustomPayload.Bee(bee.getUuid(), bee.getId(), bee.getPos(), bee.getNavigation().getCurrentPath(), bee.getHivePos(), bee.getFlowerPos(), bee.getMoveGoalTicks(), bee.getGoalSelector().getGoals().stream().map((prioritizedGoal) -> prioritizedGoal.getGoal().toString()).collect(Collectors.toSet()), bee.getPossibleHives())));
}

@Inject(method = "sendBreezeDebugData", at = @At("HEAD"))
private static void sendBreezeDebugData(BreezeEntity breeze, CallbackInfo ci) {
Expand All @@ -117,12 +209,9 @@ private static void sendGameEventListener(World world, GameEventListener eventLi
}
}

/*
public static void sendBeehiveDebugData(World world, BlockPos pos, BlockState state, BeehiveBlockEntity blockEntity) {
@Inject(method = "sendBeehiveDebugData", at = @At("HEAD"))
private static void sendBeehiveDebugData(World world, BlockPos pos, BlockState state, BeehiveBlockEntity blockEntity, CallbackInfo ci) {
sendToAll((ServerWorld) world, new DebugHiveCustomPayload(new DebugHiveCustomPayload.HiveInfo(pos, blockEntity.getType().toString(), blockEntity.getBeeCount(), blockEntity.getHoneyLevel(state), blockEntity.isSmoked())));
}
*/

//gametest
//poi

}
27 changes: 18 additions & 9 deletions src/main/java/anticope/rejects/modules/DebugRender.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,41 @@
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("bee-brain-&-hive", createRenderer(mc.debugRenderer.beeDebugRenderer::render));
addRenderer("breeze-brain", createRenderer(mc.debugRenderer.breezeDebugRenderer::render));
addRenderer("block-outline", createRenderer(mc.debugRenderer.blockOutlineDebugRenderer::render));
addRenderer("chunk-loading-progress", createRenderer(mc.debugRenderer.chunkLoadingDebugRenderer::render));
addRenderer("collision", createRenderer(mc.debugRenderer.collisionDebugRenderer::render));
addRenderer("game-event-1", createRenderer(mc.debugRenderer.gameEventDebugRenderer::render));
addRenderer("game-event-2", createRenderer(mc.debugRenderer.gameEventDebugRenderer::render));
addRenderer("mob-goals", createRenderer(mc.debugRenderer.goalSelectorDebugRenderer::render));
addRenderer("heightmap", createRenderer(mc.debugRenderer.heightmapDebugRenderer::render));
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("pathfinding-debug", createRenderer(mc.debugRenderer.pathfindingDebugRenderer::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));
addRenderer("skylight", createRenderer(mc.debugRenderer.skyLightDebugRenderer::render));
addRenderer("structure-outlines", createRenderer(mc.debugRenderer.structureDebugRenderer::render));
addRenderer("villager-/-brain-/-POI", createRenderer(mc.debugRenderer.villageDebugRenderer::render));
addRenderer("village-sections", createRenderer(mc.debugRenderer.villageSectionsDebugRenderer::render));
addRenderer("water", createRenderer(mc.debugRenderer.waterDebugRenderer::render));
addRenderer("worldgen-attempt", createRenderer(mc.debugRenderer.worldGenAttemptDebugRenderer::render));
//gametest
}

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

//TODO: add descriptions
private void addRenderer(String name, DebugRenderer renderer) {
Setting<Boolean> setting = sgGeneral.add(new BoolSetting.Builder()
.name(name)
.description("add-description-here")
.defaultValue(false)
.build()
);
Expand Down

0 comments on commit b05fbe3

Please sign in to comment.