From 267f7d3fa0362cf479b1ce8ef9b4fc8855a16d5b Mon Sep 17 00:00:00 2001 From: Aton-Kish <38515249+Aton-Kish@users.noreply.github.com> Date: Tue, 21 Mar 2023 11:06:21 +0900 Subject: [PATCH] [v2.3.2+1.19] support Minecraft 1.19.4 (#54) * bump fabric loom 1.1 * bump gradle 8 * bump fabric deps * bump reinforced storages * bump quick shulker * fix code * update release target * rename release job * add mod_id prop * bump shulker box tooltip * bump version 2.3.2+1.19 * fix shulker box tooltip integ * update quick shulker integ * add shulkerutils deps --- .github/workflows/release.yaml | 2 +- build.gradle | 8 +- gradle.properties | 21 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../ReinforcedShulkerBoxesClientMod.java | 4 +- .../quickshulker/QuickShulker.java | 8 +- .../ReinforcedShulkerBoxPreviewProvider.java | 36 +++-- .../ReinforcedShulkerBoxColoringRecipe.java | 65 +++++---- .../ReinforcedShulkerBoxCraftingRecipe.java | 130 ++++++++++-------- src/main/resources/fabric.mod.json | 4 +- 10 files changed, 164 insertions(+), 116 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 514657d..05e64f1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,7 +5,7 @@ on: - v[0-9]+.[0-9]+.[0-9]+* jobs: - build: + release: runs-on: ubuntu-22.04 env: JAVA_VERSION: 17 diff --git a/build.gradle b/build.gradle index 80256d7..610868c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.0-SNAPSHOT" + id "fabric-loom" version "1.1-SNAPSHOT" id "maven-publish" id "com.matthewprenger.cursegradle" version "1.4.0" id "com.modrinth.minotaur" version "2.+" @@ -68,6 +68,8 @@ dependencies { // Quick Shulker modImplementation "net.kyrptonaught:quickshulker:${project.quick_shulker_version}" + // Quick Shulker deps + modImplementation "net.kyrptonaught:shulkerutils:${project.shulkerutils_version}" // Shulker Box Tooltip modImplementation "com.misterpemodder:shulkerboxtooltip-fabric:${project.shulker_box_tooltip_version}" @@ -134,7 +136,7 @@ curseforge { addGameVersion "Fabric" addGameVersion "Java 17" - addGameVersion "1.19.3" + addGameVersion "1.19.4" relations { requiredDependency "fabric-api" @@ -158,7 +160,7 @@ modrinth { versionType = "release" changelog = "[v${project.version}](https://github.com/Aton-Kish/reinforced-shulker-boxes/releases/tag/v" + java.net.URLEncoder.encode(project.version, "UTF-8") + ")" - gameVersions = ["1.19.3"] + gameVersions = ["1.19.4"] loaders = ["fabric"] dependencies { diff --git a/gradle.properties b/gradle.properties index e3e8025..d748dc7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,21 +4,24 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.19.3 - yarn_mappings=1.19.3+build.5 - loader_version=0.14.14 + minecraft_version=1.19.4 + yarn_mappings=1.19.4+build.1 + loader_version=0.14.17 # Mod Properties - mod_version=2.3.1+1.19 + mod_version=2.3.2+1.19 + mod_id=reinfshulker maven_group=atonkish.reinfshulker archives_base_name=reinforced-shulker-boxes # Dependencies - fabric_version=0.74.0+1.19.3 - reinforced_core_version=3.0.5+1.19 - reinforced_chests_version=2.3.1+1.19 - quick_shulker_version=1.3.10-1.19.3 - shulker_box_tooltip_version=3.2.4+1.19.3 + fabric_version=0.76.0+1.19.4 + reinforced_core_version=3.0.6+1.19 + reinforced_chests_version=2.3.2+1.19 + quick_shulker_version=1.3.10-1.19.4 + shulker_box_tooltip_version=3.2.5+1.19.4 + # Quick Shulker deps + shulkerutils_version=1.0.4-1.19 # Distribution platform curseforge_id=529874 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f398c33..fc10b60 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/atonkish/reinfshulker/ReinforcedShulkerBoxesClientMod.java b/src/main/java/atonkish/reinfshulker/ReinforcedShulkerBoxesClientMod.java index 1b29f99..4198483 100644 --- a/src/main/java/atonkish/reinfshulker/ReinforcedShulkerBoxesClientMod.java +++ b/src/main/java/atonkish/reinfshulker/ReinforcedShulkerBoxesClientMod.java @@ -10,7 +10,7 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.block.entity.BlockEntityRendererFactories; -import net.minecraft.client.render.model.json.ModelTransformation; +import net.minecraft.client.render.model.json.ModelTransformationMode; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; @@ -69,7 +69,7 @@ private static void initializeReinforcedShulkerBoxesClient() { // Item Renderer for (Block block : ModBlocks.REINFORCED_SHULKER_BOX_MAP.get(material).values()) { - BuiltinItemRendererRegistry.INSTANCE.register(block, (ItemStack stack, ModelTransformation.Mode mode, + BuiltinItemRendererRegistry.INSTANCE.register(block, (ItemStack stack, ModelTransformationMode mode, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) -> { BlockEntity blockEntity = new ReinforcedShulkerBoxBlockEntity(material, BlockPos.ORIGIN, block.getDefaultState()); diff --git a/src/main/java/atonkish/reinfshulker/integration/quickshulker/QuickShulker.java b/src/main/java/atonkish/reinfshulker/integration/quickshulker/QuickShulker.java index 437ddf8..4955844 100644 --- a/src/main/java/atonkish/reinfshulker/integration/quickshulker/QuickShulker.java +++ b/src/main/java/atonkish/reinfshulker/integration/quickshulker/QuickShulker.java @@ -4,7 +4,6 @@ import net.kyrptonaught.quickshulker.api.ItemStackInventory; import net.kyrptonaught.quickshulker.api.QuickOpenableRegistry; -import net.kyrptonaught.quickshulker.api.QuickShulkerData; import net.kyrptonaught.quickshulker.api.RegisterQuickShulker; import net.minecraft.block.entity.BlockEntityType; @@ -26,8 +25,11 @@ public class QuickShulker implements RegisterQuickShulker { @Override public void registerProviders() { - QuickOpenableRegistry.register(ReinforcedShulkerBoxBlock.class, - new QuickShulkerData(REINFORCED_SHULKER_BOX_CONSUMER, false)); + new QuickOpenableRegistry.Builder() + .setItem(ReinforcedShulkerBoxBlock.class) + .supportsBundleing(true) + .setOpenAction(REINFORCED_SHULKER_BOX_CONSUMER) + .register(); } static { diff --git a/src/main/java/atonkish/reinfshulker/integration/shulkerboxtooltip/ReinforcedShulkerBoxPreviewProvider.java b/src/main/java/atonkish/reinfshulker/integration/shulkerboxtooltip/ReinforcedShulkerBoxPreviewProvider.java index b4e5cdd..4803b4b 100644 --- a/src/main/java/atonkish/reinfshulker/integration/shulkerboxtooltip/ReinforcedShulkerBoxPreviewProvider.java +++ b/src/main/java/atonkish/reinfshulker/integration/shulkerboxtooltip/ReinforcedShulkerBoxPreviewProvider.java @@ -1,8 +1,12 @@ package atonkish.reinfshulker.integration.shulkerboxtooltip; import com.misterpemodder.shulkerboxtooltip.api.PreviewContext; +import com.misterpemodder.shulkerboxtooltip.api.color.ColorKey; import com.misterpemodder.shulkerboxtooltip.api.provider.BlockEntityPreviewProvider; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + import net.minecraft.block.Block; import net.minecraft.util.DyeColor; @@ -10,7 +14,6 @@ import atonkish.reinfshulker.block.ReinforcedShulkerBoxBlock; public class ReinforcedShulkerBoxPreviewProvider extends BlockEntityPreviewProvider { - private static float[] SHULKER_BOX_COLOR = new float[] { 0.592f, 0.403f, 0.592f }; protected final int maxRowSize; private final ReinforcingMaterial material; @@ -29,15 +32,30 @@ public boolean showTooltipHints(PreviewContext context) { } @Override - public float[] getWindowColor(PreviewContext context) { + @Environment(EnvType.CLIENT) + public ColorKey getWindowColorKey(PreviewContext context) { DyeColor dye = ((ReinforcedShulkerBoxBlock) Block.getBlockFromItem(context.stack().getItem())).getColor(); - if (dye != null) { - float[] components = dye.getColorComponents(); - return new float[] { Math.max(0.15f, components[0]), Math.max(0.15f, components[1]), - Math.max(0.15f, components[2]) }; - } else { - return SHULKER_BOX_COLOR; - } + + if (dye == null) + return ColorKey.SHULKER_BOX; + return switch (dye) { + case ORANGE -> ColorKey.ORANGE_SHULKER_BOX; + case MAGENTA -> ColorKey.MAGENTA_SHULKER_BOX; + case LIGHT_BLUE -> ColorKey.LIGHT_BLUE_SHULKER_BOX; + case YELLOW -> ColorKey.YELLOW_SHULKER_BOX; + case LIME -> ColorKey.LIME_SHULKER_BOX; + case PINK -> ColorKey.PINK_SHULKER_BOX; + case GRAY -> ColorKey.GRAY_SHULKER_BOX; + case LIGHT_GRAY -> ColorKey.LIGHT_GRAY_SHULKER_BOX; + case CYAN -> ColorKey.CYAN_SHULKER_BOX; + case PURPLE -> ColorKey.PURPLE_SHULKER_BOX; + case BLUE -> ColorKey.BLUE_SHULKER_BOX; + case BROWN -> ColorKey.BROWN_SHULKER_BOX; + case GREEN -> ColorKey.GREEN_SHULKER_BOX; + case RED -> ColorKey.RED_SHULKER_BOX; + case BLACK -> ColorKey.BLACK_SHULKER_BOX; + default -> ColorKey.WHITE_SHULKER_BOX; + }; } @Override diff --git a/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxColoringRecipe.java b/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxColoringRecipe.java index a65e690..6b27d04 100644 --- a/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxColoringRecipe.java +++ b/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxColoringRecipe.java @@ -9,11 +9,13 @@ import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.SpecialCraftingRecipe; import net.minecraft.recipe.book.CraftingRecipeCategory; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.util.Identifier; import net.minecraft.world.World; +import org.jetbrains.annotations.Nullable; + import atonkish.reinfcore.util.ReinforcingMaterial; -import atonkish.reinfcore.util.ReinforcingMaterials; import atonkish.reinfshulker.block.ReinforcedShulkerBoxBlock; public class ReinforcedShulkerBoxColoringRecipe extends SpecialCraftingRecipe { @@ -28,44 +30,55 @@ public boolean matches(CraftingInventory craftingInventory, World world) { for (int k = 0; k < craftingInventory.size(); ++k) { ItemStack itemStack = craftingInventory.getStack(k); - if (!itemStack.isEmpty()) { - if (Block.getBlockFromItem(itemStack.getItem()) instanceof ReinforcedShulkerBoxBlock) { - ++i; - } else { - if (!(itemStack.getItem() instanceof DyeItem)) { - return false; - } - - ++j; - } - - if (j > 1 || i > 1) { - return false; - } + if (itemStack.isEmpty()) { + continue; + } + + if (Block.getBlockFromItem(itemStack.getItem()) instanceof ReinforcedShulkerBoxBlock) { + ++i; + } else if (itemStack.getItem() instanceof DyeItem) { + ++j; + } else { + return false; } + + if (j <= 1 && i <= 1) { + continue; + } + + return false; } return i == 1 && j == 1; } @Override - public ItemStack craft(CraftingInventory craftingInventory) { + public ItemStack craft(CraftingInventory craftingInventory, DynamicRegistryManager dynamicRegistryManager) { ItemStack itemStack = ItemStack.EMPTY; DyeItem dyeItem = (DyeItem) Items.WHITE_DYE; - ReinforcingMaterial material = ReinforcingMaterials.MAP.get("copper"); + + @Nullable + ReinforcingMaterial material = null; for (int i = 0; i < craftingInventory.size(); ++i) { ItemStack itemStack2 = craftingInventory.getStack(i); - if (!itemStack2.isEmpty()) { - Item item = itemStack2.getItem(); - Block block = Block.getBlockFromItem(item); - if (block instanceof ReinforcedShulkerBoxBlock) { - itemStack = itemStack2; - material = ((ReinforcedShulkerBoxBlock) block).getMaterial(); - } else if (item instanceof DyeItem) { - dyeItem = (DyeItem) item; - } + if (itemStack2.isEmpty()) { + continue; + } + + Item item = itemStack2.getItem(); + Block block = Block.getBlockFromItem(item); + if (block instanceof ReinforcedShulkerBoxBlock) { + itemStack = itemStack2; + material = ((ReinforcedShulkerBoxBlock) block).getMaterial(); + continue; } + + if (!(item instanceof DyeItem)) { + continue; + } + + dyeItem = (DyeItem) item; } ItemStack itemStack3 = ReinforcedShulkerBoxBlock.getItemStack(material, dyeItem.getColor()); diff --git a/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java b/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java index f9a75cb..3d839fe 100644 --- a/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java +++ b/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java @@ -1,9 +1,8 @@ package atonkish.reinfshulker.recipe; -import java.util.Iterator; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; -import java.util.Set; -import java.util.Map.Entry; import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.Maps; @@ -15,36 +14,43 @@ import net.minecraft.inventory.CraftingInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.ShapedRecipe; import net.minecraft.recipe.book.CraftingRecipeCategory; +import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.util.Identifier; import net.minecraft.util.JsonHelper; import net.minecraft.util.collection.DefaultedList; public class ReinforcedShulkerBoxCraftingRecipe extends ShapedRecipe { + public ReinforcedShulkerBoxCraftingRecipe(Identifier id, String group, CraftingRecipeCategory category, int width, + int height, DefaultedList input, ItemStack output, boolean showNotification) { + super(id, group, category, width, height, input, output, showNotification); + } + public ReinforcedShulkerBoxCraftingRecipe(Identifier id, String group, CraftingRecipeCategory category, int width, int height, DefaultedList input, ItemStack output) { - super(id, group, category, width, height, input, output); + this(id, group, category, width, height, input, output, true); } @Override - public ItemStack craft(CraftingInventory craftingInventory) { - ItemStack inputItemStack = craftingInventory.getStack(4); - ItemStack outputItemStack = this.getOutput().copy(); - - if (inputItemStack.hasNbt()) { - outputItemStack.setNbt(inputItemStack.getNbt().copy()); - } - - return outputItemStack; + public RecipeSerializer getSerializer() { + return ModRecipeSerializer.REINFORCED_SHULKER_BOX; } @Override - public RecipeSerializer getSerializer() { - return ModRecipeSerializer.REINFORCED_SHULKER_BOX; + public ItemStack craft(CraftingInventory craftingInventory, DynamicRegistryManager dynamicRegistryManager) { + ItemStack itemStack = this.getOutput(dynamicRegistryManager).copy(); + NbtCompound nbtCompound = craftingInventory.getStack(4).getNbt(); + + if (nbtCompound != null) { + itemStack.setNbt(nbtCompound.copy()); + } + + return itemStack; } /** @@ -54,13 +60,13 @@ public RecipeSerializer getSerializer() { static DefaultedList createPatternMatrix(String[] pattern, Map symbols, int width, int height) { DefaultedList defaultedList = DefaultedList.ofSize(width * height, Ingredient.EMPTY); - Set set = Sets.newHashSet((Iterable) symbols.keySet()); + HashSet set = Sets.newHashSet(symbols.keySet()); set.remove(" "); for (int i = 0; i < pattern.length; ++i) { for (int j = 0; j < pattern[i].length(); ++j) { String string = pattern[i].substring(j, j + 1); - Ingredient ingredient = (Ingredient) symbols.get(string); + Ingredient ingredient = symbols.get(string); if (ingredient == null) { throw new JsonSyntaxException( "Pattern references symbol '" + string + "' but it's not defined in the key"); @@ -73,9 +79,9 @@ static DefaultedList createPatternMatrix(String[] pattern, Map 3) { throw new JsonSyntaxException("Invalid pattern: too many rows, 3 is maximum"); - } else if (strings.length == 0) { + } + + if (strings.length == 0) { throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed"); - } else { - for (int i = 0; i < strings.length; ++i) { - String string = JsonHelper.asString(json.get(i), "pattern[" + i + "]"); - if (string.length() > 3) { - throw new JsonSyntaxException("Invalid pattern: too many columns, 3 is maximum"); - } + } - if (i > 0 && strings[0].length() != string.length()) { - throw new JsonSyntaxException("Invalid pattern: each row must be the same width"); - } + for (int i = 0; i < strings.length; ++i) { + String string = JsonHelper.asString(json.get(i), "pattern[" + i + "]"); + if (string.length() > 3) { + throw new JsonSyntaxException("Invalid pattern: too many columns, 3 is maximum"); + } - strings[i] = string; + if (i > 0 && strings[0].length() != string.length()) { + throw new JsonSyntaxException("Invalid pattern: each row must be the same width"); } - return strings; + strings[i] = string; } + + return strings; } /** @@ -187,24 +196,23 @@ static String[] getPattern(JsonArray json) { * @return a mapping from a symbol to the ingredient it represents */ static Map readSymbols(JsonObject json) { - Map map = Maps.newHashMap(); - Iterator> var2 = json.entrySet().iterator(); - - while (var2.hasNext()) { - Entry entry = var2.next(); - if (((String) entry.getKey()).length() != 1) { - throw new JsonSyntaxException("Invalid key entry: '" + (String) entry.getKey() - + "' is an invalid symbol (must be 1 character only)."); + HashMap map = Maps.newHashMap(); + + for (Map.Entry entry : json.entrySet()) { + if (entry.getKey().length() != 1) { + throw new JsonSyntaxException( + "Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only)."); } if (" ".equals(entry.getKey())) { throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol."); } - map.put((String) entry.getKey(), Ingredient.fromJson((JsonElement) entry.getValue())); + map.put(entry.getKey(), Ingredient.fromJson(entry.getValue())); } map.put(" ", Ingredient.EMPTY); + return map; } @@ -224,8 +232,10 @@ public ReinforcedShulkerBoxCraftingRecipe read(Identifier identifier, JsonObject map, i, j); ItemStack itemStack = ReinforcedShulkerBoxCraftingRecipe .outputFromJson(JsonHelper.getObject(jsonObject, "result")); - return new ReinforcedShulkerBoxCraftingRecipe(identifier, string, craftingRecipeCategory, - i, j, defaultedList, itemStack); + boolean bl = JsonHelper.getBoolean(jsonObject, "show_notification", true); + + return new ReinforcedShulkerBoxCraftingRecipe(identifier, string, craftingRecipeCategory, i, j, + defaultedList, itemStack, bl); } @Override @@ -242,8 +252,10 @@ public ReinforcedShulkerBoxCraftingRecipe read(Identifier identifier, PacketByte } ItemStack itemStack = packetByteBuf.readItemStack(); - return new ReinforcedShulkerBoxCraftingRecipe(identifier, string, craftingRecipeCategory, - i, j, defaultedList, itemStack); + boolean bl = packetByteBuf.readBoolean(); + + return new ReinforcedShulkerBoxCraftingRecipe(identifier, string, craftingRecipeCategory, i, j, + defaultedList, itemStack, bl); } @Override @@ -251,14 +263,12 @@ public void write(PacketByteBuf packetByteBuf, ReinforcedShulkerBoxCraftingRecip packetByteBuf.writeVarInt(recipe.getWidth()); packetByteBuf.writeVarInt(recipe.getHeight()); packetByteBuf.writeString(recipe.getGroup()); - Iterator var3 = recipe.getIngredients().iterator(); - - while (var3.hasNext()) { - Ingredient ingredient = (Ingredient) var3.next(); + packetByteBuf.writeEnumConstant(recipe.getCategory()); + for (Ingredient ingredient : recipe.getIngredients()) { ingredient.write(packetByteBuf); } - - packetByteBuf.writeItemStack(recipe.getOutput()); + packetByteBuf.writeItemStack(recipe.getOutput(null)); + packetByteBuf.writeBoolean(recipe.showNotification()); } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 72d86ba..8de8f73 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,9 +33,9 @@ "mixins": ["reinfshulker.mixins.json"], "depends": { - "fabricloader": ">=0.14.11", + "fabricloader": ">=0.14.17", "fabric-api": "*", - "minecraft": "~1.19.3", + "minecraft": "~1.19.4", "java": ">=17" }, "suggests": {