Small demo code update

This commit is contained in:
Felix Cravic 2020-12-06 20:20:05 +01:00
parent 07990b26e9
commit 40787902e3
4 changed files with 34 additions and 34 deletions

View File

@ -4,13 +4,11 @@ import demo.blocks.BurningTorchBlock;
import demo.blocks.StoneBlock; import demo.blocks.StoneBlock;
import demo.blocks.UpdatableBlockDemo; import demo.blocks.UpdatableBlockDemo;
import demo.commands.*; import demo.commands.*;
import io.netty.handler.traffic.GlobalChannelTrafficShapingHandler;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandManager; import net.minestom.server.command.CommandManager;
import net.minestom.server.extras.optifine.OptifineSupport; import net.minestom.server.extras.optifine.OptifineSupport;
import net.minestom.server.instance.block.BlockManager; import net.minestom.server.instance.block.BlockManager;
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule; import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
import net.minestom.server.network.netty.NettyServer;
import net.minestom.server.storage.StorageManager; import net.minestom.server.storage.StorageManager;
import net.minestom.server.storage.systems.FileStorageSystem; import net.minestom.server.storage.systems.FileStorageSystem;
import net.minestom.server.utils.time.TimeUnit; import net.minestom.server.utils.time.TimeUnit;
@ -20,17 +18,9 @@ import net.minestom.server.utils.time.UpdateOption;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
//System.setProperty("io.netty.leakDetection.targetRecords", "10");
//ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID);
MinecraftServer minecraftServer = MinecraftServer.init(); MinecraftServer minecraftServer = MinecraftServer.init();
MinecraftServer.setShouldProcessNettyErrors(false); // MinecraftServer.setShouldProcessNettyErrors(true);
final NettyServer nettyServer = MinecraftServer.getNettyServer();
final GlobalChannelTrafficShapingHandler trafficHandler = nettyServer.getGlobalTrafficHandler();
trafficHandler.setReadChannelLimit(500_000);
trafficHandler.setReadLimit(500_000);
BlockManager blockManager = MinecraftServer.getBlockManager(); BlockManager blockManager = MinecraftServer.getBlockManager();
blockManager.registerCustomBlock(new StoneBlock()); blockManager.registerCustomBlock(new StoneBlock());
@ -71,7 +61,7 @@ public class Main {
minecraftServer.start("0.0.0.0", 25565, PlayerInit.getResponseDataConsumer()); minecraftServer.start("0.0.0.0", 25565, PlayerInit.getResponseDataConsumer());
Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly)); //Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly));
} }
} }

View File

@ -17,6 +17,7 @@ import net.minestom.server.event.player.*;
import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.Instance; import net.minestom.server.instance.Instance;
import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.InstanceContainer;
import net.minestom.server.instance.InstanceManager;
import net.minestom.server.instance.block.Block; import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.CustomBlock; import net.minestom.server.instance.block.CustomBlock;
import net.minestom.server.inventory.Inventory; import net.minestom.server.inventory.Inventory;
@ -42,12 +43,13 @@ public class PlayerInit {
private static final Inventory inventory; private static final Inventory inventory;
static { static {
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
//StorageLocation storageLocation = MinecraftServer.getStorageManager().getLocation("instance_data", new StorageOptions().setCompression(true)); //StorageLocation storageLocation = MinecraftServer.getStorageManager().getLocation("instance_data", new StorageOptions().setCompression(true));
ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo(); ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo();
NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator(); NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator();
instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD); instanceContainer = instanceManager.createInstanceContainer(DimensionType.OVERWORLD);
instanceContainer.enableAutoChunkLoad(true); instanceContainer.enableAutoChunkLoad(true);
instanceContainer.setChunkGenerator(noiseTestGenerator); instanceContainer.setChunkGenerator(chunkGeneratorDemo);
// Load some chunks beforehand // Load some chunks beforehand
final int loopStart = -10; final int loopStart = -10;
@ -105,9 +107,9 @@ public class PlayerInit {
final Entity entity = event.getTarget(); final Entity entity = event.getTarget();
if (entity instanceof EntityCreature) { if (entity instanceof EntityCreature) {
EntityCreature creature = (EntityCreature) entity; EntityCreature creature = (EntityCreature) entity;
creature.damage(DamageType.fromPlayer(player), -1); creature.damage(DamageType.fromPlayer(player), 0);
Vector velocity = player.getPosition().copy().getDirection().multiply(6); Vector velocity = player.getPosition().copy().getDirection().multiply(3);
velocity.setY(4f); velocity.setY(3f);
entity.setVelocity(velocity); entity.setVelocity(velocity);
player.sendMessage("You attacked an entity!"); player.sendMessage("You attacked an entity!");
} else if (entity instanceof Player) { } else if (entity instanceof Player) {
@ -162,8 +164,9 @@ public class PlayerInit {
Vector velocity = player.getPosition().copy().getDirection().multiply(6); Vector velocity = player.getPosition().copy().getDirection().multiply(6);
itemEntity.setVelocity(velocity); itemEntity.setVelocity(velocity);
EntityZombie entityZombie = new EntityZombie(player.getPosition()); EntityZombie entityZombie = new EntityZombie(new Position(0, 41, 0));
entityZombie.setInstance(player.getInstance()); entityZombie.setInstance(player.getInstance());
entityZombie.setPathTo(player.getPosition());
}); });
player.addEventCallback(PlayerDisconnectEvent.class, event -> { player.addEventCallback(PlayerDisconnectEvent.class, event -> {
@ -173,9 +176,9 @@ public class PlayerInit {
player.addEventCallback(PlayerLoginEvent.class, event -> { player.addEventCallback(PlayerLoginEvent.class, event -> {
event.setSpawningInstance(instanceContainer); event.setSpawningInstance(instanceContainer);
int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000; int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 - 250;
int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000; int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 - 250;
player.setRespawnPoint(new Position(x, 70f, z)); player.setRespawnPoint(new Position(x, 45f, z));
player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> { player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
if (slot == -999) if (slot == -999)

View File

@ -4,8 +4,8 @@ import net.minestom.server.Bootstrap;
public class Start { public class Start {
public static void main(String[] args) { public static void main(String[] args) {
Bootstrap.bootstrap("demo.Main", new String[0]); Bootstrap.bootstrap("demo.Main", new String[0]);
} }
} }

View File

@ -1,12 +1,15 @@
package demo.commands; package demo.commands;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandSender; import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Arguments; import net.minestom.server.command.builder.Arguments;
import net.minestom.server.command.builder.Command; import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.Argument; import net.minestom.server.command.builder.arguments.Argument;
import net.minestom.server.command.builder.arguments.ArgumentType; import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.minecraft.SuggestionType; import net.minestom.server.entity.Entity;
import net.minestom.server.network.packet.server.play.SpawnEntityPacket;
import net.minestom.server.utils.Position;
import java.util.UUID;
public class TestCommand extends Command { public class TestCommand extends Command {
@ -14,19 +17,23 @@ public class TestCommand extends Command {
super("testcmd"); super("testcmd");
setDefaultExecutor(this::usage); setDefaultExecutor(this::usage);
Argument test = ArgumentType.DynamicWord("view_distance", SuggestionType.SUMMONABLE_ENTITIES); Argument test = ArgumentType.RelativeBlockPosition("test");
test.setCallback((source, value, error) -> {
System.out.println("ERROR " + error);
});
setDefaultExecutor((source, args) -> { setDefaultExecutor((source, args) -> {
//System.gc(); System.gc();
//source.sendMessage("Explicit GC executed!"); source.sendMessage("Explicit GC executed!");
MinecraftServer.setChunkViewDistance(2);
}); });
addSyntax((source, args) -> { addSyntax((source, args) -> {
System.out.println("hey");
SpawnEntityPacket spawnEntityPacket = new SpawnEntityPacket();
spawnEntityPacket.entityId = Entity.generateId();
spawnEntityPacket.uuid = UUID.randomUUID();
spawnEntityPacket.type = 41;
spawnEntityPacket.position = new Position(0, 40, 0);
source.asPlayer().getPlayerConnection().sendPacket(spawnEntityPacket);
}, test); }, test);
} }