From db8218350ca8f4894c0112ba4a27107fa1e7d77e Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 22 Jan 2024 21:53:18 +0100 Subject: [PATCH] added more types to shooter ammunition --- .../files/beh/item/BehItemComponents.kt | 15 +++- .../files/beh/item/comp/BehItemShooter.kt | 88 +++++++++++++++---- 2 files changed, 82 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/BehItemComponents.kt b/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/BehItemComponents.kt index e8da2f5..6b1d7bf 100644 --- a/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/BehItemComponents.kt +++ b/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/BehItemComponents.kt @@ -419,7 +419,7 @@ class BehItemComponents : MonsteraFile { fun shooter(settings: BehItemShooter.() -> Unit) { val behItemShooter = BehItemShooter().apply { settings(this) } unsafe.general.apply { - put("minecraft:shooter", behItemShooter.getData()) + put("minecraft:shooter", behItemShooter.unsafe.getData()) } } @@ -468,7 +468,18 @@ class BehItemComponents : MonsteraFile { @ExperimentalUnsignedTypes private fun sampleShooter() { shooter { - ammunition("arrow") + ammunition { + item = "minecraft:arrow" + useOffhand = true + searchInventory = true + useInCreative = true + } + ammunition { + item = "minecraft:fireworks_rocket" + useOffhand = true + searchInventory = true + useInCreative = true + } chargeOnDraw(true) launchPowerScale(1.0f) maxDrawDuration(2) diff --git a/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/comp/BehItemShooter.kt b/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/comp/BehItemShooter.kt index 0ccb4f4..cf290f5 100644 --- a/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/comp/BehItemShooter.kt +++ b/src/main/kotlin/com/lop/devtools/monstera/files/beh/item/comp/BehItemShooter.kt @@ -1,15 +1,40 @@ package com.lop.devtools.monstera.files.beh.item.comp -class BehItemShooter { +import com.lop.devtools.monstera.addon.api.MonsteraFile +import com.lop.devtools.monstera.addon.api.MonsteraUnsafe +import com.lop.devtools.monstera.addon.api.MonsteraUnsafeMap + +class BehItemShooter: MonsteraFile { + override val unsafe = Unsafe() + + inner class Unsafe: MonsteraUnsafeMap { + val general = mutableMapOf() + + val ammo = mutableListOf() + + override fun getData(): MutableMap { + if(ammo.isNotEmpty()) + general["ammunition"] = ammo.map { it.unsafe.getData() } + return general + } + } + + @Deprecated("", ReplaceWith("unsafe.general")) val general = mutableMapOf() + var chargeOnDraw: Boolean = false + set(value) { + unsafe.general["charge_on_draw"] = value + field = value + } + + + /** * Ammunition. */ - fun ammunition(ammunition: String) { - general.apply { - put("ammunition", ammunition) - } + fun ammunition(ammunition: BehItemShooterAmmo.() -> Unit) { + unsafe.ammo.add(BehItemShooterAmmo().apply(ammunition)) } /** @@ -25,39 +50,64 @@ class BehItemShooter { * Launch power scale. Default is set to 1.0. */ fun launchPowerScale(value: Float = 1.0f) { - general.apply { - put("launch_power_scale", value) - } + unsafe.general["launch_power_scale"] = value } /** * Draw Duration. Default is set to 0. */ fun maxDrawDuration(value: Int = 0) { - general.apply { - put("max_draw_duration", value) - } + unsafe.general["max_draw_duration"] = value } /** * Launch power. Default is set to 1.0. */ fun maxLaunchPower(value: Float = 1.0f) { - general.apply { - put("max_launch_power", value) - } + unsafe.general["max_launch_power"] = value } /** * Scale power by draw duration? Default is set to false. */ fun scalePowerByDrawDuration(value: Boolean = false) { - general.apply { - put("scale_power_by_draw_duration", value) - } + unsafe.general["scale_power_by_draw_duration"] = value } - fun getData(): MutableMap { - return general + @Deprecated("", ReplaceWith("unsafe.getData()")) + fun getData(): MutableMap = unsafe.getData() +} + +class BehItemShooterAmmo: MonsteraFile { + override val unsafe = Unsafe() + + inner class Unsafe: MonsteraUnsafeMap { + val general = mutableMapOf() + + override fun getData() = general } + + var item: String = "" + set(value) { + unsafe.general["item"] = value + field = value + } + + var useOffhand: Boolean = false + set(value) { + unsafe.general["use_offhand"] = value + field = value + } + + var searchInventory: Boolean = false + set(value) { + unsafe.general["search_inventory"] = value + field = value + } + + var useInCreative: Boolean = false + set(value) { + unsafe.general["use_in_creative"] = value + field = value + } } \ No newline at end of file