From b9b8121be907394797eb310bd0d23a16a956e36c Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 1 Jun 2020 11:14:36 +0100 Subject: [PATCH] Expose tags for turtle.{inspect,getItemDetail} This is simply exposed as a table from tag -> true. While this is less natural than an array, it allows for easy esting of whether a tag is present. Closes #461 --- .../computercraft/shared/turtle/apis/TurtleAPI.java | 9 +++++++-- .../shared/turtle/core/TurtleInspectCommand.java | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java index bb43c34e1..21e84199c 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java +++ b/src/main/java/dan200/computercraft/shared/turtle/apis/TurtleAPI.java @@ -19,6 +19,7 @@ import dan200.computercraft.core.tracking.TrackingField; import dan200.computercraft.shared.turtle.core.*; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.registries.ForgeRegistries; @@ -31,8 +32,8 @@ import static dan200.computercraft.api.lua.ArgumentHelper.*; public class TurtleAPI implements ILuaAPI { - private IAPIEnvironment m_environment; - private ITurtleAccess m_turtle; + private final IAPIEnvironment m_environment; + private final ITurtleAccess m_turtle; public TurtleAPI( IAPIEnvironment environment, ITurtleAccess turtle ) { @@ -351,6 +352,10 @@ public class TurtleAPI implements ILuaAPI table.put( "name", name ); table.put( "count", count ); + Map tags = new HashMap<>(); + for( ResourceLocation location : item.getTags() ) tags.put( location.toString(), true ); + table.put( "tags", tags ); + TurtleActionEvent event = new TurtleInspectItemEvent( m_turtle, stack, table ); if( MinecraftForge.EVENT_BUS.post( event ) ) return new Object[] { false, event.getFailureMessage() }; diff --git a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java index e45d9ba58..baa1ea966 100644 --- a/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java +++ b/src/main/java/dan200/computercraft/shared/turtle/core/TurtleInspectCommand.java @@ -14,6 +14,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.state.IProperty; import net.minecraft.util.Direction; +import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.common.MinecraftForge; @@ -64,6 +65,10 @@ public class TurtleInspectCommand implements ITurtleCommand } table.put( "state", stateTable ); + Map tags = new HashMap<>(); + for( ResourceLocation location : block.getTags() ) tags.put( location.toString(), true ); + table.put( "tags", tags ); + // Fire the event, exiting if it is cancelled TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, oldPosition, direction ); TurtleBlockEvent.Inspect event = new TurtleBlockEvent.Inspect( turtle, turtlePlayer, world, newPosition, state, table );