Replace all ATs with Mixin on 1.13+ in preparation for Fabric
This commit is contained in:
@@ -7,6 +7,7 @@ import com.replaymod.core.gui.GuiBackgroundProcesses;
|
||||
import com.replaymod.core.gui.GuiReplaySettings;
|
||||
import com.replaymod.core.gui.RestoreReplayGui;
|
||||
import com.replaymod.core.handler.MainMenuHandler;
|
||||
import com.replaymod.core.mixin.MinecraftAccessor;
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import com.replaymod.editor.ReplayModEditor;
|
||||
import com.replaymod.extras.ReplayModExtras;
|
||||
@@ -152,7 +153,7 @@ public class ReplayMod implements Module {
|
||||
I18n.setI18n(net.minecraft.client.resources.I18n::format);
|
||||
|
||||
//#if MC>=11300
|
||||
DeferredWorkQueue.runLater(() -> MCVer.getMinecraft().resourcePackRepository.addPackFinder(new LangResourcePack.Finder()));
|
||||
DeferredWorkQueue.runLater(() -> MCVer.getMinecraft().getResourcePackList().addPackFinder(new LangResourcePack.Finder()));
|
||||
//#endif
|
||||
|
||||
// Register all RM modules
|
||||
@@ -223,7 +224,7 @@ public class ReplayMod implements Module {
|
||||
}
|
||||
};
|
||||
//#if MC>=11300
|
||||
mc.resourcePackRepository.addPackFinder(new IPackFinder() {
|
||||
mc.getResourcePackList().addPackFinder(new IPackFinder() {
|
||||
@Override
|
||||
public <T extends ResourcePackInfo> void addPackInfosToMap(Map<String, T> map, ResourcePackInfo.IFactory<T> factory) {
|
||||
map.put("jgui", ResourcePackInfo.func_195793_a("jgui", true, () -> jGuiResourcePack, factory, ResourcePackInfo.Priority.BOTTOM));
|
||||
@@ -352,11 +353,9 @@ public class ReplayMod implements Module {
|
||||
return;
|
||||
}
|
||||
//#if MC>=10800
|
||||
//#if MC<10904
|
||||
//$$ @SuppressWarnings("unchecked")
|
||||
//#endif
|
||||
Queue<FutureTask<?>> tasks = mc.scheduledTasks;
|
||||
synchronized (mc.scheduledTasks) {
|
||||
Queue<FutureTask<?>> tasks = ((MinecraftAccessor) mc).getScheduledTasks();
|
||||
//noinspection SynchronizationOnLocalVariableOrMethodParameter
|
||||
synchronized (tasks) {
|
||||
//#else
|
||||
//$$ Queue<ListenableFutureTask<?>> tasks = scheduledTasks;
|
||||
//$$ synchronized (scheduledTasks) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.replaymod.core.handler;
|
||||
|
||||
import com.replaymod.core.mixin.GuiMainMenuAccessor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
@@ -43,8 +44,9 @@ public class MainMenuHandler {
|
||||
//#endif
|
||||
}
|
||||
//#if MC>=11300
|
||||
if (realmsOffset != 0 && gui.realmsNotification instanceof GuiScreenRealmsProxy) {
|
||||
gui.realmsNotification = new RealmsNotificationProxy((GuiScreenRealmsProxy) gui.realmsNotification, realmsOffset);
|
||||
GuiMainMenuAccessor guiA = (GuiMainMenuAccessor) gui;
|
||||
if (realmsOffset != 0 && guiA.getRealmsNotification() instanceof GuiScreenRealmsProxy) {
|
||||
guiA.setRealmsNotification(new RealmsNotificationProxy((GuiScreenRealmsProxy) guiA.getRealmsNotification(), realmsOffset));
|
||||
}
|
||||
//#endif
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(GuiMainMenu.class)
|
||||
public interface GuiMainMenuAccessor {
|
||||
//#if MC>=10904
|
||||
@Accessor
|
||||
GuiScreen getRealmsNotification();
|
||||
@Accessor
|
||||
void setRealmsNotification(GuiScreen value);
|
||||
//#endif
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(KeyBinding.class)
|
||||
public interface KeyBindingAccessor {
|
||||
@Accessor
|
||||
int getPressTime();
|
||||
@Accessor
|
||||
void setPressTime(int value);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.util.Timer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public interface MinecraftAccessor {
|
||||
@Accessor
|
||||
Timer getTimer();
|
||||
@Accessor
|
||||
void setTimer(Timer value);
|
||||
|
||||
@Accessor
|
||||
Queue<FutureTask<?>> getScheduledTasks();
|
||||
|
||||
@Accessor("hasCrashed")
|
||||
boolean hasCrashed();
|
||||
|
||||
@Accessor
|
||||
CrashReport getCrashReporter();
|
||||
}
|
||||
18
src/main/java/com/replaymod/core/mixin/MixinMinecraft.java
Normal file
18
src/main/java/com/replaymod/core/mixin/MixinMinecraft.java
Normal file
@@ -0,0 +1,18 @@
|
||||
//#if MC>=11300
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import com.replaymod.core.versions.MCVer;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public abstract class MixinMinecraft implements MCVer.MinecraftMethodAccessor {
|
||||
@Shadow protected abstract void processKeyBinds();
|
||||
|
||||
@Override
|
||||
public void replayModProcessKeyBinds() {
|
||||
processKeyBinds();
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
25
src/main/java/com/replaymod/core/mixin/TimerAccessor.java
Normal file
25
src/main/java/com/replaymod/core/mixin/TimerAccessor.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import net.minecraft.util.Timer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(Timer.class)
|
||||
public interface TimerAccessor {
|
||||
@Accessor
|
||||
long getLastSyncSysClock();
|
||||
@Accessor
|
||||
void setLastSyncSysClock(long value);
|
||||
|
||||
//#if MC>=11200
|
||||
@Accessor
|
||||
float getTickLength();
|
||||
@Accessor
|
||||
void setTickLength(float value);
|
||||
//#else
|
||||
//$$ @Accessor
|
||||
//$$ float getTimerSpeed();
|
||||
//$$ @Accessor
|
||||
//$$ void setTimerSpeed(float value);
|
||||
//#endif
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import com.replaymod.replaystudio.us.myles.ViaVersion.util.ReflectionUtil;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class EventRegistration<T> {
|
||||
public static <T> EventRegistration<T> create(Event<T> event, T callback) {
|
||||
return new EventRegistration<>(event, callback);
|
||||
}
|
||||
|
||||
public static <T> EventRegistration<T> register(Event<T> event, T callback) {
|
||||
EventRegistration<T> registration = new EventRegistration<>(event, callback);
|
||||
registration.register();
|
||||
return registration;
|
||||
}
|
||||
|
||||
private final Event<T> event;
|
||||
private final T listener;
|
||||
private boolean registered;
|
||||
|
||||
private EventRegistration(Event<T> event, T listener) {
|
||||
this.event = event;
|
||||
this.listener = listener;
|
||||
|
||||
event.register(listener);
|
||||
}
|
||||
|
||||
public void register() {
|
||||
if (registered) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
event.register(listener);
|
||||
registered = true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void unregister() {
|
||||
if (!registered) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
try {
|
||||
T[] handlers = (T[]) ReflectionUtil.get(event, "handlers", Object[].class);
|
||||
T[] copy = (T[]) new Object[handlers.length - 1];
|
||||
for (int from = 0, to = 0; from < handlers.length; from++) {
|
||||
if (handlers[from] == listener) {
|
||||
continue;
|
||||
}
|
||||
copy[to++] = handlers[from];
|
||||
}
|
||||
if (copy.length == 0) {
|
||||
copy = null;
|
||||
}
|
||||
ReflectionUtil.set(event, "handlers", copy);
|
||||
ReflectionUtil.invoke(event, "update");
|
||||
} catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
registered = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EventRegistrations {
|
||||
private List<EventRegistration<?>> registrations = new ArrayList<>();
|
||||
|
||||
public <T> EventRegistrations on(EventRegistration<T> registration) {
|
||||
registrations.add(registration);
|
||||
return this;
|
||||
}
|
||||
|
||||
public <T> EventRegistrations on(Event<T> event, T listener) {
|
||||
return on(EventRegistration.create(event, listener));
|
||||
}
|
||||
|
||||
public void register() {
|
||||
for (EventRegistration<?> registration : registrations) {
|
||||
registration.register();
|
||||
}
|
||||
}
|
||||
|
||||
public void unregister() {
|
||||
for (EventRegistration<?> registration : registrations) {
|
||||
registration.unregister();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.replaymod.core.utils;
|
||||
|
||||
import com.replaymod.core.mixin.TimerAccessor;
|
||||
import net.minecraft.util.Timer;
|
||||
|
||||
public class WrappedTimer extends Timer {
|
||||
@@ -33,16 +34,19 @@ public class WrappedTimer extends Timer {
|
||||
}
|
||||
|
||||
protected void copy(Timer from, Timer to) {
|
||||
TimerAccessor fromA = (TimerAccessor) from;
|
||||
TimerAccessor toA = (TimerAccessor) to;
|
||||
|
||||
to.elapsedTicks = from.elapsedTicks;
|
||||
to.renderPartialTicks = from.renderPartialTicks;
|
||||
to.lastSyncSysClock = from.lastSyncSysClock;
|
||||
toA.setLastSyncSysClock(fromA.getLastSyncSysClock());
|
||||
to.elapsedPartialTicks = from.elapsedPartialTicks;
|
||||
//#if MC>=11200
|
||||
to.tickLength = from.tickLength;
|
||||
toA.setTickLength(fromA.getTickLength());
|
||||
//#else
|
||||
//$$ to.ticksPerSecond = from.ticksPerSecond;
|
||||
//$$ to.lastHRTime = from.lastHRTime;
|
||||
//$$ to.timerSpeed = from.timerSpeed;
|
||||
//$$ toA.setTimerSpeed(fromA.getTimerSpeed());
|
||||
//$$ to.lastSyncHRClock = from.lastSyncHRClock;
|
||||
//#if MC>=10809
|
||||
//$$ to.counter = from.counter;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.replaymod.core.versions;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.replaymod.core.mixin.MinecraftAccessor;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -48,14 +49,11 @@ import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
//#if MC>=10800
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.GlStateManager.BooleanState;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.vertex.VertexFormatElement;
|
||||
import net.minecraft.world.WorldType;
|
||||
//#else
|
||||
//$$ import com.google.common.util.concurrent.Futures;
|
||||
//$$ import com.replaymod.render.hooks.GLStateTracker;
|
||||
//$$ import com.replaymod.render.hooks.GLStateTracker.BooleanState;
|
||||
//$$ import io.netty.handler.codec.DecoderException;
|
||||
//$$ import net.minecraft.client.resources.FileResourcePack;
|
||||
//$$
|
||||
@@ -231,63 +229,6 @@ public class MCVer {
|
||||
return world.playerEntities;
|
||||
}
|
||||
|
||||
public static BooleanState fog() {
|
||||
//#if MC>=11300
|
||||
return GlStateManager.FOG.fog;
|
||||
//#else
|
||||
//#if MC>=10809
|
||||
//$$ return GlStateManager.fogState.fog;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ return GlStateManager.fogState.field_179049_a;
|
||||
//#else
|
||||
//$$ return GLStateTracker.getInstance().fog;
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void fog(BooleanState fog) {
|
||||
//#if MC>=11300
|
||||
GlStateManager.FOG.fog = fog;
|
||||
//#else
|
||||
//#if MC>=10809
|
||||
//$$ GlStateManager.fogState.fog = fog;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ GlStateManager.fogState.field_179049_a = fog;
|
||||
//#else
|
||||
//$$ GLStateTracker.getInstance().fog = fog;
|
||||
//#endif
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static BooleanState texture2DState(int index) {
|
||||
//#if MC>=11300
|
||||
return GlStateManager.TEXTURES[index].texture2DState;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ return GlStateManager.textureState[index].texture2DState;
|
||||
//#else
|
||||
//$$ return GLStateTracker.getInstance().texture[index];
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
public static void texture2DState(int index, BooleanState texture2DState) {
|
||||
//#if MC>=11300
|
||||
GlStateManager.TEXTURES[index].texture2DState = texture2DState;
|
||||
//#else
|
||||
//#if MC>=10800
|
||||
//$$ GlStateManager.textureState[index].texture2DState = texture2DState;
|
||||
//#else
|
||||
//$$ GLStateTracker.getInstance().texture[index] = texture2DState;
|
||||
//#endif
|
||||
//#endif
|
||||
}
|
||||
|
||||
|
||||
//#if MC>=11300
|
||||
public static MainWindow newScaledResolution(Minecraft mc) {
|
||||
return mc.mainWindow;
|
||||
@@ -441,6 +382,19 @@ public class MCVer {
|
||||
return Minecraft.getInstance();
|
||||
}
|
||||
|
||||
public static float getRenderPartialTicks() {
|
||||
return ((MinecraftAccessor) getMinecraft()).getTimer().renderPartialTicks;
|
||||
}
|
||||
|
||||
//#if MC>=11300
|
||||
public static void processKeyBinds() {
|
||||
((MinecraftMethodAccessor) getMinecraft()).replayModProcessKeyBinds();
|
||||
}
|
||||
public interface MinecraftMethodAccessor {
|
||||
void replayModProcessKeyBinds();
|
||||
}
|
||||
//#endif
|
||||
|
||||
public static long milliTime() {
|
||||
//#if MC>=11300
|
||||
return Util.milliTime();
|
||||
|
||||
Reference in New Issue
Block a user