From 333269c3da85f1fa3f876748f84dd7c5f85bcf77 Mon Sep 17 00:00:00 2001 From: craisinlord Date: Fri, 16 Oct 2026 14:55:59 -0500 Subject: [PATCH] perf improvements with portal guns fix infinity crash --- .../antarchy/content/client/MoonSkyTracker.java | 8 +++++--- .../content/client/PortalGunCrosshairRenderer.java | 8 +++++--- .../content/client/PortalGunIndicatorClientState.java | 10 ++++++---- .../antarchy/content/client/MoonSkyTracker.java | 8 +++++--- .../content/client/PortalGunCrosshairRenderer.java | 8 +++++--- .../content/client/PortalGunIndicatorClientState.java | 10 ++++++---- .../antarchy/content/item/CritterCageItem.java | 2 +- .../main/resources/data/c/tags/entity_type/bosses.json | 7 +++++++ forge-1.20.1/gradle.properties | 2 +- .../mixins/infinity/ConfigGenInvocationMixin.java | 4 ++-- gradle.properties | 2 +- .../mixins/infinity/ConfigGenInvocationMixin.java | 4 ++-- 12 files changed, 46 insertions(+), 27 deletions(-) create mode 100644 common-1.21.1/src/main/resources/data/c/tags/entity_type/bosses.json diff --git a/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java b/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java index 444d94bb..08df86a3 100644 --- a/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java +++ b/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java @@ -2,6 +2,7 @@ package com.craisinlord.antarchy.content.client; import com.craisinlord.antarchy.content.network.PortalGunMoonAimPayload; import com.craisinlord.antarchy.content.portalgun.PortalGunMoonMath; +import java.lang.ref.WeakReference; import java.util.function.Consumer; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; @@ -16,7 +17,8 @@ public final class MoonSkyTracker { private static final long MAX_AGE_MILLIS = 1500L; private static final double AIM_COSINE = Math.cos(Math.toRadians(PortalGunMoonMath.AIM_TOLERANCE_DEGREES)); private static Vec3 direction; - private static ClientLevel level; + // Weak so a dimension change or logout doesn't pin the old client world in memory. + private static WeakReference level = new WeakReference<>(null); private static long recordedAt; private static Consumer sender = payload -> {}; @@ -35,7 +37,7 @@ public final class MoonSkyTracker { } Vector3f world = camera.rotation().transform(view.normalize()); direction = new Vec3(world.x, world.y, world.z).normalize(); - level = renderedLevel; + level = new WeakReference<>(renderedLevel); recordedAt = System.currentTimeMillis(); } @@ -44,7 +46,7 @@ public final class MoonSkyTracker { if (minecraft.player == null) { return; } - boolean tracked = direction != null && level == minecraft.level && System.currentTimeMillis() - recordedAt <= MAX_AGE_MILLIS; + boolean tracked = direction != null && level.get() == minecraft.level && System.currentTimeMillis() - recordedAt <= MAX_AGE_MILLIS; boolean aiming = tracked && minecraft.gameRenderer.getMainCamera().getLookVector().dot( new Vector3f((float) direction.x, (float) direction.y, (float) direction.z)) >= AIM_COSINE; sender.accept(new PortalGunMoonAimPayload(tracked, aiming)); diff --git a/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java b/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java index 0c26c5a1..e568acf1 100644 --- a/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java +++ b/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java @@ -4,6 +4,7 @@ import com.craisinlord.antarchy.content.item.PortalGunItem; import com.craisinlord.antarchy.content.network.PortalGunIndicatorPayload; import com.craisinlord.antarchy.content.portalgun.PortalGunPortalEntity; import com.mojang.blaze3d.systems.RenderSystem; +import java.lang.ref.WeakReference; import java.util.EnumSet; import java.util.Set; import java.util.UUID; @@ -19,7 +20,8 @@ public final class PortalGunCrosshairRenderer { private static final int HALF_WIDTH = 17; private static final float MISSING_BRIGHTNESS = 0.3F; private static final float MISSING_ALPHA = 0.75F; - private static ClientLevel cachedLevel; + // Weak so a dimension change or logout doesn't pin the old client world in memory. + private static WeakReference cachedLevel = new WeakReference<>(null); private static long cachedGameTime = Long.MIN_VALUE; private static UUID cachedGunId; private static Set cachedPortals = Set.of(); @@ -77,14 +79,14 @@ public final class PortalGunCrosshairRenderer { } ClientLevel level = minecraft.level; long gameTime = level.getGameTime(); - if (cachedLevel != level || cachedGameTime != gameTime || !gunId.equals(cachedGunId)) { + if (cachedLevel.get() != level || cachedGameTime != gameTime || !gunId.equals(cachedGunId)) { Set portals = EnumSet.noneOf(PortalGunPortalEntity.PortalSide.class); for (com.craisinlord.anthology.portal.PortalEntity entry : com.craisinlord.anthology.portal.PortalRegistry.all(level)) { if (entry instanceof PortalGunPortalEntity portal && portal.isAlive() && gunId.equals(portal.getGunId())) { portals.add(portal.getPortalSide()); } } - cachedLevel = level; + cachedLevel = new WeakReference<>(level); cachedGameTime = gameTime; cachedGunId = gunId; cachedPortals = Set.copyOf(portals); diff --git a/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java b/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java index 03ca1c14..956e7d91 100644 --- a/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java +++ b/common-1.20.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java @@ -2,6 +2,7 @@ package com.craisinlord.antarchy.content.client; import com.craisinlord.antarchy.content.network.PortalGunIndicatorPayload; import com.craisinlord.antarchy.content.network.PortalGunIndicatorRequestPayload; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -11,7 +12,8 @@ import net.minecraft.client.multiplayer.ClientLevel; public final class PortalGunIndicatorClientState { private static final Map STATES = new HashMap<>(); - private static ClientLevel level; + // Weak so a dimension change or logout doesn't pin the old client world in memory. + private static WeakReference level = new WeakReference<>(null); private static long lastRequestTick = Long.MIN_VALUE; private static UUID lastRequestedGun; private static Consumer requestSender = payload -> {}; @@ -28,8 +30,8 @@ public final class PortalGunIndicatorClientState { if (currentLevel == null || gunId == null || minecraft.player == null) { return; } - if (level != currentLevel) { - level = currentLevel; + if (level.get() != currentLevel) { + level = new WeakReference<>(currentLevel); STATES.clear(); lastRequestedGun = null; lastRequestTick = Long.MIN_VALUE; @@ -52,7 +54,7 @@ public final class PortalGunIndicatorClientState { public static void clear() { STATES.clear(); - level = null; + level = new WeakReference<>(null); lastRequestedGun = null; lastRequestTick = Long.MIN_VALUE; } diff --git a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java index 444d94bb..08df86a3 100644 --- a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java +++ b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/MoonSkyTracker.java @@ -2,6 +2,7 @@ package com.craisinlord.antarchy.content.client; import com.craisinlord.antarchy.content.network.PortalGunMoonAimPayload; import com.craisinlord.antarchy.content.portalgun.PortalGunMoonMath; +import java.lang.ref.WeakReference; import java.util.function.Consumer; import net.minecraft.client.Camera; import net.minecraft.client.Minecraft; @@ -16,7 +17,8 @@ public final class MoonSkyTracker { private static final long MAX_AGE_MILLIS = 1500L; private static final double AIM_COSINE = Math.cos(Math.toRadians(PortalGunMoonMath.AIM_TOLERANCE_DEGREES)); private static Vec3 direction; - private static ClientLevel level; + // Weak so a dimension change or logout doesn't pin the old client world in memory. + private static WeakReference level = new WeakReference<>(null); private static long recordedAt; private static Consumer sender = payload -> {}; @@ -35,7 +37,7 @@ public final class MoonSkyTracker { } Vector3f world = camera.rotation().transform(view.normalize()); direction = new Vec3(world.x, world.y, world.z).normalize(); - level = renderedLevel; + level = new WeakReference<>(renderedLevel); recordedAt = System.currentTimeMillis(); } @@ -44,7 +46,7 @@ public final class MoonSkyTracker { if (minecraft.player == null) { return; } - boolean tracked = direction != null && level == minecraft.level && System.currentTimeMillis() - recordedAt <= MAX_AGE_MILLIS; + boolean tracked = direction != null && level.get() == minecraft.level && System.currentTimeMillis() - recordedAt <= MAX_AGE_MILLIS; boolean aiming = tracked && minecraft.gameRenderer.getMainCamera().getLookVector().dot( new Vector3f((float) direction.x, (float) direction.y, (float) direction.z)) >= AIM_COSINE; sender.accept(new PortalGunMoonAimPayload(tracked, aiming)); diff --git a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java index 0c26c5a1..e568acf1 100644 --- a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java +++ b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunCrosshairRenderer.java @@ -4,6 +4,7 @@ import com.craisinlord.antarchy.content.item.PortalGunItem; import com.craisinlord.antarchy.content.network.PortalGunIndicatorPayload; import com.craisinlord.antarchy.content.portalgun.PortalGunPortalEntity; import com.mojang.blaze3d.systems.RenderSystem; +import java.lang.ref.WeakReference; import java.util.EnumSet; import java.util.Set; import java.util.UUID; @@ -19,7 +20,8 @@ public final class PortalGunCrosshairRenderer { private static final int HALF_WIDTH = 17; private static final float MISSING_BRIGHTNESS = 0.3F; private static final float MISSING_ALPHA = 0.75F; - private static ClientLevel cachedLevel; + // Weak so a dimension change or logout doesn't pin the old client world in memory. + private static WeakReference cachedLevel = new WeakReference<>(null); private static long cachedGameTime = Long.MIN_VALUE; private static UUID cachedGunId; private static Set cachedPortals = Set.of(); @@ -77,14 +79,14 @@ public final class PortalGunCrosshairRenderer { } ClientLevel level = minecraft.level; long gameTime = level.getGameTime(); - if (cachedLevel != level || cachedGameTime != gameTime || !gunId.equals(cachedGunId)) { + if (cachedLevel.get() != level || cachedGameTime != gameTime || !gunId.equals(cachedGunId)) { Set portals = EnumSet.noneOf(PortalGunPortalEntity.PortalSide.class); for (com.craisinlord.anthology.portal.PortalEntity entry : com.craisinlord.anthology.portal.PortalRegistry.all(level)) { if (entry instanceof PortalGunPortalEntity portal && portal.isAlive() && gunId.equals(portal.getGunId())) { portals.add(portal.getPortalSide()); } } - cachedLevel = level; + cachedLevel = new WeakReference<>(level); cachedGameTime = gameTime; cachedGunId = gunId; cachedPortals = Set.copyOf(portals); diff --git a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java index 03ca1c14..956e7d91 100644 --- a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java +++ b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/client/PortalGunIndicatorClientState.java @@ -2,6 +2,7 @@ package com.craisinlord.antarchy.content.client; import com.craisinlord.antarchy.content.network.PortalGunIndicatorPayload; import com.craisinlord.antarchy.content.network.PortalGunIndicatorRequestPayload; +import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -11,7 +12,8 @@ import net.minecraft.client.multiplayer.ClientLevel; public final class PortalGunIndicatorClientState { private static final Map STATES = new HashMap<>(); - private static ClientLevel level; + // Weak so a dimension change or logout doesn't pin the old client world in memory. + private static WeakReference level = new WeakReference<>(null); private static long lastRequestTick = Long.MIN_VALUE; private static UUID lastRequestedGun; private static Consumer requestSender = payload -> {}; @@ -28,8 +30,8 @@ public final class PortalGunIndicatorClientState { if (currentLevel == null || gunId == null || minecraft.player == null) { return; } - if (level != currentLevel) { - level = currentLevel; + if (level.get() != currentLevel) { + level = new WeakReference<>(currentLevel); STATES.clear(); lastRequestedGun = null; lastRequestTick = Long.MIN_VALUE; @@ -52,7 +54,7 @@ public final class PortalGunIndicatorClientState { public static void clear() { STATES.clear(); - level = null; + level = new WeakReference<>(null); lastRequestedGun = null; lastRequestTick = Long.MIN_VALUE; } diff --git a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/item/CritterCageItem.java b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/item/CritterCageItem.java index fd0fb289..bb4db8de 100644 --- a/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/item/CritterCageItem.java +++ b/common-1.21.1/src/main/java/com/craisinlord/antarchy/content/item/CritterCageItem.java @@ -43,7 +43,7 @@ import net.minecraft.tags.TagKey; public class CritterCageItem extends Item { public static final String ENTITY_DATA_TAG = "EntityData"; - private static final TagKey> BOSS_TAG = TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.withDefaultNamespace("bosses")); + private static final TagKey> BOSS_TAG = TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.fromNamespaceAndPath("c", "bosses")); private static final int EMPTY_STATE = 0; private static final int FILLED_PLAIN_STATE = 1; private static final int FILLED_COLORED_STATE = 2; diff --git a/common-1.21.1/src/main/resources/data/c/tags/entity_type/bosses.json b/common-1.21.1/src/main/resources/data/c/tags/entity_type/bosses.json new file mode 100644 index 00000000..bc3a319e --- /dev/null +++ b/common-1.21.1/src/main/resources/data/c/tags/entity_type/bosses.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "antarchy:king", + "antarchy:queen" + ] +} diff --git a/forge-1.20.1/gradle.properties b/forge-1.20.1/gradle.properties index cb4c2f1a..c1941b09 100644 --- a/forge-1.20.1/gradle.properties +++ b/forge-1.20.1/gradle.properties @@ -6,7 +6,7 @@ mod_name=Antarchy mod_description=ANTS! ANTS! ANTS! ANTS! mod_authors=CraisinLord mod_group_id=com.craisinlord -mod_version=1.0.4 +mod_version=1.0.5 mod_license=All Rights Reserved minecraft_version=1.20.1 diff --git a/forge-1.20.1/src/main/java/com/craisinlord/antarchy/forge/mixins/infinity/ConfigGenInvocationMixin.java b/forge-1.20.1/src/main/java/com/craisinlord/antarchy/forge/mixins/infinity/ConfigGenInvocationMixin.java index 0ecac713..088e752e 100644 --- a/forge-1.20.1/src/main/java/com/craisinlord/antarchy/forge/mixins/infinity/ConfigGenInvocationMixin.java +++ b/forge-1.20.1/src/main/java/com/craisinlord/antarchy/forge/mixins/infinity/ConfigGenInvocationMixin.java @@ -22,9 +22,9 @@ public class ConfigGenInvocationMixin { private void antarchy$safeGenerateAll(MinecraftServer server) { try { ConfigGenerator.generateAll(server); - } catch (Exception e) { + } catch (Exception | LinkageError e) { Antarchy.LOGGER.error( - "[Antarchy] Infinite Dimensions surface rule scan crashed — likely a mod has a malformed surface rule (null 'biome_is' entry). Player login will continue.", + "[Antarchy] Infinite Dimensions config generation crashed — likely a mod with a malformed surface rule or a mismatched dependency. Player login will continue.", e ); } diff --git a/gradle.properties b/gradle.properties index 37b89bac..57ab288d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.configureondemand=true minecraft_version_1_21_1=1.21.1 modid=antarchy mod_id=antarchy -mod_version=2.2.2 +mod_version=2.2.4 maven_group=com.craisinlord mixin_version=0.15.4+mixin.0.8.7 diff --git a/neoforge-1.21.1/src/main/java/com/craisinlord/antarchy/neoforge/mixins/infinity/ConfigGenInvocationMixin.java b/neoforge-1.21.1/src/main/java/com/craisinlord/antarchy/neoforge/mixins/infinity/ConfigGenInvocationMixin.java index 49ff99aa..acfe4701 100644 --- a/neoforge-1.21.1/src/main/java/com/craisinlord/antarchy/neoforge/mixins/infinity/ConfigGenInvocationMixin.java +++ b/neoforge-1.21.1/src/main/java/com/craisinlord/antarchy/neoforge/mixins/infinity/ConfigGenInvocationMixin.java @@ -22,9 +22,9 @@ public class ConfigGenInvocationMixin { private void antarchy$safeGenerateAll(MinecraftServer server) { try { ConfigGenerator.generateAll(server); - } catch (Exception e) { + } catch (Exception | LinkageError e) { Antarchy.LOGGER.error( - "[Antarchy] Infinite Dimensions surface rule scan crashed — likely a mod has a malformed surface rule (null 'biome_is' entry). Player login will continue.", + "[Antarchy] Infinite Dimensions config generation crashed — likely a mod with a malformed surface rule or a mismatched dependency. Player login will continue.", e ); }