Skip to content

Commit

Permalink
Merge branch '1.20.1' into 1.19.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	common/src/main/java/xaeroplus/mixin/client/MixinMinimapFBORenderer.java
#	common/src/main/java/xaeroplus/mixin/client/MixinMinimapRenderer.java
  • Loading branch information
rfresh2 committed Oct 31, 2024
2 parents a5d4fc8 + 37c57d7 commit d7279ce
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 291 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
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 xaeroplus.util.ColorHelper;

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,
ColorHelper.getColorRGBA(color), 0.2f, 0.25f);
matrixStack.popPose();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
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 @@ -79,9 +79,9 @@ public void reloadMapFrameBuffers() {

@ModifyArg(method = "renderChunks", at = @At(
value = "INVOKE",
target = "Lxaero/common/minimap/render/MinimapFBORenderer;renderChunksToFBO(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;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;Lcom/mojang/blaze3d/vertex/PoseStack;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 @@ -90,7 +90,7 @@ public int modifyViewW(final int viewW) {
@Inject(method = "renderChunksToFBO", at = @At(
value = "HEAD"
), remap = true) // $REMAP
public void modifyScaledSize(final MinimapSession minimapSession, final PoseStack matrixStack, 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 PoseStack matrixStack, 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 @@ -140,7 +140,7 @@ public void modifyChunkGridLineWidth(final float original) {
target = "Lnet/minecraft/client/renderer/MultiBufferSource$BufferSource;endBatch()V",
ordinal = 0
), remap = true)
public void drawRenderDistanceSquare(final MinimapSession minimapSession, final PoseStack matrixStack, 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 PoseStack matrixStack, 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 @@ -199,7 +199,7 @@ 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 PoseStack matrixStack, 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 drawWorldBorderSquare(final MinimapSession minimapSession, final PoseStack matrixStack, 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 @@ -271,7 +271,7 @@ public void correctPreRotationTranslationForSizeMult(final PoseStack instance, f
target = "Lxaero/common/graphics/ImprovedFramebuffer;bindRead()V"
)
), remap = true)
public void correctPostRotationTranslationForSizeMult(final MinimapSession minimapSession, final PoseStack matrixStack, 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 PoseStack matrixStack, 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") PoseStack shaderMatrixStack) {
float sizeMultTranslation = (halfWView / Globals.minimapSizeMultiplier) * (Globals.minimapSizeMultiplier - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,18 @@

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.mojang.blaze3d.pipeline.RenderTarget;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import xaero.common.IXaeroMinimap;
import xaero.common.graphics.CustomVertexConsumers;
import xaero.common.graphics.renderer.multitexture.MultiTextureRenderTypeRendererProvider;
import xaero.common.minimap.MinimapProcessor;
import xaero.common.minimap.radar.MinimapRadar;
import xaero.common.minimap.render.MinimapFBORenderer;
Expand Down Expand Up @@ -68,7 +65,7 @@ public void renderMinimap(
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lxaero/common/minimap/render/MinimapRenderer;renderChunks(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;DDIIFFIZZIDDZZLxaero/common/settings/ModSettings;Lxaero/common/graphics/CustomVertexConsumers;)V"
target = "Lxaero/common/minimap/render/MinimapRenderer;renderChunks(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/resources/ResourceKey;DIIFFIZZIDDZZLxaero/common/settings/ModSettings;Lxaero/common/graphics/CustomVertexConsumers;)V"
)
)
)
Expand All @@ -89,7 +86,7 @@ public int modifyMinimapSizeConstantI(final int constant) {
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lxaero/common/minimap/render/MinimapRenderer;renderChunks(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;DDIIFFIZZIDDZZLxaero/common/settings/ModSettings;Lxaero/common/graphics/CustomVertexConsumers;)V"
target = "Lxaero/common/minimap/render/MinimapRenderer;renderChunks(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/resources/ResourceKey;DIIFFIZZIDDZZLxaero/common/settings/ModSettings;Lxaero/common/graphics/CustomVertexConsumers;)V"
)
)
)
Expand All @@ -110,7 +107,7 @@ public float modifyMinimapSizeConstantF(final float constant) {
slice = @Slice(
from = @At(
value = "INVOKE",
target = "Lxaero/common/minimap/render/MinimapRenderer;renderChunks(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;DDIIFFIZZIDDZZLxaero/common/settings/ModSettings;Lxaero/common/graphics/CustomVertexConsumers;)V"
target = "Lxaero/common/minimap/render/MinimapRenderer;renderChunks(Lxaero/hud/minimap/module/MinimapSession;Lcom/mojang/blaze3d/vertex/PoseStack;Lxaero/common/minimap/MinimapProcessor;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/resources/ResourceKey;DIIFFIZZIDDZZLxaero/common/settings/ModSettings;Lxaero/common/graphics/CustomVertexConsumers;)V"
)
)
)
Expand All @@ -124,38 +121,33 @@ public float modifyMinimapSizeConstantFCircle(final float constant) {

@Redirect(method = "renderMinimap", at = @At(
value = "INVOKE",
target = "Lxaero/hud/minimap/element/render/over/MinimapElementOverMapRendererHandler;render(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/phys/Vec3;DDDDZFLcom/mojang/blaze3d/pipeline/RenderTarget;Lxaero/common/graphics/renderer/multitexture/MultiTextureRenderTypeRendererProvider;)V"),
target = "Lxaero/hud/minimap/element/render/over/MinimapElementOverMapRendererHandler;prepareRender(DDDIIIIZF)V"),
remap = true) // $REMAP
public void editOvermapRender(final MinimapElementOverMapRendererHandler instance,
final PoseStack poseStack,
final Entity entity,
final Player player,
final Vec3 renderPos,
final double playerDimDiv,
final double ps,
final double pc,
double zoom,
final boolean cave,
final float partialTicks,
final RenderTarget framebuffer,
final MultiTextureRenderTypeRendererProvider multiTextureRenderTypeRenderers
public void editOvermapRender(
final MinimapElementOverMapRendererHandler instance,
final double ps,
final double pc,
double zoom,
final int specW,
final int specH,
final int halfViewW,
final int halfViewH,
final boolean circle,
final float minimapScale
) {
if (this.minimap.usingFBO()) {
zoom = (zoom / Globals.minimapScaleMultiplier) * Globals.minimapSizeMultiplier;
}
instance.render(
poseStack,
entity,
player,
renderPos,
playerDimDiv,
instance.prepareRender(
ps,
pc,
zoom,
cave,
partialTicks,
framebuffer,
multiTextureRenderTypeRenderers
specW,
specH,
halfViewW,
halfViewH,
circle,
minimapScale
);
}

Expand Down
Loading

0 comments on commit d7279ce

Please sign in to comment.