From 7a2f84de9c98c315c1029f864db52a44141b432a Mon Sep 17 00:00:00 2001 From: DasLixou Date: Tue, 19 Apr 2022 16:35:51 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=AA=86=20Created=20NPC=20Classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/lixou/stracciatella/npc/EntityNPC.kt | 6 ++++++ src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt | 15 +++++++++++++++ .../cc/lixou/stracciatella/npc/PlayerNPC.kt | 4 ++++ 3 files changed, 25 insertions(+) create mode 100644 src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt create mode 100644 src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt create mode 100644 src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt new file mode 100644 index 0000000..f705e3d --- /dev/null +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt @@ -0,0 +1,6 @@ +package cc.lixou.stracciatella.npc + +import net.minestom.server.entity.EntityType + +class EntityNPC(private val type: EntityType): NPC { +} \ No newline at end of file diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt new file mode 100644 index 0000000..cafb656 --- /dev/null +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt @@ -0,0 +1,15 @@ +package cc.lixou.stracciatella.npc + +import net.minestom.server.entity.EntityType + +sealed interface NPC { + + fun createEntity(type: EntityType): EntityNPC { + return EntityNPC(type) + } + + fun createPlayer(): PlayerNPC { + return PlayerNPC() + } + +} \ No newline at end of file diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt new file mode 100644 index 0000000..b35c9c1 --- /dev/null +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt @@ -0,0 +1,4 @@ +package cc.lixou.stracciatella.npc + +class PlayerNPC: NPC { +} \ No newline at end of file From e0b687477565222c6e8f9bb0fe45f2a4838633af Mon Sep 17 00:00:00 2001 From: DasLixou Date: Tue, 19 Apr 2022 17:07:40 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=AA=86=20First=20PlayerNPC=20creation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/lixou/stracciatella/Stracciatella.kt | 5 +++++ src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt | 15 ++++++++++----- .../cc/lixou/stracciatella/npc/PlayerNPC.kt | 11 ++++++++++- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt index 4a42cc6..3c43edd 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt @@ -1,5 +1,6 @@ package cc.lixou.stracciatella +import cc.lixou.stracciatella.npc.NPC import net.minestom.server.MinecraftServer import net.minestom.server.coordinate.Pos import net.minestom.server.event.player.PlayerLoginEvent @@ -18,6 +19,10 @@ class Stracciatella { unit.modifier().fillHeight(0, 40, Block.GRASS_BLOCK) } + NPC.createPlayer("Kevin") { + it.teleport(Pos(2.0, 42.0, 5.0)) + } + val eventHandler = MinecraftServer.getGlobalEventHandler() eventHandler.addListener(PlayerLoginEvent::class.java) { event -> val player = event.player diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt index cafb656..55f7e58 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt @@ -1,15 +1,20 @@ package cc.lixou.stracciatella.npc import net.minestom.server.entity.EntityType +import net.minestom.server.entity.fakeplayer.FakePlayer +import net.minestom.server.entity.fakeplayer.FakePlayerOption +import java.util.* sealed interface NPC { - fun createEntity(type: EntityType): EntityNPC { - return EntityNPC(type) - } + companion object { + fun createEntity(type: EntityType): EntityNPC { + return EntityNPC(type) + } - fun createPlayer(): PlayerNPC { - return PlayerNPC() + fun createPlayer(username: String, options: FakePlayerOption = FakePlayerOption(), spawnCallback: (FakePlayer) -> Unit = { }): PlayerNPC { + return PlayerNPC(UUID.randomUUID(), username, options, spawnCallback) + } } } \ No newline at end of file diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt index b35c9c1..5aa022d 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt @@ -1,4 +1,13 @@ package cc.lixou.stracciatella.npc -class PlayerNPC: NPC { +import net.minestom.server.entity.fakeplayer.FakePlayer +import net.minestom.server.entity.fakeplayer.FakePlayerOption +import java.util.* + +class PlayerNPC(uuid: UUID, username: String, options: FakePlayerOption, spawnCallback: (FakePlayer) -> Unit) : NPC { + + init { + FakePlayer.initPlayer(uuid, username, options, spawnCallback) + } + } \ No newline at end of file From ef4476b8e007ea91136320f88e292357969d0de0 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Mon, 2 May 2022 20:47:05 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=AA=86=20simple=20EntityNPC=20working?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/lixou/stracciatella/Stracciatella.kt | 17 +++++++--- .../cc/lixou/stracciatella/npc/EntityNPC.kt | 32 ++++++++++++++++++- .../kotlin/cc/lixou/stracciatella/npc/NPC.kt | 20 ------------ .../cc/lixou/stracciatella/npc/PlayerNPC.kt | 7 +++- 4 files changed, 50 insertions(+), 26 deletions(-) delete mode 100644 src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt diff --git a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt index bd99c2a..d10bb81 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt @@ -1,9 +1,12 @@ package cc.lixou.stracciatella -import cc.lixou.stracciatella.npc.NPC import cc.lixou.stracciatella.game.GameManager +import cc.lixou.stracciatella.npc.EntityNPC +import net.kyori.adventure.text.Component import net.minestom.server.MinecraftServer import net.minestom.server.coordinate.Pos +import net.minestom.server.entity.EntityType +import net.minestom.server.entity.metadata.villager.VillagerMeta import net.minestom.server.event.player.PlayerDisconnectEvent import net.minestom.server.event.player.PlayerLoginEvent import net.minestom.server.instance.block.Block @@ -21,9 +24,15 @@ class Stracciatella { unit.modifier().fillHeight(0, 40, Block.GRASS_BLOCK) } - NPC.createPlayer("Kevin") { - it.teleport(Pos(2.0, 42.0, 5.0)) - } + val npc = EntityNPC(EntityType.VILLAGER, Pos(2.0, 42.0, 5.0), instanceContainer).meta { + it.customName = Component.text("KAKA") + it.isCustomNameVisible = true + val villagerData = it.villagerData + villagerData.type = VillagerMeta.Type.DESERT + villagerData.level = VillagerMeta.Level.MASTER + villagerData.profession = VillagerMeta.Profession.FARMER + it.villagerData = villagerData + }.spawn() val eventHandler = MinecraftServer.getGlobalEventHandler() eventHandler.addListener(PlayerDisconnectEvent::class.java) { event -> diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt index f705e3d..c2f3a62 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt @@ -1,6 +1,36 @@ package cc.lixou.stracciatella.npc +import net.minestom.server.coordinate.Pos +import net.minestom.server.entity.Entity import net.minestom.server.entity.EntityType +import net.minestom.server.entity.metadata.EntityMeta +import net.minestom.server.instance.Instance + +class EntityNPC( + type: EntityType, + private val pos: Pos, + private val instance: Instance +) { + + val entity: Entity = Entity(type) + + inline fun meta(callback: (T) -> Unit): EntityNPC { + val meta = entity.entityMeta as T + meta.setNotifyAboutChanges(false) + callback.invoke(meta) + meta.setNotifyAboutChanges(true) + + return this + } + + fun spawn(): EntityNPC { + entity.setInstance(instance, pos) + return this + } + + fun remove(): EntityNPC { + entity.remove() + return this + } -class EntityNPC(private val type: EntityType): NPC { } \ No newline at end of file diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt deleted file mode 100644 index 55f7e58..0000000 --- a/src/main/kotlin/cc/lixou/stracciatella/npc/NPC.kt +++ /dev/null @@ -1,20 +0,0 @@ -package cc.lixou.stracciatella.npc - -import net.minestom.server.entity.EntityType -import net.minestom.server.entity.fakeplayer.FakePlayer -import net.minestom.server.entity.fakeplayer.FakePlayerOption -import java.util.* - -sealed interface NPC { - - companion object { - fun createEntity(type: EntityType): EntityNPC { - return EntityNPC(type) - } - - fun createPlayer(username: String, options: FakePlayerOption = FakePlayerOption(), spawnCallback: (FakePlayer) -> Unit = { }): PlayerNPC { - return PlayerNPC(UUID.randomUUID(), username, options, spawnCallback) - } - } - -} \ No newline at end of file diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt index 5aa022d..7b698b0 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/PlayerNPC.kt @@ -4,7 +4,12 @@ import net.minestom.server.entity.fakeplayer.FakePlayer import net.minestom.server.entity.fakeplayer.FakePlayerOption import java.util.* -class PlayerNPC(uuid: UUID, username: String, options: FakePlayerOption, spawnCallback: (FakePlayer) -> Unit) : NPC { +class PlayerNPC( + username: String, + options: FakePlayerOption, + uuid: UUID = UUID.randomUUID(), + spawnCallback: (FakePlayer) -> Unit +) { init { FakePlayer.initPlayer(uuid, username, options, spawnCallback) From 325832019daf4d79a914f8bcf2e35e6e31ec4ed0 Mon Sep 17 00:00:00 2001 From: DasLixou Date: Wed, 4 May 2022 14:43:59 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=AA=86=20added=20entityNPC=20Interact?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cc/lixou/stracciatella/Stracciatella.kt | 8 ++++++++ .../cc/lixou/stracciatella/npc/EntityNPC.kt | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt index d10bb81..a0ba40e 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/Stracciatella.kt @@ -1,6 +1,7 @@ package cc.lixou.stracciatella import cc.lixou.stracciatella.game.GameManager +import cc.lixou.stracciatella.inventory.extensions.styleRadialBackground import cc.lixou.stracciatella.npc.EntityNPC import net.kyori.adventure.text.Component import net.minestom.server.MinecraftServer @@ -10,6 +11,9 @@ import net.minestom.server.entity.metadata.villager.VillagerMeta import net.minestom.server.event.player.PlayerDisconnectEvent import net.minestom.server.event.player.PlayerLoginEvent import net.minestom.server.instance.block.Block +import net.minestom.server.inventory.Inventory +import net.minestom.server.inventory.InventoryType +import net.minestom.server.item.Material class Stracciatella { @@ -32,6 +36,10 @@ class Stracciatella { villagerData.level = VillagerMeta.Level.MASTER villagerData.profession = VillagerMeta.Profession.FARMER it.villagerData = villagerData + }.interact { + val inventory = Inventory(InventoryType.CHEST_5_ROW, Component.text("Test")) + inventory.styleRadialBackground(Material.PINK_STAINED_GLASS_PANE, 5) + it.openInventory(inventory) }.spawn() val eventHandler = MinecraftServer.getGlobalEventHandler() diff --git a/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt b/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt index c2f3a62..0697728 100644 --- a/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt +++ b/src/main/kotlin/cc/lixou/stracciatella/npc/EntityNPC.kt @@ -3,8 +3,12 @@ package cc.lixou.stracciatella.npc import net.minestom.server.coordinate.Pos import net.minestom.server.entity.Entity import net.minestom.server.entity.EntityType +import net.minestom.server.entity.Player import net.minestom.server.entity.metadata.EntityMeta +import net.minestom.server.event.player.PlayerEntityInteractEvent import net.minestom.server.instance.Instance +import world.cepi.kstom.Manager +import world.cepi.kstom.event.listenOnly class EntityNPC( type: EntityType, @@ -12,6 +16,14 @@ class EntityNPC( private val instance: Instance ) { + companion object { + private val interactions = mutableMapOf Unit>() + + init { + Manager.globalEvent.listenOnly { interactions[target.entityId]?.invoke(player) } + } + } + val entity: Entity = Entity(type) inline fun meta(callback: (T) -> Unit): EntityNPC { @@ -33,4 +45,9 @@ class EntityNPC( return this } + fun interact(interaction: (Player) -> Unit): EntityNPC { + interactions[entity.entityId] = interaction + return this + } + } \ No newline at end of file From 5195ca1c7e5635a1e6774186623a0375570857dd Mon Sep 17 00:00:00 2001 From: DasLixou Date: Fri, 6 May 2022 15:54:57 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=86=99=20Updated=20Minestom?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index a92acce..68e36b8 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ repositories { } dependencies { - api 'com.github.Minestom:Minestom:ef53559349' + api 'com.github.Minestom:Minestom:cef824bc16' api 'com.github.TeamSkyBeach:KStom:86d37c4edb'