mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add stack-aware CraftingRemainingItem (#277)
* Add stack-aware CraftingRemainingItem * Add JavaDocs [norelease]
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package dev.architectury.hooks.item;
|
package dev.architectury.hooks.item;
|
||||||
|
|
||||||
|
import dev.architectury.injectables.annotations.ExpectPlatform;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
import net.minecraft.sounds.SoundSource;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user