Replace all ATs with Mixin on 1.13+ in preparation for Fabric

This commit is contained in:
Jonas Herzig
2019-04-26 11:20:31 +02:00
parent d5b9e60c4d
commit 17fe5b345f
67 changed files with 1035 additions and 399 deletions

View File

@@ -1,23 +1,19 @@
//#if MC>=10800
package com.replaymod.render.hooks;
import com.replaymod.render.mixin.ChunkRenderDispatcherAccessor;
import com.replaymod.render.mixin.WorldRendererAccessor;
import com.replaymod.render.utils.JailingQueue;
import net.minecraft.client.renderer.RegionRenderCacheBuilder;
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.chunk.ChunkRenderDispatcher;
import net.minecraft.client.renderer.chunk.ChunkRenderTask;
import net.minecraft.client.renderer.chunk.ChunkRenderWorker;
import net.minecraft.client.renderer.chunk.RenderChunk;
import java.lang.reflect.Field;
import java.util.Iterator;
//#if MC>=11300
import net.minecraft.client.renderer.WorldRenderer;
import net.minecraft.client.renderer.chunk.ChunkRenderTask;
//#else
//$$ import net.minecraft.client.renderer.RenderGlobal;
//$$ import net.minecraft.client.renderer.chunk.ChunkCompileTaskGenerator;
//#endif
//#if MC>=10904
import java.util.concurrent.PriorityBlockingQueue;
//#else
@@ -52,7 +48,7 @@ public class ChunkLoadingRenderGlobal {
) {
this.hooked = renderGlobal;
setup(renderGlobal.renderDispatcher);
setup(((WorldRendererAccessor) renderGlobal).getRenderDispatcher());
}
public void updateRenderDispatcher(ChunkRenderDispatcher renderDispatcher) {
@@ -68,26 +64,19 @@ public class ChunkLoadingRenderGlobal {
private void setup(ChunkRenderDispatcher renderDispatcher) {
this.renderDispatcher = renderDispatcher;
this.renderWorker = new CustomChunkRenderWorker(renderDispatcher, new RegionRenderCacheBuilder());
ChunkRenderDispatcherAccessor renderDispatcherAcc = (ChunkRenderDispatcherAccessor) renderDispatcher;
int workerThreads = renderDispatcher.listThreadedWorkers.size();
int workerThreads = renderDispatcherAcc.getListThreadedWorkers().size();
//#if MC>=10904
//#if MC>=11300
PriorityBlockingQueue<ChunkRenderTask> queueChunkUpdates = renderDispatcher.queueChunkUpdates;
//#else
//$$ PriorityBlockingQueue<ChunkCompileTaskGenerator> queueChunkUpdates = renderDispatcher.queueChunkUpdates;
//#endif
PriorityBlockingQueue<ChunkRenderTask> queueChunkUpdates = renderDispatcherAcc.getQueueChunkUpdates();
//#else
//$$ BlockingQueue<ChunkCompileTaskGenerator> queueChunkUpdates = renderDispatcher.queueChunkUpdates;
//#endif
workerJailingQueue = new JailingQueue<>(queueChunkUpdates);
renderDispatcher.queueChunkUpdates = workerJailingQueue;
renderDispatcherAcc.setQueueChunkUpdates(workerJailingQueue);
//#if MC>=10904
//#if MC>=11300
ChunkRenderTask element = new ChunkRenderTask(null, null, 0);
//#else
//$$ ChunkCompileTaskGenerator element = new ChunkCompileTaskGenerator(null, null, 0);
//#endif
//#else
//$$ ChunkCompileTaskGenerator element = new ChunkCompileTaskGenerator(null, null);
//#endif
element.finish();
@@ -100,7 +89,7 @@ public class ChunkLoadingRenderGlobal {
while (renderDispatcher.runChunkUploads(0)) {}
workerJailingQueue.jail(workerThreads);
renderDispatcher.queueChunkUpdates = queueChunkUpdates;
renderDispatcherAcc.setQueueChunkUpdates(queueChunkUpdates);
try {
//#if MC>=11300
@@ -116,23 +105,22 @@ public class ChunkLoadingRenderGlobal {
public void updateChunks() {
while (renderDispatcher.runChunkUploads(0)) {
hooked.displayListEntitiesDirty = true;
((WorldRendererAccessor) hooked).setDisplayListEntitiesDirty(true);
}
while (!renderDispatcher.queueChunkUpdates.isEmpty()) {
//#if MC>=10904
PriorityBlockingQueue<ChunkRenderTask> queueChunkUpdates;
//#else
//$$ BlockingQueue<ChunkCompileTaskGenerator> queueChunkUpdates;
//#endif
queueChunkUpdates = ((ChunkRenderDispatcherAccessor) renderDispatcher).getQueueChunkUpdates();
while (!queueChunkUpdates.isEmpty()) {
try {
renderWorker.processTask(
//#if MC<10904
//$$ (ChunkCompileTaskGenerator)
//#endif
renderDispatcher.queueChunkUpdates.poll());
renderWorker.processTask(queueChunkUpdates.poll());
} catch (InterruptedException ignored) { }
}
//#if MC<10904
//$$ @SuppressWarnings("unchecked")
//#endif
Iterator<RenderChunk> iterator = hooked.chunksToUpdate.iterator();
Iterator<RenderChunk> iterator = ((WorldRendererAccessor) hooked).getChunksToUpdate().iterator();
while (iterator.hasNext()) {
RenderChunk renderchunk = iterator.next();

View File

@@ -0,0 +1,16 @@
package com.replaymod.render.hooks;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
public interface FogStateCallback {
Event<FogStateCallback> EVENT = EventFactory.createArrayBacked(FogStateCallback.class,
(enabled) -> {},
(listeners) -> (enabled) -> {
for (FogStateCallback listener : listeners) {
listener.fogStateChanged(enabled);
}
});
void fogStateChanged(boolean enabled);
}

View File

@@ -15,13 +15,6 @@
//$$ }
//$$
//$$ public int activeTexture;
//$$ public BooleanState fog = new BooleanState(GL11.GL_FOG);
//$$ public BooleanState[] texture = new BooleanState[32];
//$$ {
//$$ for (int i = 0; i < texture.length; i++) {
//$$ texture[i] = new BooleanState(GL11.GL_TEXTURE_2D);
//$$ }
//$$ }
//$$
//$$ public void updateActiveTexture(int magic) {
//$$ this.activeTexture = magic - GL13.GL_TEXTURE0;
@@ -29,25 +22,8 @@
//$$
//$$ public void updateEnabledState(int magic, boolean enabled) {
//$$ switch (magic) {
//$$ case GL11.GL_FOG: fog.setState(enabled); break;
//$$ case GL11.GL_TEXTURE_2D: texture[activeTexture].setState(enabled); break;
//$$ }
//$$ }
//$$
//$$ public static class BooleanState {
//$$ public int capability;
//$$ public boolean currentState;
//$$
//$$ public BooleanState(int capability) {
//$$ this.capability = capability;
//$$ }
//$$
//$$ public void setState(boolean enabled) {
//$$ this.currentState = enabled;
//$$ }
//$$
//$$ public boolean getState() {
//$$ return currentState;
//$$ case GL11.GL_FOG: FogStateCallback.EVENT.invoker().fogStateChanged(enabled); break;
//$$ case GL11.GL_TEXTURE_2D: Texture2DStateCallback.EVENT.invoker().texture2DStateChanged(activeTexture, enabled); break;
//$$ }
//$$ }
//$$

View File

@@ -0,0 +1,16 @@
package com.replaymod.render.hooks;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
public interface Texture2DStateCallback {
Event<Texture2DStateCallback> EVENT = EventFactory.createArrayBacked(Texture2DStateCallback.class,
(slot, enabled) -> {},
(listeners) -> (slot, enabled) -> {
for (Texture2DStateCallback listener : listeners) {
listener.texture2DStateChanged(slot, enabled);
}
});
void texture2DStateChanged(int slot, boolean enabled);
}