44 lines
1.4 KiB
Java
44 lines
1.4 KiB
Java
/*
|
|
* This file is part of ComputerCraft - http://www.computercraft.info
|
|
* Copyright Daniel Ratcliffe, 2011-2021. Do not distribute without permission.
|
|
* 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.Direction;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.world.World;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
public class TurtleDetectCommand implements ITurtleCommand
|
|
{
|
|
private final InteractDirection direction;
|
|
|
|
public TurtleDetectCommand( InteractDirection direction )
|
|
{
|
|
this.direction = direction;
|
|
}
|
|
|
|
@Nonnull
|
|
@Override
|
|
public TurtleCommandResult execute( @Nonnull ITurtleAccess turtle )
|
|
{
|
|
// Get world direction from direction
|
|
Direction direction = this.direction.toWorldDir( turtle );
|
|
|
|
// Check if thing in front is air or not
|
|
World world = turtle.getWorld();
|
|
BlockPos oldPosition = turtle.getPosition();
|
|
BlockPos newPosition = oldPosition.relative( direction );
|
|
|
|
return !WorldUtil.isLiquidBlock( world, newPosition ) && !world.isEmptyBlock( newPosition )
|
|
? TurtleCommandResult.success()
|
|
: TurtleCommandResult.failure();
|
|
}
|
|
}
|