From 9c9ef59285d97aa34834d218e518b856b997ede1 Mon Sep 17 00:00:00 2001 From: Cat Core Date: Tue, 3 Sep 2024 22:38:12 +0200 Subject: [PATCH] Fix crash on server --- .../mixin/forgefml/block/BlockMixin.java | 3 + .../mixin/forgefml/item/ItemMixin.java | 4 ++ .../item/itemgroup/ItemGroupMixin.java | 1 + ...NbtIoMixin.java => Client_NbtIoMixin.java} | 5 +- .../mixin/forgefml/nbt/Server_NbtIoMixin.java | 64 +++++++++++++++++ .../forgefml/util/Server_LanguageMixin.java | 18 +++++ .../forgefml/world/Client_WorldMixin.java | 71 +++++++++++++++++++ .../forgefml/world/Server_WorldMixin.java | 57 +++++++++++++++ .../mixin/forgefml/world/WorldMixin.java | 47 ------------ .../fabricated-forge.forge.mixins.json | 10 ++- 10 files changed, 229 insertions(+), 51 deletions(-) rename src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/{NbtIoMixin.java => Client_NbtIoMixin.java} (90%) create mode 100644 src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Server_NbtIoMixin.java create mode 100644 src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/util/Server_LanguageMixin.java create mode 100644 src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Client_WorldMixin.java create mode 100644 src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Server_WorldMixin.java diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/block/BlockMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/block/BlockMixin.java index b88323c0..60ab1172 100644 --- a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/block/BlockMixin.java +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/block/BlockMixin.java @@ -86,10 +86,13 @@ public static boolean isSolid(int id) { @Shadow @Final public static Block NETHER_BRICK_FENCE; @Shadow @Final public static Block GLASS_BLOCK; + @Environment(EnvType.CLIENT) @Shadow public abstract int method_479(); + @Environment(EnvType.CLIENT) @Shadow public abstract int method_407(World world, int i, int j, int k); + @Environment(EnvType.CLIENT) @Shadow public abstract int method_463(World world, int i, int j, int k); @Shadow @Final public static Block CACTUS; diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/ItemMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/ItemMixin.java index 62eaf36d..970f7f11 100644 --- a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/ItemMixin.java +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/ItemMixin.java @@ -4,6 +4,8 @@ import fr.catcore.fabricatedforge.mixininterface.IBlock; import fr.catcore.fabricatedforge.mixininterface.IItem; import fr.catcore.fabricatedforge.mixininterface.IServerPlayerInteractionManager; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; @@ -32,8 +34,10 @@ public abstract class ItemMixin implements ItemProxy, IItem { @Shadow public abstract boolean isDamageable(); + @Environment(EnvType.CLIENT) @Shadow public abstract int method_3378(ItemStack itemStack); + @Environment(EnvType.CLIENT) @Shadow public abstract boolean method_3397(); @Shadow public abstract boolean isFood(); diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/itemgroup/ItemGroupMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/itemgroup/ItemGroupMixin.java index b587d49a..22ac3624 100644 --- a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/itemgroup/ItemGroupMixin.java +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/item/itemgroup/ItemGroupMixin.java @@ -23,6 +23,7 @@ public abstract class ItemGroupMixin implements IItemGroup { @Shadow @Final private int index; + @Environment(EnvType.CLIENT) @Shadow public abstract Item method_3320(); @Inject(method = "", at = @At(value = "FIELD", opcode = Opcodes.PUTFIELD, target = "Lnet/minecraft/item/itemgroup/ItemGroup;id:Ljava/lang/String;")) diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/NbtIoMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Client_NbtIoMixin.java similarity index 90% rename from src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/NbtIoMixin.java rename to src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Client_NbtIoMixin.java index 59051c88..3ae6cb19 100644 --- a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/NbtIoMixin.java +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Client_NbtIoMixin.java @@ -1,5 +1,7 @@ package fr.catcore.fabricatedforge.mixin.forgefml.nbt; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtIo; import org.spongepowered.asm.mixin.Mixin; @@ -8,8 +10,9 @@ import java.io.*; +@Environment(EnvType.CLIENT) @Mixin(NbtIo.class) -public abstract class NbtIoMixin { +public abstract class Client_NbtIoMixin { @Shadow public static void method_1345(NbtCompound nbtCompound, DataOutput dataOutput) { diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Server_NbtIoMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Server_NbtIoMixin.java new file mode 100644 index 00000000..4b0c2aae --- /dev/null +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/nbt/Server_NbtIoMixin.java @@ -0,0 +1,64 @@ +package fr.catcore.fabricatedforge.mixin.forgefml.nbt; + +import fr.catcore.cursedmixinextensions.annotations.Public; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtIo; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.io.*; + +@Environment(EnvType.SERVER) +@Mixin(NbtIo.class) +public abstract class Server_NbtIoMixin { + + @Shadow + public static void method_1345(NbtCompound nbtCompound, DataOutput dataOutput) { + } + + @Shadow + public static NbtCompound read(DataInput input) { + return null; + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Public + private static void method_1352(NbtCompound par0NBTTagCompound, File par1File) throws IOException { + DataOutputStream var2 = new DataOutputStream(new FileOutputStream(par1File)); + + try { + method_1345(par0NBTTagCompound, var2); + } finally { + var2.close(); + } + + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Public + private static NbtCompound method_1349(File par0File) throws IOException { + if (!par0File.exists()) { + return null; + } else { + DataInputStream var1 = new DataInputStream(new FileInputStream(par0File)); + + NbtCompound var2; + try { + var2 = read(var1); + } finally { + var1.close(); + } + + return var2; + } + } +} diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/util/Server_LanguageMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/util/Server_LanguageMixin.java new file mode 100644 index 00000000..7cbc3727 --- /dev/null +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/util/Server_LanguageMixin.java @@ -0,0 +1,18 @@ +package fr.catcore.fabricatedforge.mixin.forgefml.util; + +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.util.Language; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Environment(EnvType.SERVER) +@Mixin(Language.class) +public class Server_LanguageMixin { + @Shadow + public String code; + + public String method_636() { + return this.code; + } +} diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Client_WorldMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Client_WorldMixin.java new file mode 100644 index 00000000..cbaaf8c7 --- /dev/null +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Client_WorldMixin.java @@ -0,0 +1,71 @@ +package fr.catcore.fabricatedforge.mixin.forgefml.world; + +import fr.catcore.fabricatedforge.mixininterface.IBlock; +import fr.catcore.fabricatedforge.mixininterface.IWorld; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.Block; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.dimension.Dimension; +import net.minecraftforge.common.ForgeDirection; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Environment(EnvType.CLIENT) +@Mixin(World.class) +public abstract class Client_WorldMixin implements IWorld { + + @Shadow @Final public Dimension dimension; + + @Shadow public abstract int getBlock(int x, int y, int z); + + /** + * @author Minecraft Forge + * @reason none + */ + @Overwrite + public Biome getBiome(int par1, int par2) { + return this.dimension.getBiomeGenForCoords(par1, par2); + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Overwrite + public boolean isAir(int par1, int par2, int par3) { + int id = this.getBlock(par1, par2, par3); + return id == 0 || Block.BLOCKS[id] == null || ((IBlock)Block.BLOCKS[id]).isAirBlock((World)(Object) this, par1, par2, par3); + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Overwrite + public boolean isBlockSolid(int par1, int par2, int par3) { + Block block = Block.BLOCKS[this.getBlock(par1, par2, par3)]; + return block != null && ((IBlock)block).isBlockNormalCube((World)(Object) this, par1, par2, par3); + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Overwrite + public boolean isTopSolid(int par1, int par2, int par3) { + return this.isBlockSolidOnSide(par1, par2, par3, ForgeDirection.UP); + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Overwrite + public int getMaxBuildHeight() { + return this.dimension.getHeight(); + } +} diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Server_WorldMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Server_WorldMixin.java new file mode 100644 index 00000000..9b2fc22a --- /dev/null +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/Server_WorldMixin.java @@ -0,0 +1,57 @@ +package fr.catcore.fabricatedforge.mixin.forgefml.world; + +import fr.catcore.fabricatedforge.mixininterface.IBlock; +import fr.catcore.fabricatedforge.mixininterface.IWorld; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.block.Block; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.dimension.Dimension; +import net.minecraftforge.common.ForgeDirection; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +@Environment(EnvType.SERVER) +@Mixin(World.class) +public abstract class Server_WorldMixin implements BlockView, IWorld { + @Shadow @Final public Dimension dimension; + + @Override + public Biome getBiome(int par1, int par2) { + return this.dimension.getBiomeGenForCoords(par1, par2); + } + + @Override + public boolean isAir(int par1, int par2, int par3) { + int id = this.getBlock(par1, par2, par3); + return id == 0 || Block.BLOCKS[id] == null || ((IBlock)Block.BLOCKS[id]).isAirBlock((World)(Object) this, par1, par2, par3); + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Override + public boolean isBlockSolid(int par1, int par2, int par3) { + Block block = Block.BLOCKS[this.getBlock(par1, par2, par3)]; + return block != null && ((IBlock)block).isBlockNormalCube((World)(Object) this, par1, par2, par3); + } + + /** + * @author Minecraft Forge + * @reason none + */ + @Override + public boolean isTopSolid(int par1, int par2, int par3) { + return this.isBlockSolidOnSide(par1, par2, par3, ForgeDirection.UP); + } + + @Override + public int getMaxBuildHeight() { + return this.dimension.getHeight(); + } +} diff --git a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/WorldMixin.java b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/WorldMixin.java index 8a173a94..ac629bd3 100644 --- a/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/WorldMixin.java +++ b/src/main/java/fr/catcore/fabricatedforge/mixin/forgefml/world/WorldMixin.java @@ -143,15 +143,6 @@ public abstract class WorldMixin implements BlockView, IWorld { @Unique private static SaveHandler s_savehandler; - /** - * @author Minecraft Forge - * @reason none - */ - @Overwrite - public Biome getBiome(int par1, int par2) { - return this.dimension.getBiomeGenForCoords(par1, par2); - } - @Override public Biome getBiomeGenForCoordsBody(int par1, int par2) { if (this.isPosLoaded(par1, 0, par2)) { @@ -257,16 +248,6 @@ private PersistentStateManager getMapStorage(SaveHandler savehandler) { // ci.cancel(); // } - /** - * @author Minecraft Forge - * @reason none - */ - @Overwrite - public boolean isAir(int par1, int par2, int par3) { - int id = this.getBlock(par1, par2, par3); - return id == 0 || Block.BLOCKS[id] == null || ((IBlock)Block.BLOCKS[id]).isAirBlock((World)(Object) this, par1, par2, par3); - } - /** * @author Minecraft Forge * @reason none @@ -957,25 +938,6 @@ public void method_3725(int par1, int par2, int par3) { } - /** - * @author Minecraft Forge - * @reason none - */ - @Overwrite - public boolean isBlockSolid(int par1, int par2, int par3) { - Block block = Block.BLOCKS[this.getBlock(par1, par2, par3)]; - return block != null && ((IBlock)block).isBlockNormalCube((World)(Object) this, par1, par2, par3); - } - - /** - * @author Minecraft Forge - * @reason none - */ - @Overwrite - public boolean isTopSolid(int par1, int par2, int par3) { - return this.isBlockSolidOnSide(par1, par2, par3, ForgeDirection.UP); - } - /** * @author Minecraft Forge * @reason none @@ -1622,15 +1584,6 @@ public boolean isHighHumidity(int par1, int par2, int par3) { return this.dimension.isBlockHighHumidity(par1, par2, par3); } - /** - * @author Minecraft Forge - * @reason none - */ - @Overwrite - public int getMaxBuildHeight() { - return this.dimension.getHeight(); - } - /** * @author Minecraft Forge * @reason none diff --git a/src/main/resources/fabricated-forge.forge.mixins.json b/src/main/resources/fabricated-forge.forge.mixins.json index 9ac2db5c..84a6221d 100644 --- a/src/main/resources/fabricated-forge.forge.mixins.json +++ b/src/main/resources/fabricated-forge.forge.mixins.json @@ -5,7 +5,10 @@ "compatibilityLevel": "JAVA_8", "plugin": "fr.catcore.fabricatedforge.mixin.FabricatedForgeMixinPlugin", "server": [ - "server.dedicated.gui.PlayerStatsGuiMixin" + "nbt.Server_NbtIoMixin", + "server.dedicated.gui.PlayerStatsGuiMixin", + "util.Server_LanguageMixin", + "world.Server_WorldMixin" ], "mixins": [ "block.AbstractButtonBlockMixin", @@ -79,7 +82,6 @@ "item.ToolItemMixin", "item.itemgroup.ItemGroupMixin", "item.map.MapStateMixin", - "nbt.NbtIoMixin", "network.class_690Mixin", "network.IntegratedConnectionMixin", "network.OutboundConnectionMixin", @@ -189,7 +191,9 @@ "client.sound.SoundSystemMixin", "client.texture.ClockSpriteMixin", "client.texture.CompassSpriteMixin", - "client.world.ClientWorldMixin" + "client.world.ClientWorldMixin", + "nbt.Client_NbtIoMixin", + "world.Client_WorldMixin" ], "injectors": { "defaultRequire": 1