From cdd9dc6d17bcead180b9dfefc1c05e5f50b16060 Mon Sep 17 00:00:00 2001 From: MegumiKasuga <1926195023@qq.com> Date: Thu, 3 Oct 2024 12:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E4=B8=80=E9=83=A8?= =?UTF-8?q?=E5=88=86ItemReg=E5=92=8CItemProperties=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E4=BA=86Crafting=20Remainder=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E4=BC=9A=E5=AF=BC=E8=87=B4=E6=B8=B8=E6=88=8F=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=AD=A3=E5=B8=B8=E5=90=AF=E5=8A=A8=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/item_helper/ExternalProperties.java | 28 +++++++++++++ .../ExternalRemainderBlockItem.java | 41 +++++++++++++++++++ .../item_helper/ExternalRemainderItem.java | 39 ++++++++++++++++++ .../registrations/common/BucketItemReg.java | 3 +- .../lib/registrations/common/ItemReg.java | 3 +- 5 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 src/main/java/kasuga/lib/core/base/item_helper/ExternalProperties.java create mode 100644 src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderBlockItem.java create mode 100644 src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderItem.java diff --git a/src/main/java/kasuga/lib/core/base/item_helper/ExternalProperties.java b/src/main/java/kasuga/lib/core/base/item_helper/ExternalProperties.java new file mode 100644 index 00000000..cfed9302 --- /dev/null +++ b/src/main/java/kasuga/lib/core/base/item_helper/ExternalProperties.java @@ -0,0 +1,28 @@ +package kasuga.lib.core.base.item_helper; + +import net.minecraft.world.item.Item; + +import javax.annotation.Nonnull; +import java.util.function.Supplier; + +public class ExternalProperties extends Item.Properties { + + @Nonnull + Supplier craftingRemainderItem = () -> null; + + public ExternalProperties craftRemainder(Supplier craftingReminderItem) { + this.craftingRemainderItem = craftingReminderItem; + return this; + } + + /** + * Don't use, use {@link ExternalProperties#craftRemainder(Supplier)} instead. + * @param pCraftingRemainingItem Don't use. + * @return self. + */ + @Deprecated + @Override + public Item.Properties craftRemainder(Item pCraftingRemainingItem) { + return this; + } +} diff --git a/src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderBlockItem.java b/src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderBlockItem.java new file mode 100644 index 00000000..97b9765e --- /dev/null +++ b/src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderBlockItem.java @@ -0,0 +1,41 @@ +package kasuga.lib.core.base.item_helper; + +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.Block; + +import javax.annotation.Nonnull; +import java.util.function.Supplier; + +public class ExternalRemainderBlockItem extends BlockItem { + + @Nonnull + private final Supplier craftingRemainder; + public ExternalRemainderBlockItem(Block pBlock, Properties pProperties) { + super(pBlock, pProperties); + if (pProperties instanceof ExternalProperties externalProperties) + craftingRemainder = externalProperties.craftingRemainderItem; + else + craftingRemainder = () -> null; + } + + @Nonnull + public Supplier getCraftingRemainder() { + return craftingRemainder; + } + + @Override + public boolean hasCraftingRemainingItem(ItemStack stack) { + return super.hasCraftingRemainingItem(stack) || craftingRemainder.get() != null; + } + + @Override + public ItemStack getCraftingRemainingItem(ItemStack itemStack) { + ItemStack remain = super.getCraftingRemainingItem(itemStack); + if (remain == ItemStack.EMPTY && craftingRemainder.get() != null) { + remain = craftingRemainder.get().getDefaultInstance(); + } + return remain; + } +} diff --git a/src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderItem.java b/src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderItem.java new file mode 100644 index 00000000..4f79b057 --- /dev/null +++ b/src/main/java/kasuga/lib/core/base/item_helper/ExternalRemainderItem.java @@ -0,0 +1,39 @@ +package kasuga.lib.core.base.item_helper; + +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; + +import javax.annotation.Nonnull; +import java.util.function.Supplier; + +public class ExternalRemainderItem extends Item { + + @Nonnull + private final Supplier craftingRemainder; + public ExternalRemainderItem(Properties pProperties) { + super(pProperties); + if (pProperties instanceof ExternalProperties externalProperties) + craftingRemainder = externalProperties.craftingRemainderItem; + else + craftingRemainder = () -> null; + } + + @Nonnull + public Supplier getCraftingRemainder() { + return craftingRemainder; + } + + @Override + public boolean hasCraftingRemainingItem(ItemStack stack) { + return super.hasCraftingRemainingItem(stack) || craftingRemainder.get() != null; + } + + @Override + public ItemStack getCraftingRemainingItem(ItemStack itemStack) { + ItemStack remain = super.getCraftingRemainingItem(itemStack); + if (remain == ItemStack.EMPTY && craftingRemainder.get() != null) { + remain = craftingRemainder.get().getDefaultInstance(); + } + return remain; + } +} diff --git a/src/main/java/kasuga/lib/registrations/common/BucketItemReg.java b/src/main/java/kasuga/lib/registrations/common/BucketItemReg.java index 51f492c1..3ceaa4e1 100644 --- a/src/main/java/kasuga/lib/registrations/common/BucketItemReg.java +++ b/src/main/java/kasuga/lib/registrations/common/BucketItemReg.java @@ -1,6 +1,7 @@ package kasuga.lib.registrations.common; import kasuga.lib.core.annos.Mandatory; +import kasuga.lib.core.base.item_helper.ExternalProperties; import kasuga.lib.registrations.Reg; import kasuga.lib.registrations.registry.SimpleRegistry; import net.minecraft.client.gui.screens.MenuScreens; @@ -33,7 +34,7 @@ public class BucketItemReg extends ItemReg { private boolean customRender = false; private BucketBuilder builder; - public final Item.Properties properties = new Item.Properties(); + public final Item.Properties properties = new ExternalProperties(); private RegistryObject registryObject = null; private MenuReg menuReg = null; private Supplier fluid = null; diff --git a/src/main/java/kasuga/lib/registrations/common/ItemReg.java b/src/main/java/kasuga/lib/registrations/common/ItemReg.java index a5207174..4d7ef682 100644 --- a/src/main/java/kasuga/lib/registrations/common/ItemReg.java +++ b/src/main/java/kasuga/lib/registrations/common/ItemReg.java @@ -2,6 +2,7 @@ import kasuga.lib.core.annos.Mandatory; import kasuga.lib.core.annos.Optional; +import kasuga.lib.core.base.item_helper.ExternalProperties; import kasuga.lib.registrations.Reg; import kasuga.lib.registrations.registry.SimpleRegistry; import net.minecraft.client.gui.screens.MenuScreens; @@ -30,7 +31,7 @@ public class ItemReg extends Reg { private boolean customRender = false; private ItemBuilder builder; - public final Item.Properties properties = new Item.Properties(); + public final Item.Properties properties = new ExternalProperties(); private RegistryObject registryObject = null; private MenuReg menuReg = null; private final List> tags;