2017-05-07 00:18:59 +00:00
|
|
|
/*
|
2017-05-01 13:32:39 +00:00
|
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
2017-05-13 18:20:39 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2017. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.shared.turtle.apis;
|
|
|
|
|
2017-11-18 13:40:38 +00:00
|
|
|
import dan200.computercraft.api.lua.ILuaAPI;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.api.lua.ILuaContext;
|
|
|
|
import dan200.computercraft.api.lua.LuaException;
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
|
|
import dan200.computercraft.api.turtle.TurtleSide;
|
2018-02-16 10:33:32 +00:00
|
|
|
import dan200.computercraft.api.turtle.event.TurtleAction;
|
|
|
|
import dan200.computercraft.api.turtle.event.TurtleActionEvent;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
2018-04-17 08:22:26 +00:00
|
|
|
import dan200.computercraft.core.tracking.TrackingField;
|
2017-05-01 13:32:39 +00:00
|
|
|
import dan200.computercraft.shared.turtle.core.*;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2018-02-16 10:33:32 +00:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
2017-05-01 13:32:39 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
2017-06-12 20:08:35 +00:00
|
|
|
import java.util.Optional;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-06-12 09:28:31 +00:00
|
|
|
import static dan200.computercraft.core.apis.ArgumentHelper.*;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public class TurtleAPI implements ILuaAPI
|
|
|
|
{
|
|
|
|
private IAPIEnvironment m_environment;
|
2017-05-01 14:48:44 +00:00
|
|
|
private ITurtleAccess m_turtle;
|
2017-05-01 13:32:39 +00:00
|
|
|
|
|
|
|
public TurtleAPI( IAPIEnvironment environment, ITurtleAccess turtle )
|
|
|
|
{
|
|
|
|
m_environment = environment;
|
2017-05-01 14:48:44 +00:00
|
|
|
m_turtle = turtle;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
// ILuaAPI implementation
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
2017-05-01 13:32:39 +00:00
|
|
|
public String[] getNames()
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return new String[] {
|
|
|
|
"turtle"
|
|
|
|
};
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
2017-05-01 13:32:39 +00:00
|
|
|
public String[] getMethodNames()
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return new String[] {
|
|
|
|
"forward",
|
|
|
|
"back",
|
|
|
|
"up",
|
|
|
|
"down",
|
|
|
|
"turnLeft",
|
|
|
|
"turnRight",
|
|
|
|
"dig",
|
|
|
|
"digUp",
|
|
|
|
"digDown",
|
|
|
|
"place",
|
|
|
|
"placeUp",
|
|
|
|
"placeDown",
|
|
|
|
"drop",
|
|
|
|
"select",
|
|
|
|
"getItemCount",
|
|
|
|
"getItemSpace",
|
|
|
|
"detect",
|
|
|
|
"detectUp",
|
|
|
|
"detectDown",
|
|
|
|
"compare",
|
|
|
|
"compareUp",
|
|
|
|
"compareDown",
|
|
|
|
"attack",
|
|
|
|
"attackUp",
|
|
|
|
"attackDown",
|
|
|
|
"dropUp",
|
|
|
|
"dropDown",
|
|
|
|
"suck",
|
|
|
|
"suckUp",
|
|
|
|
"suckDown",
|
|
|
|
"getFuelLevel",
|
|
|
|
"refuel",
|
|
|
|
"compareTo",
|
|
|
|
"transferTo",
|
2017-05-01 13:32:39 +00:00
|
|
|
"getSelectedSlot",
|
|
|
|
"getFuelLimit",
|
|
|
|
"equipLeft",
|
|
|
|
"equipRight",
|
|
|
|
"inspect",
|
|
|
|
"inspectUp",
|
|
|
|
"inspectDown",
|
|
|
|
"getItemDetail",
|
2017-05-01 14:48:44 +00:00
|
|
|
};
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private Object[] tryCommand( ILuaContext context, ITurtleCommand command ) throws LuaException, InterruptedException
|
|
|
|
{
|
|
|
|
return m_turtle.executeCommand( context, command );
|
|
|
|
}
|
|
|
|
|
|
|
|
private int parseSlotNumber( Object[] arguments, int index ) throws LuaException
|
|
|
|
{
|
2017-06-12 09:28:31 +00:00
|
|
|
int slot = getInt( arguments, index );
|
|
|
|
if( slot < 1 || slot > 16 ) throw new LuaException( "Slot number " + slot + " out of range" );
|
|
|
|
return slot - 1;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private int parseOptionalSlotNumber( Object[] arguments, int index, int fallback ) throws LuaException
|
|
|
|
{
|
2018-12-23 17:46:58 +00:00
|
|
|
if( index >= arguments.length || arguments[index] == null ) return fallback;
|
2017-06-12 09:28:31 +00:00
|
|
|
|
|
|
|
int slot = getInt( arguments, index );
|
|
|
|
if( slot < 1 || slot > 16 ) throw new LuaException( "Slot number " + slot + " out of range" );
|
|
|
|
return slot - 1;
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2018-12-23 17:46:58 +00:00
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
private int parseCount( Object[] arguments, int index ) throws LuaException
|
|
|
|
{
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = optInt( arguments, index, 64 );
|
2017-05-01 14:48:44 +00:00
|
|
|
if( count >= 0 && count <= 64 )
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
return count;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new LuaException( "Item count " + count + " out of range" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Optional<TurtleSide> parseSide( Object[] arguments, int index ) throws LuaException
|
|
|
|
{
|
2017-06-12 09:28:31 +00:00
|
|
|
String side = optString( arguments, index, null );
|
|
|
|
if( side == null )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-06-12 20:08:35 +00:00
|
|
|
return Optional.empty();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-06-12 09:28:31 +00:00
|
|
|
else if( side.equalsIgnoreCase( "left" ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return Optional.of( TurtleSide.Left );
|
|
|
|
}
|
2017-06-12 09:28:31 +00:00
|
|
|
else if( side.equalsIgnoreCase( "right" ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return Optional.of( TurtleSide.Right );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new LuaException( "Invalid side" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public Object[] callMethod( @Nonnull ILuaContext context, int method, @Nonnull Object[] args ) throws LuaException, InterruptedException
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
switch( method )
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
// forward
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Forward ) );
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// back
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Back ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
// up
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Up ) );
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
// down
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Down ) );
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
// turnLeft
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleTurnCommand( TurnDirection.Left ) );
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
// turnRight
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleTurnCommand( TurnDirection.Right ) );
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
// dig
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleDigCommand( InteractDirection.Forward, side ) );
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
// digUp
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDigCommand( InteractDirection.Up, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
// digDown
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDigCommand( InteractDirection.Down, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
// place
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtlePlaceCommand( InteractDirection.Forward, args ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 10:
|
|
|
|
{
|
|
|
|
// placeUp
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtlePlaceCommand( InteractDirection.Up, args ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 11:
|
|
|
|
{
|
|
|
|
// placeDown
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtlePlaceCommand( InteractDirection.Down, args ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 12:
|
|
|
|
{
|
|
|
|
// drop
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDropCommand( InteractDirection.Forward, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 13:
|
|
|
|
{
|
|
|
|
// select
|
|
|
|
int slot = parseSlotNumber( args, 0 );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleSelectCommand( slot ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 14:
|
|
|
|
{
|
|
|
|
// getItemCount
|
|
|
|
int slot = parseOptionalSlotNumber( args, 0, m_turtle.getSelectedSlot() );
|
2017-05-01 13:32:39 +00:00
|
|
|
ItemStack stack = m_turtle.getInventory().getStackInSlot( slot );
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !stack.isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2017-05-11 00:08:26 +00:00
|
|
|
return new Object[] { stack.getCount() };
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new Object[] { 0 };
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 15:
|
|
|
|
{
|
|
|
|
// getItemSpace
|
2017-05-01 13:32:39 +00:00
|
|
|
int slot = parseOptionalSlotNumber( args, 0, m_turtle.getSelectedSlot() );
|
|
|
|
ItemStack stack = m_turtle.getInventory().getStackInSlot( slot );
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !stack.isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
return new Object[] {
|
2017-05-11 00:08:26 +00:00
|
|
|
Math.min( stack.getMaxStackSize(), 64 ) - stack.getCount()
|
2017-05-01 13:32:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
return new Object[] { 64 };
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 16:
|
|
|
|
{
|
|
|
|
// detect
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDetectCommand( InteractDirection.Forward ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 17:
|
|
|
|
{
|
|
|
|
// detectUp
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDetectCommand( InteractDirection.Up ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 18:
|
|
|
|
{
|
|
|
|
// detectDown
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDetectCommand( InteractDirection.Down ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 19:
|
|
|
|
{
|
|
|
|
// compare
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleCompareCommand( InteractDirection.Forward ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 20:
|
|
|
|
{
|
|
|
|
// compareUp
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleCompareCommand( InteractDirection.Up ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 21:
|
|
|
|
{
|
|
|
|
// compareDown
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleCompareCommand( InteractDirection.Down ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 22:
|
|
|
|
{
|
|
|
|
// attack
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleAttackCommand( InteractDirection.Forward, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 23:
|
|
|
|
{
|
|
|
|
// attackUp
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleAttackCommand( InteractDirection.Up, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 24:
|
|
|
|
{
|
|
|
|
// attackDown
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleAttackCommand( InteractDirection.Down, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 25:
|
|
|
|
{
|
|
|
|
// dropUp
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDropCommand( InteractDirection.Up, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 26:
|
|
|
|
{
|
|
|
|
// dropDown
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleDropCommand( InteractDirection.Down, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 27:
|
|
|
|
{
|
|
|
|
// suck
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleSuckCommand( InteractDirection.Forward, count ) );
|
|
|
|
}
|
|
|
|
case 28:
|
|
|
|
{
|
|
|
|
// suckUp
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleSuckCommand( InteractDirection.Up, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 29:
|
|
|
|
{
|
|
|
|
// suckDown
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleSuckCommand( InteractDirection.Down, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 30:
|
|
|
|
{
|
|
|
|
// getFuelLevel
|
|
|
|
if( m_turtle.isFuelNeeded() )
|
|
|
|
{
|
|
|
|
return new Object[] { m_turtle.getFuelLevel() };
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
else
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
return new Object[] { "unlimited" };
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 31:
|
|
|
|
{
|
|
|
|
// refuel
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 0 );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleRefuelCommand( count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 32:
|
|
|
|
{
|
|
|
|
// compareTo
|
|
|
|
int slot = parseSlotNumber( args, 0 );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleCompareToCommand( slot ) );
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
case 33:
|
|
|
|
{
|
|
|
|
// transferTo
|
|
|
|
int slot = parseSlotNumber( args, 0 );
|
2017-06-12 09:28:31 +00:00
|
|
|
int count = parseCount( args, 1 );
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleTransferToCommand( slot, count ) );
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
case 34:
|
|
|
|
{
|
|
|
|
// getSelectedSlot
|
|
|
|
return new Object[] { m_turtle.getSelectedSlot() + 1 };
|
|
|
|
}
|
|
|
|
case 35:
|
|
|
|
{
|
|
|
|
// getFuelLimit
|
|
|
|
if( m_turtle.isFuelNeeded() )
|
|
|
|
{
|
|
|
|
return new Object[] { m_turtle.getFuelLimit() };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new Object[] { "unlimited" };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case 36:
|
|
|
|
{
|
|
|
|
// equipLeft
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleEquipCommand( TurtleSide.Left ) );
|
|
|
|
}
|
|
|
|
case 37:
|
|
|
|
{
|
|
|
|
// equipRight
|
2018-04-17 08:22:26 +00:00
|
|
|
m_environment.addTrackingChange( TrackingField.TURTLE_OPS );
|
2017-05-01 13:32:39 +00:00
|
|
|
return tryCommand( context, new TurtleEquipCommand( TurtleSide.Right ) );
|
|
|
|
}
|
|
|
|
case 38:
|
|
|
|
{
|
|
|
|
// inspect
|
|
|
|
return tryCommand( context, new TurtleInspectCommand( InteractDirection.Forward ) );
|
|
|
|
}
|
|
|
|
case 39:
|
|
|
|
{
|
|
|
|
// inspectUp
|
|
|
|
return tryCommand( context, new TurtleInspectCommand( InteractDirection.Up ) );
|
|
|
|
}
|
|
|
|
case 40:
|
|
|
|
{
|
|
|
|
// inspectDown
|
|
|
|
return tryCommand( context, new TurtleInspectCommand( InteractDirection.Down ) );
|
|
|
|
}
|
|
|
|
case 41:
|
|
|
|
{
|
|
|
|
// getItemDetail
|
|
|
|
int slot = parseOptionalSlotNumber( args, 0, m_turtle.getSelectedSlot() );
|
|
|
|
ItemStack stack = m_turtle.getInventory().getStackInSlot( slot );
|
2017-05-11 00:08:26 +00:00
|
|
|
if( !stack.isEmpty() )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
Item item = stack.getItem();
|
2017-05-06 23:42:00 +00:00
|
|
|
String name = Item.REGISTRY.getNameForObject( item ).toString();
|
2017-05-01 13:32:39 +00:00
|
|
|
int damage = stack.getItemDamage();
|
2017-05-11 00:08:26 +00:00
|
|
|
int count = stack.getCount();
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-06-12 20:08:35 +00:00
|
|
|
Map<Object, Object> table = new HashMap<>();
|
2017-05-01 13:32:39 +00:00
|
|
|
table.put( "name", name );
|
|
|
|
table.put( "damage", damage );
|
|
|
|
table.put( "count", count );
|
2018-02-16 10:33:32 +00:00
|
|
|
|
|
|
|
TurtleActionEvent event = new TurtleActionEvent( m_turtle, TurtleAction.INSPECT_ITEM );
|
|
|
|
if( MinecraftForge.EVENT_BUS.post( event ) )
|
|
|
|
{
|
|
|
|
return new Object[] { false, event.getFailureMessage() };
|
|
|
|
}
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
return new Object[] { table };
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return new Object[] { null };
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
}
|