diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-08-27 22:36:16 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-08-28 17:45:56 +0800 |
| commit | 956b2efe975f20d0fd68270d9855bf8d2bc47865 (patch) | |
| tree | fda62e7cb5b7c882459da341bb0e62f08cbca489 /fabric/src/main/java/me/shedaniel | |
| parent | 50bab68a198f47090655288dcbd586958c6b59b9 (diff) | |
| download | RoughlyEnoughItems-956b2efe975f20d0fd68270d9855bf8d2bc47865.tar.gz RoughlyEnoughItems-956b2efe975f20d0fd68270d9855bf8d2bc47865.tar.bz2 RoughlyEnoughItems-956b2efe975f20d0fd68270d9855bf8d2bc47865.zip | |
Add hints for if REI does not initialize properly
Diffstat (limited to 'fabric/src/main/java/me/shedaniel')
3 files changed, 104 insertions, 1 deletions
diff --git a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java index e44cf3d09..fe507da01 100644 --- a/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java +++ b/fabric/src/main/java/me/shedaniel/rei/fabric/PluginDetectorImpl.java @@ -70,7 +70,7 @@ public class PluginDetectorImpl { } catch (Throwable t) { Throwable throwable = t; while (throwable != null) { - if (throwable.getMessage().contains("environment type SERVER") && !RoughlyEnoughItemsInitializer.isClient()) continue out; + if (throwable.getMessage() != null && throwable.getMessage().contains("environment type SERVER") && !RoughlyEnoughItemsInitializer.isClient()) continue out; throwable = throwable.getCause(); } String error = "Could not create REI Plugin [" + getSimpleName(pluginClass) + "] due to errors, provided by '" + container.getProvider().getMetadata().getId() + "'!"; 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..d6c9b70f9 --- /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 io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import me.shedaniel.architectury.utils.GameInstance; +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); + } + } +} |
