From 2affb52e477c33e74fcc07b4d444d09fcdff61ee Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 14:01:24 +0200 Subject: [PATCH 1/9] Update ai.md --- feature/entities/ai.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/feature/entities/ai.md b/feature/entities/ai.md index 9828afd..3e40a97 100644 --- a/feature/entities/ai.md +++ b/feature/entities/ai.md @@ -14,7 +14,11 @@ Every tick, the entity will find the goal to follow based on its priority. If th ## Groups -You might find yourself wanting to have multiple goals being executed at the same time. For example, having an entity attacking its target while swimming to avoid dying. This is done by adding multiple `EntityAIGroup` to the entity, each group contains a list of goals to be executed independently. +You might find yourself wanting to have multiple goals being executed at the same time. For example, having an entity attacking its target while swimming to avoid dying. This is done by adding multiple `EntityAIGroup` to the entity, each group contains a list of goals to be executed independently. + +## Example + +In this example, instances of ZombieCreature will attack nearby players or walk around based on if a player is nearby. ```java package demo.entity; @@ -29,9 +33,14 @@ public class ZombieCreature extends EntityCreature { public ZombieCreature() { super(EntityType.ZOMBIE); addAIGroup( - new EntityAIGroupBuilder() - .addGoalSelector(new RandomLookAroundGoal(this, 20)) - .build() + List.of( + new MeleeAttackGoal(this, 1.6, 20, TimeUnit.SERVER_TICK), // Attack the target + new RandomStrollGoal(this, 20) // Walk around + ) + List.of( + new LastEntityDamagerTarget(this, 32), // First target the last entity which attacked you + new ClosestEntityTarget(this, 32, entity -> entity instanceof Player) // If there is none, target the nearest player + ) ); } } From 9b24d5f1ab2ecf50e89816009f76ddbd1a63e14f Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 14:14:12 +0200 Subject: [PATCH 2/9] Update permissions.md --- feature/permissions.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/feature/permissions.md b/feature/permissions.md index 9504097..0eddc43 100644 --- a/feature/permissions.md +++ b/feature/permissions.md @@ -22,6 +22,26 @@ A [`PermissionVerifier`](https://minestom.github.io/Minestom/net/minestom/server Alternatively, `PermissionHandler#hasPermission(Permission)` can be used. It does require both the permission name and the data to be equal. +## Adding permissions to players and checking them + +In order to add a permission to a player, you will have to call the `Player#addPermission(Permission)` function, an example of proper usage would be + +```java +player.addPermission(new Permission("operator")); +``` + +If you want to check, if a player has a permission, you can use the `Player#hasPermission(Permission)` function, here is an example of checking for a permission inside of a command: + +```java +public class StopCommand extends Command { + public StopCommand() { + super("stop"); + setCondition((sender, commandString) -> sender.hasPermission(new Permission("operator")); + setDefaultExecutor((sender, context) -> MinecraftServer.stopCleanly()); + } +} +``` + ## Permission serialisation Nothing is automatically saved persistently in Minestom, permissions are not an exception. From 21336c4748faedbfc37ff723e0730b4844b2ed48 Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 14:18:30 +0200 Subject: [PATCH 3/9] Create anvilloader.md --- world/anvilloader.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 world/anvilloader.md diff --git a/world/anvilloader.md b/world/anvilloader.md new file mode 100644 index 0000000..ddc28ac --- /dev/null +++ b/world/anvilloader.md @@ -0,0 +1,37 @@ +--- +description: >- + This page describes what you need to know about chunks management, more + specifically for InstanceContainer +--- + +# Chunk management + +## Load/Save Steps + +When trying to load a chunk, the instance container does multiple checks in this order: + +1. Verify if the chunk is already loaded (stop here if yes) +2. Try to load the chunk from the instance [IChunkLoader](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html) using [IChunkLoader#loadChunk](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html#loadChunk%28net.minestom.server.instance.Instance,int,int,net.minestom.server.utils.chunk.ChunkCallback%29) (stop here if the chunk loading is successful) +3. Create a new chunk and execute the instance ChunkGenerator (if any) to it to generate all of the chunk's blocks. + +When trying to save a chunk, [IChunkLoader#saveChunk](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html#saveChunk%28net.minestom.server.instance.Chunk,java.lang.Runnable%29) is called. + +### Default behavior + +`AnvilLoader` is the default chunk loader used by all `InstanceContainer` + +## Create your own chunk type + +[Chunk](https://minestom.github.io/Minestom/net/minestom/server/instance/Chunk.html) is an abstract class, you can simply create a new class extending it to create your own implementation. + +Making your own chunk implementation allows you to customize how you want blocks to be stored, how you want chunks tick to happen, etc... + +### How to make my instance use my implementation + +If you are using a simple [InstanceContainer](https://minestom.github.io/Minestom/net/minestom/server/instance/InstanceContainer.html) with the default [IChunkLoader](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html) you will just need to change the instance's chunk supplier + +```java +instanceContainer.setChunkSupplier(YOUR_CHUNK_SUPPLIER); +``` + +It will be called when a chunk object needs to be provided. From 71fd92f19986b3dc51e5a8c3cf886e5f39d91a19 Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 14:36:02 +0200 Subject: [PATCH 4/9] Update anvilloader.md --- world/anvilloader.md | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/world/anvilloader.md b/world/anvilloader.md index ddc28ac..377bcb3 100644 --- a/world/anvilloader.md +++ b/world/anvilloader.md @@ -1,37 +1,21 @@ --- description: >- - This page describes what you need to know about chunks management, more - specifically for InstanceContainer + This page describes how to load a world folder using AnvilLoader --- -# Chunk management +## Loading a world using AnvilLoader -## Load/Save Steps +In order to load a world into an instance, use the `InstanceContainer#setChunkLoader(IChunkLoader)` function. -When trying to load a chunk, the instance container does multiple checks in this order: - -1. Verify if the chunk is already loaded (stop here if yes) -2. Try to load the chunk from the instance [IChunkLoader](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html) using [IChunkLoader#loadChunk](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html#loadChunk%28net.minestom.server.instance.Instance,int,int,net.minestom.server.utils.chunk.ChunkCallback%29) (stop here if the chunk loading is successful) -3. Create a new chunk and execute the instance ChunkGenerator (if any) to it to generate all of the chunk's blocks. - -When trying to save a chunk, [IChunkLoader#saveChunk](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html#saveChunk%28net.minestom.server.instance.Chunk,java.lang.Runnable%29) is called. - -### Default behavior - -`AnvilLoader` is the default chunk loader used by all `InstanceContainer` - -## Create your own chunk type - -[Chunk](https://minestom.github.io/Minestom/net/minestom/server/instance/Chunk.html) is an abstract class, you can simply create a new class extending it to create your own implementation. - -Making your own chunk implementation allows you to customize how you want blocks to be stored, how you want chunks tick to happen, etc... +An example of using this method to load a world is: +```java +InstanceContainer.setChunkLoader(new AnvilLoader("worlds/world")); +``` -### How to make my instance use my implementation +This will load the world inside of the `worlds/world` directory into the InstanceContainer, allowing you to use the instance as before but having the world loaded inside. -If you are using a simple [InstanceContainer](https://minestom.github.io/Minestom/net/minestom/server/instance/InstanceContainer.html) with the default [IChunkLoader](https://minestom.github.io/Minestom/net/minestom/server/instance/IChunkLoader.html) you will just need to change the instance's chunk supplier +In order to load a world, the world folder will only need the `/region` folder, as it contains the block data. -```java -instanceContainer.setChunkSupplier(YOUR_CHUNK_SUPPLIER); -``` +## Saving a world -It will be called when a chunk object needs to be provided. +Article WIP From c4b0f305cef4219d271a41f0019258ed52f7453f Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 14:36:55 +0200 Subject: [PATCH 5/9] Update instances.md --- world/instances.md | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/world/instances.md b/world/instances.md index 100ff1c..634adeb 100644 --- a/world/instances.md +++ b/world/instances.md @@ -54,14 +54,3 @@ instanceManager.registerInstance(YOUR_CUSTOM_INSTANCE); This method is ONLY required if you instantiate your instance object manually, `InstanceManager#createInstanceContainer` and `InstanceManager#createSharedInstance` already register the instance internally. -## Save your instances/chunks - -It is also essential to notice that, by default, the chunks of the instance are only stored in memory. In order to have them stored in a persistent way, you need to serialize and deserialize them. Please check the [Chunks management](chunk-management.md) page for further information. - -Minestom uses Anvil as its default world format, conveniently located in the `AnvilLoader` class. Just put your world in the `world` folder, and see it work :) - -```java -var instance = instanceManager.createInstanceContainer(); -// Save all currently loaded chunks to the IChunkLoader -instanceContainer.saveChunksToStorage(); -``` From 96d79847c806fb3f79c43ee32d5365b83a6ff80f Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 14:39:55 +0200 Subject: [PATCH 6/9] Update anvilloader.md --- world/anvilloader.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/world/anvilloader.md b/world/anvilloader.md index 377bcb3..8cbd90c 100644 --- a/world/anvilloader.md +++ b/world/anvilloader.md @@ -18,4 +18,6 @@ In order to load a world, the world folder will only need the `/region` folder, ## Saving a world -Article WIP +In order to save a world, you will have to use the `InstanceContainer#saveChunksToStorage()` function, +this will only work if you have previously loaded a world into the instance using AnvilLoader. + From 885fd3d29ff5bb4ad93b30e0f28a4a2ee97b4ad3 Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 15:41:58 +0200 Subject: [PATCH 7/9] Remove invalid links --- feature/map-rendering/glfwmaprendering.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/feature/map-rendering/glfwmaprendering.md b/feature/map-rendering/glfwmaprendering.md index 2486081..d8a4568 100644 --- a/feature/map-rendering/glfwmaprendering.md +++ b/feature/map-rendering/glfwmaprendering.md @@ -38,11 +38,9 @@ In the case that you want to render continuously, it is advised to use `setupRen This sets up a repeating task through the SchedulerManager to automatically render contents every `period`. It also binds to the correct thread before rendering for the first time. -For more in-depth examples, look at the [demo package](https://github.com/Minestom/Minestom/tree/master/src/lwjgl/java/net/minestom/demo/largeframebuffers). - ## Color mapping -As said in the [Map Rendering article](https://github.com/Minestom/Minestom/wiki/Map-Rendering), maps do not use RGB, but an index into a color palette. By default, Minestom will convert the RGB pixels from the framebuffer on the CPU after each rendering. While this works and gives appreciable results, this conversion is not done in parallel, and the higher the resolution, the longer it takes. +Maps do not use RGB, but an index into a color palette. By default, Minestom will convert the RGB pixels from the framebuffer on the CPU after each rendering. While this works and gives appreciable results, this conversion is not done in parallel, and the higher the resolution, the longer it takes. Although Graphics2D framebuffers are not able to accelerate this process, GLFW capable buffers provide a way to quickly convert. There are two ways of doing this conversion. @@ -78,4 +76,4 @@ Required files for this to work (all inside classpath, src/_something_/resources * `/shaders/mapcolorconvert.fragment.glsl` fragment shader responsible for converting RGB to map colors * `/textures/palette.png` the color palette used by maps. Can be autogenerated via `net.minestom.server.map.PaletteGenerator`, outputs to `src/lwjgl/resources/textures/palette.png`. -This renderer works by rendering your content inside an OpenGL framebuffer (see [MapColorRenderer constructor](https://github.com/Minestom/Minestom/blob/master/src/lwjgl/java/net/minestom/server/map/framebuffers/MapColorRenderer.java) for more control over the framebuffer format. By default, RGBA color texture, Depth 24 bits, and Stencil 8 bits render buffer), and then rendering a full-screen quad (with texture unit 0 containing your color result and texture unit 1 containing the palette) with the `mapcolorconvert` shader. +This renderer works by rendering your content inside an OpenGL framebuffer for more control over the framebuffer format. By default, RGBA color texture, Depth 24 bits, and Stencil 8 bits render buffer), and then rendering a full-screen quad (with texture unit 0 containing your color result and texture unit 1 containing the palette) with the `mapcolorconvert` shader. From daef9513308d5a95e5ae194fa5bc31cd24d5535d Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 15:42:50 +0200 Subject: [PATCH 8/9] fix the chunk generator link --- world/instances.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/world/instances.md b/world/instances.md index 634adeb..3f7e143 100644 --- a/world/instances.md +++ b/world/instances.md @@ -24,7 +24,7 @@ You can create an `InstanceContainer` by calling: InstanceContainer instanceContainer = instanceManager.createInstanceContainer(); ``` -In order to have a valid world generation, you need to specify which `ChunkGenerator` the instance should use, without it no chunk can be generated. (check [here](https://github.com/Minestom/Minestom/wiki/Chunk-generator) to make your own) +In order to have a valid world generation, you need to specify which `ChunkGenerator` the instance should use, without it no chunk can be generated. (check [here](https://github.com/Minestom/Minestom/wiki/world/Chunk-generator) to make your own) ```java instance.setChunkGenerator(YOUR_GENERATOR); From 1d9b530f6ece400a0c0d22ad2ded43115f311fdb Mon Sep 17 00:00:00 2001 From: CultistOfTheEnd <66495367+NuxarianCookie@users.noreply.github.com> Date: Wed, 10 May 2023 15:44:33 +0200 Subject: [PATCH 9/9] fixed the link for real this time --- world/instances.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/world/instances.md b/world/instances.md index 3f7e143..3817821 100644 --- a/world/instances.md +++ b/world/instances.md @@ -24,7 +24,7 @@ You can create an `InstanceContainer` by calling: InstanceContainer instanceContainer = instanceManager.createInstanceContainer(); ``` -In order to have a valid world generation, you need to specify which `ChunkGenerator` the instance should use, without it no chunk can be generated. (check [here](https://github.com/Minestom/Minestom/wiki/world/Chunk-generator) to make your own) +In order to have a valid world generation, you need to specify which `ChunkGenerator` the instance should use, without it no chunk can be generated. (check [here](https://github.com/Minestom/Minestom/wiki/world/generation) to make your own) ```java instance.setChunkGenerator(YOUR_GENERATOR);