From 72ced100441b1c32886ab8fabf1132420fb2054d Mon Sep 17 00:00:00 2001 From: Aton-Kish <38515249+Aton-Kish@users.noreply.github.com> Date: Mon, 11 Dec 2023 21:24:29 +0900 Subject: [PATCH] [v2.5.2+1.20] support minecraft 1.20.3/1.20.4 (#67) * bump fabric deps * updated supported minecraft version * bump up mod version * remove override decorators --- build.gradle | 9 +- gradle.properties | 8 +- .../mixin/ShulkerBoxBlockMixin.java | 7 +- .../ReinforcedShulkerBoxCraftingRecipe.java | 216 +++--------------- src/main/resources/fabric.mod.json | 3 +- src/main/resources/reinfshulker.accesswidener | 3 - 6 files changed, 49 insertions(+), 197 deletions(-) delete mode 100644 src/main/resources/reinfshulker.accesswidener diff --git a/build.gradle b/build.gradle index cba672c..b53a444 100644 --- a/build.gradle +++ b/build.gradle @@ -86,10 +86,6 @@ dependencies { modImplementation "com.misterpemodder:shulkerboxtooltip-fabric:${project.shulker_box_tooltip_version}" } -loom { - accessWidenerPath = file("src/main/resources/${project.mod_id}.accesswidener") -} - processResources { inputs.property "version", project.version @@ -154,7 +150,8 @@ curseforge { addGameVersion "Fabric" addGameVersion "Java 17" - addGameVersion "1.20.2" + addGameVersion "1.20.3" + addGameVersion "1.20.4" relations { requiredDependency "fabric-api" @@ -178,7 +175,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.20.2"] + gameVersions = ["1.20.3", "1.20.4"] loaders = ["fabric"] dependencies { diff --git a/gradle.properties b/gradle.properties index d663e79..d8cc961 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,18 +4,18 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20.2 - yarn_mappings=1.20.2+build.2 + minecraft_version=1.20.4 + yarn_mappings=1.20.4+build.1 loader_version=0.15.1 # Mod Properties - mod_version=2.5.1+1.20 + mod_version=2.5.2+1.20 mod_id=reinfshulker maven_group=atonkish.reinfshulker archives_base_name=reinforced-shulker-boxes # Dependencies - fabric_version=0.91.2+1.20.2 + fabric_version=0.91.1+1.20.4 reinforced_core_version=3.1.3+1.20 reinforced_chests_version=2.4.3+1.20 quick_shulker_version=1.4.0-1.20 diff --git a/src/main/java/atonkish/reinfshulker/mixin/ShulkerBoxBlockMixin.java b/src/main/java/atonkish/reinfshulker/mixin/ShulkerBoxBlockMixin.java index 97e7071..ad31ce8 100644 --- a/src/main/java/atonkish/reinfshulker/mixin/ShulkerBoxBlockMixin.java +++ b/src/main/java/atonkish/reinfshulker/mixin/ShulkerBoxBlockMixin.java @@ -12,7 +12,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import atonkish.reinfshulker.block.ReinforcedShulkerBoxBlock; @@ -21,8 +21,9 @@ @Mixin(ShulkerBoxBlock.class) public class ShulkerBoxBlockMixin { @Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/BlockEntity;setStackNbt(Lnet/minecraft/item/ItemStack;)V"), locals = LocalCapture.CAPTURE_FAILHARD) - public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfo info, - BlockEntity blockEntity, ShulkerBoxBlockEntity shulkerBoxBlockEntity, ItemStack itemStack) { + public void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, + CallbackInfoReturnable cir, BlockEntity blockEntity, + ShulkerBoxBlockEntity shulkerBoxBlockEntity, ItemStack itemStack) { if (blockEntity instanceof ReinforcedShulkerBoxBlockEntity) { ReinforcedShulkerBoxBlockEntity entity = (ReinforcedShulkerBoxBlockEntity) blockEntity; ((ItemStackAccessor) (Object) itemStack) diff --git a/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java b/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java index 964ac62..e153ab9 100644 --- a/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java +++ b/src/main/java/atonkish/reinfshulker/recipe/ReinforcedShulkerBoxCraftingRecipe.java @@ -1,38 +1,31 @@ package atonkish.reinfshulker.recipe; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.apache.commons.lang3.NotImplementedException; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.Sets; - import com.mojang.serialization.Codec; -import com.mojang.serialization.DataResult; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.inventory.RecipeInputInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.network.PacketByteBuf; -import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.RawShapedRecipe; 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.collection.DefaultedList; +import net.minecraft.util.dynamic.Codecs; public class ReinforcedShulkerBoxCraftingRecipe extends ShapedRecipe { - public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, int width, int height, - DefaultedList ingredients, ItemStack result, boolean showNotification) { - super(group, category, width, height, ingredients, result, showNotification); - } + final RawShapedRecipe raw; - public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, int width, int height, - DefaultedList ingredients, ItemStack result) { - this(group, category, width, height, ingredients, result, true); + public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, RawShapedRecipe raw, + ItemStack result, boolean showNotification) { + super(group, category, raw, result, showNotification); + this.raw = raw; + } + public ReinforcedShulkerBoxCraftingRecipe(String group, CraftingRecipeCategory category, RawShapedRecipe raw, + ItemStack result) { + this(group, category, raw, result, true); } @Override @@ -40,6 +33,10 @@ public RecipeSerializer getSerializer() { return ModRecipeSerializer.REINFORCED_SHULKER_BOX; } + private RawShapedRecipe getRaw() { + return this.raw; + } + @Override public ItemStack craft(RecipeInputInventory recipeInputInventory, DynamicRegistryManager dynamicRegistryManager) { ItemStack itemStack = this.getResult(dynamicRegistryManager).copy(); @@ -52,185 +49,46 @@ public ItemStack craft(RecipeInputInventory recipeInputInventory, DynamicRegistr return itemStack; } - @VisibleForTesting - static String[] removePadding(List pattern) { - int i = Integer.MAX_VALUE; - int j = 0; - int k = 0; - int l = 0; - - for (int m = 0; m < pattern.size(); ++m) { - String string = pattern.get(m); - i = Math.min(i, ReinforcedShulkerBoxCraftingRecipe.findFirstSymbol(string)); - int n = ReinforcedShulkerBoxCraftingRecipe.findLastSymbol(string); - j = Math.max(j, n); - if (n < 0) { - if (k == m) { - ++k; - } - - ++l; - continue; - } - - l = 0; - } - - if (pattern.size() == l) { - return new String[0]; - } - - String[] strings = new String[pattern.size() - l - k]; - - for (int o = 0; o < strings.length; ++o) { - strings[o] = pattern.get(o + k).substring(i, j + 1); - } - - return strings; - } - - private static int findFirstSymbol(String line) { - int i; - for (i = 0; i < line.length() && line.charAt(i) == ' '; ++i) { - } - - return i; - } - - private static int findLastSymbol(String pattern) { - int i; - for (i = pattern.length() - 1; i >= 0 && pattern.charAt(i) == ' '; --i) { - } - - return i; - } - public static class Serializer implements RecipeSerializer { - static final Codec> PATTERN_CODEC; - static final Codec KEY_ENTRY_CODEC; - private static final Codec CODEC; + public static final Codec CODEC = RecordCodecBuilder.create((instance) -> { + return instance + .group(Codecs.createStrictOptionalFieldCodec(Codec.STRING, "group", "").forGetter((recipe) -> { + return recipe.getGroup(); + }), CraftingRecipeCategory.CODEC.fieldOf("category").orElse(CraftingRecipeCategory.MISC) + .forGetter((recipe) -> { + return recipe.getCategory(); + }), RawShapedRecipe.CODEC.forGetter((recipe) -> { + return recipe.getRaw(); + }), ItemStack.RECIPE_RESULT_CODEC.fieldOf("result").forGetter((recipe) -> { + return recipe.getResult(null); + }), Codecs.createStrictOptionalFieldCodec(Codec.BOOL, "show_notification", true) + .forGetter((recipe) -> { + return recipe.showNotification(); + })) + .apply(instance, ReinforcedShulkerBoxCraftingRecipe::new); + }); public Codec codec() { return CODEC; } public ReinforcedShulkerBoxCraftingRecipe read(PacketByteBuf packetByteBuf) { - int i = packetByteBuf.readVarInt(); - int j = packetByteBuf.readVarInt(); String string = packetByteBuf.readString(); CraftingRecipeCategory craftingRecipeCategory = (CraftingRecipeCategory) packetByteBuf .readEnumConstant(CraftingRecipeCategory.class); - DefaultedList defaultedList = DefaultedList.ofSize(i * j, Ingredient.EMPTY); - - for (int k = 0; k < defaultedList.size(); ++k) { - defaultedList.set(k, Ingredient.fromPacket(packetByteBuf)); - } - + RawShapedRecipe rawShapedRecipe = RawShapedRecipe.readFromBuf(packetByteBuf); ItemStack itemStack = packetByteBuf.readItemStack(); boolean bl = packetByteBuf.readBoolean(); - return new ReinforcedShulkerBoxCraftingRecipe(string, craftingRecipeCategory, i, j, defaultedList, - itemStack, bl); + return new ReinforcedShulkerBoxCraftingRecipe(string, craftingRecipeCategory, rawShapedRecipe, itemStack, + bl); } public void write(PacketByteBuf packetByteBuf, ReinforcedShulkerBoxCraftingRecipe recipe) { - packetByteBuf.writeVarInt(recipe.getWidth()); - packetByteBuf.writeVarInt(recipe.getHeight()); packetByteBuf.writeString(recipe.getGroup()); packetByteBuf.writeEnumConstant(recipe.getCategory()); - Iterator ingredientsIterator = recipe.getIngredients().iterator(); - - while (ingredientsIterator.hasNext()) { - Ingredient ingredient = ingredientsIterator.next(); - ingredient.write(packetByteBuf); - } - + recipe.getRaw().writeToBuf(packetByteBuf); packetByteBuf.writeItemStack(recipe.getResult(null)); packetByteBuf.writeBoolean(recipe.showNotification()); } - - static { - PATTERN_CODEC = Codec.STRING.listOf().flatXmap((rows) -> { - if (rows.size() > 3) { - return DataResult.error(() -> { - return "Invalid pattern: too many rows, 3 is maximum"; - }); - } else if (rows.isEmpty()) { - return DataResult.error(() -> { - return "Invalid pattern: empty pattern not allowed"; - }); - } else { - int i = ((String) rows.get(0)).length(); - Iterator rowsIterator = rows.iterator(); - - String string; - do { - if (!rowsIterator.hasNext()) { - return DataResult.success(rows); - } - - string = rowsIterator.next(); - if (string.length() > 3) { - return DataResult.error(() -> { - return "Invalid pattern: too many columns, 3 is maximum"; - }); - } - } while (i == string.length()); - - return DataResult.error(() -> { - return "Invalid pattern: each row must be the same width"; - }); - } - }, DataResult::success); - KEY_ENTRY_CODEC = Codec.STRING.flatXmap((keyEntry) -> { - if (keyEntry.length() != 1) { - return DataResult.error(() -> { - return "Invalid key entry: '" + keyEntry + "' is an invalid symbol (must be 1 character only)."; - }); - } else { - return " ".equals(keyEntry) ? DataResult.error(() -> { - return "Invalid key entry: ' ' is a reserved symbol."; - }) : DataResult.success(keyEntry); - } - }, DataResult::success); - CODEC = ShapedRecipe.Serializer.RawShapedRecipe.CODEC.flatXmap((recipe) -> { - String[] strings = ReinforcedShulkerBoxCraftingRecipe.removePadding(recipe.pattern()); - int i = strings[0].length(); - int j = strings.length; - DefaultedList defaultedList = DefaultedList.ofSize(i * j, Ingredient.EMPTY); - Set set = Sets.newHashSet(recipe.key().keySet()); - - for (int k = 0; k < strings.length; ++k) { - String string = strings[k]; - - for (int l = 0; l < string.length(); ++l) { - String string2 = string.substring(l, l + 1); - Ingredient ingredient = string2.equals(" ") ? Ingredient.EMPTY - : (Ingredient) recipe.key().get(string2); - if (ingredient == null) { - return DataResult.error(() -> { - return "Pattern references symbol '" + string2 + "' but it's not defined in the key"; - }); - } - - set.remove(string2); - defaultedList.set(l + i * k, ingredient); - } - } - - if (!set.isEmpty()) { - return DataResult.error(() -> { - return "Key defines symbols that aren't used in pattern: " + set; - }); - } else { - ReinforcedShulkerBoxCraftingRecipe craftingRecipe = new ReinforcedShulkerBoxCraftingRecipe( - recipe.group(), recipe.category(), i, j, defaultedList, - recipe.result(), recipe.showNotification()); - return DataResult.success(craftingRecipe); - } - }, (recipe) -> { - throw new NotImplementedException( - "Serializing ReinforcedShulkerBoxCraftingRecipe is not implemented yet."); - }); - } } } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 34fd676..be1160f 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -37,12 +37,11 @@ "environment": "client" } ], - "accessWidener": "reinfshulker.accesswidener", "depends": { "fabricloader": ">=0.15.0", "fabric-api": "*", - "minecraft": "~1.20.2", + "minecraft": "~1.20.3", "java": ">=17" }, "suggests": { diff --git a/src/main/resources/reinfshulker.accesswidener b/src/main/resources/reinfshulker.accesswidener deleted file mode 100644 index c878c2f..0000000 --- a/src/main/resources/reinfshulker.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v2 named - -accessible class net/minecraft/recipe/ShapedRecipe$Serializer$RawShapedRecipe