mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-27 02:21:38 +01:00
Small demo update
This commit is contained in:
parent
e4e564ab07
commit
d0e94f0ee5
@ -7,8 +7,7 @@ import net.minestom.server.benchmark.BenchmarkManager;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.entity.*;
|
||||
import net.minestom.server.entity.damage.DamageType;
|
||||
import net.minestom.server.entity.fakeplayer.FakePlayer;
|
||||
import net.minestom.server.entity.type.monster.EntityZombie;
|
||||
import net.minestom.server.entity.type.decoration.EntityArmorStand;
|
||||
import net.minestom.server.event.GlobalEventHandler;
|
||||
import net.minestom.server.event.entity.EntityAttackEvent;
|
||||
import net.minestom.server.event.item.ItemDropEvent;
|
||||
@ -54,14 +53,6 @@ public class PlayerInit {
|
||||
instanceContainer.enableAutoChunkLoad(true);
|
||||
instanceContainer.setChunkGenerator(chunkGeneratorDemo);
|
||||
|
||||
// Load some chunks beforehand
|
||||
final int loopStart = -10;
|
||||
final int loopEnd = 10;
|
||||
for (int x = loopStart; x < loopEnd; x++)
|
||||
for (int z = loopStart; z < loopEnd; z++) {
|
||||
//instanceContainer.loadChunk(x, z);
|
||||
}
|
||||
|
||||
inventory = new Inventory(InventoryType.CHEST_1_ROW, "Test inventory");
|
||||
/*inventory.addInventoryCondition((p, slot, clickType, inventoryConditionResult) -> {
|
||||
p.sendMessage("click type inventory: " + clickType);
|
||||
@ -117,18 +108,16 @@ public class PlayerInit {
|
||||
globalEventHandler.addEventCallback(EntityAttackEvent.class, event -> {
|
||||
final Entity source = event.getEntity();
|
||||
final Entity entity = event.getTarget();
|
||||
if (entity instanceof EntityCreature) {
|
||||
EntityCreature creature = (EntityCreature) entity;
|
||||
creature.damage(DamageType.fromEntity(source), 0);
|
||||
Vector velocity = source.getPosition().clone().getDirection().multiply(3);
|
||||
velocity.setY(3f);
|
||||
entity.setVelocity(velocity);
|
||||
} else if (entity instanceof Player) {
|
||||
if (entity instanceof Player) {
|
||||
Player target = (Player) entity;
|
||||
Vector velocity = source.getPosition().clone().getDirection().multiply(4);
|
||||
velocity.setY(3.5f);
|
||||
target.setVelocity(velocity);
|
||||
target.damage(DamageType.fromEntity(source), 5);
|
||||
}else{
|
||||
Vector velocity = source.getPosition().clone().getDirection().multiply(3);
|
||||
velocity.setY(3f);
|
||||
entity.setVelocity(velocity);
|
||||
}
|
||||
|
||||
if (source instanceof Player) {
|
||||
@ -187,9 +176,8 @@ public class PlayerInit {
|
||||
Vector velocity = player.getPosition().clone().getDirection().multiply(6);
|
||||
itemEntity.setVelocity(velocity);
|
||||
|
||||
EntityZombie entityZombie = new EntityZombie(new Position(0, 41, 0));
|
||||
entityZombie.setInstance(player.getInstance());
|
||||
entityZombie.setPathTo(player.getPosition());
|
||||
EntityArmorStand entity = new EntityArmorStand(new Position(0, 41, 0));
|
||||
entity.setInstance(player.getInstance());
|
||||
});
|
||||
|
||||
globalEventHandler.addEventCallback(PlayerDisconnectEvent.class, event -> {
|
||||
@ -241,8 +229,6 @@ public class PlayerInit {
|
||||
globalEventHandler.addEventCallback(PlayerUseItemEvent.class, useEvent -> {
|
||||
final Player player = useEvent.getPlayer();
|
||||
player.sendMessage("Using item in air: " + useEvent.getItemStack().getMaterial());
|
||||
|
||||
FakePlayer.initPlayer(UUID.randomUUID(), "test", null);
|
||||
});
|
||||
|
||||
globalEventHandler.addEventCallback(PlayerUseItemOnBlockEvent.class, useEvent -> {
|
||||
@ -265,24 +251,6 @@ public class PlayerInit {
|
||||
//player.getInstance().unloadChunk(chunk);
|
||||
}
|
||||
});
|
||||
|
||||
globalEventHandler.addEventCallback(PlayerLoginEvent.class, event -> {
|
||||
//event.setPlayerUuid(UUID.randomUUID());
|
||||
//System.out.println("random "+event.getPlayerUuid());
|
||||
System.out.println("lOGIN EVENT");
|
||||
});
|
||||
|
||||
globalEventHandler.addEventCallback(AsyncPlayerPreLoginEvent.class, event -> {
|
||||
//event.setPlayerUuid(UUID.randomUUID());
|
||||
//System.out.println("random "+event.getPlayerUuid());
|
||||
//event.getPlayer().kick("test");
|
||||
System.out.println("PRElOGIN EVENT");
|
||||
|
||||
});
|
||||
|
||||
globalEventHandler.addEventCallback(PlayerSkinInitEvent.class, event -> {
|
||||
//event.setSkin(PlayerSkin.fromUsername("TheMode911"));
|
||||
});
|
||||
}
|
||||
|
||||
public static ResponseDataConsumer getResponseDataConsumer() {
|
||||
|
@ -1,15 +1,15 @@
|
||||
package demo.commands;
|
||||
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
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.entity.Entity;
|
||||
import net.minestom.server.network.packet.server.play.SpawnEntityPacket;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.instance.InstanceContainer;
|
||||
import net.minestom.server.instance.batch.BlockBatch;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
|
||||
@ -17,25 +17,26 @@ public class TestCommand extends Command {
|
||||
super("testcmd");
|
||||
setDefaultExecutor(this::usage);
|
||||
|
||||
Argument test = ArgumentType.RelativeBlockPosition("test");
|
||||
setDefaultExecutor((sender, args) -> {
|
||||
if (!sender.isPlayer()) {
|
||||
sender.sendMessage("This command may only be run by players.");
|
||||
return;
|
||||
}
|
||||
Player player = sender.asPlayer();
|
||||
|
||||
setDefaultExecutor((source, args) -> {
|
||||
System.gc();
|
||||
source.sendMessage("Explicit GC executed!");
|
||||
BlockBatch batch = new BlockBatch((InstanceContainer) player.getInstance());
|
||||
|
||||
int offset = 5;
|
||||
for (int x = 0; x < 50; x += 1) {
|
||||
for (int y = 0; y < 50; y += 1) {
|
||||
for (int z = 0; z < 50; z += 1) {
|
||||
batch.setBlockStateId(x + offset, y + offset+50, z + offset, (short) ThreadLocalRandom.current().nextInt(500));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
batch.flush(() -> sender.sendMessage(ColoredText.of(ChatColor.BRIGHT_GREEN, "Created cube.")));
|
||||
});
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void usage(CommandSender sender, Arguments arguments) {
|
||||
|
Loading…
Reference in New Issue
Block a user