diff --git a/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java b/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java index 68b5c5d78..8d69f2d17 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/network/ClientRecipeManagerSyncPack.java @@ -8,7 +8,10 @@ import dev.dubhe.anvilcraft.data.recipe.anvil.RecipeOutcome; import dev.dubhe.anvilcraft.data.recipe.anvil.RecipePredicate; import dev.dubhe.anvilcraft.init.ModNetworks; +import dev.emi.emi.runtime.EmiReloadManager; import lombok.Getter; +import me.shedaniel.rei.api.client.REIRuntime; +import me.shedaniel.rei.api.common.registry.ReloadStage; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -23,6 +26,10 @@ public class ClientRecipeManagerSyncPack implements Packet { private final List anvilRecipes; + private boolean isLoaded(String clazz) { + return ClientRecipeManagerSyncPack.class.getClassLoader().getResource(clazz) != null; + } + /** * 电网同步 */ @@ -80,5 +87,11 @@ public void encode(@NotNull FriendlyByteBuf buf) { @Environment(EnvType.CLIENT) public void handler() { Minecraft.getInstance().execute(() -> AnvilRecipeManager.setAnvilRecipeList(this.anvilRecipes)); + if (this.isLoaded("me/shedaniel/rei/impl/client/gui/screen/DefaultDisplayViewingScreen.class")) { + REIRuntime.getInstance().startReload(ReloadStage.START); + } + if (this.isLoaded("dev/emi/emi/api/EmiPlugin.class")) { + EmiReloadManager.reload(); + } } } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java index 0e987fec8..7e002c62f 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/PlayerEventListener.java @@ -5,12 +5,12 @@ import dev.dubhe.anvilcraft.api.recipe.AnvilRecipeManager; import dev.dubhe.anvilcraft.event.TooltipEventListener; import dev.dubhe.anvilcraft.network.ClientRecipeManagerSyncPack; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionResult; import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.PlayerInteractEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.network.NetworkEvent; import org.jetbrains.annotations.NotNull; @@ -37,11 +37,15 @@ public static void itemTooltip(@NotNull ItemTooltipEvent event) { TooltipEventListener.addTooltip(event.getItemStack(), event.getToolTip()); } + /** + * 服务器玩家登陆事件 + */ @SubscribeEvent - public static void serverCustomPayloadEvent( - @NotNull NetworkEvent.LoginPayloadEvent event + public static void layerLoggedInEvent( + @NotNull net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent event ) { - new ClientRecipeManagerSyncPack(AnvilRecipeManager.getAnvilRecipeList()) - .send(event.getSource().get().getSender()); + if (event.getEntity() instanceof ServerPlayer serverPlayer) + new ClientRecipeManagerSyncPack(AnvilRecipeManager.getAnvilRecipeList()) + .send(serverPlayer); } }