1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-07-01 01:23:30 +00:00

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
This commit is contained in:
SquidDev 2020-06-01 11:14:36 +01:00
parent 13de2c4dd0
commit b9b8121be9
2 changed files with 12 additions and 2 deletions

View File

@ -19,6 +19,7 @@
import dan200.computercraft.shared.turtle.core.*; import dan200.computercraft.shared.turtle.core.*;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
@ -31,8 +32,8 @@
public class TurtleAPI implements ILuaAPI public class TurtleAPI implements ILuaAPI
{ {
private IAPIEnvironment m_environment; private final IAPIEnvironment m_environment;
private ITurtleAccess m_turtle; private final ITurtleAccess m_turtle;
public TurtleAPI( IAPIEnvironment environment, ITurtleAccess turtle ) public TurtleAPI( IAPIEnvironment environment, ITurtleAccess turtle )
{ {
@ -351,6 +352,10 @@ public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull O
table.put( "name", name ); table.put( "name", name );
table.put( "count", count ); table.put( "count", count );
Map<String, Boolean> 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 ); TurtleActionEvent event = new TurtleInspectItemEvent( m_turtle, stack, table );
if( MinecraftForge.EVENT_BUS.post( event ) ) return new Object[] { false, event.getFailureMessage() }; if( MinecraftForge.EVENT_BUS.post( event ) ) return new Object[] { false, event.getFailureMessage() };

View File

@ -14,6 +14,7 @@
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.state.IProperty; import net.minecraft.state.IProperty;
import net.minecraft.util.Direction; import net.minecraft.util.Direction;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -64,6 +65,10 @@ public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
} }
table.put( "state", stateTable ); table.put( "state", stateTable );
Map<String, Boolean> 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 // Fire the event, exiting if it is cancelled
TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, oldPosition, direction ); TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, oldPosition, direction );
TurtleBlockEvent.Inspect event = new TurtleBlockEvent.Inspect( turtle, turtlePlayer, world, newPosition, state, table ); TurtleBlockEvent.Inspect event = new TurtleBlockEvent.Inspect( turtle, turtlePlayer, world, newPosition, state, table );