diff --git a/src/main/java/net/frozenblock/lib/debug/client/impl/DebugRenderManager.java b/src/main/java/net/frozenblock/lib/debug/client/impl/DebugRenderManager.java index d8caf0eec..6162bd527 100644 --- a/src/main/java/net/frozenblock/lib/debug/client/impl/DebugRenderManager.java +++ b/src/main/java/net/frozenblock/lib/debug/client/impl/DebugRenderManager.java @@ -33,6 +33,7 @@ import net.frozenblock.lib.debug.client.renderer.ImprovedGameEventListenerRenderer; import net.frozenblock.lib.debug.client.renderer.ImprovedGoalSelectorDebugRenderer; import net.frozenblock.lib.debug.client.renderer.WindDebugRenderer; +import net.frozenblock.lib.debug.client.renderer.WindDisturbanceDebugRenderer; import net.frozenblock.lib.debug.networking.GoalDebugRemovePayload; import net.frozenblock.lib.debug.networking.ImprovedGameEventDebugPayload; import net.frozenblock.lib.debug.networking.ImprovedGameEventListenerDebugPayload; @@ -127,6 +128,20 @@ public static void init() { registerRenderer(FrozenSharedConstants.id("wind"), windDebugRenderer::render); }); + + DebugRendererEvents.DEBUG_RENDERERS_CREATED.register(client -> { + WindDisturbanceDebugRenderer windDisturbanceDebugRenderer = new WindDisturbanceDebugRenderer(client); + + ClientTickEvents.START_WORLD_TICK.register(clientLevel -> { + if (FrozenLibConfig.IS_DEBUG) { + windDisturbanceDebugRenderer.tick(); + } + }); + + addClearRunnable(windDisturbanceDebugRenderer::clear); + + registerRenderer(FrozenSharedConstants.id("wind_disturbance"), windDisturbanceDebugRenderer::render); + }); } public static void clearAdditionalRenderers() { diff --git a/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDebugRenderer.java b/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDebugRenderer.java index dbbdc44f1..edbd814b9 100644 --- a/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDebugRenderer.java +++ b/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDebugRenderer.java @@ -28,24 +28,19 @@ import net.fabricmc.api.Environment; import net.frozenblock.lib.core.client.api.FrustumUtil; import net.frozenblock.lib.wind.api.ClientWindManager; -import net.frozenblock.lib.wind.api.WindDisturbance; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.debug.DebugRenderer; -import net.minecraft.core.BlockPos; import net.minecraft.util.FastColor; import net.minecraft.util.Mth; -import net.minecraft.world.phys.AABB; +import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; -import net.minecraft.world.phys.shapes.Shapes; import org.jetbrains.annotations.NotNull; @Environment(EnvType.CLIENT) public class WindDebugRenderer implements DebugRenderer.SimpleDebugRenderer { private final Minecraft minecraft; - private List> windDisturbances = Collections.emptyList(); private List accessedWindPositions = Collections.emptyList(); private List>> windNodes = Collections.emptyList(); @@ -54,9 +49,6 @@ public WindDebugRenderer(Minecraft client) { } public void tick() { - this.windDisturbances = ImmutableList.copyOf( - ClientWindManager.getWindDisturbances() - ); this.accessedWindPositions = ClientWindManager.getAccessedPositions(); this.windNodes = ImmutableList.copyOf( this.createAllWindNodes() @@ -65,62 +57,21 @@ public void tick() { @Override public void clear() { - this.windDisturbances = Collections.emptyList(); this.accessedWindPositions = Collections.emptyList(); this.windNodes = Collections.emptyList(); } @Override public void render(PoseStack matrices, MultiBufferSource vertexConsumers, double cameraX, double cameraY, double cameraZ) { - this.windDisturbances.forEach( - windDisturbance -> { - LevelRenderer.renderVoxelShape( - matrices, - vertexConsumers.getBuffer(RenderType.lines()), - Shapes.create(windDisturbance.affectedArea), - -cameraX, - -cameraY, - -cameraZ, - 0.5F, - 1F, - 0.5F, - 0.35F, - true - ); - renderFilledBox( - matrices, - vertexConsumers, - AABB.ofSize(windDisturbance.origin, 0.2D, 0.2D, 0.2D), - cameraX, cameraY, cameraZ - ); - } - ); - renderWindNodesFromList(matrices, vertexConsumers, cameraX, cameraY, cameraZ, this.windNodes); } private @NotNull List>> createAllWindNodes() { List>> windNodes = new ArrayList<>(); - this.windDisturbances.forEach( - windDisturbance -> { - if (FrustumUtil.isVisible(windDisturbance.affectedArea)) { - BlockPos.betweenClosed( - BlockPos.containing(windDisturbance.affectedArea.getMinPosition()), - BlockPos.containing(windDisturbance.affectedArea.getMaxPosition()) - ).forEach( - blockPos -> { - Vec3 blockPosCenter = Vec3.atCenterOf(blockPos); - windNodes.add(createWindNodes(blockPosCenter, 1D, true)); - } - ); - } - } - ); - this.accessedWindPositions.forEach( vec3 -> { if (FrustumUtil.isVisible(vec3, 0.5D)) { - windNodes.add(createWindNodes(vec3, 1.5D, false)); + windNodes.add(createWindNodes(this.minecraft.level, vec3, 1.5D, false)); } } ); @@ -128,11 +79,11 @@ public void render(PoseStack matrices, MultiBufferSource vertexConsumers, double return windNodes; } - private @NotNull List> createWindNodes(Vec3 origin, double stretch, boolean disturbanceOnly) { + protected static @NotNull List> createWindNodes(Level level, Vec3 origin, double stretch, boolean disturbanceOnly) { List> windNodes = new ArrayList<>(); Vec3 wind = disturbanceOnly ? - ClientWindManager.getRawDisturbanceMovement(this.minecraft.level, origin) - : ClientWindManager.getWindMovement(this.minecraft.level, origin); + ClientWindManager.getRawDisturbanceMovement(level, origin) + : ClientWindManager.getWindMovement(level, origin); double windlength = wind.length(); if (windlength != 0D) { int increments = 3; @@ -155,15 +106,15 @@ public void render(PoseStack matrices, MultiBufferSource vertexConsumers, double ); lineStart = lineEnd; wind = disturbanceOnly ? - ClientWindManager.getRawDisturbanceMovement(this.minecraft.level, lineStart) - : ClientWindManager.getWindMovement(this.minecraft.level, lineStart); + ClientWindManager.getRawDisturbanceMovement(level, lineStart) + : ClientWindManager.getWindMovement(level, lineStart); } } return windNodes; } - private int calculateNodeColor(double strength, boolean disturbanceOnly) { + protected static int calculateNodeColor(double strength, boolean disturbanceOnly) { return FastColor.ARGB32.color( 255, (int) Mth.lerp(strength, 255, 0), @@ -172,7 +123,7 @@ private int calculateNodeColor(double strength, boolean disturbanceOnly) { ); } - private static void renderWindNodesFromList( + protected static void renderWindNodesFromList( PoseStack matrices, MultiBufferSource vertexConsumers, double cameraX, @@ -183,7 +134,7 @@ private static void renderWindNodesFromList( windNodes.forEach(nodes -> renderWindNodes(matrices, vertexConsumers, cameraX, cameraY, cameraZ, nodes)); } - private static void renderWindNodes( + protected static void renderWindNodes( PoseStack matrices, MultiBufferSource vertexConsumers, double cameraX, @@ -210,16 +161,6 @@ private static void renderWindNodes( } } - private static void renderFilledBox( - PoseStack matrices, - MultiBufferSource vertexConsumers, - @NotNull AABB box, - double cameraX, double cameraY, double cameraZ - ) { - Vec3 vec3 = new Vec3(-cameraX, -cameraY, -cameraZ); - DebugRenderer.renderFilledBox(matrices, vertexConsumers, box.move(vec3), 1F, 1F, 1F, 1F); - } - private static void drawLine( @NotNull PoseStack matrices, @NotNull MultiBufferSource vertexConsumers, diff --git a/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDisturbanceDebugRenderer.java b/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDisturbanceDebugRenderer.java new file mode 100644 index 000000000..92762db51 --- /dev/null +++ b/src/main/java/net/frozenblock/lib/debug/client/renderer/WindDisturbanceDebugRenderer.java @@ -0,0 +1,128 @@ +/* + * Copyright (C) 2024 FrozenBlock + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.frozenblock.lib.debug.client.renderer; + +import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.datafixers.util.Pair; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.frozenblock.lib.core.client.api.FrustumUtil; +import net.frozenblock.lib.wind.api.ClientWindManager; +import net.frozenblock.lib.wind.api.WindDisturbance; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.LevelRenderer; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.client.renderer.debug.DebugRenderer; +import net.minecraft.core.BlockPos; +import net.minecraft.util.FastColor; +import net.minecraft.util.Mth; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; +import net.minecraft.world.phys.shapes.Shapes; +import org.jetbrains.annotations.NotNull; + +@Environment(EnvType.CLIENT) +public class WindDisturbanceDebugRenderer implements DebugRenderer.SimpleDebugRenderer { + private final Minecraft minecraft; + private List> windDisturbances = Collections.emptyList(); + private List>> windNodes = Collections.emptyList(); + + public WindDisturbanceDebugRenderer(Minecraft client) { + this.minecraft = client; + } + + public void tick() { + this.windDisturbances = ImmutableList.copyOf( + ClientWindManager.getWindDisturbances() + ); + this.windNodes = ImmutableList.copyOf( + this.createAllWindNodes() + ); + } + + @Override + public void clear() { + this.windDisturbances = Collections.emptyList(); + this.windNodes = Collections.emptyList(); + } + + @Override + public void render(PoseStack matrices, MultiBufferSource vertexConsumers, double cameraX, double cameraY, double cameraZ) { + this.windDisturbances.forEach( + windDisturbance -> { + LevelRenderer.renderVoxelShape( + matrices, + vertexConsumers.getBuffer(RenderType.lines()), + Shapes.create(windDisturbance.affectedArea), + -cameraX, + -cameraY, + -cameraZ, + 0.5F, + 1F, + 0.5F, + 0.35F, + true + ); + renderFilledBox( + matrices, + vertexConsumers, + AABB.ofSize(windDisturbance.origin, 0.2D, 0.2D, 0.2D), + cameraX, cameraY, cameraZ + ); + } + ); + + WindDebugRenderer.renderWindNodesFromList(matrices, vertexConsumers, cameraX, cameraY, cameraZ, this.windNodes); + } + + private @NotNull List>> createAllWindNodes() { + List>> windNodes = new ArrayList<>(); + this.windDisturbances.forEach( + windDisturbance -> { + if (FrustumUtil.isVisible(windDisturbance.affectedArea)) { + BlockPos.betweenClosed( + BlockPos.containing(windDisturbance.affectedArea.getMinPosition()), + BlockPos.containing(windDisturbance.affectedArea.getMaxPosition()) + ).forEach( + blockPos -> { + Vec3 blockPosCenter = Vec3.atCenterOf(blockPos); + windNodes.add(WindDebugRenderer.createWindNodes(this.minecraft.level, blockPosCenter, 1D, true)); + } + ); + } + } + ); + return windNodes; + } + + private static void renderFilledBox( + PoseStack matrices, + MultiBufferSource vertexConsumers, + @NotNull AABB box, + double cameraX, double cameraY, double cameraZ + ) { + Vec3 vec3 = new Vec3(-cameraX, -cameraY, -cameraZ); + DebugRenderer.renderFilledBox(matrices, vertexConsumers, box.move(vec3), 1F, 1F, 1F, 1F); + } +} diff --git a/src/main/resources/assets/frozenlib/lang/en_us.json b/src/main/resources/assets/frozenlib/lang/en_us.json index ca32c6b99..b892e6214 100644 --- a/src/main/resources/assets/frozenlib/lang/en_us.json +++ b/src/main/resources/assets/frozenlib/lang/en_us.json @@ -89,6 +89,7 @@ "debug.light": "Light", "debug.breeze": "Breeze", "debug.wind": "Wind", + "debug.wind_disturbance": "Wind Disturbance", "debug.neighbor_update": "Neighbor Updates", "debug.game_event": "Game Events",