Moved the demo server to the test directory

This commit is contained in:
themode 2020-10-11 16:02:26 +02:00
parent e783d33767
commit 551bd42b48
22 changed files with 116 additions and 41 deletions

View File

@ -1,6 +1,5 @@
package net.minestom.demo.largeframebuffers;
import fr.themode.demo.MainDemo;
import net.minestom.server.MinecraftServer;
import net.minestom.server.chat.ColoredText;
import net.minestom.server.entity.GameMode;
@ -49,9 +48,10 @@ public class Demo {
MapColorRenderer renderer = new MapColorRenderer(glfwFramebuffer, OpenGLRendering::render);
glfwFramebuffer.unbindContextFromThread();
// renderingLoop(0, directFramebuffer, Demo::directRendering);
// renderingLoop(101, graphics2DFramebuffer, Demo::graphics2DRendering);
renderingLoop(201, glfwFramebuffer, f -> {});
// renderingLoop(0, directFramebuffer, Demo::directRendering);
// renderingLoop(101, graphics2DFramebuffer, Demo::graphics2DRendering);
renderingLoop(201, glfwFramebuffer, f -> {
});
glfwFramebuffer.setupRenderLoop(15, TimeUnit.MILLISECOND, renderer);
@ -68,27 +68,27 @@ public class Demo {
private static void createFrame(Instance instance, int id, int x, int y, int z) {
EntityItemFrame itemFrame = new EntityItemFrame(new Position(x, y, z), EntityItemFrame.ItemFrameOrientation.NORTH);
itemFrame.getPosition().setYaw(180f);
ItemStack map = new ItemStack(Material.FILLED_MAP, (byte)1);
ItemStack map = new ItemStack(Material.FILLED_MAP, (byte) 1);
map.setItemMeta(new MapMeta(id));
itemFrame.setItemStack(map);
itemFrame.setInstance(instance);
itemFrame.setCustomNameVisible(true);
itemFrame.setCustomName(ColoredText.of("MapID: "+id));
itemFrame.setCustomName(ColoredText.of("MapID: " + id));
}
private static void setupMaps(Instance instance, int mapIDStart, int zCoordinate) {
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
createFrame(instance, mapIDStart+y*4+x, 2-x, 45-y, zCoordinate);
createFrame(instance, mapIDStart + y * 4 + x, 2 - x, 45 - y, zCoordinate);
}
}
}
private static <T extends LargeFramebuffer> void renderingLoop(int mapIDStart, T framebuffer, Consumer<T> renderingCode) {
final Framebuffer[] subviews = new Framebuffer[4*4];
final Framebuffer[] subviews = new Framebuffer[4 * 4];
for (int i = 0; i < subviews.length; i++) {
int x = (i % 4)*128;
int y = (i / 4)*128;
int x = (i % 4) * 128;
int y = (i / 4) * 128;
subviews[i] = framebuffer.createSubView(x, y);
}
MinecraftServer.getSchedulerManager().buildTask(() -> {
@ -109,14 +109,14 @@ public class Demo {
}
private static void directRendering(LargeDirectFramebuffer framebuffer) {
Arrays.fill(framebuffer.getColors(), 0, 512*40+128, MapColors.COLOR_CYAN.baseColor());
Arrays.fill(framebuffer.getColors(), 512*40+128, framebuffer.getColors().length, MapColors.COLOR_RED.baseColor());
Arrays.fill(framebuffer.getColors(), 0, 512 * 40 + 128, MapColors.COLOR_CYAN.baseColor());
Arrays.fill(framebuffer.getColors(), 512 * 40 + 128, framebuffer.getColors().length, MapColors.COLOR_RED.baseColor());
}
private static void graphics2DRendering(LargeGraphics2DFramebuffer framebuffer) {
Graphics2D renderer = framebuffer.getRenderer();
renderer.setColor(Color.BLACK);
renderer.clearRect(0,0,512,512);
renderer.clearRect(0, 0, 512, 512);
renderer.setColor(Color.WHITE);
renderer.drawString("Here's a very very long string that needs multiple maps to fit", 0, 100);
}

View File

@ -0,0 +1,75 @@
package net.minestom.demo.largeframebuffers;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.GameMode;
import net.minestom.server.event.player.PlayerLoginEvent;
import net.minestom.server.event.player.PlayerSpawnEvent;
import net.minestom.server.instance.*;
import net.minestom.server.instance.batch.ChunkBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.network.ConnectionManager;
import net.minestom.server.utils.Position;
import net.minestom.server.world.biomes.Biome;
import java.util.Arrays;
import java.util.List;
public class MainDemo {
public static void main(String[] args) {
// Initialization
MinecraftServer minecraftServer = MinecraftServer.init();
InstanceManager instanceManager = MinecraftServer.getInstanceManager();
// Create the instance
InstanceContainer instanceContainer = instanceManager.createInstanceContainer();
// Set the ChunkGenerator
instanceContainer.setChunkGenerator(new GeneratorDemo());
// Enable the auto chunk loading (when players come close)
instanceContainer.enableAutoChunkLoad(true);
// Add event listeners
ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
connectionManager.addPlayerInitialization(player -> {
// Set the spawning instance
player.addEventCallback(PlayerLoginEvent.class, event -> {
event.setSpawningInstance(instanceContainer);
player.setRespawnPoint(new Position(0,45,0));
});
// Teleport the player at spawn
player.addEventCallback(PlayerSpawnEvent.class, event -> {
player.teleport(new Position(0, 45, 0));
player.setGameMode(GameMode.CREATIVE);
});
});
// Start the server
minecraftServer.start("localhost", 25565);
}
private static class GeneratorDemo implements ChunkGenerator {
@Override
public void generateChunkData(ChunkBatch batch, int chunkX, int chunkZ) {
// Set chunk blocks
for (byte x = 0; x < Chunk.CHUNK_SIZE_X; x++)
for (byte z = 0; z < Chunk.CHUNK_SIZE_Z; z++) {
for (byte y = 0; y < 40; y++) {
batch.setBlock(x, y, z, Block.STONE);
}
}
}
@Override
public void fillBiomes(Biome[] biomes, int chunkX, int chunkZ) {
Arrays.fill(biomes, MinecraftServer.getBiomeManager().getById(0));
}
@Override
public List<ChunkPopulator> getPopulators() {
return null;
}
}
}

View File

@ -1,9 +1,9 @@
package fr.themode.demo;
package demo;
import fr.themode.demo.blocks.BurningTorchBlock;
import fr.themode.demo.blocks.StoneBlock;
import fr.themode.demo.blocks.UpdatableBlockDemo;
import fr.themode.demo.commands.*;
import demo.blocks.BurningTorchBlock;
import demo.blocks.StoneBlock;
import demo.blocks.UpdatableBlockDemo;
import demo.commands.*;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandManager;
import net.minestom.server.instance.block.BlockManager;

View File

@ -1,4 +1,4 @@
package fr.themode.demo;
package demo;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.GameMode;

View File

@ -1,8 +1,8 @@
package fr.themode.demo;
package demo;
import fr.themode.demo.blocks.StoneBlock;
import fr.themode.demo.generator.ChunkGeneratorDemo;
import fr.themode.demo.generator.NoiseTestGenerator;
import demo.blocks.StoneBlock;
import demo.generator.ChunkGeneratorDemo;
import demo.generator.NoiseTestGenerator;
import net.minestom.server.MinecraftServer;
import net.minestom.server.attribute.Attribute;
import net.minestom.server.attribute.AttributeOperation;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.blocks;
package demo.blocks;
import net.minestom.server.data.Data;
import net.minestom.server.entity.Entity;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.blocks;
package demo.blocks;
import net.minestom.server.data.Data;
import net.minestom.server.entity.Player;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.blocks;
package demo.blocks;
import net.minestom.server.data.Data;
import net.minestom.server.entity.Player;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandProcessor;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Arguments;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Arguments;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Arguments;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandProcessor;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.command.CommandProcessor;
import net.minestom.server.command.CommandSender;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.Command;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.commands;
package demo.commands;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.Arguments;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.entity;
package demo.entity;
import net.minestom.server.attribute.Attribute;
import net.minestom.server.entity.LivingEntity;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.entity;
package demo.entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.LivingEntity;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.entity;
package demo.entity;
import net.minestom.server.entity.ai.goal.RandomLookAroundGoal;
import net.minestom.server.entity.type.monster.EntityZombie;

View File

@ -1,12 +1,12 @@
package fr.themode.demo.generator;
package demo.generator;
import net.minestom.server.MinecraftServer;
import net.minestom.server.world.biomes.Biome;
import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.ChunkGenerator;
import net.minestom.server.instance.ChunkPopulator;
import net.minestom.server.instance.batch.ChunkBatch;
import net.minestom.server.instance.block.Block;
import net.minestom.server.world.biomes.Biome;
import java.util.Arrays;
import java.util.List;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.generator;
package demo.generator;
import de.articdive.jnoise.JNoise;
import de.articdive.jnoise.interpolation.InterpolationType;

View File

@ -1,4 +1,4 @@
package fr.themode.demo.generator;
package demo.generator;
import lombok.Data;
import net.minestom.server.instance.Chunk;