-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct the empty check for shulker boxes
- Loading branch information
1 parent
77565f5
commit d913084
Showing
1 changed file
with
5 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,17 @@ | ||
package carpetextra.utils; | ||
|
||
import net.minecraft.component.DataComponentTypes; | ||
import net.minecraft.component.type.NbtComponent; | ||
import net.minecraft.component.type.ContainerComponent; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.nbt.NbtElement; | ||
import net.minecraft.nbt.NbtList; | ||
|
||
public class InventoryUtils | ||
{ | ||
public class InventoryUtils { | ||
/** | ||
* Checks if the given Shulker Box (or other storage item with the | ||
* same NBT data structure) currently contains any items. | ||
* @return true if the item's stored inventory has any items | ||
*/ | ||
public static boolean shulkerBoxHasItems(ItemStack stackShulkerBox) | ||
{ | ||
NbtComponent nbtComponent = stackShulkerBox.get(DataComponentTypes.BLOCK_ENTITY_DATA); | ||
if (nbtComponent == null) | ||
return false; | ||
/* FIXME find a new way of doing this */ | ||
NbtCompound nbt = nbtComponent.getNbt(); | ||
|
||
if (nbt != null && nbt.contains("BlockEntityTag", NbtElement.COMPOUND_TYPE)) | ||
{ | ||
NbtCompound tag = nbt.getCompound("BlockEntityTag"); | ||
|
||
if (tag.contains("Items", NbtElement.LIST_TYPE)) | ||
{ | ||
NbtList tagList = tag.getList("Items", NbtElement.COMPOUND_TYPE); | ||
return !tagList.isEmpty(); | ||
} | ||
} | ||
|
||
return false; | ||
public static boolean shulkerBoxHasItems(ItemStack stackShulkerBox) { | ||
ContainerComponent containerComponent = stackShulkerBox.get(DataComponentTypes.CONTAINER); | ||
return containerComponent != null && !containerComponent.iterateNonEmpty().iterator().hasNext(); | ||
} | ||
} |