Skip to content

Commit

Permalink
Prevent turtles moving beyond the world border
Browse files Browse the repository at this point in the history
As tiles outside the world border are not ticked, turtles are rendered
entirely useless. Furthermore, the turtle animation will never progress
resulting in visual glitches.

In order to avoid this, we ensure the target position is within the
world border when moving to it.
  • Loading branch information
SquidDev committed Feb 12, 2018
1 parent 3b3dd80 commit 94e10d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Expand Up @@ -496,10 +496,11 @@ public boolean teleportTo( @Nonnull World world, @Nonnull BlockPos pos )
return true; return true;
} }


if ( !world.isBlockLoaded( pos ) ) // Ensure the chunk is loaded
{ if( !world.isBlockLoaded( pos ) ) return false;
return false;
} // Ensure we're inside the world border
if( !world.getWorldBorder().contains( pos ) ) return false;


oldOwner.notifyMoveStart(); oldOwner.notifyMoveStart();


Expand Down
Expand Up @@ -14,9 +14,9 @@
import dan200.computercraft.shared.util.WorldUtil; import dan200.computercraft.shared.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World; import net.minecraft.world.World;


import javax.annotation.Nonnull; import javax.annotation.Nonnull;
Expand Down Expand Up @@ -170,6 +170,10 @@ else if( position.getY() > world.getHeight() - 1 )
{ {
return TurtleCommandResult.failure( "Cannot leave loaded world" ); return TurtleCommandResult.failure( "Cannot leave loaded world" );
} }
if( !world.getWorldBorder().contains( position ) )
{
return TurtleCommandResult.failure( "Cannot pass the world border" );
}
return TurtleCommandResult.success(); return TurtleCommandResult.success();
} }
} }

0 comments on commit 94e10d1

Please sign in to comment.