diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-08-27 05:26:06 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-08-27 05:26:31 +0800 |
| commit | 113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8 (patch) | |
| tree | da371c2c28ec95167aea4ebc91a6ff4a9f5f59b3 /fabric/src/main/java/me | |
| parent | a4776b33fd86731249cf9b02c2ea6fff1bce9350 (diff) | |
| download | RoughlyEnoughItems-113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8.tar.gz RoughlyEnoughItems-113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8.tar.bz2 RoughlyEnoughItems-113fe8f692f4f9bb113d28f6a1b3375bd8f0eec8.zip | |
Add hints for if REI does not initialize properly
Diffstat (limited to 'fabric/src/main/java/me')
| -rw-r--r-- | fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java | 45 | ||||
| -rw-r--r-- | fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinPacketEncoder.java | 58 |
2 files changed, 103 insertions, 0 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java new file mode 100644 index 000000000..d23118c3a --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java @@ -0,0 +1,45 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.mixin.fabric; + +import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; +import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket; +import net.minecraft.world.item.crafting.RecipeManager; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ClientPacketListener.class) +public class MixinClientPacketListener { + @Shadow @Final private RecipeManager recipeManager; + + @Inject(method = "handleUpdateRecipes", at = @At("HEAD")) + private void handleUpdateRecipes(ClientboundUpdateRecipesPacket clientboundUpdateRecipesPacket, CallbackInfo ci) { + RoughlyEnoughItemsCoreClient.PRE_UPDATE_RECIPES.invoker().update(recipeManager); + } +}
\ No newline at end of file diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinPacketEncoder.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinPacketEncoder.java new file mode 100644 index 000000000..30e2f1a6d --- /dev/null +++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinPacketEncoder.java @@ -0,0 +1,58 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.mixin.fabric; + +import dev.architectury.utils.GameInstance; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.network.PacketEncoder; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.level.ServerPlayer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(PacketEncoder.class) +public class MixinPacketEncoder { + @Inject(method = "encode", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/protocol/Packet;isSkippable()Z")) + private void failedToEncode(ChannelHandlerContext channelHandlerContext, Packet<?> packet, ByteBuf byteBuf, CallbackInfo ci) { + if (packet instanceof ClientboundUpdateRecipesPacket) { + MinecraftServer server = GameInstance.getServer(); + String issue = "REI: Server failed to synchronize recipe data with the client! " + + "Please check the server console log for errors, this breaks REI and vanilla recipe books!"; + server.execute(() -> { + for (ServerPlayer player : server.getPlayerList().getPlayers()) { + player.sendMessage(new TextComponent(issue).withStyle(ChatFormatting.RED), Util.NIL_UUID); + } + }); + System.out.println(issue); + } + } +} |
