Get rid of all the ATs in favor of Mixins

This commit is contained in:
Jonas Herzig
2019-05-06 16:53:39 +02:00
parent 2094c518a0
commit bd91d0d3bd
41 changed files with 302 additions and 778 deletions

View File

@@ -1,6 +1,5 @@
package com.replaymod.recording.handler;
import com.replaymod.recording.mixin.EntityLivingBaseAccessor;
import com.replaymod.recording.mixin.IntegratedServerAccessor;
import com.replaymod.recording.packet.PacketListener;
import de.johni0702.minecraft.gui.utils.EventRegistrations;
@@ -24,10 +23,7 @@ import net.minecraftforge.fml.common.gameevent.TickEvent;
//#endif
//#if MC>=10904
//#if MC>=11300
//#else
//$$ import net.minecraft.entity.EntityLiving;
//#endif
import com.replaymod.recording.mixin.EntityLivingBaseAccessor;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.EnumHand;
@@ -169,8 +165,14 @@ public class RecordingEventHandler extends EventRegistrations {
//$$ // Note: this leaves the lastY value offset by the eye height but because it's only used for relative
//$$ // movement, that doesn't matter.
//$$ S18PacketEntityTeleport teleportPacket = new S18PacketEntityTeleport(player);
//$$ teleportPacket.field_149457_c = MathHelper.floor_double(player.boundingBox.minY * 32);
//$$ packet = teleportPacket;
//$$ packet = new S18PacketEntityTeleport(
//$$ teleportPacket.func_149451_c(),
//$$ teleportPacket.func_149449_d(),
//$$ MathHelper.floor_double(player.boundingBox.minY * 32),
//$$ teleportPacket.func_149446_f(),
//$$ teleportPacket.func_149450_g(),
//$$ teleportPacket.func_149447_h()
//$$ );
//#endif
} else {
byte newYaw = (byte) ((int) (player.rotationYaw * 256.0F / 360.0F));
@@ -340,7 +342,7 @@ public class RecordingEventHandler extends EventRegistrations {
//#if MC>=11300
dataManager.register(EntityLivingBaseAccessor.getLivingFlags(), (byte) state);
//#else
//$$ dataManager.register(EntityLiving.HAND_STATES, (byte) state);
//$$ dataManager.register(EntityLivingBaseAccessor.getLivingFlags(), (byte) state);
//#endif
packetListener.save(new SPacketEntityMetadata(player.getEntityId(), dataManager, true));
}

View File

@@ -6,13 +6,13 @@ import org.spongepowered.asm.mixin.gen.Accessor;
import javax.annotation.Nonnull;
//#if MC>=11300
//#if MC>=10904
import net.minecraft.network.datasync.DataParameter;
//#endif
@Mixin(EntityLivingBase.class)
public interface EntityLivingBaseAccessor {
//#if MC>=11300
//#if MC>=10904
@Accessor("LIVING_FLAGS")
@Nonnull
@SuppressWarnings("ConstantConditions")

View File

@@ -1,4 +1,4 @@
//#if MC>=11300
//#if MC>=10800
package com.replaymod.recording.mixin;
import com.replaymod.recording.packet.ResourcePackRecorder;
@@ -39,7 +39,11 @@ public abstract class MixinDownloadingPackFinder implements ResourcePackRecorder
//$$ @Redirect(method = "download", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resource/ClientResourcePackCreator;loadServerPack(Ljava/io/File;)Ljava/util/concurrent/CompletableFuture;"))
//$$ private CompletableFuture<Object>
//#else
//#if MC>=10800
@Redirect(method = "downloadResourcePack", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/DownloadingPackFinder;func_195741_a(Ljava/io/File;)Lcom/google/common/util/concurrent/ListenableFuture;"))
//#else
//$$ @Redirect(method = "func_180601_a", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/ResourcePackRepository;func_177319_a(Ljava/io/File;)Lcom/google/common/util/concurrent/ListenableFuture;"))
//#endif
private ListenableFuture<Object>
//#endif
recordDownloadedPack(DownloadingPackFinder downloadingPackFinder, File file) {

View File

@@ -7,16 +7,8 @@ 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

@@ -7,16 +7,8 @@ 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

@@ -130,7 +130,7 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
//#if MC>=10800
UUID uuid = ((SPacketSpawnPlayer) packet).getUniqueId();
//#else
//$$ UUID uuid = ((S0CPacketSpawnPlayer) packet).field_148955_b.getId();
//$$ UUID uuid = ((S0CPacketSpawnPlayer) packet).func_148948_e().getId();
//#endif
Set<String> uuids = new HashSet<>(Arrays.asList(metaData.getPlayers()));
uuids.add(uuid.toString());
@@ -300,16 +300,21 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
@SuppressWarnings("unchecked")
private byte[] getPacketData(Packet packet) throws Exception {
//#if MC>=10904
if (packet instanceof SPacketSpawnMob) {
SPacketSpawnMob p = (SPacketSpawnMob) packet;
SPacketSpawnMobAccessor pa = (SPacketSpawnMobAccessor) p;
if (pa.getDataManager() == null) {
pa.setDataManager(new EntityDataManager(null));
if (p.getDataManagerEntries() != null) {
//#if MC>=10904
for (EntityDataManager.DataEntry<?> entry : p.getDataManagerEntries()) {
DataManager_set(pa.getDataManager(), entry);
}
//#else
//$$ for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_149027_c()) {
//$$ pa.getDataManager().addObject(wo.getDataValueId(), wo.getObject());
//$$ }
//#endif
}
}
}
@@ -320,45 +325,18 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
if (pa.getDataManager() == null) {
pa.setDataManager(new EntityDataManager(null));
if (p.getDataManagerEntries() != null) {
//#if MC>=10904
for (EntityDataManager.DataEntry<?> entry : p.getDataManagerEntries()) {
DataManager_set(pa.getDataManager(), entry);
}
//#else
//$$ for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_148944_c()) {
//$$ pa.getDataManager().addObject(wo.getDataValueId(), wo.getObject());
//$$ }
//#endif
}
}
}
//#else
//$$ if(packet instanceof S0FPacketSpawnMob) {
//$$ S0FPacketSpawnMob p = (S0FPacketSpawnMob) packet;
//$$ if (p.field_149043_l == null) {
//$$ p.field_149043_l = new DataWatcher(null);
//$$ if(p.func_149027_c() != null) {
//$$ for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_149027_c()) {
//$$ p.field_149043_l.addObject(wo.getDataValueId(), wo.getObject());
//$$ }
//$$ }
//$$ }
//$$ }
//$$
//$$ if(packet instanceof S0CPacketSpawnPlayer) {
//$$ S0CPacketSpawnPlayer p = (S0CPacketSpawnPlayer) packet;
//#if MC>=10809
//$$ if (p.watcher == null) {
//$$ p.watcher = new DataWatcher(null);
//$$ if(p.func_148944_c() != null) {
//$$ for(DataWatcher.WatchableObject wo : p.func_148944_c()) {
//$$ p.watcher.addObject(wo.getDataValueId(), wo.getObject());
//#else
//$$ if (p.field_148960_i == null) {
//$$ p.field_148960_i = new DataWatcher(null);
//$$ if(p.func_148944_c() != null) {
//$$ for(DataWatcher.WatchableObject wo : (List<DataWatcher.WatchableObject>) p.func_148944_c()) {
//$$ p.field_148960_i.addObject(wo.getDataValueId(), wo.getObject());
//#endif
//$$ }
//$$ }
//$$ }
//$$ }
//#endif
//#if MC>=10800
Integer packetId = connectionState.getPacketId(EnumPacketDirection.CLIENTBOUND, packet);

View File

@@ -7,6 +7,7 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.ServerList;
import net.minecraft.client.resources.DownloadingPackFinder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -17,12 +18,10 @@ import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.client.resources.I18n;
//#endif
//#if MC>=11300
//#if MC>=10800
import de.johni0702.minecraft.gui.utils.Consumer;
import net.minecraft.client.resources.DownloadingPackFinder;
//#else
//$$ import net.minecraft.client.gui.GuiScreenWorking;
//$$ import net.minecraft.client.resources.ResourcePackRepository;
//$$ import net.minecraft.util.HttpUtil;
//#endif
@@ -33,8 +32,6 @@ import net.minecraft.network.play.server.SPacketResourcePackSend;
//#endif
//#if MC>=10800
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
//#if MC>=11400
//$$ import java.util.concurrent.CompletableFuture;
//#else
@@ -42,12 +39,8 @@ import com.google.common.util.concurrent.ListenableFuture;
//#endif
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.NetworkManager;
//#if MC<11300
//$$ import org.apache.commons.io.FileUtils;
//#endif
import javax.annotation.Nonnull;
//#else
//$$ import com.replaymod.core.mixin.ResourcePackRepositoryAccessor;
//$$ import net.minecraft.client.multiplayer.ServerData.ServerResourceMode;
//$$ import net.minecraft.client.multiplayer.ServerList;
//$$ import net.minecraft.client.resources.FileResourcePack;
@@ -192,7 +185,6 @@ public class ResourcePackRecorder {
throwable -> mc.getConnection().sendPacket(makeStatusPacket(hash, Action.FAILED_DOWNLOAD)));
}
//#if MC>=11300
private
//#if MC>=11400
//$$ CompletableFuture<?>
@@ -209,102 +201,6 @@ public class ResourcePackRecorder {
void setRequestCallback(Consumer<File> callback);
}
//#else
//$$ private ListenableFuture downloadResourcePack(final int requestId, String url, String hash) {
//$$ final ResourcePackRepository repo = mc.mcResourcePackRepository;
//$$ String fileName;
//$$ if (hash.matches("^[a-f0-9]{40}$")) {
//$$ fileName = hash;
//$$ } else {
//$$ fileName = url.substring(url.lastIndexOf("/") + 1);
//$$
//$$ if (fileName.contains("?")) {
//$$ fileName = fileName.substring(0, fileName.indexOf("?"));
//$$ }
//$$
//$$ if (!fileName.endsWith(".zip")) {
//$$ return Futures.immediateFailedFuture(new IllegalArgumentException("Invalid filename; must end in .zip"));
//$$ }
//$$
//$$ fileName = "legacy_" + fileName.replaceAll("\\W", "");
//$$ }
//$$
//$$ final File file = new File(repo.dirServerResourcepacks, fileName);
//#if MC>=10809
//$$ repo.lock.lock();
//#else
//$$ repo.field_177321_h.lock();
//#endif
//$$ try {
//#if MC>=10809
//$$ repo.clearResourcePack();
//#else
//$$ repo.func_148529_f();
//#endif
//$$
//$$ if (file.exists() && hash.length() == 40) {
//$$ try {
//$$ String fileHash = Hashing.sha1().hashBytes(Files.toByteArray(file)).toString();
//$$ if (fileHash.equals(hash)) {
//$$ recordResourcePack(file, requestId);
//$$ return setServerResourcePack(file);
//$$ }
//$$
//$$ logger.warn("File " + file + " had wrong hash (expected " + hash + ", found " + fileHash + "). Deleting it.");
//$$ FileUtils.deleteQuietly(file);
//$$ } catch (IOException ioexception) {
//$$ logger.warn("File " + file + " couldn\'t be hashed. Deleting it.", ioexception);
//$$ FileUtils.deleteQuietly(file);
//$$ }
//$$ }
//$$
//$$ final GuiScreenWorking guiScreen = new GuiScreenWorking();
//$$ final Minecraft mc = Minecraft.getMinecraft();
//$$
//$$ Futures.getUnchecked(mc.addScheduledTask(() -> mc.displayGuiScreen(guiScreen)));
//$$
//#if MC>=10809
//#if MC>=11002
//#if MC>=11100
//$$ Map<String, String> sessionInfo = ResourcePackRepository.getDownloadHeaders();
//#else
//$$ Map<String, String> sessionInfo = ResourcePackRepository.func_190115_a();
//#endif
//#else
//$$ Map<String, String> sessionInfo = Minecraft.getSessionInfo();
//#endif
//$$ repo.downloadingPacks = HttpUtil.downloadResourcePack(file, url, sessionInfo, 50 * 1024 * 1024, guiScreen, mc.getProxy());
//$$ Futures.addCallback(repo.downloadingPacks, new FutureCallback<Object>() {
//#else
//$$ Map sessionInfo = Minecraft.getSessionInfo();
//$$ repo.field_177322_i = HttpUtil.func_180192_a(file, url, sessionInfo, 50 * 1024 * 1024, guiScreen, mc.getProxy());
//$$ Futures.addCallback(repo.field_177322_i, new FutureCallback() {
//#endif
//$$ @Override
//$$ public void onSuccess(Object value) {
//$$ recordResourcePack(file, requestId);
//$$ setServerResourcePack(file);
//$$ }
//$$
//$$ @Override
//$$ public void onFailure(@Nonnull Throwable throwable) {
//$$ throwable.printStackTrace();
//$$ }
//$$ });
//#if MC>=10809
//$$ return repo.downloadingPacks;
//#else
//$$ return repo.field_177322_i;
//#endif
//$$ } finally {
//#if MC>=10809
//$$ repo.lock.unlock();
//#else
//$$ repo.field_177321_h.unlock();
//#endif
//$$ }
//$$ }
//#endif
//#else
//$$ public synchronized S3FPacketCustomPayload handleResourcePack(S3FPacketCustomPayload packet) {
//$$ final int requestId = nextRequestId++;
//$$ final String url = new String(packet.func_149168_d(), Charsets.UTF_8);
@@ -338,7 +234,8 @@ public class ResourcePackRecorder {
//$$ }
//$$
//$$ private void downloadResourcePack(final int requestId, String url) {
//$$ final ResourcePackRepository repo = mc.mcResourcePackRepository;
//$$ final ResourcePackRepository repo = mc.getResourcePackRepository();
//$$ final ResourcePackRepositoryAccessor acc = (ResourcePackRepositoryAccessor) repo;
//$$
//$$ String fileName = url.substring(url.lastIndexOf("/") + 1);
//$$
@@ -352,7 +249,7 @@ public class ResourcePackRecorder {
//$$
//$$ fileName = fileName.replaceAll("\\W", "");
//$$
//$$ File file = new File(repo.field_148534_e, fileName);
//$$ File file = new File(acc.getCacheDir(), fileName);
//$$
//$$ HashMap<String, String> hashmap = new HashMap<>();
//$$ hashmap.put("X-Minecraft-Username", mc.getSession().getUsername());
@@ -362,14 +259,14 @@ public class ResourcePackRecorder {
//$$ GuiScreenWorking guiScreen = new GuiScreenWorking();
//$$ Minecraft.getMinecraft().displayGuiScreen(guiScreen);
//$$ repo.func_148529_f();
//$$ repo.field_148533_g = true;
//$$ acc.setActive(true);
//$$ // Lambdas MUST NOT be used with methods that need re-obfuscation in FG prior to 2.2 (will result in AbstractMethodError)
//$$ //noinspection Convert2Lambda
//$$ HttpUtil.downloadResourcePack(file, url, new HttpUtil.DownloadListener() {
//$$ public void onDownloadComplete(File file) {
//$$ if (repo.field_148533_g) {
//$$ repo.field_148533_g = false;
//$$ repo.field_148532_f = new FileResourcePack(file);
//$$ if (acc.isActive()) {
//$$ acc.setActive(false);
//$$ acc.setPack(new FileResourcePack(file));
//$$ Minecraft.getMinecraft().scheduleResourcesRefresh();
//$$ recordResourcePack(file, requestId);
//$$ }