perf improvements with portal guns
fix infinity crash
This commit is contained in:
1 parent
d54264c6c8
commit
333269c3da
12 files changed
+46
-27
No files matched your search
+5
-3
@@ -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<ClientLevel> level = new WeakReference<>(null);
|
||||
private static long recordedAt;
|
||||
private static Consumer<PortalGunMoonAimPayload> 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));
|
||||
|
||||
+5
-3
@@ -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<ClientLevel> cachedLevel = new WeakReference<>(null);
|
||||
private static long cachedGameTime = Long.MIN_VALUE;
|
||||
private static UUID cachedGunId;
|
||||
private static Set<PortalGunPortalEntity.PortalSide> 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<PortalGunPortalEntity.PortalSide> 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);
|
||||
|
||||
+6
-4
@@ -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<UUID, PortalGunIndicatorPayload> 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<ClientLevel> level = new WeakReference<>(null);
|
||||
private static long lastRequestTick = Long.MIN_VALUE;
|
||||
private static UUID lastRequestedGun;
|
||||
private static Consumer<PortalGunIndicatorRequestPayload> 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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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<EntityType<?>> BOSS_TAG = TagKey.create(Registries.ENTITY_TYPE, ResourceLocation.withDefaultNamespace("bosses"));
|
||||
private static final TagKey<EntityType<?>> 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;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"antarchy:king",
|
||||
"antarchy:queen"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user