From 95e363563a6377cf773ba27a2b16fade6ded22f2 Mon Sep 17 00:00:00 2001 From: Patbox <39821509+Patbox@users.noreply.github.com> Date: Mon, 16 Jan 2023 22:54:21 +0100 Subject: [PATCH] Fix mods triggering resource reload too early, add check for path, fix rei compat --- gradle.properties | 4 ++-- .../common/impl/client/ClientUtils.java | 3 ++- polymer-core/build.gradle | 4 ++-- .../core/api/item/PolymerItemGroupUtils.java | 7 +++++- .../core/impl/client/compat/CompatUtils.java | 13 +++++------ .../impl/client/compat/ReiCompatibility.java | 21 +++++++++++++----- .../ReloadableResourceManagerImplMixin.java | 6 ++--- .../item/ServerPlayNetworkHandlerMixin.java | 7 +++--- .../networking/mixin/PlayerManagerMixin.java | 21 ++++++++++++++++++ .../impl/generation/DefaultRPBuilder.java | 22 ++++++++++--------- 10 files changed, 72 insertions(+), 36 deletions(-) diff --git a/gradle.properties b/gradle.properties index dcdff872..5ebd5dfd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,11 +8,11 @@ yarn_mappings=1.19.3+build.1 loader_version=0.14.12 #Fabric api -fabric_version=0.68.1+1.19.3 +fabric_version=0.72.0+1.19.3 maven_group = eu.pb4 -mod_version = 0.3.6 +mod_version = 0.3.7 minecraft_version_supported = ">=1.19.3-beta.3" diff --git a/polymer-common/src/main/java/eu/pb4/polymer/common/impl/client/ClientUtils.java b/polymer-common/src/main/java/eu/pb4/polymer/common/impl/client/ClientUtils.java index 444cac6a..e87c5bee 100644 --- a/polymer-common/src/main/java/eu/pb4/polymer/common/impl/client/ClientUtils.java +++ b/polymer-common/src/main/java/eu/pb4/polymer/common/impl/client/ClientUtils.java @@ -10,6 +10,7 @@ @Environment(EnvType.CLIENT) public class ClientUtils { public static final String PACK_ID = "$polymer-resources"; + public static volatile ServerPlayerEntity backupPlayer; public static boolean isResourcePackLoaded() { return MinecraftClient.getInstance().getResourcePackManager().getEnabledNames().contains(PACK_ID); @@ -22,7 +23,7 @@ public static boolean isSingleplayer() { public static ServerPlayerEntity getPlayer() { return MinecraftClient.getInstance().getServer() != null && MinecraftClient.getInstance().player != null ? MinecraftClient.getInstance().getServer().getPlayerManager().getPlayer(MinecraftClient.getInstance().player.getUuid()) - : null; + : backupPlayer; } public static boolean isClientThread() { diff --git a/polymer-core/build.gradle b/polymer-core/build.gradle index d91310ba..b137b973 100644 --- a/polymer-core/build.gradle +++ b/polymer-core/build.gradle @@ -54,8 +54,8 @@ dependencies { modCompileOnly "mcp.mobius.waila:wthit:fabric-5.1.3" //modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:9.1.530" - modCompileOnly "me.shedaniel:RoughlyEnoughItems-fabric:9.1.565" - modCompileOnly modLocalRuntime("dev.emi:emi:0.5.3+1.19.3") + modCompileOnly "me.shedaniel:RoughlyEnoughItems-fabric:10.0.581" + modCompileOnly /*modLocalRuntime*/("dev.emi:emi:0.5.3+1.19.3") //modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-common:11.0.0.206") //modCompileOnlyApi modLocalRuntime("mezz.jei:jei-1.19-fabric:11.0.0.206") diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemGroupUtils.java b/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemGroupUtils.java index 5a6695ff..c9673113 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemGroupUtils.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/api/item/PolymerItemGroupUtils.java @@ -8,6 +8,7 @@ import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroups; import net.minecraft.item.ItemStack; +import net.minecraft.resource.featuretoggle.FeatureSet; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; import org.jetbrains.annotations.Nullable; @@ -30,7 +31,11 @@ private PolymerItemGroupUtils() {} public static final SimpleEvent LIST_EVENT = new SimpleEvent<>(); public static Contents getContentsFor(ServerPlayerEntity player, ItemGroup group) { - return ((ItemGroupExtra) group).polymer$getContentsWith(player.world.getEnabledFeatures(), CommonImplUtils.permissionCheck(player, "op_items", 2)); + return getContentsFor(group, player.world.getEnabledFeatures(), CommonImplUtils.permissionCheck(player, "op_items", 2)); + } + + public static Contents getContentsFor(ItemGroup group, FeatureSet featureSet, boolean operator) { + return ((ItemGroupExtra) group).polymer$getContentsWith(featureSet, operator); } /** diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java index 09e6cdf3..9c43ffc5 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/CompatUtils.java @@ -15,21 +15,18 @@ @ApiStatus.Internal public class CompatUtils { public static void iterateItems(Consumer consumer) { + var stacks = ItemStackSet.create(); + for (var group : ItemGroups.getGroups()) { if (group.getType() != ItemGroup.Type.CATEGORY) { continue; } - - var stacks = ItemStackSet.create(); - stacks.addAll(((ClientItemGroupExtension) group).polymer$getStacksGroup()); stacks.addAll(((ClientItemGroupExtension) group).polymer$getStacksSearch()); + } - if (stacks != null) { - for (var stack : stacks) { - consumer.accept(stack); - } - } + for (var stack : stacks) { + consumer.accept(stack); } } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java index 2bd3f2c2..fc5c98ab 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/impl/client/compat/ReiCompatibility.java @@ -3,12 +3,17 @@ import eu.pb4.polymer.core.api.item.PolymerItemUtils; import eu.pb4.polymer.core.impl.PolymerImpl; import eu.pb4.polymer.core.impl.PolymerImplUtils; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; +import me.shedaniel.rei.api.client.REIRuntime; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.entry.comparison.EntryComparator; import me.shedaniel.rei.api.common.entry.comparison.ItemComparatorRegistry; import me.shedaniel.rei.api.common.entry.type.VanillaEntryTypes; +import me.shedaniel.rei.impl.client.REIRuntimeImpl; +import me.shedaniel.rei.impl.init.RoughlyEnoughItemsInitializer; import net.minecraft.item.ItemStack; import java.util.function.Predicate; @@ -26,10 +31,6 @@ public class ReiCompatibility implements REIClientPlugin { return 0; }; - static { - CompatUtils.registerReload(() -> update(EntryRegistry.getInstance())); - } - private static void update(EntryRegistry registry) { try { registry.removeEntryIf(SHOULD_REMOVE); @@ -40,7 +41,17 @@ private static void update(EntryRegistry registry) { } } - public static void registerEvents() {} + public static void registerEvents() { + CompatUtils.registerReload(() -> { + try { + RoughlyEnoughItemsCoreClient.reloadPlugins(null, null); + }catch (Throwable e) { + e.printStackTrace(); + } + + //update(EntryRegistry.getInstance()); + }); + } @Override public void registerItemComparators(ItemComparatorRegistry registry) { diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/ReloadableResourceManagerImplMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/ReloadableResourceManagerImplMixin.java index 82d82f82..b60349cf 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/ReloadableResourceManagerImplMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/client/ReloadableResourceManagerImplMixin.java @@ -23,9 +23,9 @@ public class ReloadableResourceManagerImplMixin { @Inject(method = "reload", at = @At("RETURN")) private void polymer$onReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture initialStage, List packs, CallbackInfoReturnable cir) { - var server = MinecraftClient.getInstance().getServer(); - if (server != null) { - server.execute(() -> PolymerUtils.reloadWorld(ClientUtils.getPlayer())); + var player = ClientUtils.getPlayer(); + if (player != null) { + player.server.execute(() -> PolymerUtils.reloadWorld(player)); } } } diff --git a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java index 1faf9dc5..1a5ee73c 100644 --- a/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java +++ b/polymer-core/src/main/java/eu/pb4/polymer/core/mixin/item/ServerPlayNetworkHandlerMixin.java @@ -72,8 +72,7 @@ public abstract class ServerPlayNetworkHandlerMixin { @Inject(method = "onPlayerInteractBlock", at = @At("TAIL")) - private void polymer_updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) { - + private void polymer$updateMoreBlocks(PlayerInteractBlockC2SPacket packet, CallbackInfo ci) { if (PolymerImpl.RESEND_BLOCKS_AROUND_CLICK) { var base = packet.getBlockHitResult().getBlockPos(); for (Direction direction : Direction.values()) { @@ -90,14 +89,14 @@ private void polymer_updateMoreBlocks(PlayerInteractBlockC2SPacket packet, Callb } } - var stack = this.player.getStackInHand(packet.getHand()); + /*var stack = this.player.getStackInHand(packet.getHand()); if (stack.getItem() instanceof PolymerItem virtualItem) { var data = PolymerItemUtils.getItemSafely(virtualItem, stack, this.player); if (data.item() instanceof BlockItem || data.item() instanceof BucketItem) { this.onPlayerInteractItem(new PlayerInteractItemC2SPacket(packet.getHand(), 0)); } - } + }*/ } @Inject(method = "onClickSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;updateLastActionTime()V", shift = At.Shift.AFTER)) diff --git a/polymer-networking/src/main/java/eu/pb4/polymer/networking/mixin/PlayerManagerMixin.java b/polymer-networking/src/main/java/eu/pb4/polymer/networking/mixin/PlayerManagerMixin.java index 90910ade..2ae62d12 100644 --- a/polymer-networking/src/main/java/eu/pb4/polymer/networking/mixin/PlayerManagerMixin.java +++ b/polymer-networking/src/main/java/eu/pb4/polymer/networking/mixin/PlayerManagerMixin.java @@ -1,7 +1,11 @@ package eu.pb4.polymer.networking.mixin; +import eu.pb4.polymer.common.impl.client.ClientUtils; import eu.pb4.polymer.networking.api.PolymerServerNetworking; import eu.pb4.polymer.networking.impl.TempPlayerLoginAttachments; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; import net.minecraft.network.ClientConnection; import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket; import net.minecraft.server.PlayerManager; @@ -21,6 +25,7 @@ public class PlayerManagerMixin { if (handshake != null) { handshake.apply(player.networkHandler); + PolymerServerNetworking.AFTER_HANDSHAKE_APPLY.invoke(x -> x.accept(player.networkHandler, handshake)); } @@ -41,4 +46,20 @@ public class PlayerManagerMixin { connection.send(new PlayerRespawnS2CPacket(world.getDimensionKey(), world.getRegistryKey(), BiomeAccess.hashSeed(((ServerWorld) world).getSeed()),player.interactionManager.getGameMode(), player.interactionManager.getPreviousGameMode(), world.isDebugWorld(), ((ServerWorld) world).isFlat(), (byte) 0xFF, player.getLastDeathPos())); } } + + @Environment(EnvType.CLIENT) + @Inject(method = "onPlayerConnect", at = @At("HEAD")) + private void polymerNet$storePlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { + if (player.server.isHost(player.getGameProfile())) { + ClientUtils.backupPlayer = player; + } + } + + @Environment(EnvType.CLIENT) + @Inject(method = "onPlayerConnect", at = @At("TAIL")) + private void polymerNet$removePlayer(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci) { + if (player.server.isHost(player.getGameProfile())) { + ClientUtils.backupPlayer = null; + } + } } diff --git a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java index f4f72792..95478562 100644 --- a/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java +++ b/polymer-resource-pack/src/main/java/eu/pb4/polymer/resourcepack/impl/generation/DefaultRPBuilder.java @@ -148,17 +148,19 @@ public boolean copyAssets(String modId) { try { for (var rootPaths : container.getRootPaths()) { Path assets = rootPaths.resolve("assets"); - Files.walk(assets).forEach((file) -> { - var relative = assets.relativize(file); - var path = relative.toString().replace("\\", "/"); - if (Files.isRegularFile(file)) { - try { - this.addData("assets/" + path, Files.readAllBytes(file)); - } catch (IOException e) { - e.printStackTrace(); + if (Files.exists(assets)) { + Files.walk(assets).forEach((file) -> { + var relative = assets.relativize(file); + var path = relative.toString().replace("\\", "/"); + if (Files.isRegularFile(file)) { + try { + this.addData("assets/" + path, Files.readAllBytes(file)); + } catch (IOException e) { + e.printStackTrace(); + } } - } - }); + }); + } } return true;