Skip to content

Commit

Permalink
getter on gamevalues in GameValues.kt and add vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingPig525 committed Sep 10, 2024
1 parent 79db2f6 commit cc5c7b8
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 95 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class GameValue(private val type: String, private var target: Target = Target.De
""".trimIndent()
}

fun target(newTarget: Target) {
this.target = newTarget
fun target(target: Target) {
this.target = target
}

enum class Target {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,7 @@ class LocItem(val x: Float, val y: Float, val z: Float, val pitch: Float = 0f, v
}
return null
}
val List<Number>.locItem: LocItem?
get() = this.toLocItem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MinecraftItem(val nbt: String) : Item(ID.ITEM), JsonData {

companion object {
fun String.toMinecraftItem() = MinecraftItem(this.replace("\"", "\\\""))
val String.mcItem get() = toMinecraftItem()
fun mcItemOf(type: String, count: Short = 1) = """{Count:${count}b,DF_NBT:3700,id:"$type"}""".toMinecraftItem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class NumItem(private val value: Float) : Item(ID.NUMBER), JsonData {

companion object {
fun Number.toNumItem(): NumItem = NumItem(this.toFloat())
val Number.numItem get() = toNumItem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ class StringItem(val text: String) : Item(ID.STRING), JsonData {

companion object {
fun String.toStringItem(): StringItem = StringItem(this)
val String.stringItem get() = toStringItem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class TextItem(val text: String) : Item(ID.RICHTEXT), JsonData {

companion object {
fun String.toTextItem(): TextItem = TextItem(this)
val String.textItem get() = toTextItem()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ class VarItem(val name: String, val scope: Scope = Scope.GAME) : Item(ID.VAR),

companion object {
fun String.toVarItem(scope: Scope = Scope.GAME): VarItem = VarItem(this, scope)
val String.gameVar get() = toVarItem()
val String.saveVar get() = toVarItem(Scope.SAVE)
val String.localVar get() = toVarItem(Scope.LOCAL)
val String.lineVar get() = toVarItem(Scope.LINE)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
package io.github.flyingpig525.base.item.type

class VecItem
import io.github.flyingpig525.base.JsonData
import io.github.flyingpig525.base.item.Item

class VecItem(x: Number, y: Number, z: Number) : Item(ID.VECTOR), JsonData {
val x = x.toFloat()
val y = y.toFloat()
val z = z.toFloat()

override fun getJsonData(): String {
return """
"x": $x,
"y": $y,
"z": $z
""".trimIndent()
}

companion object {
fun List<Number>.toVecItem(): VecItem? {
if (this.size == 3) return VecItem(this[0].toFloat(), this[1].toFloat(), this[2].toFloat())
return null
}
}

}

0 comments on commit cc5c7b8

Please sign in to comment.