From 28fd5700e8a7df4dba0bc1bb03a2077366fd524e Mon Sep 17 00:00:00 2001 From: Patbox Date: Wed, 5 Jun 2024 09:01:36 +0200 Subject: [PATCH] Update to 1.21 --- gradle.properties | 12 +++---- .../elements/AnimatedGuiElementBuilder.java | 36 ++++++++++++++++--- .../sgui/api/elements/GuiElementBuilder.java | 36 ++++++++++++++++--- .../mixin/ServerPlayNetworkHandlerMixin.java | 2 +- .../java/eu/pb4/sgui/testmod/SGuiTest.java | 4 +-- 5 files changed, 73 insertions(+), 17 deletions(-) diff --git a/gradle.properties b/gradle.properties index 53304f3..7a0ff20 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,16 +3,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version=1.20.5 -yarn_mappings=1.20.5+build.1 -loader_version=0.15.10 +minecraft_version=1.21-pre2 +yarn_mappings=1.21-pre2+build.2 +loader_version=0.15.11 -#Fabric api -fabric_version=0.97.8+1.20.5 +# Fabric API +fabric_version=0.99.4+1.21 # Mod Properties -mod_version = 1.5.1+1.20.5 +mod_version = 1.6.0+1.21 maven_group = eu.pb4 archives_base_name = sgui diff --git a/src/main/java/eu/pb4/sgui/api/elements/AnimatedGuiElementBuilder.java b/src/main/java/eu/pb4/sgui/api/elements/AnimatedGuiElementBuilder.java index 3b43aa5..96f6fa4 100644 --- a/src/main/java/eu/pb4/sgui/api/elements/AnimatedGuiElementBuilder.java +++ b/src/main/java/eu/pb4/sgui/api/elements/AnimatedGuiElementBuilder.java @@ -4,7 +4,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTextures; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.minecraft.component.DataComponentType; +import net.minecraft.component.ComponentType; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.CustomModelDataComponent; import net.minecraft.component.type.LoreComponent; @@ -14,6 +14,10 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Text; import net.minecraft.util.Rarity; @@ -196,11 +200,11 @@ public AnimatedGuiElementBuilder noDefaults() { } @Nullable - public T getComponent(DataComponentType type) { + public T getComponent(ComponentType type) { return this.itemStack.get(type); } - public AnimatedGuiElementBuilder setComponent(DataComponentType type, @Nullable T value) { + public AnimatedGuiElementBuilder setComponent(ComponentType type, @Nullable T value) { this.itemStack.set(type, value); return this; } @@ -230,11 +234,35 @@ public AnimatedGuiElementBuilder hideDefaultTooltip() { * @param level the level of the specified enchantment * @return this element builder */ - public AnimatedGuiElementBuilder enchant(Enchantment enchantment, int level) { + public AnimatedGuiElementBuilder enchant(RegistryEntry enchantment, int level) { this.itemStack.addEnchantment(enchantment, level); return this; } + /** + * Give the element the specified enchantment. + * + * @param server MinecraftServer + * @param enchantment the enchantment to apply + * @param level the level of the specified enchantment + * @return this element builder + */ + public AnimatedGuiElementBuilder enchant(MinecraftServer server, RegistryKey enchantment, int level) { + return enchant(server.getRegistryManager(), enchantment, level); + } + + /** + * Give the element the specified enchantment. + * + * @param lookup WrapperLookup + * @param enchantment the enchantment to apply + * @param level the level of the specified enchantment + * @return this element builder + */ + public AnimatedGuiElementBuilder enchant(RegistryWrapper.WrapperLookup lookup, RegistryKey enchantment, int level) { + return enchant(lookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(enchantment), level); + } + /** * Sets the element to have an enchantment glint. * diff --git a/src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java b/src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java index 836f9c1..c098416 100644 --- a/src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java +++ b/src/main/java/eu/pb4/sgui/api/elements/GuiElementBuilder.java @@ -4,7 +4,7 @@ import com.mojang.authlib.minecraft.MinecraftProfileTextures; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; -import net.minecraft.component.DataComponentType; +import net.minecraft.component.ComponentType; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.CustomModelDataComponent; import net.minecraft.component.type.LoreComponent; @@ -14,6 +14,10 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.MinecraftServer; import net.minecraft.text.Text; import net.minecraft.util.Rarity; @@ -200,11 +204,11 @@ public GuiElementBuilder noDefaults() { } @Nullable - public T getComponent(DataComponentType type) { + public T getComponent(ComponentType type) { return this.itemStack.get(type); } - public GuiElementBuilder setComponent(DataComponentType type, @Nullable T value) { + public GuiElementBuilder setComponent(ComponentType type, @Nullable T value) { this.itemStack.set(type, value); return this; } @@ -243,11 +247,35 @@ public GuiElementBuilder hideTooltip() { * @param level the level of the specified enchantment * @return this element builder */ - public GuiElementBuilder enchant(Enchantment enchantment, int level) { + public GuiElementBuilder enchant(RegistryEntry enchantment, int level) { this.itemStack.addEnchantment(enchantment, level); return this; } + /** + * Give the element the specified enchantment. + * + * @param server MinecraftServer + * @param enchantment the enchantment to apply + * @param level the level of the specified enchantment + * @return this element builder + */ + public GuiElementBuilder enchant(MinecraftServer server, RegistryKey enchantment, int level) { + return enchant(server.getRegistryManager(), enchantment, level); + } + + /** + * Give the element the specified enchantment. + * + * @param lookup WrapperLookup + * @param enchantment the enchantment to apply + * @param level the level of the specified enchantment + * @return this element builder + */ + public GuiElementBuilder enchant(RegistryWrapper.WrapperLookup lookup, RegistryKey enchantment, int level) { + return enchant(lookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT).getOrThrow(enchantment), level); + } + /** * Sets the element to have an enchantment glint. * diff --git a/src/main/java/eu/pb4/sgui/mixin/ServerPlayNetworkHandlerMixin.java b/src/main/java/eu/pb4/sgui/mixin/ServerPlayNetworkHandlerMixin.java index 2a20c4e..3303d3d 100644 --- a/src/main/java/eu/pb4/sgui/mixin/ServerPlayNetworkHandlerMixin.java +++ b/src/main/java/eu/pb4/sgui/mixin/ServerPlayNetworkHandlerMixin.java @@ -181,7 +181,7 @@ public ServerPlayNetworkHandlerMixin(MinecraftServer server, ClientConnection co private void sgui$catchRecipeRequests(CraftRequestC2SPacket packet, CallbackInfo ci) { if (this.player.currentScreenHandler instanceof VirtualScreenHandler handler && handler.getGui() instanceof SimpleGui gui) { try { - gui.onCraftRequest(packet.getRecipe(), packet.shouldCraftAll()); + gui.onCraftRequest(packet.getRecipeId(), packet.shouldCraftAll()); } catch (Throwable e) { handler.getGui().handleException(e); } diff --git a/src/testmod/java/eu/pb4/sgui/testmod/SGuiTest.java b/src/testmod/java/eu/pb4/sgui/testmod/SGuiTest.java index 07a6a69..9037009 100644 --- a/src/testmod/java/eu/pb4/sgui/testmod/SGuiTest.java +++ b/src/testmod/java/eu/pb4/sgui/testmod/SGuiTest.java @@ -86,7 +86,7 @@ public boolean canPlayerClose() { .setItem(Items.NETHERITE_AXE).setDamage(150).saveItemStack() .setItem(Items.DIAMOND_AXE).setDamage(150).unbreakable().saveItemStack() .setItem(Items.GOLDEN_AXE).glow().saveItemStack() - .setItem(Items.IRON_AXE).enchant(Enchantments.AQUA_AFFINITY, 1).hideDefaultTooltip().saveItemStack() + .setItem(Items.IRON_AXE).enchant(objectCommandContext.getSource().getRegistryManager(), Enchantments.AQUA_AFFINITY, 1).hideDefaultTooltip().saveItemStack() .setItem(Items.STONE_AXE).noDefaults().saveItemStack() .setItem(Items.WOODEN_AXE).saveItemStack() .setInterval(10).setRandom(true) @@ -535,7 +535,7 @@ public boolean onSelectedSlotChange(int slot) { .setItem(Items.NETHERITE_AXE).setDamage(150).saveItemStack() .setItem(Items.DIAMOND_AXE).setDamage(150).unbreakable().saveItemStack() .setItem(Items.GOLDEN_AXE).glow().saveItemStack() - .setItem(Items.IRON_AXE).enchant(Enchantments.AQUA_AFFINITY, 1).saveItemStack() + .setItem(Items.IRON_AXE).enchant(objectCommandContext.getSource().getRegistryManager(), Enchantments.AQUA_AFFINITY, 1).saveItemStack() .setItem(Items.STONE_AXE).saveItemStack() .setItem(Items.WOODEN_AXE).saveItemStack() .setInterval(10).setRandom(true)