From 3c2cc17d38a6d46bb8408a08de83b1f433d57a06 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Thu, 8 Aug 2024 10:56:20 +0200 Subject: [PATCH 1/6] update releases script --- scripts/upload_releases.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/upload_releases.sh b/scripts/upload_releases.sh index 8d54f66e..a0d4d20d 100755 --- a/scripts/upload_releases.sh +++ b/scripts/upload_releases.sh @@ -93,8 +93,10 @@ function release_curseforge() { # Hardcoded from https://minecraft.curseforge.com/api/game/versions # I'm not betting on these changing any time soon, so hardcoding is ok - local CURSEFORGE_JAVA_VERSION=8326 # Java 17 + local CURSEFORGE_JAVA_17_VERSION=8326 # Java 17 + local CURSEFORGE_JAVA_21_VERSION=11135 # Java 21 local CURSEFORGE_FABRIC_VERSION=7499 + local CURSEFORGE_QUILT_VERSION=9153 local CURSEFORGE_FORGE_VERSION=7498 local CURSEFORGE_NEOFORGE_VERSION=10150 local CURSEFORGE_CLIENT_VERSION=9638 @@ -129,10 +131,11 @@ EOF ) local CURSEFORGE_FABRIC_GAMEVERS="[\ -$CURSEFORGE_JAVA_VERSION,\ +$CURSEFORGE_JAVA_21_VERSION,\ $CURSEFORGE_CLIENT_VERSION,\ $CURSEFORGE_SERVER_VERSION,\ $CURSEFORGE_FABRIC_VERSION,\ +$CURSEFORGE_QUILT_VERSION,\ $CURSEFORGE_GAME_VERSION]" CURSEFORGE_FABRIC_SPEC=$(echo "$CURSEFORGE_FABRIC_SPEC" | \ @@ -156,7 +159,7 @@ EOF ) local CURSEFORGE_NEOFORGE_GAMEVERS="[\ -$CURSEFORGE_JAVA_VERSION,\ +$CURSEFORGE_JAVA_21_VERSION,\ $CURSEFORGE_CLIENT_VERSION,\ $CURSEFORGE_SERVER_VERSION,\ $CURSEFORGE_NEOFORGE_VERSION,\ From 0b289d53f23b7490eb65d91d0cf7c394c3a1b456 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Sat, 24 Aug 2024 20:23:28 +0200 Subject: [PATCH 2/6] Fix loading error for item stack strings with multiple components --- .../vazkii/patchouli/common/util/ItemStackUtil.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java b/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java index 6a020f23..6136851a 100644 --- a/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java +++ b/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java @@ -143,6 +143,7 @@ private static String[] splitStacksFromSerializedIngredient(String ingredientSer int lastIndex = 0; int braces = 0; + int brackets = 0; Character insideString = null; for (int i = 0; i < ingredientSerialized.length(); i++) { switch (ingredientSerialized.charAt(i)) { @@ -156,6 +157,16 @@ private static String[] splitStacksFromSerializedIngredient(String ingredientSer braces--; } break; + case '[': + if (insideString == null) { + brackets++; + } + break; + case ']': + if (insideString == null) { + brackets--; + } + break; case '\'': insideString = insideString == null ? '\'' : null; break; @@ -163,7 +174,7 @@ private static String[] splitStacksFromSerializedIngredient(String ingredientSer insideString = insideString == null ? '"' : null; break; case ',': - if (braces <= 0) { + if (braces <= 0 && brackets <= 0) { result.add(ingredientSerialized.substring(lastIndex, i)); lastIndex = i + 1; break; From bee74da69f8294522419cac7586f307b752bb191 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Sat, 24 Aug 2024 20:27:14 +0200 Subject: [PATCH 3/6] Bump neoforge version --- NeoForge/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NeoForge/build.gradle b/NeoForge/build.gradle index 000ebbd7..fb8dfb5e 100644 --- a/NeoForge/build.gradle +++ b/NeoForge/build.gradle @@ -37,7 +37,7 @@ runs { } dependencies { - implementation "net.neoforged:neoforge:21.0.106-beta" + implementation "net.neoforged:neoforge:21.0.143" implementation project(":Xplat") compileOnly "mezz.jei:jei-1.21-common-api:19.5.0.33" From f0df6548578d544702f42ad40325709f0362bb17 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Sat, 24 Aug 2024 20:28:21 +0200 Subject: [PATCH 4/6] Refactor networking --- .../handler/NeoForgeClientPayloadHandler.java | 22 +++++--------- .../patchouli/network/MessageOpenBookGui.java | 29 +++++++------------ .../network/MessageReloadBookContents.java | 10 +------ 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java b/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java index e6b57280..36015e49 100644 --- a/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java +++ b/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java @@ -15,24 +15,18 @@ public static NeoForgeClientPayloadHandler getInstance() { } public void handleData(final MessageOpenBookGui data, final IPayloadContext context) { - context.enqueueWork(() -> { + try { ClientBookRegistry.INSTANCE.displayBookGui(data.book(), data.entry(), data.page()); - }) - .exceptionally(e -> { - // Handle exception - context.disconnect(Component.translatable("patchouli.networking.open_book.failed", e.getMessage())); - return null; - }); + } catch(Exception e) { + context.disconnect(Component.translatable("patchouli.networking.open_book.failed", e.getMessage())); + } } public void handleData(final MessageReloadBookContents data, final IPayloadContext context) { - context.enqueueWork(() -> { + try { ClientBookRegistry.INSTANCE.reload(); - }) - .exceptionally(e -> { - // Handle exception - context.disconnect(Component.translatable("patchouli.networking.reload_contents.failed", e.getMessage())); - return null; - }); + } catch(Exception e) { + context.disconnect(Component.translatable("patchouli.networking.reload_contents.failed", e.getMessage())); + } } } diff --git a/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java b/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java index 99400926..f0988d1b 100644 --- a/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java +++ b/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java @@ -1,6 +1,7 @@ package vazkii.patchouli.network; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; @@ -10,28 +11,18 @@ import org.jetbrains.annotations.Nullable; public record MessageOpenBookGui(ResourceLocation book, @Nullable ResourceLocation entry, int page) implements CustomPacketPayload { - public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "open_book"); - public static final StreamCodec CODEC = CustomPacketPayload.codec( - MessageOpenBookGui::write, - MessageOpenBookGui::new); + public static final StreamCodec CODEC = StreamCodec.composite( + ResourceLocation.STREAM_CODEC, + MessageOpenBookGui::book, + ByteBufCodecs.STRING_UTF8.map(entry -> entry.isEmpty() ? null : ResourceLocation.tryParse(entry), entry -> entry == null ? "" : entry.toString()), + MessageOpenBookGui::entry, + ByteBufCodecs.VAR_INT, + MessageOpenBookGui::page, + MessageOpenBookGui::new + ); public static final Type TYPE = new Type<>(ID); - public MessageOpenBookGui(FriendlyByteBuf buf) { - this(buf.readResourceLocation(), getEntry(buf), buf.readVarInt()); - } - - private static ResourceLocation getEntry(FriendlyByteBuf buf) { - String entry = buf.readUtf(); - return entry.isEmpty() ? null : ResourceLocation.tryParse(entry); - } - - public void write(FriendlyByteBuf buf) { - buf.writeResourceLocation(book); - buf.writeUtf(entry == null ? "" : entry.toString()); - buf.writeVarInt(page); - } - @Override public Type type() { return TYPE; diff --git a/Xplat/src/main/java/vazkii/patchouli/network/MessageReloadBookContents.java b/Xplat/src/main/java/vazkii/patchouli/network/MessageReloadBookContents.java index 4149b722..b9049d62 100644 --- a/Xplat/src/main/java/vazkii/patchouli/network/MessageReloadBookContents.java +++ b/Xplat/src/main/java/vazkii/patchouli/network/MessageReloadBookContents.java @@ -9,17 +9,9 @@ public record MessageReloadBookContents() implements CustomPacketPayload { public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "reload_books"); - public static final StreamCodec CODEC = CustomPacketPayload.codec( - MessageReloadBookContents::write, - MessageReloadBookContents::new); + public static final StreamCodec CODEC = StreamCodec.unit(new MessageReloadBookContents()); public static final Type TYPE = new Type<>(ID); - public MessageReloadBookContents(final FriendlyByteBuf packetBuffer) { - this(); - } - - public void write(FriendlyByteBuf buf) {} - @Override public Type type() { return TYPE; From 7e1ccf548d2a7a7bb4eafac58a521b3663a76fa0 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Sat, 24 Aug 2024 20:29:25 +0200 Subject: [PATCH 5/6] Simplify book model --- .../client/FabricClientInitializer.java | 4 +- .../client/NeoForgeClientInitializer.java | 5 +- .../patchouli/client/base/BookModel.java | 72 +++++++++---------- .../mixin/client/AccessorModelBakery.java | 14 ---- .../resources/patchouli_xplat.mixins.json | 1 - 5 files changed, 38 insertions(+), 58 deletions(-) delete mode 100644 Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java diff --git a/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java b/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java index 9942c7bf..bc01af95 100644 --- a/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java +++ b/Fabric/src/main/java/vazkii/patchouli/fabric/client/FabricClientInitializer.java @@ -62,9 +62,7 @@ public void onInitializeClient() { PatchouliItems.BOOK_ID.equals(ctx.topLevelId().id()) // checks namespace and path && ctx.topLevelId().getVariant().equals("inventory") && oldModel != null) { - return new BookModel(oldModel, ctx.loader(), (model) -> { - return Minecraft.getInstance().getModelManager().getModel(model); - }); + return new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(model)); } return oldModel; } diff --git a/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java b/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java index 9f8a9007..d28f53e0 100644 --- a/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java +++ b/NeoForge/src/main/java/vazkii/patchouli/neoforge/client/NeoForgeClientInitializer.java @@ -151,9 +151,6 @@ public static void onInitializeClient(FMLClientSetupEvent evt) { @SubscribeEvent public static void replaceBookModel(ModelEvent.ModifyBakingResult evt) { ModelResourceLocation key = ModelResourceLocation.inventory(PatchouliItems.BOOK_ID); - evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, evt.getModelBakery(), (model) -> { - ModelResourceLocation modelPath = ModelResourceLocation.standalone(model); - return Minecraft.getInstance().getModelManager().getModel(modelPath); - })); + evt.getModels().computeIfPresent(key, (k, oldModel) -> new BookModel(oldModel, (model) -> Minecraft.getInstance().getModelManager().getModel(ModelResourceLocation.standalone(model)))); } } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java b/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java index 78956972..9b7361eb 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java @@ -2,7 +2,6 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.ItemOverrides; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -16,7 +15,6 @@ import vazkii.patchouli.common.book.Book; import vazkii.patchouli.common.item.ItemModBook; -import vazkii.patchouli.mixin.client.AccessorModelBakery; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -29,42 +27,10 @@ public class BookModel implements BakedModel { private final BakedModel original; private final ItemOverrides itemHandler; - public BookModel(BakedModel original, ModelBakery loader, Function modelGetter) { + public BookModel(BakedModel original, Function modelGetter) { this.original = original; - BlockModel missing = (BlockModel) ((AccessorModelBakery) loader).invokeGetModel(ModelBakery.MISSING_MODEL_LOCATION); - - this.itemHandler = new ItemOverrides(new ModelBaker() { - // soft implement IModelBakerExtension - public Function getModelTextureGetter() { - return null; - } - - // soft implement IModelBakerExtension - public BakedModel bake(ResourceLocation location, ModelState state, Function sprites) { - return null; - } - - // soft implement IModelBakerExtension - public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function sprites) { - return null; - } - - // soft implement IModelBakerExtension - public UnbakedModel getTopLevelModel(ModelResourceLocation location) { - return null; - } - @Override - public UnbakedModel getModel(ResourceLocation resourceLocation) { - return null; - } - - @Nullable - @Override - public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) { - return null; - } - }, missing, Collections.emptyList()) { + this.itemHandler = new ItemOverrides(DummyModelBaker.INSTANCE, null, Collections.emptyList()) { @Override public BakedModel resolve(@NotNull BakedModel original, @NotNull ItemStack stack, @Nullable ClientLevel world, @Nullable LivingEntity entity, int seed) { @@ -119,4 +85,38 @@ public TextureAtlasSprite getParticleIcon() { public ItemTransforms getTransforms() { return original.getTransforms(); } + + private static class DummyModelBaker implements ModelBaker { + static ModelBaker INSTANCE = new DummyModelBaker(); + // soft implement IModelBakerExtension + public Function getModelTextureGetter() { + return null; + } + + // soft implement IModelBakerExtension + public BakedModel bake(ResourceLocation location, ModelState state, Function sprites) { + return null; + } + + // soft implement IModelBakerExtension + public BakedModel bakeUncached(UnbakedModel model, ModelState state, Function sprites) { + return null; + } + + // soft implement IModelBakerExtension + public UnbakedModel getTopLevelModel(ModelResourceLocation location) { + return null; + } + + @Override + public UnbakedModel getModel(ResourceLocation resourceLocation) { + return null; + } + + @Nullable + @Override + public BakedModel bake(ResourceLocation resourceLocation, ModelState modelState) { + return null; + } + } } diff --git a/Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java b/Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java deleted file mode 100644 index 6a1eb110..00000000 --- a/Xplat/src/main/java/vazkii/patchouli/mixin/client/AccessorModelBakery.java +++ /dev/null @@ -1,14 +0,0 @@ -package vazkii.patchouli.mixin.client; - -import net.minecraft.client.resources.model.ModelBakery; -import net.minecraft.client.resources.model.UnbakedModel; -import net.minecraft.resources.ResourceLocation; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(ModelBakery.class) -public interface AccessorModelBakery { - @Invoker("getModel") - UnbakedModel invokeGetModel(ResourceLocation location); -} diff --git a/Xplat/src/main/resources/patchouli_xplat.mixins.json b/Xplat/src/main/resources/patchouli_xplat.mixins.json index 0ebe4417..869b4465 100644 --- a/Xplat/src/main/resources/patchouli_xplat.mixins.json +++ b/Xplat/src/main/resources/patchouli_xplat.mixins.json @@ -10,7 +10,6 @@ "client": [ "client.AccessorClientAdvancements", "client.AccessorKeyMapping", - "client.AccessorModelBakery", "client.AccessorMultiBufferSource", "client.AccessorScreen", "client.MixinClientAdvancements", From 88d194ebb1d8f6bb2e25efd3db42c9474f1c6889 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Sat, 24 Aug 2024 21:06:16 +0200 Subject: [PATCH 6/6] spotless apply --- .../network/handler/NeoForgeClientPayloadHandler.java | 4 ++-- .../src/main/java/vazkii/patchouli/client/base/BookModel.java | 1 + .../java/vazkii/patchouli/network/MessageOpenBookGui.java | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java b/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java index 36015e49..5b083c63 100644 --- a/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java +++ b/NeoForge/src/main/java/vazkii/patchouli/neoforge/network/handler/NeoForgeClientPayloadHandler.java @@ -17,7 +17,7 @@ public static NeoForgeClientPayloadHandler getInstance() { public void handleData(final MessageOpenBookGui data, final IPayloadContext context) { try { ClientBookRegistry.INSTANCE.displayBookGui(data.book(), data.entry(), data.page()); - } catch(Exception e) { + } catch (Exception e) { context.disconnect(Component.translatable("patchouli.networking.open_book.failed", e.getMessage())); } } @@ -25,7 +25,7 @@ public void handleData(final MessageOpenBookGui data, final IPayloadContext cont public void handleData(final MessageReloadBookContents data, final IPayloadContext context) { try { ClientBookRegistry.INSTANCE.reload(); - } catch(Exception e) { + } catch (Exception e) { context.disconnect(Component.translatable("patchouli.networking.reload_contents.failed", e.getMessage())); } } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java b/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java index 9b7361eb..dce9c3f1 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/base/BookModel.java @@ -88,6 +88,7 @@ public ItemTransforms getTransforms() { private static class DummyModelBaker implements ModelBaker { static ModelBaker INSTANCE = new DummyModelBaker(); + // soft implement IModelBakerExtension public Function getModelTextureGetter() { return null; diff --git a/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java b/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java index f0988d1b..f6d8540f 100644 --- a/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java +++ b/Xplat/src/main/java/vazkii/patchouli/network/MessageOpenBookGui.java @@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; public record MessageOpenBookGui(ResourceLocation book, @Nullable ResourceLocation entry, int page) implements CustomPacketPayload { + public static final ResourceLocation ID = ResourceLocation.fromNamespaceAndPath(PatchouliAPI.MOD_ID, "open_book"); public static final StreamCodec CODEC = StreamCodec.composite( ResourceLocation.STREAM_CODEC,