improve test gen

This commit is contained in:
Eoghanmc22 2020-08-20 12:39:09 -04:00
parent c16b716350
commit 56cace9402
3 changed files with 45 additions and 25 deletions

View File

@ -271,8 +271,8 @@ public class PlayerInit {
}); });
player.addEventCallback(PlayerSpawnEvent.class, event -> { player.addEventCallback(PlayerSpawnEvent.class, event -> {
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.CREATIVE);
player.teleport(new Position(0, 41f, 0)); player.teleport(new Position(0, 73f, 0));
//player.setHeldItemSlot((byte) 5); //player.setHeldItemSlot((byte) 5);

View File

@ -2,7 +2,6 @@ package fr.themode.demo.generator;
import de.articdive.jnoise.JNoise; import de.articdive.jnoise.JNoise;
import de.articdive.jnoise.interpolation.InterpolationType; import de.articdive.jnoise.interpolation.InterpolationType;
import lombok.Data;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.ChunkGenerator; import net.minestom.server.instance.ChunkGenerator;
@ -37,9 +36,18 @@ public class NoiseTestGenerator extends ChunkGenerator {
//} else { //} else {
// batch.setBlock(x, y, z, Block.GOLD_BLOCK); // batch.setBlock(x, y, z, Block.GOLD_BLOCK);
//} //}
batch.setBlock(x, y, z, Block.GRASS_BLOCK); if (y == 0) {
batch.setBlock(x, y, z, Block.BEDROCK);
} else if (y == height-1) {
batch.setBlock(x, y, z, Block.GRASS_BLOCK);
} else if (y > height-7) {
batch.setBlock(x, y, z, Block.DIRT);
} else {
batch.setBlock(x, y, z, Block.STONE);
}
} }
if (height < 61) { if (height < 61) {
batch.setBlock(x, height-1, z, Block.DIRT);
for (int y = 0; y < 61 - height; y++) { for (int y = 0; y < 61 - height; y++) {
batch.setBlock(x, y + height, z, Block.WATER); batch.setBlock(x, y + height, z, Block.WATER);
} }
@ -60,33 +68,13 @@ public class NoiseTestGenerator extends ChunkGenerator {
return list; return list;
} }
@Data
public static class Structure {
private final Map<BlockPosition, Block> blocks = new HashMap<>();
public void build(ChunkBatch batch, BlockPosition pos) {
blocks.forEach((bPos, block) -> {
if (bPos.getX() + pos.getX() >= Chunk.CHUNK_SIZE_X || bPos.getX() + pos.getX() < 0)
return;
if (bPos.getZ() + pos.getZ() >= Chunk.CHUNK_SIZE_Z || bPos.getZ() + pos.getZ() < 0)
return;
batch.setBlock(bPos.clone().add(pos), block);
});
}
public void addBlock(Block block, int localX, int localY, int localZ) {
blocks.put(new BlockPosition(localX, localY, localZ), block);
}
}
private class TreePopulator implements ChunkPopulator { private class TreePopulator implements ChunkPopulator {
final Structure tree; final Structure tree;
public TreePopulator() { public TreePopulator() {
tree = new Structure(); tree = new Structure();
tree.addBlock(Block.DIRT, 0, -1, 0);
tree.addBlock(Block.OAK_LOG, 0, 0, 0); tree.addBlock(Block.OAK_LOG, 0, 0, 0);
tree.addBlock(Block.OAK_LOG, 0, 1, 0); tree.addBlock(Block.OAK_LOG, 0, 1, 0);
tree.addBlock(Block.OAK_LOG, 0, 2, 0); tree.addBlock(Block.OAK_LOG, 0, 2, 0);
@ -171,6 +159,7 @@ public class NoiseTestGenerator extends ChunkGenerator {
tree.addBlock(Block.OAK_LEAVES, -1, 4, -1); tree.addBlock(Block.OAK_LEAVES, -1, 4, -1);
} }
//todo improve
@Override @Override
public void populateChunk(ChunkBatch batch, Chunk chunk) { public void populateChunk(ChunkBatch batch, Chunk chunk) {
for (int i = -2; i < 18; i++) { for (int i = -2; i < 18; i++) {

View File

@ -0,0 +1,31 @@
package fr.themode.demo.generator;
import lombok.Data;
import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.batch.ChunkBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.utils.BlockPosition;
import java.util.HashMap;
import java.util.Map;
@Data
public class Structure {
private final Map<BlockPosition, Block> blocks = new HashMap<>();
public void build(ChunkBatch batch, BlockPosition pos) {
blocks.forEach((bPos, block) -> {
if (bPos.getX() + pos.getX() >= Chunk.CHUNK_SIZE_X || bPos.getX() + pos.getX() < 0)
return;
if (bPos.getZ() + pos.getZ() >= Chunk.CHUNK_SIZE_Z || bPos.getZ() + pos.getZ() < 0)
return;
batch.setBlock(bPos.clone().add(pos), block);
});
}
public void addBlock(Block block, int localX, int localY, int localZ) {
blocks.put(new BlockPosition(localX, localY, localZ), block);
}
}