1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-14 12:10:30 +00:00

ItemGroup info on getItemDetail (#1127)

This commit is contained in:
Luiz Krüger 2022-07-16 17:30:20 -03:00 committed by GitHub
parent bd5de11ad5
commit 969feb4a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import dan200.computercraft.shared.util.NBTUtil;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.EnchantedBookItem;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.INBT;
@ -67,6 +68,7 @@ public class ItemData
}
data.put( "tags", DataHelpers.getTags( stack.getItem().getTags() ) );
data.put( "itemGroups", getItemGroups( stack ) );
CompoundNBT tag = stack.getTag();
if( tag != null && tag.contains( "display", Constants.NBT.TAG_COMPOUND ) )
@ -116,6 +118,30 @@ public class ItemData
}
}
/**
* Retrieve all item groups an item stack pertains to.
*
* @param stack Stack to analyse
* @return A filled list that contains pairs of item group IDs and their display names.
*/
@Nonnull
private static List<Map<String, Object>> getItemGroups( @Nonnull ItemStack stack )
{
List<Map<String, Object>> groups = new ArrayList<>( 1 );
for( ItemGroup group : stack.getItem().getCreativeTabs() )
{
if( group == null ) continue;
Map<String, Object> groupData = new HashMap<>( 2 );
groupData.put( "id", group.langId );
groupData.put( "displayName", group.displayName.getString() );
groups.add( groupData );
}
return groups;
}
/**
* Retrieve all visible enchantments from given stack. Try to follow all tooltip rules : order and visibility.
*

View File

@ -107,7 +107,9 @@ public class InventoryMethods implements GenericPeripheral
*
* The returned information contains the same information as each item in
* {@link #list}, as well as additional details like the display name
* (`displayName`) and item durability (`damage`, `maxDamage`, `durability`).
* (`displayName`), item groups (`itemGroups`), which are the creative tabs
* an item will appear under, and item and item durability (`damage`,
* `maxDamage`, `durability`).
*
* Some items include more information (such as enchantments) - it is
* recommended to print it out using @{textutils.serialize} or in the Lua
@ -127,6 +129,11 @@ public class InventoryMethods implements GenericPeripheral
*
* print(("%s (%s)"):format(item.displayName, item.name))
* print(("Count: %d/%d"):format(item.count, item.maxCount))
*
* for _, group in pairs(item.itemGroups) do
* print(("Group: %s"):format(group.displayName))
* end
*
* if item.damage then
* print(("Damage: %d/%d"):format(item.damage, item.maxDamage))
* end

View File

@ -11,3 +11,7 @@ public net.minecraft.client.Minecraft field_71462_r # currentScreen
# SpeakerInstance/SpeakerManager
public net.minecraft.client.audio.SoundSource func_216421_a(I)V # pumpBuffers
public net.minecraft.client.audio.SoundEngine field_217940_j # executor
# ItemData
public net.minecraft.item.ItemGroup field_78034_o # langId
public net.minecraft.item.ItemGroup field_242391_q # displayName