diff options
author | makamys <makamys@outlook.com> | 2022-06-09 12:57:52 +0200 |
---|---|---|
committer | makamys <makamys@outlook.com> | 2022-06-09 12:57:52 +0200 |
commit | 5bea63de0d78487b91dd701a8f6931b9314f2be5 (patch) | |
tree | 9a23fc91c986d8763b31c48f670b812e9ce24c8a /src/main/java/makamys/neodymium/mixin | |
parent | 5820fe56fb4022ddda044a8fe502b59e18147836 (diff) | |
download | Neodymium-5bea63de0d78487b91dd701a8f6931b9314f2be5.tar.gz Neodymium-5bea63de0d78487b91dd701a8f6931b9314f2be5.tar.bz2 Neodymium-5bea63de0d78487b91dd701a8f6931b9314f2be5.zip |
Rebrand pt. 1: Rename mod to Neodymium
Diffstat (limited to 'src/main/java/makamys/neodymium/mixin')
6 files changed, 339 insertions, 0 deletions
diff --git a/src/main/java/makamys/neodymium/mixin/MixinChunkCache.java b/src/main/java/makamys/neodymium/mixin/MixinChunkCache.java new file mode 100644 index 0000000..b4a7368 --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinChunkCache.java @@ -0,0 +1,29 @@ +package makamys.neodymium.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import makamys.neodymium.LODMod; +import makamys.neodymium.renderer.FarChunkCache; +import makamys.neodymium.renderer.LODRenderer; +import net.minecraft.world.ChunkCache; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +@Mixin(ChunkCache.class) +abstract class MixinChunkCache { + + @Redirect(method = "<init>*", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;getChunkFromChunkCoords(II)Lnet/minecraft/world/chunk/Chunk;")) + private Chunk redirectGetChunkFromChunkCoords(World world, int p1, int p2) { + Chunk chunk = world.getChunkFromChunkCoords(p1, p2); + if(LODMod.isActive() && FarChunkCache.class.isInstance(this.getClass()) && chunk.isEmpty()) { + Chunk myChunk = LODMod.renderer.getChunkFromChunkCoords(p1, p2); + if(myChunk != null) { + chunk = myChunk; + } + } + return chunk; + } + +} diff --git a/src/main/java/makamys/neodymium/mixin/MixinEntityRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinEntityRenderer.java new file mode 100644 index 0000000..66d95ae --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinEntityRenderer.java @@ -0,0 +1,35 @@ +package makamys.neodymium.mixin; + +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import makamys.neodymium.LODMod; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.entity.EntityLivingBase; + +@Mixin(EntityRenderer.class) +abstract class MixinEntityRenderer { + + @Shadow + private float farPlaneDistance; + + @Inject(method = "setupCameraTransform", at = @At(value = "FIELD", target = "Lnet/minecraft/client/renderer/EntityRenderer;farPlaneDistance:F", shift = At.Shift.AFTER, ordinal = 1)) + private void onConstructed(CallbackInfo ci) { + if(LODMod.isActive()) { + farPlaneDistance *= LODMod.renderer.getFarPlaneDistanceMultiplier(); + } + } + + @Inject(method = "setupFog", at = @At(value = "RETURN")) + private void afterSetupFog(int mode, float alpha, CallbackInfo ci) { + if(LODMod.isActive()) { + LODMod.renderer.afterSetupFog(mode, alpha, farPlaneDistance); + } + } +} diff --git a/src/main/java/makamys/neodymium/mixin/MixinRenderBlocks.java b/src/main/java/makamys/neodymium/mixin/MixinRenderBlocks.java new file mode 100644 index 0000000..0f8ff41 --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinRenderBlocks.java @@ -0,0 +1,29 @@ +package makamys.neodymium.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import makamys.neodymium.LODMod; +import makamys.neodymium.renderer.FarChunkCache; +import net.minecraft.block.Block; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraft.world.chunk.Chunk; + +@Mixin(RenderBlocks.class) +abstract class MixinRenderBlocks { + + @Redirect(method = "renderBlockLiquid", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;shouldSideBeRendered(Lnet/minecraft/world/IBlockAccess;IIII)Z")) + public boolean shouldSideBeRendered(Block block, IBlockAccess ba, int x, int y, int z, int w) { + if(LODMod.isActive()) { + return LODMod.renderer.shouldSideBeRendered(block, ba, x, y, z, w); + } else { + return block.shouldSideBeRendered(ba, x, y, z, w); + } + } + +} diff --git a/src/main/java/makamys/neodymium/mixin/MixinRenderGlobal.java b/src/main/java/makamys/neodymium/mixin/MixinRenderGlobal.java new file mode 100644 index 0000000..dc561a2 --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinRenderGlobal.java @@ -0,0 +1,40 @@ +package makamys.neodymium.mixin; + +import java.nio.IntBuffer; + +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import makamys.neodymium.LODMod; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.entity.Entity; + +@Mixin(RenderGlobal.class) +abstract class MixinRenderGlobal { + + @Shadow + private WorldRenderer[] sortedWorldRenderers; + + @Redirect(method = "renderSortedRenderers", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/RenderGlobal;renderAllRenderLists(ID)V")) + private void redirectRenderAllRenderLists(RenderGlobal thiz, int p1, double p2) { + if(LODMod.shouldRenderVanillaWorld()) { + thiz.renderAllRenderLists(p1, p2); + } + } + + @Inject(method = "renderSortedRenderers", at = @At(value = "HEAD")) + public void preRenderSortedRenderers(int startRenderer, int numRenderers, int renderPass, double partialTickTime, CallbackInfoReturnable cir) { + if(LODMod.isActive()) { + LODMod.renderer.preRenderSortedRenderers(renderPass, partialTickTime, sortedWorldRenderers); + } + } +} diff --git a/src/main/java/makamys/neodymium/mixin/MixinRenderGlobal_OptiFine.java b/src/main/java/makamys/neodymium/mixin/MixinRenderGlobal_OptiFine.java new file mode 100644 index 0000000..dad164c --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinRenderGlobal_OptiFine.java @@ -0,0 +1,25 @@ +package makamys.neodymium.mixin; + +import java.nio.IntBuffer; + +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import makamys.neodymium.LODMod; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.RenderGlobal; + +@Mixin(RenderGlobal.class) +abstract class MixinRenderGlobal_OptiFine { + + // for OptiFine's Fast Render option + @Redirect(method = "renderSortedRenderersFast", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glCallLists(Ljava/nio/IntBuffer;)V"), remap=false) + private void redirectRenderAllRenderLists(IntBuffer buffer) { + if(LODMod.shouldRenderVanillaWorld()) { + GL11.glCallLists(buffer); + } + } + +} diff --git a/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java new file mode 100644 index 0000000..47450c3 --- /dev/null +++ b/src/main/java/makamys/neodymium/mixin/MixinWorldRenderer.java @@ -0,0 +1,181 @@ +package makamys.neodymium.mixin; + +import java.util.ArrayList; +import java.util.List; + +import org.lwjgl.opengl.GL11; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import makamys.neodymium.LODMod; +import makamys.neodymium.ducks.IWorldRenderer; +import makamys.neodymium.renderer.ChunkMesh; +import makamys.neodymium.renderer.FarChunkCache; +import makamys.neodymium.renderer.FarWorldRenderer; +import makamys.neodymium.renderer.LODRenderer; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.entity.RenderItem; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.ChunkCache; +import net.minecraft.world.World; + +@Mixin(WorldRenderer.class) +abstract class MixinWorldRenderer implements IWorldRenderer { + + @Shadow + public int posX; + @Shadow + public int posY; + @Shadow + public int posZ; + + @Shadow + private boolean isInFrustum; + @Shadow + public boolean[] skipRenderPass; + @Shadow + private int glRenderList; + + @Shadow + public boolean needsUpdate; + + boolean savedDrawnStatus; + + public List<ChunkMesh> chunkMeshes; + + @Redirect(method = "setPosition", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/entity/RenderItem;renderAABB(Lnet/minecraft/util/AxisAlignedBB;)V")) + private void redirectRenderAABB(AxisAlignedBB p1) { + if(!FarWorldRenderer.class.isInstance(this.getClass())) { + RenderItem.renderAABB(p1); + } + } + + @Redirect(method = "updateRenderer", at = @At(value = "NEW", target = "Lnet/minecraft/world/ChunkCache;")) + private ChunkCache redirectConstructChunkCache(World p1, int p2, int p3, int p4, int p5, int p6, int p7, int p8) { + if(!FarWorldRenderer.class.isInstance(this.getClass())) { + return new ChunkCache(p1, p2, p3, p4, p5, p6, p7, p8); + } else { + return new FarChunkCache(p1, p2, p3, p4, p5, p6, p7, p8); + } + } + + @Inject(method = "updateRenderer", at = @At(value = "HEAD")) + private void preUpdateRenderer(CallbackInfo ci) { + saveDrawnStatus(); + + if(LODMod.isActive()) { + if(needsUpdate) { + if(chunkMeshes != null) { + chunkMeshes.clear(); + } else { + chunkMeshes = new ArrayList<>(); + } + } else { + chunkMeshes = null; + } + } + } + + @Inject(method = "updateRenderer", at = @At(value = "RETURN")) + private void postUpdateRenderer(CallbackInfo ci) { + notifyIfDrawnStatusChanged(); + + if(LODMod.isActive()) { + if(chunkMeshes != null) { + LODMod.renderer.onWorldRendererPost(WorldRenderer.class.cast(this)); + chunkMeshes.clear(); + } + } + } + + @Inject(method = "postRenderBlocks", at = @At(value = "HEAD")) + private void prePostRenderBlocks(int pass, EntityLivingBase entity, CallbackInfo ci) { + if(LODMod.isActive() && !LODMod.disableChunkMeshes) { + if(chunkMeshes != null) { + chunkMeshes.add(ChunkMesh.fromTessellator(pass, WorldRenderer.class.cast(this), Tessellator.instance)); + } + } + } + + @Redirect(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/Tessellator;draw()I")) + private int redirectPostRenderBlocksDraw() { + if(!FarWorldRenderer.class.isInstance(this.getClass())) { + return Tessellator.instance.draw(); + } else { + Tessellator.instance.reset(); + return 0; + } + } + + // There's probably a nicer way to do this + + @Redirect(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glPopMatrix()V")) + private void redirectPostRenderBlocksGL1() { + if(!FarWorldRenderer.class.isInstance(this.getClass())) { + GL11.glPopMatrix(); + } + } + + @Redirect(method = "postRenderBlocks", at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/GL11;glEndList()V")) + private void redirectPostRenderBlocksGL2() { + if(!FarWorldRenderer.class.isInstance(this.getClass())) { + GL11.glEndList(); + } + } + + // XXX this is inconsistent, Forge callbacks are preserved in postRenderBlocks but not preRenderBlocks + + @Inject(method = "preRenderBlocks", at = @At(value = "HEAD")) + private void preRenderBlocksInjector(CallbackInfo ci) { + if(FarWorldRenderer.class.isInstance(this.getClass())) { + Tessellator.instance.setTranslation((double)(-this.posX), (double)(-this.posY), (double)(-this.posZ)); + ci.cancel(); + } + } + + @Inject(method = "setDontDraw", at = @At(value = "HEAD")) + private void preSetDontDraw(CallbackInfo ci) { + if(LODMod.isActive()) { + LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), LODRenderer.WorldRendererChange.DELETED); + } + } + + @Override + public List<ChunkMesh> getChunkMeshes() { + return chunkMeshes; + } + + @Inject(method = "updateInFrustum", at = @At(value = "HEAD")) + private void preUpdateInFrustum(CallbackInfo ci) { + saveDrawnStatus(); + } + + @Inject(method = "updateInFrustum", at = @At(value = "RETURN")) + private void postUpdateInFrustum(CallbackInfo ci) { + notifyIfDrawnStatusChanged(); + } + + private void saveDrawnStatus() { + savedDrawnStatus = isDrawn(); + } + + private void notifyIfDrawnStatusChanged() { + boolean drawn = isDrawn(); + if(LODMod.isActive() && drawn != savedDrawnStatus) { + LODMod.renderer.onWorldRendererChanged(WorldRenderer.class.cast(this), drawn ? LODRenderer.WorldRendererChange.VISIBLE : LODRenderer.WorldRendererChange.INVISIBLE); + } + } + + @Override + public boolean isDrawn() { + return isInFrustum && (!skipRenderPass[0] || !skipRenderPass[1]); + } +} |