From 40787902e3556c8aacc89f196516086e421b75af Mon Sep 17 00:00:00 2001 From: Felix Cravic Date: Sun, 6 Dec 2020 20:20:05 +0100 Subject: [PATCH] Small demo code update --- src/test/java/demo/Main.java | 14 ++-------- src/test/java/demo/PlayerInit.java | 21 ++++++++------- src/test/java/demo/Start.java | 6 ++--- src/test/java/demo/commands/TestCommand.java | 27 ++++++++++++-------- 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/test/java/demo/Main.java b/src/test/java/demo/Main.java index db1fe8826..aae23d3f9 100644 --- a/src/test/java/demo/Main.java +++ b/src/test/java/demo/Main.java @@ -4,13 +4,11 @@ import demo.blocks.BurningTorchBlock; import demo.blocks.StoneBlock; import demo.blocks.UpdatableBlockDemo; import demo.commands.*; -import io.netty.handler.traffic.GlobalChannelTrafficShapingHandler; import net.minestom.server.MinecraftServer; import net.minestom.server.command.CommandManager; import net.minestom.server.extras.optifine.OptifineSupport; import net.minestom.server.instance.block.BlockManager; 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.systems.FileStorageSystem; import net.minestom.server.utils.time.TimeUnit; @@ -20,17 +18,9 @@ import net.minestom.server.utils.time.UpdateOption; public class Main { public static void main(String[] args) { - //System.setProperty("io.netty.leakDetection.targetRecords", "10"); - //ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.PARANOID); - MinecraftServer minecraftServer = MinecraftServer.init(); - MinecraftServer.setShouldProcessNettyErrors(false); - - final NettyServer nettyServer = MinecraftServer.getNettyServer(); - final GlobalChannelTrafficShapingHandler trafficHandler = nettyServer.getGlobalTrafficHandler(); - trafficHandler.setReadChannelLimit(500_000); - trafficHandler.setReadLimit(500_000); + // MinecraftServer.setShouldProcessNettyErrors(true); BlockManager blockManager = MinecraftServer.getBlockManager(); blockManager.registerCustomBlock(new StoneBlock()); @@ -71,7 +61,7 @@ public class Main { minecraftServer.start("0.0.0.0", 25565, PlayerInit.getResponseDataConsumer()); - Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly)); + //Runtime.getRuntime().addShutdownHook(new Thread(MinecraftServer::stopCleanly)); } } diff --git a/src/test/java/demo/PlayerInit.java b/src/test/java/demo/PlayerInit.java index 12b1b1696..28bcb8eb3 100644 --- a/src/test/java/demo/PlayerInit.java +++ b/src/test/java/demo/PlayerInit.java @@ -17,6 +17,7 @@ import net.minestom.server.event.player.*; import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Instance; 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.CustomBlock; import net.minestom.server.inventory.Inventory; @@ -42,12 +43,13 @@ public class PlayerInit { private static final Inventory inventory; static { + InstanceManager instanceManager = MinecraftServer.getInstanceManager(); //StorageLocation storageLocation = MinecraftServer.getStorageManager().getLocation("instance_data", new StorageOptions().setCompression(true)); ChunkGeneratorDemo chunkGeneratorDemo = new ChunkGeneratorDemo(); NoiseTestGenerator noiseTestGenerator = new NoiseTestGenerator(); - instanceContainer = MinecraftServer.getInstanceManager().createInstanceContainer(DimensionType.OVERWORLD); + instanceContainer = instanceManager.createInstanceContainer(DimensionType.OVERWORLD); instanceContainer.enableAutoChunkLoad(true); - instanceContainer.setChunkGenerator(noiseTestGenerator); + instanceContainer.setChunkGenerator(chunkGeneratorDemo); // Load some chunks beforehand final int loopStart = -10; @@ -105,9 +107,9 @@ public class PlayerInit { final Entity entity = event.getTarget(); if (entity instanceof EntityCreature) { EntityCreature creature = (EntityCreature) entity; - creature.damage(DamageType.fromPlayer(player), -1); - Vector velocity = player.getPosition().copy().getDirection().multiply(6); - velocity.setY(4f); + creature.damage(DamageType.fromPlayer(player), 0); + Vector velocity = player.getPosition().copy().getDirection().multiply(3); + velocity.setY(3f); entity.setVelocity(velocity); player.sendMessage("You attacked an entity!"); } else if (entity instanceof Player) { @@ -162,8 +164,9 @@ public class PlayerInit { Vector velocity = player.getPosition().copy().getDirection().multiply(6); itemEntity.setVelocity(velocity); - EntityZombie entityZombie = new EntityZombie(player.getPosition()); + EntityZombie entityZombie = new EntityZombie(new Position(0, 41, 0)); entityZombie.setInstance(player.getInstance()); + entityZombie.setPathTo(player.getPosition()); }); player.addEventCallback(PlayerDisconnectEvent.class, event -> { @@ -173,9 +176,9 @@ public class PlayerInit { player.addEventCallback(PlayerLoginEvent.class, event -> { event.setSpawningInstance(instanceContainer); - int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000; - int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 2000 - 1000; - player.setRespawnPoint(new Position(x, 70f, z)); + int x = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 - 250; + int z = Math.abs(ThreadLocalRandom.current().nextInt()) % 1000 - 250; + player.setRespawnPoint(new Position(x, 45f, z)); player.getInventory().addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> { if (slot == -999) diff --git a/src/test/java/demo/Start.java b/src/test/java/demo/Start.java index b5b11421c..cbe8595c8 100644 --- a/src/test/java/demo/Start.java +++ b/src/test/java/demo/Start.java @@ -4,8 +4,8 @@ import net.minestom.server.Bootstrap; public class Start { - public static void main(String[] args) { - Bootstrap.bootstrap("demo.Main", new String[0]); - } + public static void main(String[] args) { + Bootstrap.bootstrap("demo.Main", new String[0]); + } } diff --git a/src/test/java/demo/commands/TestCommand.java b/src/test/java/demo/commands/TestCommand.java index 9d845d8e9..4ff028414 100644 --- a/src/test/java/demo/commands/TestCommand.java +++ b/src/test/java/demo/commands/TestCommand.java @@ -1,12 +1,15 @@ package demo.commands; -import net.minestom.server.MinecraftServer; import net.minestom.server.command.CommandSender; import net.minestom.server.command.builder.Arguments; import net.minestom.server.command.builder.Command; import net.minestom.server.command.builder.arguments.Argument; 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 { @@ -14,19 +17,23 @@ public class TestCommand extends Command { super("testcmd"); setDefaultExecutor(this::usage); - Argument test = ArgumentType.DynamicWord("view_distance", SuggestionType.SUMMONABLE_ENTITIES); - - test.setCallback((source, value, error) -> { - System.out.println("ERROR " + error); - }); + Argument test = ArgumentType.RelativeBlockPosition("test"); setDefaultExecutor((source, args) -> { - //System.gc(); - //source.sendMessage("Explicit GC executed!"); - MinecraftServer.setChunkViewDistance(2); + System.gc(); + source.sendMessage("Explicit GC executed!"); }); 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); }