Skip to content

Commit

Permalink
修正**i的同步时的reload
Browse files Browse the repository at this point in the history
  • Loading branch information
dmzz-yyhyy committed Jun 29, 2024
1 parent a48db13 commit 023c71b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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;
Expand All @@ -22,6 +25,10 @@
public class ClientRecipeManagerSyncPack implements Packet {
private final List<AnvilRecipe> anvilRecipes;

private boolean isLoaded(String clazz) {
return ClientRecipeManagerSyncPack.class.getClassLoader().getResource(clazz) != null;
}

/**
* 电网同步
*/
Expand Down Expand Up @@ -79,5 +86,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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -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);
}
}

0 comments on commit 023c71b

Please sign in to comment.