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
|
2019-01-01 01:10:18 +00:00
|
|
|
* Copyright Daniel Ratcliffe, 2011-2019. Do not distribute without permission.
|
2017-05-01 13:32:39 +00:00
|
|
|
* Send enquiries to dratcliffe@gmail.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
package dan200.computercraft.shared.turtle.core;
|
|
|
|
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleAccess;
|
|
|
|
import dan200.computercraft.api.turtle.ITurtleCommand;
|
|
|
|
import dan200.computercraft.api.turtle.TurtleCommandResult;
|
|
|
|
import dan200.computercraft.shared.util.WorldUtil;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
2018-12-23 17:46:58 +00:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2017-05-01 13:32:39 +00:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2017-05-01 13:32:39 +00:00
|
|
|
public class TurtleDetectCommand implements ITurtleCommand
|
|
|
|
{
|
|
|
|
private final InteractDirection m_direction;
|
|
|
|
|
|
|
|
public TurtleDetectCommand( InteractDirection direction )
|
|
|
|
{
|
|
|
|
m_direction = direction;
|
|
|
|
}
|
|
|
|
|
2017-05-06 23:07:42 +00:00
|
|
|
@Nonnull
|
2017-05-01 13:32:39 +00:00
|
|
|
@Override
|
2017-05-06 23:07:42 +00:00
|
|
|
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
|
|
|
// Get world direction from direction
|
|
|
|
EnumFacing direction = m_direction.toWorldDir( turtle );
|
|
|
|
|
|
|
|
// Check if thing in front is air or not
|
|
|
|
World world = turtle.getWorld();
|
|
|
|
BlockPos oldPosition = turtle.getPosition();
|
|
|
|
BlockPos newPosition = oldPosition.offset( direction );
|
|
|
|
|
2018-12-26 10:28:32 +00:00
|
|
|
if( !WorldUtil.isLiquidBlock( world, newPosition ) && !world.isAirBlock( newPosition ) )
|
2017-05-01 13:32:39 +00:00
|
|
|
{
|
2018-12-26 10:28:32 +00:00
|
|
|
return TurtleCommandResult.success();
|
2017-05-01 13:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TurtleCommandResult.failure();
|
|
|
|
}
|
|
|
|
}
|