diff --git a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/camera/CameraPosition.java b/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/camera/CameraPosition.java deleted file mode 100644 index f50de799..00000000 --- a/mod/src/main/java/dev/loki/lovisual/features/module/modules/misc/optimize/particle/camera/CameraPosition.java +++ /dev/null @@ -1,32 +0,0 @@ -package dev.loki.lovisual.features.module.modules.misc.optimize.particle.camera; - -import net.minecraft.client.Minecraft; -import net.minecraft.world.phys.Vec3; - -/** - * Cached camera position accessor for the particle optimization layer. - * Vanilla {@code Particle.move} recomputes the camera position via - * {@code Minecraft.getInstance().gameRenderer.mainCamera().position()} per - * particle per tick — but the camera only moves once per frame. This helper - * is the single point where the camera position is sampled, so - * {@link ParticleMixin} reads it without re-walking the gameRenderer chain - * per particle. - * - *

Ported from {@code zako.opt.particle.CameraPosition} (ZakoOpt, LGPL-3.0). - * Original author: Zako — https://t.me/StarikZako. Render-thread only — - * particle ticking runs on the render thread. - */ -public final class CameraPosition { - - private CameraPosition() { - } - - /** - * Sample the current camera position. Caller must not cache the returned - * {@link Vec3} — it may be a reused instance whose values change between - * frames. - */ - public static Vec3 get() { - return Minecraft.getInstance().gameRenderer.mainCamera().position(); - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/LoVisualMixinPlugin.java b/mod/src/main/java/dev/loki/lovisual/mixins/LoVisualMixinPlugin.java index 664e5c34..1a73df53 100644 --- a/mod/src/main/java/dev/loki/lovisual/mixins/LoVisualMixinPlugin.java +++ b/mod/src/main/java/dev/loki/lovisual/mixins/LoVisualMixinPlugin.java @@ -21,8 +21,7 @@ public final class LoVisualMixinPlugin implements IMixinConfigPlugin { "dev.loki.lovisual.mixins.sodium.terrain.SodiumShaderChunkRendererMixin", "dev.loki.lovisual.mixins.sodium.vertex.SodiumVertexConsumerTrackerMixin", "dev.loki.lovisual.mixins.sodium.placement.SodiumPlaceCullMixin", - "dev.loki.lovisual.mixins.sodium.placement.SodiumPlaceHideMixin", - "dev.loki.lovisual.mixins.optimize.entity.SodiumEntityRendererMixin" + "dev.loki.lovisual.mixins.sodium.placement.SodiumPlaceHideMixin" ); private static final Set OPTIONAL_IRIS_MIXINS = Set.of( "dev.loki.lovisual.mixins.iris.render.IrisCommonUniformsMixin", diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BaseSpawnerMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BaseSpawnerMixin.java deleted file mode 100644 index 52be9e45..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BaseSpawnerMixin.java +++ /dev/null @@ -1,47 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.block; - -import dev.loki.lovisual.features.module.modules.misc.optimize.block.TickCached; -import net.minecraft.world.level.BaseSpawner; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -/** - * Stage 3: implements {@link TickCached} on {@link BaseSpawner} — adds the - * per-tick cache slot that {@link dev.loki.lovisual.features.module.modules.misc.optimize.block.SpawnerCache} - * reads back to skip the per-frame {@code extractEntity} rebuild of the - * spawner's display mob. - * - *

The vanilla {@code SpawnerRenderer.extractRenderState} rebuilds the - * display entity's render state every frame for every spawner in view; - * the display entity only changes on tick boundaries (spin speed, mob - * rotation, etc.), so caching by tick removes that rebuild from the hot path. - * - *

Ported from {@code zako.opt.mixin.block.BaseSpawnerMixin} (ZakoOpt, - * LGPL-3.0). Original author: Zako — https://t.me/StarikZako. Field/method - * prefix changed from {@code zakoopt$} to {@code lovisual$}. - */ -@Mixin(BaseSpawner.class) -public abstract class BaseSpawnerMixin implements TickCached { - - @Unique - private Object lovisual$cached; - - @Unique - private long lovisual$cachedTick = Long.MIN_VALUE; - - @Override - public Object lovisual$cached() { - return lovisual$cached; - } - - @Override - public long lovisual$cachedTick() { - return lovisual$cachedTick; - } - - @Override - public void lovisual$setCached(Object value, long tick) { - lovisual$cached = value; - lovisual$cachedTick = tick; - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BlockEntityMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BlockEntityMixin.java deleted file mode 100644 index 985f8c6b..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BlockEntityMixin.java +++ /dev/null @@ -1,142 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.block; - -import dev.loki.lovisual.features.module.modules.misc.optimize.block.CachedLight; -import dev.loki.lovisual.features.module.modules.misc.optimize.block.CachedValidity; -import dev.loki.lovisual.features.module.modules.misc.optimize.block.TickCached; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -/** - * Stage 3: implements {@link TickCached}, {@link CachedLight} and - * {@link CachedValidity} on {@link BlockEntity} — adds the per-tick cache - * slot (object + tick), the per-tick block-light lookups, the per-tick - * should-render distance check, and the per-state validity cache. - * - *

The vanilla {@code BlockEntityType.isValid(state)} is called every - * frame per block-entity in view but only changes on a state transition; - * {@code LightCoordsUtil.getLightCoords(level, pos)} walks the chunk's light - * section data per call; {@code BlockEntityRenderer.shouldRender} does a - * distance check that only changes when the entity moves across the cull - * boundary. All three are cached via the interface fields implemented here. - * - *

Ported from {@code zako.opt.mixin.block.BlockEntityMixin} (ZakoOpt, - * LGPL-3.0). Original author: Zako — https://t.me/StarikZako. Field/method - * prefix changed from {@code zakoopt$} to {@code lovisual$}. - */ -@Mixin(BlockEntity.class) -public abstract class BlockEntityMixin implements TickCached, CachedLight, CachedValidity { - - // --- TickCached --- - @Unique - private Object lovisual$cached; - @Unique - private long lovisual$cachedTick = Long.MIN_VALUE; - - // --- CachedLight --- - @Unique - private int lovisual$light; - @Unique - private long lovisual$lightTick = Long.MIN_VALUE; - @Unique - private int lovisual$pairLight; - @Unique - private long lovisual$pairLightTick = Long.MIN_VALUE; - - // --- CachedValidity --- - @Unique - private BlockState lovisual$validState; - @Unique - private boolean lovisual$valid; - @Unique - private long lovisual$distanceTick = Long.MIN_VALUE; - @Unique - private boolean lovisual$inDistance; - - // --- TickCached --- - - @Override - public Object lovisual$cached() { - return lovisual$cached; - } - - @Override - public long lovisual$cachedTick() { - return lovisual$cachedTick; - } - - @Override - public void lovisual$setCached(Object value, long tick) { - lovisual$cached = value; - lovisual$cachedTick = tick; - } - - // --- CachedLight --- - - @Override - public int lovisual$light() { - return lovisual$light; - } - - @Override - public long lovisual$lightTick() { - return lovisual$lightTick; - } - - @Override - public void lovisual$setLight(int light, long tick) { - lovisual$light = light; - lovisual$lightTick = tick; - } - - @Override - public int lovisual$pairLight() { - return lovisual$pairLight; - } - - @Override - public long lovisual$pairLightTick() { - return lovisual$pairLightTick; - } - - @Override - public void lovisual$setPairLight(int light, long tick) { - lovisual$pairLight = light; - lovisual$pairLightTick = tick; - } - - // --- CachedValidity --- - - @Override - public BlockState lovisual$validState() { - return lovisual$validState; - } - - @Override - public boolean lovisual$valid() { - return lovisual$valid; - } - - @Override - public void lovisual$setValid(BlockState state, boolean valid) { - lovisual$validState = state; - lovisual$valid = valid; - } - - @Override - public long lovisual$distanceTick() { - return lovisual$distanceTick; - } - - @Override - public boolean lovisual$inDistance() { - return lovisual$inDistance; - } - - @Override - public void lovisual$setInDistance(boolean inDistance, long tick) { - lovisual$inDistance = inDistance; - lovisual$distanceTick = tick; - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BlockEntityRenderStateMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BlockEntityRenderStateMixin.java deleted file mode 100644 index 30f1e14e..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/BlockEntityRenderStateMixin.java +++ /dev/null @@ -1,57 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.block; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import dev.loki.lovisual.features.module.modules.misc.optimize.block.CachedLight; -import dev.loki.lovisual.render.engine.optimize.OptimizeToggles; -import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState; -import net.minecraft.client.renderer.feature.ModelFeatureRenderer; -import net.minecraft.core.BlockPos; -import net.minecraft.util.LightCoordsUtil; -import net.minecraft.world.level.BlockAndLightGetter; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Stage 3: cache per-tick block-light lookups on every block-entity in view. - * - *

Vanilla {@code BlockEntityRenderState.extractBase} calls - * {@link LightCoordsUtil#getLightCoords} every frame per block-entity — that - * walks the chunk's light section data per call, and the light value only - * changes on tick boundaries. This WrapOperation wraps the call to consult - * the per-tick cache slot on the {@link BlockEntity} (via the - * {@link CachedLight} mixin from Stage 3-continued-2) before falling through - * to the original. - * - *

Ported from {@code zako.opt.mixin.block.BlockEntityRenderStateMixin} - * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * Gated on the {@code blockEntityCache} toggle via - * {@link OptimizeToggles#blockEntityCache()}. When the toggle is off, the - * original runs unchanged. - */ -@Mixin(BlockEntityRenderState.class) -public abstract class BlockEntityRenderStateMixin { - - @WrapOperation( - method = "extractBase", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/util/LightCoordsUtil;getLightCoords(Lnet/minecraft/world/level/BlockAndLightGetter;Lnet/minecraft/core/BlockPos;)I") - ) - private static int lovisual$cachedLight(BlockAndLightGetter level, BlockPos pos, Operation original, - BlockEntity blockEntity, BlockEntityRenderState state, - ModelFeatureRenderer.CrumblingOverlay crumbling) { - if (!OptimizeToggles.blockEntityCache() || !(level instanceof Level world)) { - return original.call(level, pos); - } - if (!(blockEntity instanceof CachedLight cache)) { - return original.call(level, pos); - } - long tick = world.getGameTime(); - if (cache.lovisual$lightTick() != tick) { - cache.lovisual$setLight(original.call(level, pos), tick); - } - return cache.lovisual$light(); - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/ChestRendererMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/ChestRendererMixin.java deleted file mode 100644 index 05bdd51b..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/block/ChestRendererMixin.java +++ /dev/null @@ -1,92 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.block; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import dev.loki.lovisual.features.module.modules.misc.optimize.block.CachedLight; -import dev.loki.lovisual.features.module.modules.misc.optimize.block.TickCached; -import dev.loki.lovisual.render.engine.optimize.OptimizeToggles; -import it.unimi.dsi.fastutil.ints.Int2IntFunction; -import net.minecraft.client.renderer.blockentity.ChestRenderer; -import net.minecraft.client.renderer.blockentity.state.ChestRenderState; -import net.minecraft.client.renderer.feature.ModelFeatureRenderer; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.ChestBlock; -import net.minecraft.world.level.block.DoubleBlockCombiner; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Stage 3: double-chest combine cache + double-chest pair-light cache. - * - *

Two WrapOperations on {@link ChestRenderer#extractRenderState}: - *

- * - *

Ported from {@code zako.opt.mixin.block.ChestRendererMixin} (ZakoOpt, - * LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * Combine cache gated on {@code blockEntityCache} toggle; pair-light cache - * gated on {@code microOpts} toggle (matches ZakoOpt's microOpts2 split — - * Stage 1 collapsed microOpts2 into microOpts, so both paths read the same - * toggle). - */ -@Mixin(ChestRenderer.class) -public abstract class ChestRendererMixin { - - @WrapOperation( - method = "extractRenderState(Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/client/renderer/blockentity/state/ChestRenderState;FLnet/minecraft/world/phys/Vec3;Lnet/minecraft/client/renderer/feature/ModelFeatureRenderer$CrumblingOverlay;)V", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/level/block/ChestBlock;combine(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Z)Lnet/minecraft/world/level/block/DoubleBlockCombiner$NeighborCombineResult;") - ) - private DoubleBlockCombiner.NeighborCombineResult lovisual$cachedCombine( - ChestBlock block, BlockState state, Level level, BlockPos pos, boolean ignoreBlocked, - Operation> original, - BlockEntity blockEntity, ChestRenderState renderState, float partialTick, Vec3 camera, - ModelFeatureRenderer.CrumblingOverlay crumbling) { - if (!OptimizeToggles.blockEntityCache()) { - return original.call(block, state, level, pos, ignoreBlocked); - } - if (!(blockEntity instanceof TickCached cache)) { - return original.call(block, state, level, pos, ignoreBlocked); - } - long tick = level.getGameTime(); - if (cache.lovisual$cachedTick() != tick || cache.lovisual$cached() == null) { - cache.lovisual$setCached(original.call(block, state, level, pos, ignoreBlocked), tick); - } - return (DoubleBlockCombiner.NeighborCombineResult) cache.lovisual$cached(); - } - - @WrapOperation( - method = "extractRenderState(Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/client/renderer/blockentity/state/ChestRenderState;FLnet/minecraft/world/phys/Vec3;Lnet/minecraft/client/renderer/feature/ModelFeatureRenderer$CrumblingOverlay;)V", - at = @At(value = "INVOKE", - target = "Lit/unimi/dsi/fastutil/ints/Int2IntFunction;applyAsInt(I)I") - ) - private int lovisual$cachedPairLight(Int2IntFunction combiner, int light, Operation original, - BlockEntity blockEntity, ChestRenderState renderState, float partialTick, Vec3 camera, - ModelFeatureRenderer.CrumblingOverlay crumbling) { - Level level = blockEntity.getLevel(); - if (!OptimizeToggles.microOpts() || level == null) { - return original.call(combiner, light); - } - if (!(blockEntity instanceof CachedLight cache)) { - return original.call(combiner, light); - } - long tick = level.getGameTime(); - if (cache.lovisual$pairLightTick() != tick) { - cache.lovisual$setPairLight(original.call(combiner, light), tick); - } - return cache.lovisual$pairLight(); - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/EntityNameMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/EntityNameMixin.java deleted file mode 100644 index 08420803..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/EntityNameMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.entity; - -import dev.loki.lovisual.features.module.modules.misc.optimize.entity.CachedName; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -/** - * Stage 3: implements {@link CachedName} on {@link Entity} — adds the cached - * name-tag fields (name + tick) that {@link EntityRendererNameMixin} populates - * and reads back. Vanilla {@code Entity.getDisplayName()} rebuilds the team - * prefix + name + suffix on every call; renderers call it once per frame per - * entity in view, so caching by tick cuts the per-frame cost. - * - *

Ported from {@code zako.opt.mixin.entity.EntityNameMixin} (ZakoOpt, - * LGPL-3.0). Original author: Zako — https://t.me/StarikZako. Field/method - * prefix changed from {@code zakoopt$} to {@code lovisual$}. - */ -@Mixin(Entity.class) -public abstract class EntityNameMixin implements CachedName { - - @Unique - private Component lovisual$name; - - @Unique - private long lovisual$nameTick = Long.MIN_VALUE; - - @Override - public Component lovisual$name() { - return lovisual$name; - } - - @Override - public long lovisual$nameTick() { - return lovisual$nameTick; - } - - @Override - public void lovisual$setName(Component name, long tick) { - lovisual$name = name; - lovisual$nameTick = tick; - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/EntityRenderStateEntityMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/EntityRenderStateEntityMixin.java deleted file mode 100644 index e2330d2a..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/EntityRenderStateEntityMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.entity; - -import dev.loki.lovisual.features.module.modules.misc.optimize.entity.StateEntity; -import net.minecraft.client.renderer.entity.state.EntityRenderState; -import net.minecraft.world.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; - -/** - * Stage 3: implements {@link StateEntity} on {@link EntityRenderState} — adds - * the back-reference field to the source {@link Entity}. Render-states are - * rebuilt every frame, so they can't keep their own pointer — the - * {@link EntityRendererStateMixin} captures it once per state construction - * via {@code createRenderState} and downstream renderers read it back. - * - *

Ported from {@code zako.opt.mixin.entity.EntityRenderStateEntityMixin} - * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * Prefix changed from {@code zakoopt$} to {@code lovisual$}. - */ -@Mixin(EntityRenderState.class) -public abstract class EntityRenderStateEntityMixin implements StateEntity { - - @Unique - private Entity lovisual$entity; - - @Override - public Entity lovisual$entity() { - return lovisual$entity; - } - - @Override - public void lovisual$entity(Entity entity) { - lovisual$entity = entity; - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/SodiumEntityRendererMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/SodiumEntityRendererMixin.java deleted file mode 100644 index 69de7148..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/SodiumEntityRendererMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.entity; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import dev.loki.lovisual.features.module.modules.misc.optimize.entity.CachedStack; -import dev.loki.lovisual.render.engine.optimize.OptimizeToggles; -import org.lwjgl.system.MemoryStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Stage 3: hot-path helper for Sodium's entity cuboid renderer — wraps - * {@code MemoryStack.stackPush()} so the render thread's stack is cached by - * identity instead of being looked up via ThreadLocal on every cuboid. Sodium - * calls this once per cuboid per frame (thousands of times for dense entity - * scenes), so the cached lookup is a measurable win on the hot path. - * - *

Uses {@code WrapOperation} rather than {@code @Redirect} because - * MixinExtras 0.5.4 (which Fabric Loader 0.19.3 ships with) crashes on a - * static {@code @Redirect} here — pinned to 0.5.5 in {@code build.gradle}, - * but the convention is kept for safety. The mixin is registered with - * {@code remap = false} because the target is a Sodium class, not a Mojang one. - * - *

Ported from {@code zako.opt.mixin.entity.SodiumEntityRendererMixin} - * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * Gated on the {@code microOpts} toggle via {@link OptimizeToggles#microOpts()}. - * When the toggle is off, the original runs unchanged. - * - *

Registered conditionally via {@code LoVisualMixinPlugin} — only applied - * when Sodium is loaded. See {@code lovisual.mixins.json} entry in the - * {@code client} array. - */ -@Mixin(targets = "net.caffeinemc.mods.sodium.client.render.immediate.model.EntityRenderer", remap = false) -public abstract class SodiumEntityRendererMixin { - - @WrapOperation( - method = "renderCuboid", - at = @At(value = "INVOKE", - target = "Lorg/lwjgl/system/MemoryStack;stackPush()Lorg/lwjgl/system/MemoryStack;") - ) - private static MemoryStack lovisual$cachedStack(Operation original) { - return OptimizeToggles.microOpts() ? CachedStack.push() : original.call(); - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/renderer/EntityRendererNameMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/renderer/EntityRendererNameMixin.java deleted file mode 100644 index 7eeea3db..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/renderer/EntityRendererNameMixin.java +++ /dev/null @@ -1,51 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.entity.renderer; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import dev.loki.lovisual.features.module.modules.misc.optimize.entity.CachedName; -import dev.loki.lovisual.render.engine.optimize.OptimizeToggles; -import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -/** - * Stage 3: caches {@code Entity.getDisplayName()} per tick. The vanilla - * implementation rebuilds a {@link Component} (team prefix + name + suffix) - * every call; renderers call it once per frame per entity in view. Wrapping - * the call here keeps the per-frame cost to one identity check + read, - * instead of a full Component rebuild + style lookup. - * - *

The cache is keyed by game tick — name parts only change on tick - * boundaries (team membership, name change). On the first call of a tick the - * original runs and the result is stored; subsequent calls in the same tick - * return the cached instance. - * - *

Ported from {@code zako.opt.mixin.entity.EntityRendererNameMixin} - * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * Gated on the {@code microOpts} toggle via {@link OptimizeToggles#microOpts()}. - * When the toggle is off, the original runs unchanged. - */ -@Mixin(EntityRenderer.class) -public abstract class EntityRendererNameMixin { - - @WrapOperation( - method = "getNameTag", - at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/entity/Entity;getDisplayName()Lnet/minecraft/network/chat/Component;") - ) - private Component lovisual$cachedName(Entity entity, Operation original) { - if (!OptimizeToggles.microOpts()) { - return original.call(entity); - } - if (!(entity instanceof CachedName cache)) { - return original.call(entity); - } - long tick = entity.level().getGameTime(); - if (cache.lovisual$nameTick() != tick) { - cache.lovisual$setName(original.call(entity), tick); - } - return cache.lovisual$name(); - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/renderer/EntityRendererStateMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/renderer/EntityRendererStateMixin.java deleted file mode 100644 index 2085f8a1..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/entity/renderer/EntityRendererStateMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.entity.renderer; - -import com.llamalad7.mixinextras.sugar.Local; -import dev.loki.lovisual.features.module.modules.misc.optimize.entity.StateEntity; -import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.client.renderer.entity.state.EntityRenderState; -import net.minecraft.world.entity.Entity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/** - * Stage 3: captures the source {@link Entity} on every freshly-built - * {@link EntityRenderState}. Vanilla's {@code createRenderState(entity, partial)} - * returns a state without back-reference; this inject at RETURN stores the - * entity on the state via the {@link StateEntity} contract so downstream - * renderers (model feature renderer, item feature renderer, future LOD mixins) - * can reach the live entity. - * - *

Ported from {@code zako.opt.mixin.entity.EntityRendererStateMixin} - * (ZakoOpt, LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * The original used {@code @ModifyReturnValue}; LoVisual uses {@code @Inject} - * at RETURN with {@code CallbackInfoReturnable} so the mixin stays simple and - * doesn't rely on the (more fragile across versions) MixinExtras return-value - * transformer — the captured state is set as a side effect, not returned. - */ -@Mixin(EntityRenderer.class) -public abstract class EntityRendererStateMixin { - - @Inject( - method = "createRenderState(Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/entity/state/EntityRenderState;", - at = @At("RETURN") - ) - private void lovisual$rememberEntity(Entity entity, float partialTick, - CallbackInfoReturnable cir, - @Local(argsOnly = true) Entity localEntity) { - EntityRenderState state = cir.getReturnValue(); - if (state instanceof StateEntity stateEntity) { - stateEntity.lovisual$entity(localEntity); - } - } -} diff --git a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/particle/ParticleMixin.java b/mod/src/main/java/dev/loki/lovisual/mixins/optimize/particle/ParticleMixin.java deleted file mode 100644 index 446317c0..00000000 --- a/mod/src/main/java/dev/loki/lovisual/mixins/optimize/particle/ParticleMixin.java +++ /dev/null @@ -1,111 +0,0 @@ -package dev.loki.lovisual.mixins.optimize.particle; - -import dev.loki.lovisual.features.module.modules.misc.optimize.particle.camera.CameraPosition; -import dev.loki.lovisual.render.engine.optimize.OptimizeToggles; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.particle.BaseAshSmokeParticle; -import net.minecraft.client.particle.BubbleColumnUpParticle; -import net.minecraft.client.particle.CampfireSmokeParticle; -import net.minecraft.client.particle.Particle; -import net.minecraft.world.phys.Vec3; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/** - * Stage 3: per-particle light cache + far-particle physics skip. - * - *

Two optimizations in one mixin (matches ZakoOpt): - *

- * - *

Ported from {@code zako.opt.mixin.particle.ParticleMixin} (ZakoOpt, - * LGPL-3.0). Original author: Zako — https://t.me/StarikZako. - * Light-cache gated on the {@code microOpts} toggle (Stage 1 wiring); - * physics-skip also gated on {@code microOpts} since both are micro-opts. - * When the toggle is off, the original code runs unchanged. - */ -@Mixin(Particle.class) -public abstract class ParticleMixin { - - @Shadow - @Final - protected ClientLevel level; - - @Shadow - protected boolean hasPhysics; - - @Shadow - protected double x; - - @Shadow - protected double y; - - @Shadow - protected double z; - - @Unique - private boolean lovisual$physicsBefore; - - @Unique - private long lovisual$lightTick = Long.MIN_VALUE; - - @Unique - private int lovisual$light; - - @Inject(method = "getLightCoords", at = @At("HEAD"), cancellable = true) - private void lovisual$cachedLight(float partialTick, CallbackInfoReturnable cir) { - if (lovisual$lightTick == level.getGameTime() && OptimizeToggles.particleLight()) { - cir.setReturnValue(lovisual$light); - } - } - - @Inject(method = "getLightCoords", at = @At("RETURN")) - private void lovisual$storeLight(float partialTick, CallbackInfoReturnable cir) { - lovisual$light = cir.getReturnValueI(); - lovisual$lightTick = level.getGameTime(); - } - - @Inject(method = "move", at = @At("HEAD")) - private void lovisual$cheapPhysics(double dx, double dy, double dz, CallbackInfo ci) { - lovisual$physicsBefore = hasPhysics; - if (hasPhysics && OptimizeToggles.particlePhysics() && lovisual$skipCollision()) { - hasPhysics = false; - } - } - - @Inject(method = "move", at = @At("RETURN")) - private void lovisual$restorePhysics(double dx, double dy, double dz, CallbackInfo ci) { - hasPhysics = lovisual$physicsBefore; - } - - @Unique - private boolean lovisual$skipCollision() { - Object self = this; - if (self instanceof BaseAshSmokeParticle - || self instanceof CampfireSmokeParticle - || self instanceof BubbleColumnUpParticle) { - return true; - } - Vec3 cam = CameraPosition.get(); - double ddx = x - cam.x; - double ddy = y - cam.y; - double ddz = z - cam.z; - return ddx * ddx + ddy * ddy + ddz * ddz > 16 * 16; - } -} diff --git a/mod/src/main/resources/lovisual.mixins.json b/mod/src/main/resources/lovisual.mixins.json index 000e84c4..2c8a271f 100644 --- a/mod/src/main/resources/lovisual.mixins.json +++ b/mod/src/main/resources/lovisual.mixins.json @@ -33,22 +33,12 @@ "world.level.LevelMixin" ], "client": [ - "optimize.block.BaseSpawnerMixin", - "optimize.block.BlockEntityMixin", - "optimize.block.BlockEntityRenderStateMixin", - "optimize.block.ChestRendererMixin", - "optimize.entity.EntityNameMixin", - "optimize.entity.EntityRenderStateEntityMixin", "optimize.entity.LivingEntityLodMixin", - "optimize.entity.SodiumEntityRendererMixin", - "optimize.entity.renderer.EntityRendererNameMixin", - "optimize.entity.renderer.EntityRendererStateMixin", "optimize.gl.GlCommandEncoderClearMixin", "optimize.gl.GlCommandEncoderTexBufferMixin", "optimize.gl.RenderTypesMixin", "optimize.hud.OptimizeDebugHudMixin", "optimize.particle.BubbleColumnUpParticleMixin", - "optimize.particle.ParticleMixin", "optimize.world.LevelRendererOutlineMixin", "accessors.blaze3d.GlTextureInvoker", "accessors.blaze3d.GpuDeviceAccessor",