- add comments to Region

- lookup surface y for searches
This commit is contained in:
dags- 2020-06-06 18:00:11 +01:00
parent 9c3a05c8d7
commit 0140a8bcd8
4 changed files with 27 additions and 3 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}