mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-14 20:20:30 +00:00
ItemGroup info on getItemDetail (#1127)
This commit is contained in:
parent
bd5de11ad5
commit
969feb4a1c
@ -10,6 +10,7 @@ import dan200.computercraft.shared.util.NBTUtil;
|
|||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.EnchantmentHelper;
|
import net.minecraft.enchantment.EnchantmentHelper;
|
||||||
import net.minecraft.item.EnchantedBookItem;
|
import net.minecraft.item.EnchantedBookItem;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.CompoundNBT;
|
import net.minecraft.nbt.CompoundNBT;
|
||||||
import net.minecraft.nbt.INBT;
|
import net.minecraft.nbt.INBT;
|
||||||
@ -67,6 +68,7 @@ public class ItemData
|
|||||||
}
|
}
|
||||||
|
|
||||||
data.put( "tags", DataHelpers.getTags( stack.getItem().getTags() ) );
|
data.put( "tags", DataHelpers.getTags( stack.getItem().getTags() ) );
|
||||||
|
data.put( "itemGroups", getItemGroups( stack ) );
|
||||||
|
|
||||||
CompoundNBT tag = stack.getTag();
|
CompoundNBT tag = stack.getTag();
|
||||||
if( tag != null && tag.contains( "display", Constants.NBT.TAG_COMPOUND ) )
|
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.
|
* Retrieve all visible enchantments from given stack. Try to follow all tooltip rules : order and visibility.
|
||||||
*
|
*
|
||||||
|
@ -107,7 +107,9 @@ public class InventoryMethods implements GenericPeripheral
|
|||||||
*
|
*
|
||||||
* The returned information contains the same information as each item in
|
* The returned information contains the same information as each item in
|
||||||
* {@link #list}, as well as additional details like the display name
|
* {@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
|
* Some items include more information (such as enchantments) - it is
|
||||||
* recommended to print it out using @{textutils.serialize} or in the Lua
|
* 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(("%s (%s)"):format(item.displayName, item.name))
|
||||||
* print(("Count: %d/%d"):format(item.count, item.maxCount))
|
* 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
|
* if item.damage then
|
||||||
* print(("Damage: %d/%d"):format(item.damage, item.maxDamage))
|
* print(("Damage: %d/%d"):format(item.damage, item.maxDamage))
|
||||||
* end
|
* end
|
||||||
|
@ -11,3 +11,7 @@ public net.minecraft.client.Minecraft field_71462_r # currentScreen
|
|||||||
# SpeakerInstance/SpeakerManager
|
# SpeakerInstance/SpeakerManager
|
||||||
public net.minecraft.client.audio.SoundSource func_216421_a(I)V # pumpBuffers
|
public net.minecraft.client.audio.SoundSource func_216421_a(I)V # pumpBuffers
|
||||||
public net.minecraft.client.audio.SoundEngine field_217940_j # executor
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user