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;
|
|
|
|
|
|
|
|
import com.google.common.base.Optional;
|
|
|
|
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;
|
|
|
|
import dan200.computercraft.core.apis.IAPIEnvironment;
|
|
|
|
import dan200.computercraft.core.apis.ILuaAPI;
|
|
|
|
import dan200.computercraft.shared.turtle.core.*;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
|
|
|
public void startup( )
|
|
|
|
{
|
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
|
2017-05-01 14:48:44 +00:00
|
|
|
@Override
|
|
|
|
public void advance( double _dt )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void shutdown( )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
int slot = parseOptionalSlotNumber( arguments, index, 99 );
|
|
|
|
if( slot == 99 )
|
|
|
|
{
|
|
|
|
throw new LuaException( "Expected number" );
|
|
|
|
}
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int parseOptionalSlotNumber( Object[] arguments, int index, int fallback ) throws LuaException
|
|
|
|
{
|
|
|
|
if( arguments.length <= index || !(arguments[index] instanceof Number) )
|
|
|
|
{
|
|
|
|
return fallback;
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
int slot = ((Number)arguments[index]).intValue();
|
|
|
|
if( slot >= 1 && slot <= 16 )
|
|
|
|
{
|
2017-05-01 13:32:39 +00:00
|
|
|
return slot - 1;
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
2017-05-01 13:32:39 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
throw new LuaException( "Slot number " + slot + " out of range" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private int parseCount( Object[] arguments, int index ) throws LuaException
|
|
|
|
{
|
|
|
|
if( arguments.length <= index || !(arguments[index] instanceof Number) )
|
2017-05-01 14:48:44 +00:00
|
|
|
{
|
|
|
|
throw new LuaException( "Expected number" );
|
|
|
|
}
|
|
|
|
int count = ((Number)arguments[index]).intValue();
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if( arguments.length <= index || arguments[index] == null )
|
|
|
|
{
|
|
|
|
return Optional.absent();
|
|
|
|
}
|
|
|
|
if( !(arguments[ index ] instanceof String) )
|
|
|
|
{
|
|
|
|
throw new LuaException( "Expected string" );
|
|
|
|
}
|
|
|
|
if( arguments[ index ].equals( "left" ) )
|
|
|
|
{
|
|
|
|
return Optional.of( TurtleSide.Left );
|
|
|
|
}
|
|
|
|
else if( arguments[ index ].equals( "right" ) )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Forward ) );
|
|
|
|
}
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// back
|
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
|
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Up ) );
|
|
|
|
}
|
|
|
|
case 3:
|
|
|
|
{
|
|
|
|
// down
|
|
|
|
return tryCommand( context, new TurtleMoveCommand( MoveDirection.Down ) );
|
|
|
|
}
|
|
|
|
case 4:
|
|
|
|
{
|
|
|
|
// turnLeft
|
|
|
|
return tryCommand( context, new TurtleTurnCommand( TurnDirection.Left ) );
|
|
|
|
}
|
|
|
|
case 5:
|
|
|
|
{
|
|
|
|
// turnRight
|
|
|
|
return tryCommand( context, new TurtleTurnCommand( TurnDirection.Right ) );
|
|
|
|
}
|
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
// dig
|
2017-05-01 13:32:39 +00:00
|
|
|
Optional<TurtleSide> side = parseSide( args, 0 );
|
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 );
|
|
|
|
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 );
|
|
|
|
return tryCommand( context, new TurtleDigCommand( InteractDirection.Down, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 9:
|
|
|
|
{
|
|
|
|
// place
|
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
|
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
|
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-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
2017-05-01 14:48:44 +00:00
|
|
|
count = parseCount( args, 0 );
|
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 );
|
|
|
|
if( stack != null )
|
|
|
|
{
|
|
|
|
return new Object[] { stack.stackSize };
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
if( stack != null )
|
|
|
|
{
|
|
|
|
return new Object[] {
|
|
|
|
Math.min( stack.getMaxStackSize(), 64 ) - stack.stackSize
|
|
|
|
};
|
|
|
|
}
|
|
|
|
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 );
|
|
|
|
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 );
|
|
|
|
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 );
|
|
|
|
return tryCommand( context, new TurtleAttackCommand( InteractDirection.Down, side ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 25:
|
|
|
|
{
|
|
|
|
// dropUp
|
2017-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
|
|
|
count = parseCount( args, 0 );
|
|
|
|
}
|
|
|
|
return tryCommand( context, new TurtleDropCommand( InteractDirection.Up, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 26:
|
|
|
|
{
|
|
|
|
// dropDown
|
2017-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
|
|
|
count = parseCount( args, 0 );
|
|
|
|
}
|
|
|
|
return tryCommand( context, new TurtleDropCommand( InteractDirection.Down, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 27:
|
|
|
|
{
|
|
|
|
// suck
|
2017-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
|
|
|
count = parseCount( args, 0 );
|
|
|
|
}
|
2017-05-01 14:48:44 +00:00
|
|
|
return tryCommand( context, new TurtleSuckCommand( InteractDirection.Forward, count ) );
|
|
|
|
}
|
|
|
|
case 28:
|
|
|
|
{
|
|
|
|
// suckUp
|
2017-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
|
|
|
count = parseCount( args, 0 );
|
|
|
|
}
|
|
|
|
return tryCommand( context, new TurtleSuckCommand( InteractDirection.Up, count ) );
|
2017-05-01 14:48:44 +00:00
|
|
|
}
|
|
|
|
case 29:
|
|
|
|
{
|
|
|
|
// suckDown
|
2017-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
|
|
|
count = parseCount( args, 0 );
|
|
|
|
}
|
|
|
|
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-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 0 )
|
|
|
|
{
|
|
|
|
count = parseCount( args, 0 );
|
|
|
|
}
|
|
|
|
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-05-01 13:32:39 +00:00
|
|
|
int count = 64;
|
|
|
|
if( args.length > 1 )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
return tryCommand( context, new TurtleEquipCommand( TurtleSide.Left ) );
|
|
|
|
}
|
|
|
|
case 37:
|
|
|
|
{
|
|
|
|
// equipRight
|
|
|
|
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 );
|
|
|
|
if( stack != null && stack.stackSize > 0 )
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
int count = stack.stackSize;
|
|
|
|
|
|
|
|
Map<Object, Object> table = new HashMap<Object, Object>();
|
|
|
|
table.put( "name", name );
|
|
|
|
table.put( "damage", damage );
|
|
|
|
table.put( "count", count );
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|