Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
migrate overwrite in RenderGlobal
Browse files Browse the repository at this point in the history
  • Loading branch information
mist475 committed Oct 11, 2023
1 parent e5884dd commit bdfd24f
Showing 1 changed file with 10 additions and 145 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
package mist475.mcpatcherforge.mixins.early.client.renderer;

import java.nio.IntBuffer;
import java.util.Arrays;
import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.EntitySorter;
import net.minecraft.client.renderer.RenderGlobal;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IWorldAccess;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -38,49 +27,8 @@
@Mixin(RenderGlobal.class)
public abstract class MixinRenderGlobal implements IWorldAccess {

@Shadow
public List<TileEntity> tileEntities;
@Shadow
private WorldClient theWorld;
@Shadow
private List<WorldRenderer> worldRenderersToUpdate;
@Shadow
private WorldRenderer[] sortedWorldRenderers;
@Shadow
private WorldRenderer[] worldRenderers;
@Shadow
private int renderChunksWide;
@Shadow
private int renderChunksTall;
@Shadow
private int renderChunksDeep;
@Shadow
private int glRenderListBase;
@Shadow
private Minecraft mc;
@Shadow
private IntBuffer glOcclusionQueryBase;
@Shadow
private boolean occlusionEnabled;
@Shadow
private int minBlockX;
@Shadow
private int minBlockY;
@Shadow
private int minBlockZ;
@Shadow
private int maxBlockX;
@Shadow
private int maxBlockY;
@Shadow
private int maxBlockZ;
@Shadow
private int renderDistanceChunks;
@Shadow
private int renderEntitiesStartupCounter;

@Shadow
protected abstract void markRenderersForNewPosition(int p_72722_1_, int p_72722_2_, int p_72722_3_);

@Redirect(
method = "<init>(Lnet/minecraft/client/Minecraft;)V",
Expand All @@ -92,99 +40,16 @@ private int modifyRenderGlobal(int n) {
return n / 3 * 5;
}

/**
* @author Mist475 (adapted from Paul Rupe)
* @reason Only changes the increase of one variable, couldn't manage to target it though :(
*/
@Overwrite
public void loadRenderers() {
if (this.theWorld != null) {
Blocks.leaves.setGraphicsLevel(this.mc.gameSettings.fancyGraphics);
Blocks.leaves2.setGraphicsLevel(this.mc.gameSettings.fancyGraphics);
this.renderDistanceChunks = this.mc.gameSettings.renderDistanceChunks;
int i;

if (this.worldRenderers != null) {
for (i = 0; i < this.worldRenderers.length; ++i) {
this.worldRenderers[i].stopRendering();
}
}

i = this.renderDistanceChunks * 2 + 1;
this.renderChunksWide = i;
this.renderChunksTall = 16;
this.renderChunksDeep = i;
this.worldRenderers = new WorldRenderer[this.renderChunksWide * this.renderChunksTall
* this.renderChunksDeep];
this.sortedWorldRenderers = new WorldRenderer[this.renderChunksWide * this.renderChunksTall
* this.renderChunksDeep];
int j = 0;
int k = 0;
this.minBlockX = 0;
this.minBlockY = 0;
this.minBlockZ = 0;
this.maxBlockX = this.renderChunksWide;
this.maxBlockY = this.renderChunksTall;
this.maxBlockZ = this.renderChunksDeep;
int l;

for (l = 0; l < this.worldRenderersToUpdate.size(); ++l) {
this.worldRenderersToUpdate.get(l).needsUpdate = false;
}

this.worldRenderersToUpdate.clear();
this.tileEntities.clear();
this.onStaticEntitiesChanged();

for (l = 0; l < this.renderChunksWide; ++l) {
for (int i1 = 0; i1 < this.renderChunksTall; ++i1) {
for (int j1 = 0; j1 < this.renderChunksDeep; ++j1) {
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l] = new WorldRenderer(
this.theWorld,
this.tileEntities,
l * 16,
i1 * 16,
j1 * 16,
this.glRenderListBase + j);

if (this.occlusionEnabled) {
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l].glOcclusionQuery = this.glOcclusionQueryBase.get(k);
}

this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l].isWaitingOnOcclusionQuery = false;
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l].isVisible = true;
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l].isInFrustum = true;
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l].chunkIndex = k++;
this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l].markDirty();
this.sortedWorldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide
+ l] = this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l];
this.worldRenderersToUpdate
.add(this.worldRenderers[(j1 * this.renderChunksTall + i1) * this.renderChunksWide + l]);
j += 5; // only change, someone help please!
}
}
}

if (this.theWorld != null) {
EntityLivingBase entitylivingbase = this.mc.renderViewEntity;

if (entitylivingbase != null) {
this.markRenderersForNewPosition(
MathHelper.floor_double(entitylivingbase.posX),
MathHelper.floor_double(entitylivingbase.posY),
MathHelper.floor_double(entitylivingbase.posZ));
Arrays.sort(this.sortedWorldRenderers, new EntitySorter(entitylivingbase));
}
}

this.renderEntitiesStartupCounter = 2;
}
@ModifyVariable(
method = "loadRenderers()V",
at = @At(
value = "INVOKE",
target = "Ljava/util/List;add(Ljava/lang/Object;)Z",
remap = false,
shift = At.Shift.AFTER),
ordinal = 1)
private int modifyLoadRenderers(int input) {
return input + 2;
}

// Order important here!
Expand Down

0 comments on commit bdfd24f

Please sign in to comment.