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,5 +1,7 @@
package com.replaymod.recording.handler;
import com.replaymod.recording.mixin.EntityLivingBaseAccessor;
import com.replaymod.recording.mixin.IntegratedServerAccessor;
import com.replaymod.recording.packet.PacketListener;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
@@ -15,7 +17,6 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
//#if MC>=10904
//#if MC>=11300
import net.minecraft.entity.EntityLivingBase;
//#else
//$$ import net.minecraft.entity.EntityLiving;
//#endif
@@ -316,7 +317,7 @@ public class RecordingEventHandler {
EntityDataManager dataManager = new EntityDataManager(null);
int state = (wasHandActive ? 1 : 0) | (lastActiveHand == EnumHand.OFF_HAND ? 2 : 0);
//#if MC>=11300
dataManager.register(EntityLivingBase.LIVING_FLAGS, (byte) state);
dataManager.register(EntityLivingBaseAccessor.getLivingFlags(), (byte) state);
//#else
//$$ dataManager.register(EntityLiving.HAND_STATES, (byte) state);
//#endif
@@ -436,7 +437,7 @@ public class RecordingEventHandler {
if (event.phase != TickEvent.Phase.START) return;
if (mc.isIntegratedServerRunning()) {
IntegratedServer server = mc.getIntegratedServer();
if (server != null && server.isGamePaused) {
if (server != null && ((IntegratedServerAccessor) server).isGamePaused()) {
packetListener.setServerWasPaused();
}
}

View File

@@ -0,0 +1,21 @@
package com.replaymod.recording.mixin;
import net.minecraft.entity.EntityLivingBase;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import javax.annotation.Nonnull;
//#if MC>=11300
import net.minecraft.network.datasync.DataParameter;
//#endif
@Mixin(EntityLivingBase.class)
public interface EntityLivingBaseAccessor {
//#if MC>=11300
@Accessor("LIVING_FLAGS")
@Nonnull
@SuppressWarnings("ConstantConditions")
static DataParameter<Byte> getLivingFlags() { return null; }
//#endif
}

View File

@@ -0,0 +1,11 @@
package com.replaymod.recording.mixin;
import net.minecraft.server.integrated.IntegratedServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(IntegratedServer.class)
public interface IntegratedServerAccessor {
@Accessor("isGamePaused")
boolean isGamePaused();
}

View File

@@ -1,6 +1,7 @@
//#if MC>=11300
package com.replaymod.recording.mixin;
import com.replaymod.core.mixin.KeyBindingAccessor;
import com.replaymod.core.versions.MCVer;
import com.replaymod.extras.advancedscreenshots.AdvancedScreenshots;
import com.replaymod.replay.ReplayModReplay;
@@ -27,7 +28,8 @@ public abstract class MixinKeyboardListener {
// (and therefore before RM's release), this code will have to be removed then and handling code updated
KeyBinding keyBindChat = MCVer.getMinecraft().gameSettings.keyBindChat;
if (action == 1 && keyBindChat.matchesKey(key, scanCode)) {
keyBindChat.pressTime++;
KeyBindingAccessor acc = (KeyBindingAccessor) keyBindChat;
acc.setPressTime(acc.getPressTime() + 1);
BasicEventHooks.fireKeyInput();
ci.cancel();
}

View File

@@ -0,0 +1,22 @@
package com.replaymod.recording.mixin;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.network.play.server.SPacketSpawnMob;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SPacketSpawnMob.class)
public interface SPacketSpawnMobAccessor {
//#if MC>=10904
@Accessor
//#else
//$$ @Accessor("field_149043_l")
//#endif
EntityDataManager getDataManager();
//#if MC>=10904
@Accessor
//#else
//$$ @Accessor("field_149043_l")
//#endif
void setDataManager(EntityDataManager value);
}

View File

@@ -0,0 +1,22 @@
package com.replaymod.recording.mixin;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.network.play.server.SPacketSpawnPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SPacketSpawnPlayer.class)
public interface SPacketSpawnPlayerAccessor {
//#if MC>=10809
@Accessor("watcher")
//#else
//$$ @Accessor("field_148960_i")
//#endif
EntityDataManager getDataManager();
//#if MC>=10809
@Accessor("watcher")
//#else
//$$ @Accessor("field_148960_i")
//#endif
void setDataManager(EntityDataManager value);
}

View File

@@ -6,6 +6,8 @@ import com.replaymod.editor.gui.MarkerProcessor;
import com.replaymod.recording.ReplayModRecording;
import com.replaymod.recording.Setting;
import com.replaymod.recording.handler.ConnectionEventHandler;
import com.replaymod.recording.mixin.SPacketSpawnMobAccessor;
import com.replaymod.recording.mixin.SPacketSpawnPlayerAccessor;
import com.replaymod.replaystudio.data.Marker;
import com.replaymod.replaystudio.replay.ReplayFile;
import com.replaymod.replaystudio.replay.ReplayMetaData;
@@ -301,11 +303,12 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
//#if MC>=10904
if (packet instanceof SPacketSpawnMob) {
SPacketSpawnMob p = (SPacketSpawnMob) packet;
if (p.dataManager == null) {
p.dataManager = new EntityDataManager(null);
SPacketSpawnMobAccessor pa = (SPacketSpawnMobAccessor) p;
if (pa.getDataManager() == null) {
pa.setDataManager(new EntityDataManager(null));
if (p.getDataManagerEntries() != null) {
for (EntityDataManager.DataEntry<?> entry : p.getDataManagerEntries()) {
DataManager_set(p.dataManager, entry);
DataManager_set(pa.getDataManager(), entry);
}
}
}
@@ -313,11 +316,12 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
if (packet instanceof SPacketSpawnPlayer) {
SPacketSpawnPlayer p = (SPacketSpawnPlayer) packet;
if (p.watcher == null) {
p.watcher = new EntityDataManager(null);
SPacketSpawnPlayerAccessor pa = (SPacketSpawnPlayerAccessor) p;
if (pa.getDataManager() == null) {
pa.setDataManager(new EntityDataManager(null));
if (p.getDataManagerEntries() != null) {
for (EntityDataManager.DataEntry<?> entry : p.getDataManagerEntries()) {
DataManager_set(p.watcher, entry);
DataManager_set(pa.getDataManager(), entry);
}
}
}