From 146fe8b8b91863d77ebb983af66624c8681ac666 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 16 Jun 2022 17:58:10 +0800 Subject: [PATCH 1/2] Add stack-aware CraftingRemainingItem (#277) * Add stack-aware CraftingRemainingItem * Add JavaDocs [norelease] --- .../hooks/item/ItemStackHooks.java | 25 +++++++++++++ .../hooks/item/fabric/ItemStackHooksImpl.java | 36 +++++++++++++++++++ .../hooks/item/forge/ItemStackHooksImpl.java | 32 +++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 fabric/src/main/java/dev/architectury/hooks/item/fabric/ItemStackHooksImpl.java create mode 100644 forge/src/main/java/dev/architectury/hooks/item/forge/ItemStackHooksImpl.java diff --git a/common/src/main/java/dev/architectury/hooks/item/ItemStackHooks.java b/common/src/main/java/dev/architectury/hooks/item/ItemStackHooks.java index 5f50428c..d5d6b37c 100644 --- a/common/src/main/java/dev/architectury/hooks/item/ItemStackHooks.java +++ b/common/src/main/java/dev/architectury/hooks/item/ItemStackHooks.java @@ -19,6 +19,7 @@ package dev.architectury.hooks.item; +import dev.architectury.injectables.annotations.ExpectPlatform; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; @@ -53,4 +54,28 @@ public final class ItemStackHooks { } } } + + /** + * Returns whether the given item stack has a remaining item after crafting. + * This method is stack-aware only on Forge. + * + * @param stack the item stack + * @return whether the given item stack has a remaining item after crafting + */ + @ExpectPlatform + public static boolean hasCraftingRemainingItem(ItemStack stack) { + throw new AssertionError(); + } + + /** + * Returns the remaining item for a given item stack after crafting. + * This method is stack-aware only on Forge. + * + * @param stack the item stack + * @return the remaining item for a given item stack after crafting + */ + @ExpectPlatform + public static ItemStack getCraftingRemainingItem(ItemStack stack) { + throw new AssertionError(); + } } diff --git a/fabric/src/main/java/dev/architectury/hooks/item/fabric/ItemStackHooksImpl.java b/fabric/src/main/java/dev/architectury/hooks/item/fabric/ItemStackHooksImpl.java new file mode 100644 index 00000000..ec578e02 --- /dev/null +++ b/fabric/src/main/java/dev/architectury/hooks/item/fabric/ItemStackHooksImpl.java @@ -0,0 +1,36 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package dev.architectury.hooks.item.fabric; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; + +public class ItemStackHooksImpl { + public static boolean hasCraftingRemainingItem(ItemStack stack) { + return stack.getItem().hasCraftingRemainingItem(); + } + + public static ItemStack getCraftingRemainingItem(ItemStack stack) { + if (!hasCraftingRemainingItem(stack)) return ItemStack.EMPTY; + Item item = stack.getItem().getCraftingRemainingItem(); + return item == null || item == Items.AIR ? ItemStack.EMPTY : item.getDefaultInstance(); + } +} diff --git a/forge/src/main/java/dev/architectury/hooks/item/forge/ItemStackHooksImpl.java b/forge/src/main/java/dev/architectury/hooks/item/forge/ItemStackHooksImpl.java new file mode 100644 index 00000000..ea30294e --- /dev/null +++ b/forge/src/main/java/dev/architectury/hooks/item/forge/ItemStackHooksImpl.java @@ -0,0 +1,32 @@ +/* + * This file is part of architectury. + * Copyright (C) 2020, 2021, 2022 architectury + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package dev.architectury.hooks.item.forge; + +import net.minecraft.world.item.ItemStack; + +public class ItemStackHooksImpl { + public static boolean hasCraftingRemainingItem(ItemStack stack) { + return stack.hasContainerItem(); + } + + public static ItemStack getCraftingRemainingItem(ItemStack stack) { + return stack.getContainerItem(); + } +} From 4f17a84f1eb19ab417ae93812274d4eab9f1d946 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 16 Jun 2022 12:02:58 +0200 Subject: [PATCH 2/2] Apply LQF for better decompilation, bump version for release --- build.gradle | 2 ++ gradle.properties | 2 +- settings.gradle | 1 - 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 110affba..c9ceabb5 100644 --- a/build.gradle +++ b/build.gradle @@ -10,6 +10,7 @@ plugins { id "architectury-plugin" version "3.4-SNAPSHOT" id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false id "org.cadixdev.licenser" version "0.6.1" + id "io.github.juuxel.loom-quiltflower" version "1.7.2" apply false id "me.shedaniel.unified-publishing" version "0.1.+" apply false id "maven-publish" } @@ -20,6 +21,7 @@ architectury { subprojects { apply plugin: "dev.architectury.loom" + apply plugin: "io.github.juuxel.loom-quiltflower" loom { silentMojangMappingsLicense() diff --git a/gradle.properties b/gradle.properties index e18df335..b57ee11d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ artifact_type=release archives_base_name=architectury archives_base_name_snapshot=architectury-snapshot -base_version=4.4 +base_version=4.5 maven_group=dev.architectury fabric_loader_version=0.13.3 diff --git a/settings.gradle b/settings.gradle index 938c20fb..8bfde812 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,7 +3,6 @@ pluginManagement { maven { url "https://maven.fabricmc.net/" } maven { url "https://maven.architectury.dev/" } maven { url "https://files.minecraftforge.net/maven/" } - maven { url "https://server.bbkr.space/artifactory/libs-release/" } gradlePluginPortal() } }