Skip to content

Commit

Permalink
Merge branch '1.20.6' into 1.21
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/xaeroplus/mixin/client/MixinWaypointsIngameRenderer.java
#	common/src/main/java/xaeroplus/mixin/client/mc/MixinWorldRenderer.java
  • Loading branch information
rfresh2 committed Oct 31, 2024
2 parents d94a73d + a7a1a90 commit db7943b
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 294 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package xaeroplus.feature.render;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BeaconRenderer;
import net.minecraft.client.renderer.culling.Frustum;
import net.minecraft.client.renderer.entity.EntityRenderDispatcher;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import xaero.common.HudMod;
import xaero.common.minimap.waypoints.Waypoint;
import xaero.common.minimap.waypoints.WaypointVisibilityType;
import xaero.common.settings.ModSettings;
import xaero.hud.minimap.BuiltInHudModules;
import xaero.hud.minimap.module.MinimapSession;
import xaeroplus.settings.Settings;

import java.util.ArrayList;
import java.util.List;

import static net.minecraft.client.renderer.blockentity.BeaconRenderer.BEAM_LOCATION;

public class WaypointBeaconRenderer {
public static final WaypointBeaconRenderer INSTANCE = new WaypointBeaconRenderer();
private final List<Waypoint> waypointList = new ArrayList<>();
private long lastWaypointRenderListUpdate = -1L;

public void updateWaypointRenderList(final MinimapSession session, final ModSettings settings) {
waypointList.clear();
session.getWaypointSession().getCollector().collect(waypointList);
waypointList.removeIf(w -> {
if (w.isDisabled()
|| w.getVisibility() == WaypointVisibilityType.WORLD_MAP_LOCAL
|| w.getVisibility() == WaypointVisibilityType.WORLD_MAP_GLOBAL) {
return true;
}
return !settings.getDeathpoints() && w.getPurpose().isDeath();
});
waypointList.sort(Waypoint::compareTo);
}

public void renderWaypointBeacons(float tickDelta, PoseStack matrixStack) {
var session = BuiltInHudModules.MINIMAP.getCurrentSession();
if (session == null) return;
var settings = HudMod.INSTANCE.getSettings();
if (settings == null) return;
if (!settings.getShowIngameWaypoints()) return;
var currentWorld = session.getWorldManager().getCurrentWorld();
if (currentWorld == null) return;
if (System.currentTimeMillis() - lastWaypointRenderListUpdate > 50L) {
updateWaypointRenderList(session, settings);
lastWaypointRenderListUpdate = System.currentTimeMillis();
}
var dimDiv = session.getDimensionHelper().getDimensionDivision(currentWorld);
var mc = Minecraft.getInstance();
if (mc.level == null || mc.cameraEntity == null) return;
var cameraPos = mc.cameraEntity.position();
double distanceScale = settings.dimensionScaledMaxWaypointDistance ? mc.level.dimensionType().coordinateScale() : 1.0;
double waypointsDistance = settings.getMaxWaypointsDistance();
double waypointsDistanceMin = settings.waypointsDistanceMin;
for (int i = 0; i < waypointList.size(); i++) {
final var w = waypointList.get(i);
double offX = (double)w.getX(dimDiv) - cameraPos.x + 0.5;
double offZ = (double)w.getZ(dimDiv) - cameraPos.z + 0.5;
double unscaledDistance2D = Math.sqrt(offX * offX + offZ * offZ);
double distance2D = unscaledDistance2D * distanceScale;
var shouldRender = w.isDestination()
|| (w.getPurpose().isDeath()
|| w.isGlobal()
|| w.isTemporary() && settings.temporaryWaypointsGlobal
|| waypointsDistance == 0.0
|| !(distance2D > waypointsDistance)
) && (waypointsDistanceMin == 0.0 || !(unscaledDistance2D < waypointsDistanceMin));;
if (shouldRender)
renderWaypointBeacon(w, dimDiv, tickDelta, matrixStack);
}
}

public void renderWaypointBeacon(final Waypoint waypoint, final double dimDiv, float tickDelta, PoseStack matrixStack) {
final Minecraft mc = Minecraft.getInstance();
if (mc.level == null || mc.cameraEntity == null) return;
final Vec3 playerVec = mc.cameraEntity.position();
Vec3 waypointVec = new Vec3(waypoint.getX(dimDiv), playerVec.y, waypoint.getZ(dimDiv));
final double xzDistance = playerVec.distanceTo(waypointVec);
if (xzDistance < Settings.REGISTRY.waypointBeaconDistanceMin.getAsInt()) return;
final int farScale = Settings.REGISTRY.waypointBeaconScaleMin.getAsInt();
final double maxRenderDistance = Math.min(mc.options.renderDistance().get() << 4, farScale == 0 ? Integer.MAX_VALUE : farScale << 4);
if (xzDistance > maxRenderDistance) {
final Vec3 delta = waypointVec.subtract(playerVec).normalize();
waypointVec = playerVec.add(new Vec3(delta.x * maxRenderDistance, delta.y * maxRenderDistance, delta.z * maxRenderDistance));
}
final EntityRenderDispatcher entityRenderDispatcher = mc.getEntityRenderDispatcher();
final Camera camera = entityRenderDispatcher.camera;
final Frustum frustum = mc.levelRenderer.cullingFrustum;
if (camera == null || frustum == null) return;
final double viewX = camera.getPosition().x();
final double viewZ = camera.getPosition().z();
final double x = waypointVec.x - viewX;
final double z = waypointVec.z - viewZ;
final double y = -100;
if (!frustum.isVisible(new AABB(waypointVec.x-1, -100, waypointVec.z-1, waypointVec.x+1, 500, waypointVec.z+1))) return;
final int color = waypoint.getWaypointColor().getHex();
final MultiBufferSource.BufferSource entityVertexConsumers = mc.renderBuffers().bufferSource();
final long time = mc.level.getGameTime();
matrixStack.pushPose();
matrixStack.translate(x, y, z);
BeaconRenderer.renderBeaconBeam(
matrixStack, entityVertexConsumers, BEAM_LOCATION, tickDelta, 1.0f, time, 0, 355,
color, 0.2f, 0.25f);
matrixStack.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import net.minecraft.world.entity.player.Player;
import org.joml.Matrix4f;
import org.joml.Matrix4fStack;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -81,9 +83,9 @@ public void reloadMapFrameBuffers() {

@ModifyArg(method = "renderChunks", at = @At(
value = "INVOKE",
target = "Lxaero/common/minimap/render/MinimapFBORenderer;renderChunksToFBO(Lxaero/hud/minimap/module/MinimapSession;Lnet/minecraft/client/gui/GuiGraphics;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/phys/Vec3;DDIIFFIZZZIDDZZLxaero/common/graphics/CustomVertexConsumers;)V"
target = "Lxaero/common/minimap/render/MinimapFBORenderer;renderChunksToFBO(Lxaero/hud/minimap/module/MinimapSession;Lnet/minecraft/client/gui/GuiGraphics;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/resources/ResourceKey;DIFIZZIDDZLxaero/common/graphics/CustomVertexConsumers;)V"
),
index = 9,
index = 6,
remap = true) // $REMAP
public int modifyViewW(final int viewW) {
return viewW * Globals.minimapScaleMultiplier;
Expand All @@ -93,7 +95,7 @@ public int modifyViewW(final int viewW) {
value = "INVOKE",
target = "Lnet/minecraft/client/gui/GuiGraphics;pose()Lcom/mojang/blaze3d/vertex/PoseStack;"
), remap = true)
public void modifyScaledSize(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Player player, final Entity renderEntity, final Vec3 renderPos, final double playerDimDiv, final double mapDimensionScale, final int bufferSize, final int viewW, final float sizeFix, final float partial, final int level, final boolean retryIfError, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final boolean circle, final CustomVertexConsumers cvc, final CallbackInfo ci,
public void modifyScaledSize(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Vec3 renderPos, final ResourceKey<Level> mapDimension, final double mapDimensionScale, final int viewW, final float partial, final int level, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final CustomVertexConsumers cvc, final CallbackInfo ci,
@Share("scaledSize") LocalIntRef scaledSize) {
int s = 256 * Globals.minimapScaleMultiplier * Globals.minimapSizeMultiplier;
if (Globals.minimapSizeMultiplier > 1) {
Expand Down Expand Up @@ -143,7 +145,7 @@ public float modifyChunkGridLineWidth(final float original) {
target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V",
ordinal = 0
), remap = true)
public void drawRenderDistanceSquare(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Player player, final Entity renderEntity, final Vec3 renderPos, final double playerDimDiv, final double mapDimensionScale, final int bufferSize, final int viewW, final float sizeFix, final float partial, final int level, final boolean retryIfError, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final boolean circle, final CustomVertexConsumers cvc, final CallbackInfo ci,
public void drawRenderDistanceSquare(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Vec3 renderPos, final ResourceKey<Level> mapDimension, final double mapDimensionScale, final int viewW, final float partial, final int level, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final CustomVertexConsumers cvc, final CallbackInfo ci,
@Local(name = "xFloored") int xFloored,
@Local(name = "zFloored") int zFloored,
@Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers,
Expand Down Expand Up @@ -204,11 +206,11 @@ public void drawRenderDistanceSquare(final MinimapSession minimapSession, final
target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V",
ordinal = 0
), remap = true)
public void drawWorldBorderSquare(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Player player, final Entity renderEntity, final Vec3 renderPos, final double playerDimDiv, final double mapDimensionScale, final int bufferSize, final int viewW, final float sizeFix, final float partial, final int level, final boolean retryIfError, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final boolean circle, final CustomVertexConsumers cvc, final CallbackInfo ci,
@Local(name = "xFloored") int xFloored,
@Local(name = "zFloored") int zFloored,
@Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers,
@Local(name = "matrixStack") PoseStack matrixStack
public void drawWorldBorderSquare(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Vec3 renderPos, final ResourceKey<Level> mapDimension, final double mapDimensionScale, final int viewW, final float partial, final int level, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final CustomVertexConsumers cvc, final CallbackInfo ci,
@Local(name = "xFloored") int xFloored,
@Local(name = "zFloored") int zFloored,
@Local(name = "renderTypeBuffers") MultiBufferSource.BufferSource renderTypeBuffers,
@Local(name = "matrixStack") PoseStack matrixStack
) {
final boolean isDimensionSwitched = Globals.getCurrentDimensionId() != Minecraft.getInstance().level.dimension();
if (!Settings.REGISTRY.showWorldBorderSetting.get() || isDimensionSwitched) return;
Expand Down Expand Up @@ -279,7 +281,7 @@ public Matrix4f correctPreRotationTranslationForSizeMult(final Matrix4fStack ins
target = "Lxaero/common/graphics/ImprovedFramebuffer;bindRead()V"
)
), remap = true)
public void correctPostRotationTranslationForSizeMult(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Player player, final Entity renderEntity, final Vec3 renderPos, final double playerDimDiv, final double mapDimensionScale, final int bufferSize, final int viewW, final float sizeFix, final float partial, final int level, final boolean retryIfError, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final boolean circle, final CustomVertexConsumers cvc, final CallbackInfo ci,
public void correctPostRotationTranslationForSizeMult(final MinimapSession minimapSession, final GuiGraphics guiGraphics, final MinimapProcessor minimap, final Vec3 renderPos, final ResourceKey<Level> mapDimension, final double mapDimensionScale, final int viewW, final float partial, final int level, final boolean useWorldMap, final boolean lockedNorth, final int shape, final double ps, final double pc, final boolean cave, final CustomVertexConsumers cvc, final CallbackInfo ci,
@Local(name = "halfWView") float halfWView,
@Local(name = "shaderMatrixStack") Matrix4fStack shaderMatrixStack) {
float sizeMultTranslation = (halfWView / Globals.minimapSizeMultiplier) * (Globals.minimapSizeMultiplier - 1);
Expand Down
Loading

0 comments on commit db7943b

Please sign in to comment.