mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-10-31 23:26:19 +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:
parent
13de2c4dd0
commit
b9b8121be9
@ -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<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 );
|
||||
if( MinecraftForge.EVENT_BUS.post( event ) ) return new Object[] { false, event.getFailureMessage() };
|
||||
|
||||
|
@ -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<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
|
||||
TurtlePlayer turtlePlayer = TurtlePlaceCommand.createPlayer( turtle, oldPosition, direction );
|
||||
TurtleBlockEvent.Inspect event = new TurtleBlockEvent.Inspect( turtle, turtlePlayer, world, newPosition, state, table );
|
||||
|
Loading…
Reference in New Issue
Block a user