mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-08-29 00:32:18 +00:00
Re-implement turtle.getItemDetails() detailed mode
Incomplete - Missing item "tags", otherwise fully functional. - Fixes #41
This commit is contained in:
parent
3ba7acc414
commit
ca69d755e6
@ -7,14 +7,19 @@ package dan200.computercraft.shared.peripheral.generic.data;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import dan200.computercraft.shared.util.NBTUtil;
|
||||
import net.fabricmc.fabric.api.tag.TagRegistry;
|
||||
import net.fabricmc.fabric.impl.tag.extension.TagDelegate;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.item.EnchantedBookItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -51,7 +56,7 @@ public class ItemData
|
||||
|
||||
fillBasic( data, stack );
|
||||
|
||||
data.put( "displayName", stack.toHoverableText().getString() );
|
||||
data.put( "displayName", stack.getName().getString() );
|
||||
data.put( "maxCount", stack.getMaxCount() );
|
||||
|
||||
if( stack.isDamageable() )
|
||||
@ -81,6 +86,8 @@ public class ItemData
|
||||
data.put( "unbreakable", true );
|
||||
}
|
||||
|
||||
// data.put("tags", DataHelpers.getTags( ??? ));
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import dan200.computercraft.api.turtle.event.TurtleInspectItemEvent;
|
||||
import dan200.computercraft.core.apis.IAPIEnvironment;
|
||||
import dan200.computercraft.core.asm.TaskCallback;
|
||||
import dan200.computercraft.core.tracking.TrackingField;
|
||||
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
|
||||
import dan200.computercraft.shared.turtle.core.InteractDirection;
|
||||
import dan200.computercraft.shared.turtle.core.MoveDirection;
|
||||
import dan200.computercraft.shared.turtle.core.TurnDirection;
|
||||
@ -724,13 +725,9 @@ public class TurtleAPI implements ILuaAPI {
|
||||
return new Object[] {null};
|
||||
}
|
||||
|
||||
Item item = stack.getItem();
|
||||
String name = Registry.ITEM.getId(item)
|
||||
.toString();
|
||||
int count = stack.getCount();
|
||||
Map<String, Object> table = new HashMap<>();
|
||||
table.put("name", name);
|
||||
table.put("count", count);
|
||||
Map<String, Object> table = detailed
|
||||
? ItemData.fill( new HashMap<>(), stack )
|
||||
: ItemData.fillBasicSafe( new HashMap<>(), stack );
|
||||
|
||||
TurtleActionEvent event = new TurtleInspectItemEvent(this.turtle, stack, table, detailed);
|
||||
if (TurtleEvent.post(event)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user