From 5e4b08a8f5da2225d338a19d2f3971bb5fa02c2e Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Thu, 11 May 2023 14:14:56 -0400 Subject: [PATCH 1/7] Add support for Fabric datagen from runClient --- fabric/build.gradle | 1 + .../modernfix/ModernFixClientFabric.java | 5 +++ .../fabric/datagen/RuntimeDatagen.java | 40 +++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java diff --git a/fabric/build.gradle b/fabric/build.gradle index a68aea14..37d7d169 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -35,6 +35,7 @@ dependencies { modIncludeImplementation(fabricApi.module("fabric-command-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } modIncludeImplementation(fabricApi.module("fabric-models-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } modImplementation(fabricApi.module("fabric-resource-loader-v0", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } + modImplementation(fabricApi.module("fabric-data-generation-api-v1", rootProject.fabric_api_version)) { exclude group: 'net.fabricmc', module: 'fabric-loader' } modCompileOnly("com.terraformersmc:modmenu:${rootProject.modmenu_version}") { transitive false } // Remove the next line if you don't want to depend on the API // modApi "me.shedaniel:architectury-fabric:${rootProject.architectury_version}" diff --git a/fabric/src/main/java/org/embeddedt/modernfix/ModernFixClientFabric.java b/fabric/src/main/java/org/embeddedt/modernfix/ModernFixClientFabric.java index b7f8db62..7fd97b77 100644 --- a/fabric/src/main/java/org/embeddedt/modernfix/ModernFixClientFabric.java +++ b/fabric/src/main/java/org/embeddedt/modernfix/ModernFixClientFabric.java @@ -4,7 +4,9 @@ import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; +import org.embeddedt.modernfix.fabric.datagen.RuntimeDatagen; import java.util.concurrent.atomic.AtomicBoolean; @@ -29,5 +31,8 @@ public class ModernFixClientFabric implements ClientModInitializer { ServerLifecycleEvents.SERVER_STARTED.register(server -> { commonMod.onServerStarted(server); }); + if(FabricLoader.getInstance().isModLoaded("fabric-data-generation-api-v1")) { + RuntimeDatagen.init(); + } } } diff --git a/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java b/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java new file mode 100644 index 00000000..91e13676 --- /dev/null +++ b/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java @@ -0,0 +1,40 @@ +package org.embeddedt.modernfix.fabric.datagen; + +import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; +import net.fabricmc.fabric.impl.datagen.FabricDataGenHelper; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.network.chat.TextComponent; +import org.embeddedt.modernfix.ModernFix; + +import java.lang.reflect.Method; + +public class RuntimeDatagen { + private static final boolean SHOULD_RUNTIME_DATAGEN = System.getProperty("fabric-api.datagen.output-dir") != null; + + private static void runRuntimeDatagen() { + // call runInternal directly to avoid exiting immediately + try { + System.setProperty("fabric-api.datagen", "true"); + Method method = FabricDataGenHelper.class.getDeclaredMethod("runInternal"); + method.setAccessible(true); + method.invoke(null); + } catch(Throwable e) { + ModernFix.LOGGER.error("Error running datagen", e); + } finally { + System.clearProperty("fabric-api.datagen"); + } + } + + public static void init() { + if(!SHOULD_RUNTIME_DATAGEN) + return; + ScreenEvents.AFTER_INIT.register(((client, s, scaledWidth, scaledHeight) -> { + if(s instanceof TitleScreen screen) { + screen.addRenderableWidget(new Button(screen.width / 2 - 100 - 50, screen.height / 4 + 48, 50, 20, new TextComponent("DG"), (arg) -> { + runRuntimeDatagen(); + })); + } + })); + } +} From 45d308c6a47035843d165c06f21e083cfcd7ce25 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sat, 13 May 2023 09:36:34 -0400 Subject: [PATCH 2/7] Fix incorrect logic in packet leak patch Related: #97 --- .../ClientPlayNetHandlerMixin.java | 33 ------------------- .../SCustomPayloadPlayPacketMixin.java | 12 ++----- .../modernfix/duck/IClientNetHandler.java | 7 ---- 3 files changed, 3 insertions(+), 49 deletions(-) delete mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java delete mode 100644 common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java deleted file mode 100644 index 630007a8..00000000 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.embeddedt.modernfix.common.mixin.bugfix.packet_leak; - -import net.minecraft.client.multiplayer.ClientPacketListener; -import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; -import org.embeddedt.modernfix.annotation.ClientOnlyMixin; -import org.embeddedt.modernfix.duck.IClientNetHandler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ClientPacketListener.class) -@ClientOnlyMixin -public class ClientPlayNetHandlerMixin implements IClientNetHandler { - private FriendlyByteBuf savedCopy = null; - /** - * @author embeddedt - * @reason Release the packet buffer at the end. Needed in f - */ - @Redirect(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;")) - private FriendlyByteBuf saveCopyForRelease(ClientboundCustomPayloadPacket instance) { - FriendlyByteBuf copy = instance.getData(); - savedCopy = copy; - return copy; - } - - @Override - public FriendlyByteBuf getCopiedCustomBuffer() { - FriendlyByteBuf copy = savedCopy; - savedCopy = null; - return copy; - } -} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java index 083f0c0f..2862becd 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java @@ -5,7 +5,6 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; -import org.embeddedt.modernfix.duck.IClientNetHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -32,14 +31,9 @@ public class SCustomPayloadPlayPacketMixin { @Redirect(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientGamePacketListener;handleCustomPayload(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V")) private void handleAndFree(ClientGamePacketListener instance, ClientboundCustomPayloadPacket sCustomPayloadPlayPacket) { - try { - instance.handleCustomPayload(sCustomPayloadPlayPacket); - } finally { - FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer(); - if(copied != null) - copied.release(); - } + /* in 1.16, this method creates a copy inside it, but handles freeing correctly */ + instance.handleCustomPayload(sCustomPayloadPlayPacket); if(this.needsRelease) - this.data.release(); + this.data.release(); /* free our own copy of the data if needed */ } } diff --git a/common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java b/common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java deleted file mode 100644 index 71b1a0a6..00000000 --- a/common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.embeddedt.modernfix.duck; - -import net.minecraft.network.FriendlyByteBuf; - -public interface IClientNetHandler { - FriendlyByteBuf getCopiedCustomBuffer(); -} From eb925bc3bafa513897a7c39143ed98073cd6f03d Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 14 May 2023 19:23:36 -0400 Subject: [PATCH 3/7] Fix performance issue when loading large NBT maps Array map was not being changed to hash map until AFTER the insertions, which is bad --- .../org/embeddedt/modernfix/util/CanonizingStringMap.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/util/CanonizingStringMap.java b/common/src/main/java/org/embeddedt/modernfix/util/CanonizingStringMap.java index e5bb2f2d..05bd219b 100644 --- a/common/src/main/java/org/embeddedt/modernfix/util/CanonizingStringMap.java +++ b/common/src/main/java/org/embeddedt/modernfix/util/CanonizingStringMap.java @@ -77,11 +77,15 @@ public class CanonizingStringMap implements Map { public void putAll(@NotNull Map map) { if(map.size() == 0) return; + // grow early if we know there are enough non-overlapping keys + if((map.size() - backingMap.size()) > GROWTH_THRESHOLD && !(backingMap instanceof Object2ObjectOpenHashMap)) { + backingMap = new Object2ObjectOpenHashMap<>(backingMap); + } map.forEach((String key, T val) -> { key = KEY_INTERNER.intern(key); backingMap.put(key, val); }); - // if it's too big to be an array, grow it + // if it's still an array, and now too big, grow it if(backingMap.size() > GROWTH_THRESHOLD && !(backingMap instanceof Object2ObjectOpenHashMap)) { backingMap = new Object2ObjectOpenHashMap<>(backingMap); } From 0f2764b79d4d458f8af6f28d4292737db023654c Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 14 May 2023 19:48:57 -0400 Subject: [PATCH 4/7] Revert "Fix incorrect logic in packet leak patch" This reverts commit 45d308c6a47035843d165c06f21e083cfcd7ce25. --- .../ClientPlayNetHandlerMixin.java | 33 +++++++++++++++++++ .../SCustomPayloadPlayPacketMixin.java | 12 +++++-- .../modernfix/duck/IClientNetHandler.java | 7 ++++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java create mode 100644 common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java new file mode 100644 index 00000000..630007a8 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java @@ -0,0 +1,33 @@ +package org.embeddedt.modernfix.common.mixin.bugfix.packet_leak; + +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; +import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.duck.IClientNetHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +@Mixin(ClientPacketListener.class) +@ClientOnlyMixin +public class ClientPlayNetHandlerMixin implements IClientNetHandler { + private FriendlyByteBuf savedCopy = null; + /** + * @author embeddedt + * @reason Release the packet buffer at the end. Needed in f + */ + @Redirect(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;")) + private FriendlyByteBuf saveCopyForRelease(ClientboundCustomPayloadPacket instance) { + FriendlyByteBuf copy = instance.getData(); + savedCopy = copy; + return copy; + } + + @Override + public FriendlyByteBuf getCopiedCustomBuffer() { + FriendlyByteBuf copy = savedCopy; + savedCopy = null; + return copy; + } +} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java index 2862becd..083f0c0f 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java @@ -5,6 +5,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket; import net.minecraft.resources.ResourceLocation; import org.embeddedt.modernfix.annotation.ClientOnlyMixin; +import org.embeddedt.modernfix.duck.IClientNetHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -31,9 +32,14 @@ public class SCustomPayloadPlayPacketMixin { @Redirect(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientGamePacketListener;handleCustomPayload(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V")) private void handleAndFree(ClientGamePacketListener instance, ClientboundCustomPayloadPacket sCustomPayloadPlayPacket) { - /* in 1.16, this method creates a copy inside it, but handles freeing correctly */ - instance.handleCustomPayload(sCustomPayloadPlayPacket); + try { + instance.handleCustomPayload(sCustomPayloadPlayPacket); + } finally { + FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer(); + if(copied != null) + copied.release(); + } if(this.needsRelease) - this.data.release(); /* free our own copy of the data if needed */ + this.data.release(); } } diff --git a/common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java b/common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java new file mode 100644 index 00000000..71b1a0a6 --- /dev/null +++ b/common/src/main/java/org/embeddedt/modernfix/duck/IClientNetHandler.java @@ -0,0 +1,7 @@ +package org.embeddedt.modernfix.duck; + +import net.minecraft.network.FriendlyByteBuf; + +public interface IClientNetHandler { + FriendlyByteBuf getCopiedCustomBuffer(); +} From b21ee9a7e721f92aa0a8a1a44d79f871fdb1131e Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 14 May 2023 19:59:39 -0400 Subject: [PATCH 5/7] Hopefully more stable version of the original packet fix --- .../ClientPlayNetHandlerMixin.java | 16 +++---------- .../SCustomPayloadPlayPacketMixin.java | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java index 630007a8..cfc92448 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/ClientPlayNetHandlerMixin.java @@ -11,23 +11,13 @@ import org.spongepowered.asm.mixin.injection.Redirect; @Mixin(ClientPacketListener.class) @ClientOnlyMixin -public class ClientPlayNetHandlerMixin implements IClientNetHandler { - private FriendlyByteBuf savedCopy = null; +public class ClientPlayNetHandlerMixin { /** * @author embeddedt - * @reason Release the packet buffer at the end. Needed in f + * @reason allow the other function to track use of the buffer */ @Redirect(method = "handleCustomPayload", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;getData()Lnet/minecraft/network/FriendlyByteBuf;")) private FriendlyByteBuf saveCopyForRelease(ClientboundCustomPayloadPacket instance) { - FriendlyByteBuf copy = instance.getData(); - savedCopy = copy; - return copy; - } - - @Override - public FriendlyByteBuf getCopiedCustomBuffer() { - FriendlyByteBuf copy = savedCopy; - savedCopy = null; - return copy; + return ((IClientNetHandler)instance).getCopiedCustomBuffer(); } } diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java index 083f0c0f..8b0a8f37 100644 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java +++ b/common/src/main/java/org/embeddedt/modernfix/common/mixin/bugfix/packet_leak/SCustomPayloadPlayPacketMixin.java @@ -15,9 +15,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientboundCustomPayloadPacket.class) @ClientOnlyMixin -public class SCustomPayloadPlayPacketMixin { +public abstract class SCustomPayloadPlayPacketMixin implements IClientNetHandler { @Shadow private FriendlyByteBuf data; + @Shadow public abstract FriendlyByteBuf getData(); + + private FriendlyByteBuf usedByteBuf = null; + private boolean needsRelease; @Inject(method = "(Lnet/minecraft/resources/ResourceLocation;Lnet/minecraft/network/FriendlyByteBuf;)V", at = @At("RETURN")) @@ -30,16 +34,25 @@ public class SCustomPayloadPlayPacketMixin { this.needsRelease = true; } + @Override + public FriendlyByteBuf getCopiedCustomBuffer() { + FriendlyByteBuf buf = this.getData(); + usedByteBuf = buf; + return buf; + } + @Redirect(method = "handle(Lnet/minecraft/network/protocol/game/ClientGamePacketListener;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/game/ClientGamePacketListener;handleCustomPayload(Lnet/minecraft/network/protocol/game/ClientboundCustomPayloadPacket;)V")) private void handleAndFree(ClientGamePacketListener instance, ClientboundCustomPayloadPacket sCustomPayloadPlayPacket) { + usedByteBuf = null; try { instance.handleCustomPayload(sCustomPayloadPlayPacket); } finally { - FriendlyByteBuf copied = ((IClientNetHandler)instance).getCopiedCustomBuffer(); - if(copied != null) - copied.release(); + FriendlyByteBuf buf = usedByteBuf; + if(buf != null && buf.refCnt() > 0) { + buf.release(); + } } - if(this.needsRelease) + if(this.needsRelease && this.data.refCnt() > 0) this.data.release(); } } From c1c9c02ff4e20dba3e2caf191c287b4cf000d3e9 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Sun, 14 May 2023 20:25:36 -0400 Subject: [PATCH 6/7] Remove blockstate compression --- .../BlockBehaviourMixin.java | 14 --- .../BlockStateBaseMixin.java | 102 ------------------ .../main/resources/modernfix.accesswidener | 10 -- .../forge/ModernFixPlatformHooksImpl.java | 49 ++------- 4 files changed, 8 insertions(+), 167 deletions(-) delete mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockBehaviourMixin.java delete mode 100644 common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockStateBaseMixin.java diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockBehaviourMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockBehaviourMixin.java deleted file mode 100644 index 08bb7a52..00000000 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockBehaviourMixin.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.embeddedt.modernfix.common.mixin.perf.compress_blockstate; - -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; - -@Mixin(BlockBehaviour.class) -public class BlockBehaviourMixin { - @Overwrite - protected boolean isAir(BlockState state) { - return state.getBlock().properties.isAir; - } -} diff --git a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockStateBaseMixin.java b/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockStateBaseMixin.java deleted file mode 100644 index 630c0234..00000000 --- a/common/src/main/java/org/embeddedt/modernfix/common/mixin/perf/compress_blockstate/BlockStateBaseMixin.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.embeddedt.modernfix.common.mixin.perf.compress_blockstate; - -import com.google.common.collect.ImmutableMap; -import com.mojang.serialization.MapCodec; -import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.state.BlockBehaviour; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.StateHolder; -import net.minecraft.world.level.block.state.properties.Property; -import net.minecraft.world.level.material.Material; -import org.objectweb.asm.Opcodes; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(BlockBehaviour.BlockStateBase.class) -public abstract class BlockStateBaseMixin extends StateHolder { - protected BlockStateBaseMixin(Block object, ImmutableMap, Comparable> immutableMap, MapCodec mapCodec) { - super(object, immutableMap, mapCodec); - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;material:Lnet/minecraft/world/level/material/Material;" - )) - private Material getMaterial(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.material; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;destroySpeed:F" - )) - private float getDestroyTime(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.destroyTime; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;requiresCorrectToolForDrops:Z" - )) - private boolean getRequiresTool(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.requiresCorrectToolForDrops; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;canOcclude:Z" - )) - private boolean getCanOcclude(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.canOcclude; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;isRedstoneConductor:Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;" - )) - private BlockBehaviour.StatePredicate getRedstoneConductor(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.isRedstoneConductor; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;isSuffocating:Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;" - )) - private BlockBehaviour.StatePredicate getSuffocating(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.isSuffocating; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;isViewBlocking:Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;" - )) - private BlockBehaviour.StatePredicate getViewBlocking(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.isViewBlocking; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;hasPostProcess:Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;" - )) - private BlockBehaviour.StatePredicate getPostProcess(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.hasPostProcess; - } - - @Redirect(method = "*", at = @At( - value = "FIELD", - opcode = Opcodes.GETFIELD, - target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;emissiveRendering:Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;" - )) - private BlockBehaviour.StatePredicate getEmissiveRendering(BlockBehaviour.BlockStateBase base) { - return this.owner.properties.emissiveRendering; - } -} diff --git a/common/src/main/resources/modernfix.accesswidener b/common/src/main/resources/modernfix.accesswidener index 4f571127..bc312130 100644 --- a/common/src/main/resources/modernfix.accesswidener +++ b/common/src/main/resources/modernfix.accesswidener @@ -14,16 +14,6 @@ accessible field net/minecraft/client/renderer/texture/Stitcher$Holder width I accessible field net/minecraft/client/renderer/texture/Stitcher$Holder height I accessible field net/minecraft/network/syncher/EntityDataAccessor id I mutable field net/minecraft/network/syncher/EntityDataAccessor id I -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isAir Z -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties material Lnet/minecraft/world/level/material/Material; -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties destroyTime F -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties requiresCorrectToolForDrops Z -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties canOcclude Z -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isRedstoneConductor Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate; -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isSuffocating Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate; -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties isViewBlocking Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate; -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasPostProcess Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate; -accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties emissiveRendering Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate; accessible class net/minecraft/client/resources/model/ModelBakery$BlockStateDefinitionException accessible field net/minecraft/network/syncher/SynchedEntityData itemsById Ljava/util/Map; accessible field net/minecraft/network/syncher/SynchedEntityData ENTITY_ID_POOL Ljava/util/Map; diff --git a/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java b/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java index f8eb19e6..4cc7fac1 100644 --- a/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java +++ b/forge/src/main/java/org/embeddedt/modernfix/platform/forge/ModernFixPlatformHooksImpl.java @@ -4,7 +4,6 @@ import com.google.common.io.Resources; import com.mojang.blaze3d.platform.NativeImage; import com.mojang.brigadier.CommandDispatcher; import cpw.mods.modlauncher.*; -import cpw.mods.modlauncher.api.INameMappingService; import cpw.mods.modlauncher.api.LamdbaExceptionUtils; import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -18,20 +17,21 @@ import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.fml.ModLoader; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; import net.minecraftforge.fml.loading.FMLLoader; import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.loading.LoadingModList; import net.minecraftforge.fml.loading.moddiscovery.ExplodedDirectoryLocator; import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.server.ServerLifecycleHooks; +import org.embeddedt.modernfix.core.ModernFixMixinPlugin; import org.embeddedt.modernfix.forge.classloading.FastAccessTransformerList; import org.embeddedt.modernfix.forge.classloading.ModernFixResourceFinder; -import org.embeddedt.modernfix.core.ModernFixMixinPlugin; import org.embeddedt.modernfix.forge.packet.PacketHandler; import org.embeddedt.modernfix.util.DummyList; import org.objectweb.asm.Opcodes; -import org.objectweb.asm.tree.*; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.MethodNode; import org.spongepowered.asm.mixin.injection.struct.InjectorGroupInfo; import java.io.IOException; @@ -43,11 +43,11 @@ import java.lang.reflect.Method; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; -import java.util.*; +import java.util.Enumeration; +import java.util.Map; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; public class ModernFixPlatformHooksImpl { public static boolean isClient() { @@ -206,40 +206,7 @@ public class ModernFixPlatformHooksImpl { } public static void applyASMTransformers(String mixinClassName, ClassNode targetClass) { - if(mixinClassName.equals("org.embeddedt.modernfix.common.compress_blockstate.perf.mixin.BlockStateBaseMixin")) { - // Delete unused fields off BlockStateBase - Set fieldsToDelete = Stream.of( - "field_235702_f_", // isAir - "field_235703_g_", // material - "field_235705_i_", // destroySpeed - "field_235706_j_", // requiresCorrectToolForDrops - "field_235707_k_", // canOcclude - "field_235708_l_", // isRedstoneConductor - "field_235709_m_", // isSuffocating - "field_235710_n_", // isViewBlocking - "field_235711_o_", // hasPostProcess - "field_235712_p_" // emissiveRendering - ).map(name -> ObfuscationReflectionHelper.remapName(INameMappingService.Domain.FIELD, name)).collect(Collectors.toSet()); - targetClass.fields.removeIf(field -> { - if(fieldsToDelete.contains(field.name)) { - return true; - } - return false; - }); - for(MethodNode m : targetClass.methods) { - if(m.name.equals("")) { - ListIterator iter = m.instructions.iterator(); - while(iter.hasNext()) { - AbstractInsnNode node = iter.next(); - if(node.getOpcode() == Opcodes.PUTFIELD) { - if(fieldsToDelete.contains(((FieldInsnNode)node).name)) { - iter.remove(); - } - } - } - } - } - } else if(mixinClassName.equals("org.embeddedt.modernfix.forge.valhesia.chunk_deadlock.bugfix.mixin.BlockStateBaseMixin")) { + if(mixinClassName.equals("org.embeddedt.modernfix.forge.valhesia.chunk_deadlock.bugfix.mixin.BlockStateBaseMixin")) { // We need to destroy Valhelsia's callback so it can never run getBlockState for(MethodNode m : targetClass.methods) { if(m.name.contains("valhelsia_placeDousedTorch")) { From fc69d55314f41d62fa351aa7108132d21dd53ca3 Mon Sep 17 00:00:00 2001 From: embeddedt <42941056+embeddedt@users.noreply.github.com> Date: Mon, 15 May 2023 11:11:09 -0400 Subject: [PATCH 7/7] Fix compile error --- .../embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java b/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java index 91e13676..6dfa4959 100644 --- a/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java +++ b/fabric/src/main/java/org/embeddedt/modernfix/fabric/datagen/RuntimeDatagen.java @@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; import net.fabricmc.fabric.impl.datagen.FabricDataGenHelper; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.TitleScreen; -import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.Component; import org.embeddedt.modernfix.ModernFix; import java.lang.reflect.Method; @@ -31,7 +31,7 @@ public class RuntimeDatagen { return; ScreenEvents.AFTER_INIT.register(((client, s, scaledWidth, scaledHeight) -> { if(s instanceof TitleScreen screen) { - screen.addRenderableWidget(new Button(screen.width / 2 - 100 - 50, screen.height / 4 + 48, 50, 20, new TextComponent("DG"), (arg) -> { + screen.addRenderableWidget(new Button(screen.width / 2 - 100 - 50, screen.height / 4 + 48, 50, 20, Component.literal("DG"), (arg) -> { runRuntimeDatagen(); })); }