From 0140a8bcd89344c87b5af7663e32cedc0181a0f9 Mon Sep 17 00:00:00 2001 From: dags- Date: Sat, 6 Jun 2020 18:00:11 +0100 Subject: [PATCH] - add comments to Region - lookup surface y for searches --- .../java/com/terraforged/command/TerraCommand.java | 6 ++++-- .../terraforged/command/search/BiomeSearchTask.java | 7 +++++++ .../terraforged/command/search/BothSearchTask.java | 5 +++++ .../command/search/TerrainSearchTask.java | 12 +++++++++++- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/terraforged/command/TerraCommand.java b/src/main/java/com/terraforged/command/TerraCommand.java index de8677e..318b5e3 100644 --- a/src/main/java/com/terraforged/command/TerraCommand.java +++ b/src/main/java/com/terraforged/command/TerraCommand.java @@ -194,7 +194,8 @@ public class TerraCommand { UUID playerID = context.getSource().asPlayer().getUniqueID(); MinecraftServer server = context.getSource().getServer(); WorldGenerator worldGenerator = terraContext.factory.get(); - Search search = new TerrainSearchTask(pos, worldGenerator, target); + IWorldReader reader = context.getSource().asPlayer().getServerWorld(); + Search search = new TerrainSearchTask(pos, reader, worldGenerator, target); doSearch(server, playerID, search); context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); @@ -235,8 +236,9 @@ public class TerraCommand { UUID playerID = context.getSource().asPlayer().getUniqueID(); MinecraftServer server = context.getSource().getServer(); WorldGenerator worldGenerator = terraContext.factory.get(); + IWorldReader reader = context.getSource().asPlayer().getServerWorld(); Search biomeSearch = new BiomeSearchTask(pos, world, biome); - Search terrainSearch = new TerrainSearchTask(pos, worldGenerator, target); + Search terrainSearch = new TerrainSearchTask(pos, reader, worldGenerator, target); Search search = new BothSearchTask(pos, biomeSearch, terrainSearch); doSearch(server, playerID, search); context.getSource().sendFeedback(new StringTextComponent("Searching..."), false); diff --git a/src/main/java/com/terraforged/command/search/BiomeSearchTask.java b/src/main/java/com/terraforged/command/search/BiomeSearchTask.java index 7164ffe..58d8d84 100644 --- a/src/main/java/com/terraforged/command/search/BiomeSearchTask.java +++ b/src/main/java/com/terraforged/command/search/BiomeSearchTask.java @@ -3,6 +3,7 @@ package com.terraforged.command.search; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorldReader; import net.minecraft.world.biome.Biome; +import net.minecraft.world.gen.Heightmap; public class BiomeSearchTask extends Search { @@ -24,4 +25,10 @@ public class BiomeSearchTask extends Search { public boolean test(BlockPos pos) { return reader.getNoiseBiomeRaw(pos.getX() >> 2, pos.getY(), pos.getZ() >> 2) == biome; } + + @Override + public BlockPos success(BlockPos.Mutable pos) { + pos.setY(reader.getHeight(Heightmap.Type.MOTION_BLOCKING, pos.getX(), pos.getZ())); + return super.success(pos); + } } diff --git a/src/main/java/com/terraforged/command/search/BothSearchTask.java b/src/main/java/com/terraforged/command/search/BothSearchTask.java index 2e8acaf..b2fb6a9 100644 --- a/src/main/java/com/terraforged/command/search/BothSearchTask.java +++ b/src/main/java/com/terraforged/command/search/BothSearchTask.java @@ -24,4 +24,9 @@ public class BothSearchTask extends Search { public boolean test(BlockPos pos) { return a.test(pos) && b.test(pos); } + + @Override + public BlockPos success(BlockPos.Mutable pos) { + return a.success(pos); + } } diff --git a/src/main/java/com/terraforged/command/search/TerrainSearchTask.java b/src/main/java/com/terraforged/command/search/TerrainSearchTask.java index 1a7155e..d357917 100644 --- a/src/main/java/com/terraforged/command/search/TerrainSearchTask.java +++ b/src/main/java/com/terraforged/command/search/TerrainSearchTask.java @@ -4,17 +4,21 @@ import com.terraforged.core.cell.Cell; import com.terraforged.world.WorldGenerator; import com.terraforged.world.terrain.Terrain; import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IWorldReader; +import net.minecraft.world.gen.Heightmap; public class TerrainSearchTask extends Search { private final Terrain type; + private final IWorldReader reader; private final WorldGenerator generator; private final Cell cell = new Cell(); - public TerrainSearchTask(BlockPos center, WorldGenerator generator, Terrain type) { + public TerrainSearchTask(BlockPos center, IWorldReader reader, WorldGenerator generator, Terrain type) { super(center, 256); this.type = type; this.generator = generator; + this.reader = reader; } @Override @@ -27,4 +31,10 @@ public class TerrainSearchTask extends Search { generator.getHeightmap().apply(cell, pos.getX(), pos.getZ()); return cell.terrain == type; } + + @Override + public BlockPos success(BlockPos.Mutable pos) { + pos.setY(reader.getHeight(Heightmap.Type.MOTION_BLOCKING, pos.getX(), pos.getZ())); + return super.success(pos); + } }