mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Update
This commit is contained in:
parent
cb194db4c0
commit
656ccac26d
@ -38,4 +38,7 @@ dependencies {
|
||||
|
||||
compile 'com.github.TheMode:CommandBuilder:611d16a487'
|
||||
|
||||
// https://mvnrepository.com/artifact/javax.vecmath/vecmath
|
||||
compile group: 'javax.vecmath', name: 'vecmath', version: '1.5.2' // Used for Fastnoise
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.themode.demo;
|
||||
|
||||
import fr.themode.demo.generator.ChunkGeneratorDemo;
|
||||
import fr.themode.demo.generator.NoiseTestGenerator;
|
||||
import fr.themode.minestom.MinecraftServer;
|
||||
import fr.themode.minestom.benchmark.BenchmarkManager;
|
||||
import fr.themode.minestom.entity.Entity;
|
||||
@ -27,18 +28,19 @@ public class PlayerInit {
|
||||
|
||||
static {
|
||||
ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo();
|
||||
NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator();
|
||||
//instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(new File("chunk_data"));
|
||||
instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer();
|
||||
instanceContainer.enableAutoChunkLoad(true);
|
||||
instanceContainer.setChunkGenerator(chunkGeneratorDemo);
|
||||
instanceContainer.setChunkGenerator(noiseTestGenerator);
|
||||
|
||||
// Load some chunks beforehand
|
||||
int loopStart = -2;
|
||||
int loopEnd = 2;
|
||||
long time = System.currentTimeMillis();
|
||||
for (int x = loopStart; x < loopEnd; x++)
|
||||
for (int z = loopStart; z < loopEnd; z++) {
|
||||
instanceContainer.loadChunk(x, z);
|
||||
}
|
||||
System.out.println("Time to load all chunks: " + (System.currentTimeMillis() - time) + " ms");
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
@ -127,8 +129,8 @@ public class PlayerInit {
|
||||
});
|
||||
|
||||
player.setEventCallback(PlayerSpawnEvent.class, event -> {
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
player.teleport(new Position(0, 66, 0));
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
player.teleport(new Position(0, 75, 0));
|
||||
|
||||
/*Random random = new Random();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
|
@ -0,0 +1,41 @@
|
||||
package fr.themode.demo.generator;
|
||||
|
||||
import fr.themode.minestom.instance.Biome;
|
||||
import fr.themode.minestom.instance.ChunkGenerator;
|
||||
import fr.themode.minestom.instance.batch.ChunkBatch;
|
||||
import fr.themode.minestom.utils.noise.FastNoise;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class NoiseTestGenerator extends ChunkGenerator {
|
||||
|
||||
private Random random = new Random();
|
||||
private FastNoise fastNoise = new FastNoise();
|
||||
private int totalChunk = 15;
|
||||
|
||||
{
|
||||
fastNoise.SetNoiseType(FastNoise.NoiseType.Simplex);
|
||||
fastNoise.SetInterp(FastNoise.Interp.Linear);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateChunkData(ChunkBatch batch, int chunkX, int chunkZ) {
|
||||
for (byte x = 0; x < 16; x++)
|
||||
for (byte z = 0; z < 16; z++) {
|
||||
float height = fastNoise.GetSimplex(x + 16 * chunkX, z + 16 * chunkZ) * 135;
|
||||
height = Math.max(height, 70);
|
||||
for (byte y = 0; y < height; y++) {
|
||||
if (random.nextInt(100) > 10) {
|
||||
batch.setCustomBlock(x, y, z, "custom_block");
|
||||
} else {
|
||||
batch.setBlock(x, y, z, (short) 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(int chunkX, int chunkZ) {
|
||||
return Biome.PLAINS;
|
||||
}
|
||||
}
|
@ -54,8 +54,8 @@ public class MinecraftServer {
|
||||
public static final int THREAD_COUNT_SCHEDULER = 1;
|
||||
|
||||
// Config
|
||||
public static final int CHUNK_VIEW_DISTANCE = 5;
|
||||
public static final int ENTITY_VIEW_DISTANCE = 2;
|
||||
public static final int CHUNK_VIEW_DISTANCE = 10;
|
||||
public static final int ENTITY_VIEW_DISTANCE = 5;
|
||||
// Can be modified at performance cost when decreased
|
||||
private static final int MS_TO_SEC = 1000;
|
||||
public static final int TICK_MS = MS_TO_SEC / 20;
|
||||
|
@ -886,9 +886,9 @@ public class Player extends LivingEntity {
|
||||
int serverRange = MinecraftServer.CHUNK_VIEW_DISTANCE;
|
||||
int playerRange = getSettings().viewDistance;
|
||||
if (playerRange == 0) {
|
||||
return serverRange; // Didn't receive settings packet yet
|
||||
return serverRange; // Didn't receive settings packet yet (is the case on login)
|
||||
} else {
|
||||
return playerRange < serverRange ? playerRange : serverRange;
|
||||
return Math.min(playerRange, serverRange);
|
||||
}
|
||||
}
|
||||
|
||||
@ -901,6 +901,8 @@ public class Player extends LivingEntity {
|
||||
OFF
|
||||
}
|
||||
|
||||
// Settings enum
|
||||
|
||||
public enum MainHand {
|
||||
LEFT,
|
||||
RIGHT
|
||||
|
@ -141,11 +141,17 @@ public abstract class Instance implements BlockModifier, DataContainer {
|
||||
}
|
||||
|
||||
public void loadChunk(Position position, Consumer<Chunk> callback) {
|
||||
int chunkX = Math.floorDiv((int) position.getX(), 16);
|
||||
int chunkZ = Math.floorDiv((int) position.getY(), 16);
|
||||
int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX());
|
||||
int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ());
|
||||
loadChunk(chunkX, chunkZ, callback);
|
||||
}
|
||||
|
||||
public void loadOptionalChunk(Position position, Consumer<Chunk> callback) {
|
||||
int chunkX = ChunkUtils.getChunkCoordinate((int) position.getX());
|
||||
int chunkZ = ChunkUtils.getChunkCoordinate((int) position.getZ());
|
||||
loadOptionalChunk(chunkX, chunkZ, callback);
|
||||
}
|
||||
|
||||
public short getBlockId(int x, int y, int z) {
|
||||
Chunk chunk = getChunkAt(x, z);
|
||||
return chunk.getBlockId((byte) (x % 16), (byte) y, (byte) (z % 16));
|
||||
|
@ -35,7 +35,7 @@ public class InstanceContainer extends Instance {
|
||||
private ChunkGenerator chunkGenerator;
|
||||
private Map<Long, Chunk> chunks = new ConcurrentHashMap<>();
|
||||
|
||||
private boolean autoChunkLoad;
|
||||
private volatile boolean autoChunkLoad;
|
||||
|
||||
protected InstanceContainer(UUID uniqueId, File folder) {
|
||||
super(uniqueId);
|
||||
@ -207,6 +207,7 @@ public class InstanceContainer extends Instance {
|
||||
@Override
|
||||
public void loadOptionalChunk(int chunkX, int chunkZ, Consumer<Chunk> callback) {
|
||||
Chunk chunk = getChunk(chunkX, chunkZ);
|
||||
System.out.println("test load: " + chunk + " : " + hasEnabledAutoChunkLoad());
|
||||
if (chunk != null) {
|
||||
if (callback != null)
|
||||
callback.accept(chunk);
|
||||
|
@ -46,6 +46,8 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
connectionManager.createPlayer(playerUuid, username, connection);
|
||||
Player player = connectionManager.getPlayer(connection);
|
||||
|
||||
MinecraftServer.getEntityManager().addWaitingPlayer(player);
|
||||
|
||||
GameMode gameMode = GameMode.SURVIVAL;
|
||||
Dimension dimension = Dimension.OVERWORLD;
|
||||
LevelType levelType = LevelType.DEFAULT;
|
||||
@ -94,8 +96,6 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
if (playerInitialization != null)
|
||||
playerInitialization.accept(player);
|
||||
|
||||
MinecraftServer.getEntityManager().addWaitingPlayer(player);
|
||||
|
||||
|
||||
{
|
||||
CommandManager commandManager = MinecraftServer.getCommandManager();
|
||||
|
2184
src/main/java/fr/themode/minestom/utils/noise/FastNoise.java
Normal file
2184
src/main/java/fr/themode/minestom/utils/noise/FastNoise.java
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user