Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Begin state, bump Minestom
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed May 27, 2022
1 parent 8b3e013 commit 8089dc2
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 70 deletions.
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ repositories {

maven(url = "https://jitpack.io")
maven(url = "https://repo.spongepowered.org/maven")
maven(url = "https://repo.minestom.com/repository/maven-public/")
maven(url = "https://repo.velocitypowered.com/snapshots/")
}

Expand All @@ -33,10 +32,10 @@ dependencies {
compileOnly(kotlin("reflect"))

// Compile Minestom into project
compileOnly("com.github.LeoDog896", "Minestom", "fc441737f4")
compileOnly("com.github.Minestom", "Minestom", "7867313290")

// Get KStom
compileOnly("com.github.Project-Cepi:KStom:f962764331")
compileOnly("com.github.Project-Cepi:KStom:82f7000079")

// Use MobExtension
compileOnly("com.github.Project-Cepi:MobExtension:4eb377e311")
Expand All @@ -45,10 +44,13 @@ dependencies {
compileOnly("com.github.Project-Cepi.Particable:common:ad9ec542a8")

// import kotlinx serialization
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1")
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.3")

// Add Kepi
compileOnly("com.github.Project-Cepi:Kepi:991a24276e")

// Add MiniMessage
implementation("net.kyori:adventure-text-minimessage:4.10.1")
}

tasks.withType<Test> {
Expand Down
36 changes: 5 additions & 31 deletions src/main/kotlin/world/cepi/region/api/Region.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import org.jglrxavpok.hephaistos.nbt.NBTCompound
import org.jglrxavpok.hephaistos.nbt.NBTCompoundLike
import world.cepi.kstom.Manager
import world.cepi.kstom.event.listenOnly
import world.cepi.kstom.item.get
import world.cepi.kstom.item.set
import world.cepi.kstom.serializer.BossBarSerializer
import world.cepi.kstom.serializer.ComponentSerializer
import world.cepi.kstom.serializer.NBTSerializer
import world.cepi.region.Selection
Expand Down Expand Up @@ -50,8 +47,10 @@ data class Region(
var displayName: Component? = null,

/** If this region's name is hidden */
var hidden: Boolean = false
) : TagHandler {
var hidden: Boolean = false,

val states: MutableList<RegionState> = mutableListOf()
) : TagHandler by TagHandler.newHandler() {

/**
* True, if this region contains at least one block.
Expand All @@ -60,18 +59,13 @@ data class Region(
val defined: Boolean
get() = selections.isEmpty()

@Serializable(with = NBTSerializer::class)
private val nbtCompound = NBTCompound()

val snapshots: MutableList<RegionSnapshot> = mutableListOf()

/**
* The volume of this region in cubic meters.
*/
val volume: Int
get() = selections
.filter { selections.none { sel -> sel.containsAll(it) } }
.map { it.xRange.size * it.yRange.size * it.zRange.size }.sum()
.sumOf { it.xRange.size * it.yRange.size * it.zRange.size }

/**
* Checks if the given block position is inside of this
Expand Down Expand Up @@ -182,26 +176,6 @@ data class Region(
}
}
}

override fun <T : Any?> getTag(tag: Tag<T>): T? {
return tag.read(nbtCompound)
}

override fun <T : Any?> setTag(tag: Tag<T>, value: T?) {
tag.write(nbtCompound.toMutableCompound(), value)
}

override fun readableCopy(): TagReadable {
TODO("Not yet implemented")
}

override fun updateContent(compound: NBTCompoundLike) {
TODO("Not yet implemented")
}

override fun asCompound(): NBTCompound {
TODO("Not yet implemented")
}
}

var Player.region: Region?
Expand Down
23 changes: 0 additions & 23 deletions src/main/kotlin/world/cepi/region/api/RegionSnapshot.kt

This file was deleted.

24 changes: 24 additions & 0 deletions src/main/kotlin/world/cepi/region/api/RegionState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package world.cepi.region.api

import kotlinx.serialization.Serializable
import net.minestom.server.instance.block.Block
import world.cepi.kstom.serializer.BlockSerializer

@Serializable
data class RegionState(val blockStates: List<@Serializable(with = BlockSerializer::class) Block>) {
companion object {
fun from(region: Region) = RegionState(region.selections.map { selection ->
selection.xRange.map { x ->
selection.yRange.map { y ->
selection.zRange.map { z ->
region.instance.getBlock(x, y, z)
}
}.flatten()
}.flatten()
}.flatten())
}

fun put(region: Region) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object RegionArguments {
}

val existingRegion = ArgumentType.Word("region").map { name ->
RegionProvider[name]?: throw ArgumentSyntaxException("Invalid region", name, 1)
RegionProvider[name] ?: throw ArgumentSyntaxException("Invalid region", name, 1)
}.suggest {
RegionProvider.regions.values
.map { it.name }
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/world/cepi/region/command/RegionCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ object RegionCommand : Kommand({
sender.sendFormattedTranslatableMessage("common", "world.none")
}

syntax(spawn, existingRegion, amount).onlyPlayers {
if (!MobUtils.hasMobEgg(sender)) return@onlyPlayers
syntax(spawn, existingRegion, amount) {
if (!MobUtils.hasMobEgg(sender)) return@syntax

val mob = player.mobEgg ?: return@onlyPlayers
val mob = player.mobEgg ?: return@syntax

repeat(!amount) {
mob.spawnMob(player.instance!!, (!existingRegion).selections.random().random())
}
}
}.onlyPlayers()

syntax(create, regionName, world) {
val instance = if (sender is Player) {
Expand Down Expand Up @@ -115,6 +115,6 @@ object RegionCommand : Kommand({
""".trimIndent()
}

addSubcommands(SelectionsSubcommand, MetaSubcommand)
addSubcommands(SelectionsSubcommand, MetaSubcommand, StateSubcommand)

}, "region")
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ object SelectionsSubcommand : Kommand({
val pos1 by literal
val pos2 by literal

onlyPlayers
onlyPlayers()

playerCallbackFailMessage = { sender ->
sender.sendFormattedTranslatableMessage("common", "command.only_players")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package world.cepi.region.command.subcommand

import world.cepi.kstom.command.arguments.literal
import world.cepi.kstom.command.kommand.Kommand
import world.cepi.region.api.RegionState
import world.cepi.region.command.RegionArguments

object StateSubcommand : Kommand({
val add by literal

syntax(RegionArguments.existingRegion, add) {
val region = (!RegionArguments.existingRegion)
region.states.add(RegionState.from(region))
}
}, "state")
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package world.cepi.region.serialization

import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import net.minestom.server.instance.Instance
import world.cepi.kstom.Manager
import world.cepi.region.Selection
import world.cepi.region.api.Region
import world.cepi.region.api.RegionSnapshot

object InstanceSerializer : KSerializer<Instance> {
override val descriptor: SerialDescriptor = String.serializer().descriptor
Expand Down

0 comments on commit 8089dc2

Please sign in to comment.