mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-03 14:01:58 +01:00
Merge remote-tracking branch 'upstream/master'
# Conflicts: # src/main/java/net/minestom/server/entity/Player.java
This commit is contained in:
commit
bdab9bf71f
@ -1,14 +1,16 @@
|
||||
package fr.themode.demo.commands;
|
||||
|
||||
import fr.themode.demo.generator.ChunkGeneratorDemo;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.CommandProcessor;
|
||||
import net.minestom.server.entity.EntityCreature;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.world.Dimension;
|
||||
|
||||
public class SimpleCommand implements CommandProcessor {
|
||||
@Override
|
||||
public String getCommandName() {
|
||||
return "follow";
|
||||
return "test";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,9 +24,15 @@ public class SimpleCommand implements CommandProcessor {
|
||||
|
||||
Instance instance = player.getInstance();
|
||||
|
||||
for (EntityCreature creature : instance.getCreatures()) {
|
||||
/*for (EntityCreature creature : instance.getCreatures()) {
|
||||
creature.setPathTo(player.getPosition());
|
||||
}
|
||||
}*/
|
||||
|
||||
Instance inst = MinecraftServer.getInstanceManager().createInstanceContainer(Dimension.NETHER);
|
||||
inst.enableAutoChunkLoad(true);
|
||||
inst.setChunkGenerator(new ChunkGeneratorDemo());
|
||||
|
||||
player.setInstance(inst);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class ChunkGeneratorDemo extends ChunkGenerator {
|
||||
if (random.nextInt(100) > 10) {
|
||||
batch.setCustomBlock(x, y, z, "custom_block");
|
||||
} else {
|
||||
batch.setBlock(x, y, z, Block.COMMAND_BLOCK);
|
||||
batch.setBlock(x, y, z, Block.DIAMOND_BLOCK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -350,6 +350,12 @@ public class Player extends LivingEntity {
|
||||
}
|
||||
viewableChunks.clear();
|
||||
|
||||
if (this.instance != null) {
|
||||
Dimension instanceDimension = instance.getDimension();
|
||||
if (dimension != instanceDimension)
|
||||
sendDimension(instanceDimension);
|
||||
}
|
||||
|
||||
long[] visibleChunks = ChunkUtils.getChunksInRange(position, getChunkRange());
|
||||
int length = visibleChunks.length;
|
||||
|
||||
@ -659,7 +665,8 @@ public class Player extends LivingEntity {
|
||||
return gameMode == GameMode.CREATIVE;
|
||||
}
|
||||
|
||||
public void setDimension(Dimension dimension) {
|
||||
// Require sending chunk data after
|
||||
public void sendDimension(Dimension dimension) {
|
||||
if (dimension == null)
|
||||
throw new IllegalArgumentException("Dimension cannot be null!");
|
||||
if (dimension.equals(getDimension()))
|
||||
|
@ -113,7 +113,7 @@ public class AStarPathfinder {
|
||||
Block targetBlock = Block.fromId(instance.getBlockId(target));
|
||||
Block belowBlock = Block.fromId(instance.getBlockId(target.clone().add(0, -1, 0)));
|
||||
|
||||
boolean result = targetBlock.isAir() && belowBlock.isSolid();
|
||||
boolean result = !targetBlock.isSolid() && belowBlock.isSolid();
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -138,7 +138,6 @@ public class AStarPathfinder {
|
||||
private static boolean isShorter(Node neighbor, Node current) {
|
||||
return getTentativeGScore(neighbor, current) < neighbor.g;
|
||||
}
|
||||
|
||||
private static LinkedList<BlockPosition> buildPath(Node finalNode) {
|
||||
LinkedList<BlockPosition> result = new LinkedList<>();
|
||||
Node cache = finalNode;
|
||||
@ -146,25 +145,26 @@ public class AStarPathfinder {
|
||||
result.add(cache.blockPosition);
|
||||
cache = cache.parent;
|
||||
}
|
||||
// Make the list start->end
|
||||
Collections.reverse(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class Node {
|
||||
public int g, h, f;
|
||||
public int g, f;
|
||||
public Node parent;
|
||||
private int x, y, z;
|
||||
private BlockPosition blockPosition;
|
||||
|
||||
public Node(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.blockPosition = new BlockPosition(x, y, z);
|
||||
public Node(BlockPosition blockPosition) {
|
||||
this.x = blockPosition.getX();
|
||||
this.y = blockPosition.getY();
|
||||
this.z = blockPosition.getZ();
|
||||
this.blockPosition = blockPosition.clone();
|
||||
}
|
||||
|
||||
public static Node fromBlockPosition(BlockPosition blockPosition) {
|
||||
Node node = new Node(blockPosition.getX(), blockPosition.getY(), blockPosition.getZ());
|
||||
Node node = new Node(blockPosition);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||
import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.ChunkUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.world.Dimension;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@ -28,6 +29,8 @@ public abstract class Instance implements BlockModifier, DataContainer {
|
||||
protected static final ChunkLoaderIO CHUNK_LOADER_IO = new ChunkLoaderIO();
|
||||
protected static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager();
|
||||
|
||||
private Dimension dimension;
|
||||
|
||||
// Entities present in this instance
|
||||
protected Set<Player> players = new CopyOnWriteArraySet<>();
|
||||
protected Set<EntityCreature> creatures = new CopyOnWriteArraySet<>();
|
||||
@ -39,8 +42,9 @@ public abstract class Instance implements BlockModifier, DataContainer {
|
||||
|
||||
private Data data;
|
||||
|
||||
protected Instance(UUID uniqueId) {
|
||||
protected Instance(UUID uniqueId, Dimension dimension) {
|
||||
this.uniqueId = uniqueId;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
public abstract void refreshBlockId(int x, int y, int z, short blockId);
|
||||
@ -123,6 +127,11 @@ public abstract class Instance implements BlockModifier, DataContainer {
|
||||
}
|
||||
//
|
||||
|
||||
|
||||
public Dimension getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
public Set<Player> getPlayers() {
|
||||
return Collections.unmodifiableSet(players);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import net.minestom.server.utils.BlockPosition;
|
||||
import net.minestom.server.utils.ChunkUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.SerializerUtils;
|
||||
import net.minestom.server.world.Dimension;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
@ -39,8 +40,8 @@ public class InstanceContainer extends Instance {
|
||||
|
||||
private boolean autoChunkLoad;
|
||||
|
||||
protected InstanceContainer(UUID uniqueId, File folder) {
|
||||
super(uniqueId);
|
||||
protected InstanceContainer(UUID uniqueId, Dimension dimension, File folder) {
|
||||
super(uniqueId, dimension);
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package net.minestom.server.instance;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.utils.thread.MinestomThread;
|
||||
import net.minestom.server.world.Dimension;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
@ -16,17 +17,21 @@ public class InstanceManager {
|
||||
|
||||
private Set<Instance> instances = Collections.synchronizedSet(new HashSet<>());
|
||||
|
||||
public InstanceContainer createInstanceContainer(File folder) {
|
||||
public InstanceContainer createInstanceContainer(Dimension dimension, File folder) {
|
||||
if (folder != null && !folder.exists())
|
||||
folder.mkdir();
|
||||
|
||||
InstanceContainer instance = new InstanceContainer(UUID.randomUUID(), folder);
|
||||
InstanceContainer instance = new InstanceContainer(UUID.randomUUID(), dimension, folder);
|
||||
this.instances.add(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public InstanceContainer createInstanceContainer(Dimension dimension) {
|
||||
return createInstanceContainer(dimension, null);
|
||||
}
|
||||
|
||||
public InstanceContainer createInstanceContainer() {
|
||||
return createInstanceContainer(null);
|
||||
return createInstanceContainer(Dimension.OVERWORLD);
|
||||
}
|
||||
|
||||
public SharedInstance createSharedInstance(InstanceContainer instanceContainer) {
|
||||
|
@ -20,7 +20,7 @@ public class SharedInstance extends Instance {
|
||||
private InstanceContainer instanceContainer;
|
||||
|
||||
protected SharedInstance(UUID uniqueId, InstanceContainer instanceContainer) {
|
||||
super(uniqueId);
|
||||
super(uniqueId, instanceContainer.getDimension());
|
||||
this.instanceContainer = instanceContainer;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user