From a6ec046e18e35647569de592afc5df344cfa8b47 Mon Sep 17 00:00:00 2001 From: cao-awa Date: Wed, 27 Nov 2024 10:08:20 +0800 Subject: [PATCH] Add reified type to field and variable declarations. Moved template name to last one parameter. --- .../cao/awa/conium/ConiumServerInitializer.kt | 8 +- .../bedrock/event/BedrockBeforeEvents.kt | 4 +- .../event/context/BedrockEventContext.kt | 2 +- .../item/use/BedrockItemUseOnBeforeEvent.kt | 7 +- .../bedrock/item/stack/BedrockItemStack.kt | 2 +- .../script/BedrockScriptAnonymousObjectMap.kt | 14 +-- .../conium/bedrock/system/BedrockSystem.kt | 2 +- .../conium/bedrock/system/task/ConiumTask.kt | 2 +- .../bedrock/world/AbstractBedrockWorld.kt | 2 +- .../awa/conium/bedrock/world/BedrockWorld.kt | 12 +- .../bedrock/world/player/BedrockPlayer.kt | 2 +- .../player/screen/BedrockOnScreenDisplay.kt | 2 +- .../screen/title/BedrockScreenDisplayTitle.kt | 9 +- .../cao/awa/conium/block/ConiumBlock.kt | 14 +-- .../chest/close/ConiumChestClosedEvent.kt | 4 +- .../chest/close/ConiumChestClosingEvent.kt | 4 +- .../trapped/ConiumTrappedChestClosedEvent.kt | 6 +- .../trapped/ConiumTrappedChestClosingEvent.kt | 6 +- .../chest/open/ConiumChestOpenedEvent.kt | 4 +- .../chest/open/ConiumChestOpeningEvent.kt | 4 +- .../trapped/ConiumTrappedChestOpenedEvent.kt | 6 +- .../trapped/ConiumTrappedChestOpeningEvent.kt | 6 +- .../close/ConiumShulkerBoxClosedEvent.kt | 6 +- .../close/ConiumShulkerBoxClosingEvent.kt | 6 +- .../open/ConiumShulkerBoxOpenedEvent.kt | 6 +- .../open/ConiumShulkerBoxOpeningEvent.kt | 6 +- .../event/breaking/ConiumBreakBlockEvent.kt | 6 +- .../breaking/ConiumBreakingBlockEvent.kt | 6 +- .../event/breaking/ConiumBrokenBlockEvent.kt | 6 +- .../event/place/ConiumPlaceBlockEvent.kt | 6 +- .../event/place/ConiumPlacedBlockEvent.kt | 6 +- .../tick/ConiumBlockScheduleTickEvent.kt | 6 +- .../tick/ConiumBlockScheduleTickedEvent.kt | 6 +- .../fluid/ConiumFluidScheduleTickEvent.kt | 6 +- .../fluid/ConiumFluidScheduleTickedEvent.kt | 6 +- .../block/event/use/ConiumUseBlockEvent.kt | 6 +- .../block/event/use/ConiumUsedBlockEvent.kt | 6 +- .../block/template/ConiumBlockTemplate.kt | 2 +- .../collision/ConiumBlockCollisionTemplate.kt | 4 +- .../ConiumExplosionResistanceTemplate.kt | 2 +- .../ConiumBlockInstrumentTemplate.kt | 2 +- .../luminance/ConiumLuminanceTemplate.kt | 2 +- .../template/map/ConiumMapColorTemplate.kt | 2 +- .../template/mining/ConiumHardnessTemplate.kt | 2 +- .../ConiumBlockPathFindThroughTemplate.kt | 2 +- .../ConiumBlockPistonBehaviorsTemplate.kt | 2 +- .../ConiumBlockReplaceableTemplate.kt | 2 +- .../ConiumBlockMovementVelocityTemplate.kt | 2 +- .../entity/renderer/ConiumEntityRenderers.kt | 4 +- .../cao/awa/conium/codec/ConiumPacketCodec.kt | 14 ++- .../conium/component/ConiumComponentTypes.kt | 4 +- .../conium/datapack/ConiumJsonDataLoader.kt | 28 ++--- .../datapack/block/ConiumBlockManager.kt | 13 +- .../datapack/entity/ConiumEntityManager.kt | 2 +- .../inject/item/ItemPropertyInject.kt | 12 +- .../inject/item/ItemPropertyInjectManager.kt | 46 +++---- .../component/ItemPropertyInjectComponent.kt | 15 ++- .../ItemPropertyInjectComponentValue.kt | 2 +- .../conium/datapack/item/ConiumItemManager.kt | 12 +- .../datapack/item/fuel/ConiumFuelRegistry.kt | 14 +-- .../datapack/recipe/ConiumRecipeManager.kt | 116 +++++++++--------- .../datapack/script/ConiumScriptManager.kt | 45 ++++--- .../cao/awa/conium/entity/ConiumEntity.kt | 12 +- .../ConiumEntityAttributeRegistry.kt | 4 +- .../entity/builder/ConiumEntityBuilder.kt | 7 +- .../event/damage/ConiumEntityDamageEvent.kt | 8 +- .../event/damage/ConiumEntityDamagedEvent.kt | 8 +- .../entity/event/die/ConiumEntityDeadEvent.kt | 6 +- .../entity/event/die/ConiumEntityDieEvent.kt | 6 +- .../event/tick/ConiumEntityTickEvent.kt | 6 +- .../event/tick/ConiumEntityTickedEvent.kt | 6 +- .../entity/template/ConiumEntityTemplate.kt | 2 +- ...ConiumBedrockEntityCollisionBoxTemplate.kt | 20 +-- .../ConiumEntityDimensionTemplate.kt | 21 ++-- .../pushable/ConiumEntityPushableTemplate.kt | 2 +- .../model/ConiumEntityModelTemplate.kt | 2 +- .../server/tick/ConiumServerTickEvent.kt | 6 +- .../server/tick/ConiumServerTickTailEvent.kt | 6 +- .../conium/event/type/ConiumEventArgTypes.kt | 5 + .../event/use/ConiumItemUseOnBlockEvent.kt | 9 +- .../event/use/ConiumItemUsedOnBlockEvent.kt | 10 +- .../item/template/ConiumItemTemplate.kt | 9 +- .../action/ConiumUseActionTemplate.kt | 2 +- .../template/armor/ConiumArmorTemplate.kt | 2 +- .../template/armor/ConiumWearableTemplate.kt | 6 +- .../ConiumBedrockUseAnimationTemplate.kt | 9 +- .../damage/ConiumBedrockDamageTemplate.kt | 2 +- ...niumBedrockCanDestroyInCreativeTemplate.kt | 12 +- .../ConiumBedrockDurabilityTemplate.kt | 4 +- .../bedrock/food/ConiumBedrockFoodTemplate.kt | 11 +- .../glint/ConiumBedrockGlintTemplate.kt | 2 +- .../size/ConiumBedrockMaxStackSizeTemplate.kt | 2 +- .../wearable/ConiumBedrockWearableTemplate.kt | 2 +- .../consumable/ConiumConsumableTemplate.kt | 2 +- .../ConiumCanDestroyInCreativeTemplate.kt | 11 +- .../durability/ConiumDurabilityTemplate.kt | 8 +- .../template/egg/ConiumSpawnEggTemplate.kt | 2 +- .../item/template/food/ConiumFoodTemplate.kt | 2 +- .../item/template/fuel/ConiumFuelTemplate.kt | 6 +- .../template/glint/ConiumGlintTemplate.kt | 2 +- .../template/rarity/ConiumRarityTemplate.kt | 4 +- .../rarity/epic/ConiumCommonRarityTemplate.kt | 2 +- .../rarity/epic/ConiumEpicRarityTemplate.kt | 2 +- .../rarity/epic/ConiumRareRarityTemplate.kt | 2 +- .../epic/ConiumUncommonRarityTemplate.kt | 2 +- .../count/ConiumStackMaxCountTemplate.kt | 2 +- .../template/tool/ConiumItemToolTemplate.kt | 57 ++++++--- .../tool/axe/ConiumItemAxeTemplate.kt | 52 ++++++-- .../tool/axe/ConiumItemDiamondAxeTemplate.kt | 8 +- .../tool/axe/ConiumItemGoldenAxeTemplate.kt | 8 +- .../tool/axe/ConiumItemIronAxeTemplate.kt | 8 +- .../axe/ConiumItemNetheriteAxeTemplate.kt | 8 +- .../tool/axe/ConiumItemStoneAxeTemplate.kt | 8 +- .../tool/axe/ConiumItemWoodenAxeTemplate.kt | 8 +- .../ConiumItemDiamondPickaxeTemplate.kt | 8 +- .../ConiumItemGoldenPickaxeTemplate.kt | 8 +- .../pickaxe/ConiumItemIronPickaxeTemplate.kt | 8 +- .../ConiumItemNetheritePickaxeTemplate.kt | 4 +- .../tool/pickaxe/ConiumItemPickaxeTemplate.kt | 57 +++++++-- .../pickaxe/ConiumItemStonePickaxeTemplate.kt | 4 +- .../ConiumItemWoodenPickaxeTemplate.kt | 4 +- .../extent/block/ConiumBlockKotlinExtents.kt | 8 +- .../component/ConiumComponentsExtents.kt | 6 +- .../entity/ConiumEntityKotlinExtents.kt | 19 ++- .../kotlin/extent/innate/ConiumInnate.kt | 7 ++ .../extent/item/ConiumItemKotlinExtents.kt | 4 +- .../recipe/ConiumRecipeTypeKotlinExtends.kt | 2 +- .../conium/network/ConiumPacketRegistry.kt | 14 +-- .../registry/SynchronizeRegistryPayload.kt | 6 +- .../parameter/type/DynamicArgTypeBuilder.kt | 2 + .../cao/awa/conium/random/ConiumRandom.kt | 4 +- .../recipe/ConiumBedrockRecipeBuilder.kt | 14 +-- .../recipe/template/ConiumRecipeTemplate.kt | 24 ++-- .../ConiumBedrockRecipeFurnaceTemplate.kt | 7 +- .../ConiumBedrockRecipeShapedTemplate.kt | 6 +- .../awa/conium/registry/ConiumRegistryKeys.kt | 4 +- .../cao/awa/conium/script/ScriptExport.kt | 13 +- .../cao/awa/conium/script/kts/ConiumScript.kt | 16 ++- .../translate/ConiumScriptTranslator.kt | 6 +- ...niumTypescriptAnonymousObjectTranslator.kt | 9 +- ...oniumTypescriptDefineVariableTranslator.kt | 3 +- .../script/typescript/TypescriptPrototype.kt | 3 + .../cao/awa/conium/template/ConiumTemplate.kt | 7 +- .../conium/template/ConiumTemplateFactor.kt | 6 +- 144 files changed, 643 insertions(+), 616 deletions(-) rename src/main/java/com/github/cao/awa/conium/script/translate/kts/file/{object => obj}/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt (71%) diff --git a/src/main/java/com/github/cao/awa/conium/ConiumServerInitializer.kt b/src/main/java/com/github/cao/awa/conium/ConiumServerInitializer.kt index b0c3a16..e9368c4 100644 --- a/src/main/java/com/github/cao/awa/conium/ConiumServerInitializer.kt +++ b/src/main/java/com/github/cao/awa/conium/ConiumServerInitializer.kt @@ -2,11 +2,15 @@ package com.github.cao.awa.conium import com.github.cao.awa.conium.Conium.Companion.debug import com.github.cao.awa.conium.client.ConiumClient +import com.github.cao.awa.conium.kotlin.extent.innate.asIt import com.github.cao.awa.conium.network.ConiumPacketRegistry import com.github.cao.awa.conium.network.packet.client.configuration.registry.SynchronizeRegistryPayload import com.github.cao.awa.conium.server.ConiumDedicatedServer import net.fabricmc.api.DedicatedServerModInitializer import net.fabricmc.fabric.api.networking.v1.ServerConfigurationConnectionEvents +import net.minecraft.network.PacketByteBuf +import net.minecraft.network.codec.PacketCodec +import net.minecraft.network.packet.CustomPayload.Id import net.minecraft.server.MinecraftServer import net.minecraft.server.network.ServerConfigurationNetworkHandler import org.apache.logging.log4j.LogManager @@ -41,12 +45,12 @@ class ConiumServerInitializer : DedicatedServerModInitializer { } ConiumPacketRegistry.registerServer() - ConiumPacketRegistry.packets.let { packets -> + ConiumPacketRegistry.packets.let { packets: MutableMap, PacketCodec> -> LOGGER.info("Loaded ${packets.size} network packets") debug( "Loaded {} server network packets: {}", { packets.size }, - { packets }, + packets::asIt, LOGGER::info ) } diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt index a0e6831..ac6496e 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/BedrockBeforeEvents.kt @@ -8,9 +8,9 @@ import com.github.cao.awa.conium.bedrock.event.item.use.BedrockItemUseOnBeforeEv @BedrockScriptApiFacade("WorldBeforeEvents") class BedrockBeforeEvents { companion object { - val EVENTS = BedrockBeforeEvents() + val EVENTS: BedrockBeforeEvents = BedrockBeforeEvents() } @BedrockScriptApi - val itemUseOn = BedrockItemUseOnBeforeEvent() + val itemUseOn: BedrockItemUseOnBeforeEvent = BedrockItemUseOnBeforeEvent() } diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/context/BedrockEventContext.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/context/BedrockEventContext.kt index ac285e8..45b1f48 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/context/BedrockEventContext.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/context/BedrockEventContext.kt @@ -8,7 +8,7 @@ import com.github.cao.awa.sinuatum.util.collection.CollectionFactor abstract class BedrockEventContext(val scriptSource: Any) { companion object { - var system = BedrockSystem() + var system: BedrockSystem = BedrockSystem() var currentPosting: Any? = null val contexts: MutableMap = CollectionFactor.hashMap() diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt index c564e33..61ebe51 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/item/use/BedrockItemUseOnBeforeEvent.kt @@ -9,19 +9,20 @@ import com.github.cao.awa.conium.event.context.ConiumEventContextBuilder import com.github.cao.awa.conium.event.type.ConiumEventArgTypes import com.github.cao.awa.conium.event.type.ConiumEventType import com.github.cao.awa.conium.parameter.ParameterSelective1 +import net.minecraft.item.ItemUsageContext @BedrockScriptApi @BedrockScriptApiFacade("ItemUseOnBeforeEventSignal") class BedrockItemUseOnBeforeEvent { @BedrockScriptApi fun subscribe(action: ParameterSelective1) { - val currentPosting = BedrockEventContext.currentPosting!! + val currentPosting: Any = BedrockEventContext.currentPosting!! ConiumEventContextBuilder.request( ConiumEventType.ITEM_USE_ON_BLOCK, ConiumEventArgTypes.ITEM_USAGE_CONTEXT - ).presage { _, usage -> - action.arise(usage.toBedrock(currentPosting)) + ).presage { _: Any, usage: ItemUsageContext -> + action(usage.toBedrock(currentPosting)) BedrockEventContext.clearContext(currentPosting) diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt b/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt index dd05c4f..7a95161 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/item/stack/BedrockItemStack.kt @@ -8,7 +8,7 @@ import net.minecraft.registry.Registries @BedrockScriptApi @BedrockScriptApiFacade("ItemStack") class BedrockItemStack(private val delegate: ItemStack) { - val typeId get() = typeId() + val typeId: String get() = typeId() private fun typeId(): String = Registries.ITEM.getId(this.delegate.item).toString() } diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt b/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt index 93c3800..c27b510 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/script/BedrockScriptAnonymousObjectMap.kt @@ -16,19 +16,15 @@ open class BedrockScriptAnonymousObjectMap : Iterable> { - return this.map.iterator() - } + override fun iterator(): Iterator> = this.map.iterator() } fun BedrockScriptAnonymousObjectMap.toDynamicArgs(): MutableMap, Any?> { - val map = CollectionFactor.hashMap, Any?>() - for (entry in this) { - map[arg(entry.key, entry.key.javaClass)] = entry.value + val map: MutableMap, Any?> = CollectionFactor.hashMap() + for ((key: String, value: Any?) in this) { + map[arg(key, key.javaClass)] = value } return map } \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt b/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt index 77ae8bb..fcd3a0f 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/system/BedrockSystem.kt @@ -13,7 +13,7 @@ class BedrockSystem : AbstractBedrockSystem() { override fun runInterval(callback: () -> Unit, tickInterval: Int): IntegerReceptacle { println("RunningInterval") - val id = this.tasks.size + val id: Int = this.tasks.size this.tasks[id] = ConiumTask(tickInterval, callback) return IntegerReceptacle(id) } diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/system/task/ConiumTask.kt b/src/main/java/com/github/cao/awa/conium/bedrock/system/task/ConiumTask.kt index 9ef9556..4156f99 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/system/task/ConiumTask.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/system/task/ConiumTask.kt @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.bedrock.system.task class ConiumTask(private val interval: Int = -1, private val action: () -> Unit) { - private var tickingInterval = this.interval + private var tickingInterval: Int = this.interval fun tick() { if (this.interval == -1) { diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt index d565f3e..70c131b 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/AbstractBedrockWorld.kt @@ -6,7 +6,7 @@ import com.github.cao.awa.conium.bedrock.world.player.delegate.BedrockPlayerDele @BedrockScriptApiFacade("World") abstract class AbstractBedrockWorld { - val beforeEvents get() = eventsBefore() + val beforeEvents: BedrockBeforeEvents get() = eventsBefore() abstract fun getPlayers(): BedrockPlayerDelegate diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt index 6e0ca68..f11bde6 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/BedrockWorld.kt @@ -7,7 +7,7 @@ import net.minecraft.world.World @BedrockScriptApi open class BedrockWorld(private val delegate: World) : AbstractBedrockWorld() { companion object { - val DUMMY = DummyBedrockWorld() + val DUMMY: DummyBedrockWorld = DummyBedrockWorld() } private val players: BedrockPlayerDelegate = BedrockPlayerDelegate(this.delegate) @@ -16,13 +16,7 @@ open class BedrockWorld(private val delegate: World) : AbstractBedrockWorld() { } class DummyBedrockWorld : AbstractBedrockWorld() { - override fun getPlayers(): BedrockPlayerDelegate { - TODO("Will not be implements") - } + override fun getPlayers(): BedrockPlayerDelegate = TODO("Will not be implements") } -fun World.toBedrock(): BedrockWorld { - return BedrockWorld( - this - ) -} \ No newline at end of file +fun World.toBedrock(): BedrockWorld = BedrockWorld(this) \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt index 1dbd05a..4a61d3e 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/BedrockPlayer.kt @@ -8,7 +8,7 @@ import net.minecraft.entity.player.PlayerEntity @BedrockScriptApi @BedrockScriptApiFacade("Player") class BedrockPlayer(private val delegate: PlayerEntity) { - val onScreenDisplay = BedrockOnScreenDisplay(this) + val onScreenDisplay: BedrockOnScreenDisplay = BedrockOnScreenDisplay(this) } fun PlayerEntity.toBedrock(): BedrockPlayer { diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt index 5982dd5..9dda680 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/BedrockOnScreenDisplay.kt @@ -9,7 +9,7 @@ import com.github.cao.awa.conium.bedrock.world.player.screen.title.BedrockScreen @BedrockScriptApi @BedrockScriptApiFacade("ScreenDisplay") class BedrockOnScreenDisplay(val player: BedrockPlayer) { - private val screenDisplayTitle = BedrockScreenDisplayTitle("", "") + private val screenDisplayTitle: BedrockScreenDisplayTitle = BedrockScreenDisplayTitle("", "") fun setTitle(title: String, properties: BedrockScriptAnonymousObjectMap) = this.screenDisplayTitle.setTitle(title, properties) fun updateSubtitle(title: String) = this.screenDisplayTitle.updateSubtitle(title) diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/title/BedrockScreenDisplayTitle.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/title/BedrockScreenDisplayTitle.kt index d29560d..93df823 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/title/BedrockScreenDisplayTitle.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/player/screen/title/BedrockScreenDisplayTitle.kt @@ -5,11 +5,12 @@ import com.github.cao.awa.conium.bedrock.script.toDynamicArgs import com.github.cao.awa.conium.parameter.DynamicArgsBuilder import com.github.cao.awa.conium.parameter.type.DynamicArgTypeBuilder.arg import net.minecraft.client.MinecraftClient +import net.minecraft.client.gui.hud.InGameHud import net.minecraft.text.Text class BedrockScreenDisplayTitle(private var title: String, private var subtitle: String, private var active: Boolean = false) { fun setTitle(title: String, properties: BedrockScriptAnonymousObjectMap) { - MinecraftClient.getInstance().inGameHud.let { inGameHud -> + MinecraftClient.getInstance().inGameHud.let { inGameHud: InGameHud -> inGameHud.setTitle(Text.of(title)) properties["subtitle"]?.let { inGameHud.setSubtitle(Text.of(it as String)) @@ -19,13 +20,11 @@ class BedrockScreenDisplayTitle(private var title: String, private var subtitle: arg("fadeInDuration", Int::class.java), arg("stayDuration", Int::class.java), arg("fadeOutDuration", Int::class.java), - ).arising(Any(), properties.toDynamicArgs()) { _, fadeInTicks, stayTicks, fadeOutTicks -> + ).arising(Any(), properties.toDynamicArgs()) { _: Any, fadeInTicks: Int, stayTicks: Int, fadeOutTicks: Int -> inGameHud.setTitleTicks(fadeInTicks, stayTicks, fadeOutTicks) } } } - fun updateSubtitle(title: String) { - MinecraftClient.getInstance().inGameHud.setSubtitle(Text.of(title)) - } + fun updateSubtitle(title: String) = MinecraftClient.getInstance().inGameHud.setSubtitle(Text.of(title)) } diff --git a/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt b/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt index 7e7bbc1..5ced1fb 100644 --- a/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt +++ b/src/main/java/com/github/cao/awa/conium/block/ConiumBlock.kt @@ -14,18 +14,12 @@ import net.minecraft.world.BlockView class ConiumBlock(private val setting: ConiumBlockSettings) : Block(setting.vanillaSettings) { companion object { fun create(builder: ConiumBlockBuilder, settings: ConiumBlockSettings): ConiumBlock { - builder.templates.forEach { - it.prepare(settings) - } + builder.templates.forEach { it.prepare(settings) } - return ConiumBlock(settings).also { block -> - builder.templates.forEach { - it.attach(block) - } + return ConiumBlock(settings).also { block: ConiumBlock -> + builder.templates.forEach { it.attach(block) } - builder.templates.forEach { - it.complete(block) - } + builder.templates.forEach { it.complete(block) } } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosedEvent.kt index a1b6cbc..89b1aff 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosedEvent.kt @@ -40,8 +40,8 @@ class ConiumChestClosedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosingEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosingEvent.kt index 48b82d4..e6c2873 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosingEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/ConiumChestClosingEvent.kt @@ -40,8 +40,8 @@ class ConiumChestClosingEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosedEvent.kt index bcff6e9..3a795f5 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosedEvent.kt @@ -44,8 +44,8 @@ class ConiumTrappedChestClosedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) } } } @@ -67,7 +67,7 @@ class ConiumTrappedChestClosedEvent : ConiumEvent - val trappedContext = request(ConiumEventType.TRAPPED_CHEST_CLOSED) + val trappedContext: ConiumEventContext<*> = request(ConiumEventType.TRAPPED_CHEST_CLOSED) trappedContext[ConiumEventArgTypes.WORLD] = world trappedContext[ConiumEventArgTypes.PLAYER] = player diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosingEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosingEvent.kt index 633974b..f8f50cf 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosingEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/close/trapped/ConiumTrappedChestClosingEvent.kt @@ -44,8 +44,8 @@ class ConiumTrappedChestClosingEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) } } } @@ -67,7 +67,7 @@ class ConiumTrappedChestClosingEvent : ConiumEvent - val trappedContext = request(ConiumEventType.TRAPPED_CHEST_CLOSING) + val trappedContext: ConiumEventContext<*> = request(ConiumEventType.TRAPPED_CHEST_CLOSING) trappedContext[ConiumEventArgTypes.WORLD] = world trappedContext[ConiumEventArgTypes.PLAYER] = player diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpenedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpenedEvent.kt index 8e3e93e..04215ea 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpenedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpenedEvent.kt @@ -40,8 +40,8 @@ class ConiumChestOpenedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpeningEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpeningEvent.kt index faf5fcd..d90d2ed 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpeningEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/ConiumChestOpeningEvent.kt @@ -40,8 +40,8 @@ class ConiumChestOpeningEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as ChestBlockEntity, blockState, blockPos, viewerManager) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpenedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpenedEvent.kt index 4bf5386..67b3ab2 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpenedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpenedEvent.kt @@ -44,8 +44,8 @@ class ConiumTrappedChestOpenedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) } } } @@ -67,7 +67,7 @@ class ConiumTrappedChestOpenedEvent : ConiumEvent - val trappedContext = request(ConiumEventType.TRAPPED_CHEST_OPENED) + val trappedContext: ConiumEventContext<*> = request(ConiumEventType.TRAPPED_CHEST_OPENED) trappedContext[ConiumEventArgTypes.WORLD] = world trappedContext[ConiumEventArgTypes.PLAYER] = player diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpeningEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpeningEvent.kt index 9d114cf..c7d2616 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpeningEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/chest/open/trapped/ConiumTrappedChestOpeningEvent.kt @@ -44,8 +44,8 @@ class ConiumTrappedChestOpeningEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockEntity as TrappedChestBlockEntity, blockState, blockPos, viewerManager) } } } @@ -67,7 +67,7 @@ class ConiumTrappedChestOpeningEvent : ConiumEvent - val trappedContext = request(ConiumEventType.TRAPPED_CHEST_OPENING) + val trappedContext: ConiumEventContext<*> = request(ConiumEventType.TRAPPED_CHEST_OPENING) trappedContext[ConiumEventArgTypes.WORLD] = world trappedContext[ConiumEventArgTypes.PLAYER] = player diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosedEvent.kt index 9ddc902..0a3dc42 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosedEvent.kt @@ -31,9 +31,9 @@ class ConiumShulkerBoxClosedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) + ).arise { identity: Any, world: World, pos: PlayerEntity, blockEntity: BlockEntity, blockState: AbstractBlockState, blockPos: BlockPos -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosingEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosingEvent.kt index 7bd6529..89ab4d3 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosingEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/close/ConiumShulkerBoxClosingEvent.kt @@ -31,9 +31,9 @@ class ConiumShulkerBoxClosingEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) + ).arise { identity: Any, world: World, pos: PlayerEntity, blockEntity: BlockEntity, blockState: AbstractBlockState, blockPos: BlockPos -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpenedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpenedEvent.kt index 513fb03..93fae78 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpenedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpenedEvent.kt @@ -34,9 +34,9 @@ class ConiumShulkerBoxOpenedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) + ).arise { identity: Any, world: World, pos: PlayerEntity, blockEntity: BlockEntity, blockState: AbstractBlockState, blockPos: BlockPos -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt index 24e0702..21a8dde 100644 --- a/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/entity/event/shulker/open/ConiumShulkerBoxOpeningEvent.kt @@ -35,9 +35,9 @@ class ConiumShulkerBoxOpeningEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) + ).arise { identity: Any, world: World, pos: PlayerEntity, blockEntity: BlockEntity, blockState: AbstractBlockState, blockPos: BlockPos -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockEntity as ShulkerBoxBlockEntity, blockState, blockPos) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakBlockEvent.kt index 52d53d1..8ee1248 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakBlockEvent.kt @@ -19,9 +19,9 @@ class ConiumBreakBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockPos) + ).arise { identity: Any, world: World, player: PlayerEntity, blockPos: BlockPos -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockPos) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakingBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakingBlockEvent.kt index 12bbc4a..6760625 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakingBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBreakingBlockEvent.kt @@ -21,9 +21,9 @@ class ConiumBreakingBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockPos, state) + ).arise { identity: Any, world: World, player: PlayerEntity, blockPos: BlockPos, state: AbstractBlockState -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockPos, state) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBrokenBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBrokenBlockEvent.kt index 335c5bf..ae7c4ab 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBrokenBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/breaking/ConiumBrokenBlockEvent.kt @@ -21,9 +21,9 @@ class ConiumBrokenBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockPos, state) + ).arise { identity: Any, world: World, player: PlayerEntity, blockPos: BlockPos, state: AbstractBlockState -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockPos, state) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlaceBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlaceBlockEvent.kt index fc3c2d4..9d92662 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlaceBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlaceBlockEvent.kt @@ -15,9 +15,9 @@ class ConiumPlaceBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(context) + ).arise { identity: Any, context: ItemPlacementContext -> + noFailure(identity) { parameterSelective -> + parameterSelective(context) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlacedBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlacedBlockEvent.kt index b22080a..6ce7794 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlacedBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/place/ConiumPlacedBlockEvent.kt @@ -23,9 +23,9 @@ class ConiumPlacedBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(world, entity, blockPos, blockState, itemStack) + ).arise { identity: Any, world: World, entity: LivingEntity, blockPos: BlockPos, blockState: AbstractBlockState, itemStack: ItemStack -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, entity, blockPos, blockState, itemStack) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickEvent.kt index e5aa182..c567bc8 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickEvent.kt @@ -23,9 +23,9 @@ class ConiumBlockScheduleTickEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockState, scheduler, random) + ).arise { identity: Any, world: ServerWorld, pos: BlockPos, blockState: AbstractBlockState, scheduler: ScheduledTickView, random: Random -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockState, scheduler, random) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickedEvent.kt index cc48b6d..ab47b54 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/tick/ConiumBlockScheduleTickedEvent.kt @@ -23,9 +23,9 @@ class ConiumBlockScheduleTickedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockState, scheduler, random) + ).arise { identity: Any, world: ServerWorld, pos: BlockPos, blockState: AbstractBlockState, scheduler: ScheduledTickView, random: Random -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockState, scheduler, random) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickEvent.kt index be30d67..f865710 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickEvent.kt @@ -23,9 +23,9 @@ class ConiumFluidScheduleTickEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockState, fluidState, scheduler) + ).arise { identity: Any, world: ServerWorld, pos: BlockPos, blockState: AbstractBlockState, fluidState: FluidState, scheduler: ScheduledTickView -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockState, fluidState, scheduler) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickedEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickedEvent.kt index d11218f..191f340 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/tick/fluid/ConiumFluidScheduleTickedEvent.kt @@ -23,9 +23,9 @@ class ConiumFluidScheduleTickedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, pos, blockState, fluidState, scheduler) + ).arise { identity: Any, world: ServerWorld, pos: BlockPos, blockState: AbstractBlockState, fluidState: FluidState, scheduler: ScheduledTickView -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, pos, blockState, fluidState, scheduler) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUseBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUseBlockEvent.kt index b6f2998..8a26664 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUseBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUseBlockEvent.kt @@ -23,9 +23,9 @@ class ConiumUseBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockPos, blockState, hitResult) + ).arise { identity: Any, world: World, player: PlayerEntity, blockPos: BlockPos, blockState: AbstractBlockState, hitResult: BlockHitResult -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockPos, blockState, hitResult) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUsedBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUsedBlockEvent.kt index d3b04b4..0f3a486 100644 --- a/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUsedBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/block/event/use/ConiumUsedBlockEvent.kt @@ -25,9 +25,9 @@ class ConiumUsedBlockEvent : ConiumEvent - noFailure(identity) { - it.arise(world, player, blockPos, blockState, hitResult, actionResult) + ).arise { identity: Any, world: World, player: PlayerEntity, blockPos: BlockPos, blockState: AbstractBlockState, hitResult: BlockHitResult, actionResult: ActionResult -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, player, blockPos, blockState, hitResult, actionResult) } } } diff --git a/src/main/java/com/github/cao/awa/conium/block/template/ConiumBlockTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/ConiumBlockTemplate.kt index b447ded..a41e3f3 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/ConiumBlockTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/ConiumBlockTemplate.kt @@ -5,7 +5,7 @@ import com.github.cao.awa.conium.block.setting.ConiumBlockSettings import com.github.cao.awa.conium.template.ConiumTemplate import net.minecraft.block.AbstractBlock -abstract class ConiumBlockTemplate(name: String) : ConiumTemplate(name) { +abstract class ConiumBlockTemplate(isClient: Boolean = false, name: String) : ConiumTemplate(isClient, name) { override fun attach(target: ConiumBlock) { // Do nothing. } diff --git a/src/main/java/com/github/cao/awa/conium/block/template/collision/ConiumBlockCollisionTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/collision/ConiumBlockCollisionTemplate.kt index f6039d8..8b96136 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/collision/ConiumBlockCollisionTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/collision/ConiumBlockCollisionTemplate.kt @@ -19,7 +19,7 @@ class ConiumBlockCollisionTemplate( private val py2: Int = 16, private val pz2: Int = 16, name: String = COLLISION -) : ConiumBlockTemplate(name) { +) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockCollisionTemplate = element.objectOrBoolean( @@ -40,7 +40,7 @@ class ConiumBlockCollisionTemplate( // Only 6 cube data: // - origin x, origin y, origin z // - size x, size y, size z - return IntArray(6).also { array -> + return IntArray(6).also { array: IntArray -> var index = 0 // Create cubed from callback. cube { diff --git a/src/main/java/com/github/cao/awa/conium/block/template/explosion/resistance/ConiumExplosionResistanceTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/explosion/resistance/ConiumExplosionResistanceTemplate.kt index 8f7af9c..d6dad1b 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/explosion/resistance/ConiumExplosionResistanceTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/explosion/resistance/ConiumExplosionResistanceTemplate.kt @@ -6,7 +6,7 @@ import com.google.gson.JsonElement import net.minecraft.block.AbstractBlock import net.minecraft.registry.RegistryWrapper.WrapperLookup -open class ConiumExplosionResistanceTemplate(private val explosionResistance: Float, name: String = EXPLOSION_RESISTANCE) : ConiumBlockTemplate(name) { +open class ConiumExplosionResistanceTemplate(private val explosionResistance: Float, name: String = EXPLOSION_RESISTANCE) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumExplosionResistanceTemplate = ConiumExplosionResistanceTemplate(element.asFloat) diff --git a/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt index 0bc1231..217bbfe 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/instrument/ConiumBlockInstrumentTemplate.kt @@ -7,7 +7,7 @@ import net.minecraft.block.AbstractBlock import net.minecraft.block.enums.NoteBlockInstrument import net.minecraft.registry.RegistryWrapper.WrapperLookup -open class ConiumBlockInstrumentTemplate(private val instrument: NoteBlockInstrument, name: String = INSTRUMENT) : ConiumBlockTemplate(name) { +open class ConiumBlockInstrumentTemplate(private val instrument: NoteBlockInstrument, name: String = INSTRUMENT) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockInstrumentTemplate = ConiumBlockInstrumentTemplate(createBehaviors(element.asString)) diff --git a/src/main/java/com/github/cao/awa/conium/block/template/luminance/ConiumLuminanceTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/luminance/ConiumLuminanceTemplate.kt index df14081..de64f05 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/luminance/ConiumLuminanceTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/luminance/ConiumLuminanceTemplate.kt @@ -6,7 +6,7 @@ import com.google.gson.JsonElement import net.minecraft.block.AbstractBlock import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumLuminanceTemplate(private val level: Int, name: String = LUMINANCE) : ConiumBlockTemplate(name) { +class ConiumLuminanceTemplate(private val level: Int, name: String = LUMINANCE) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumLuminanceTemplate = ConiumLuminanceTemplate(validateLuminance(element.asInt)) diff --git a/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumMapColorTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumMapColorTemplate.kt index 3713c6e..e6ee1fb 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumMapColorTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumMapColorTemplate.kt @@ -8,7 +8,7 @@ import net.minecraft.block.AbstractBlock import net.minecraft.block.MapColor import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumMapColorTemplate(private val color: MapColor, name: String = MAP_COLOR) : ConiumBlockTemplate(name) { +class ConiumMapColorTemplate(private val color: MapColor, name: String = MAP_COLOR) : ConiumBlockTemplate(name = name) { companion object { // Not completed supports. @JvmStatic diff --git a/src/main/java/com/github/cao/awa/conium/block/template/mining/ConiumHardnessTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/mining/ConiumHardnessTemplate.kt index ce8d61d..93548cb 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/mining/ConiumHardnessTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/mining/ConiumHardnessTemplate.kt @@ -6,7 +6,7 @@ import com.google.gson.JsonElement import net.minecraft.block.AbstractBlock import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumHardnessTemplate(private val hardness: Float, name: String = HARDNESS) : ConiumBlockTemplate(name) { +class ConiumHardnessTemplate(private val hardness: Float, name: String = HARDNESS) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumHardnessTemplate = ConiumHardnessTemplate(element.asFloat) diff --git a/src/main/java/com/github/cao/awa/conium/block/template/path/through/ConiumBlockPathFindThroughTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/path/through/ConiumBlockPathFindThroughTemplate.kt index e8de29a..7d9e611 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/path/through/ConiumBlockPathFindThroughTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/path/through/ConiumBlockPathFindThroughTemplate.kt @@ -12,7 +12,7 @@ class ConiumBlockPathFindThroughTemplate( private val landPathThrough: Boolean, private val waterPathThrough: Boolean, private val airPathThrough: Boolean -) : ConiumBlockTemplate(PATH_FIND_THROUGH) { +) : ConiumBlockTemplate(name = PATH_FIND_THROUGH) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockPathFindThroughTemplate { diff --git a/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt index 1b6d9ab..96c2165 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/piston/ConiumBlockPistonBehaviorsTemplate.kt @@ -7,7 +7,7 @@ import net.minecraft.block.AbstractBlock import net.minecraft.block.piston.PistonBehavior import net.minecraft.registry.RegistryWrapper.WrapperLookup -open class ConiumBlockPistonBehaviorsTemplate(private val behavior: PistonBehavior, name: String = PISTON_BEHAVIOR) : ConiumBlockTemplate(name) { +open class ConiumBlockPistonBehaviorsTemplate(private val behavior: PistonBehavior, name: String = PISTON_BEHAVIOR) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockPistonBehaviorsTemplate = ConiumBlockPistonBehaviorsTemplate(createBehaviors(element.asString)) diff --git a/src/main/java/com/github/cao/awa/conium/block/template/replaceable/ConiumBlockReplaceableTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/replaceable/ConiumBlockReplaceableTemplate.kt index 366a5ab..8ea3fdc 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/replaceable/ConiumBlockReplaceableTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/replaceable/ConiumBlockReplaceableTemplate.kt @@ -6,7 +6,7 @@ import com.google.gson.JsonElement import net.minecraft.block.AbstractBlock import net.minecraft.registry.RegistryWrapper.WrapperLookup -open class ConiumBlockReplaceableTemplate(private val replaceable: Boolean, name: String = REPLACEABLE) : ConiumBlockTemplate(name) { +open class ConiumBlockReplaceableTemplate(private val replaceable: Boolean, name: String = REPLACEABLE) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockReplaceableTemplate = ConiumBlockReplaceableTemplate(element.asBoolean) diff --git a/src/main/java/com/github/cao/awa/conium/block/template/velocity/ConiumBlockMovementVelocityTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/velocity/ConiumBlockMovementVelocityTemplate.kt index 7aab384..0099f24 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/velocity/ConiumBlockMovementVelocityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/velocity/ConiumBlockMovementVelocityTemplate.kt @@ -8,7 +8,7 @@ import com.google.gson.JsonElement import net.minecraft.block.AbstractBlock import net.minecraft.registry.RegistryWrapper.WrapperLookup -open class ConiumBlockMovementVelocityTemplate(private val walkVelocity: Float, private val jumpVelocity: Float, name: String = MOVEMENT_VELOCITY) : ConiumBlockTemplate(name) { +open class ConiumBlockMovementVelocityTemplate(private val walkVelocity: Float, private val jumpVelocity: Float, name: String = MOVEMENT_VELOCITY) : ConiumBlockTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockMovementVelocityTemplate = element.ifJsonObject({ diff --git a/src/main/java/com/github/cao/awa/conium/client/entity/renderer/ConiumEntityRenderers.kt b/src/main/java/com/github/cao/awa/conium/client/entity/renderer/ConiumEntityRenderers.kt index af076ed..8c1d193 100644 --- a/src/main/java/com/github/cao/awa/conium/client/entity/renderer/ConiumEntityRenderers.kt +++ b/src/main/java/com/github/cao/awa/conium/client/entity/renderer/ConiumEntityRenderers.kt @@ -13,7 +13,5 @@ object ConiumEntityRenderers { val renderers: MutableMap, EntityRendererFactory> = CollectionFactor.hashMap() @JvmStatic - fun clearRenderers() { - this.renderers.clear() - } + fun clearRenderers() = this.renderers.clear() } diff --git a/src/main/java/com/github/cao/awa/conium/codec/ConiumPacketCodec.kt b/src/main/java/com/github/cao/awa/conium/codec/ConiumPacketCodec.kt index c40740f..0c0beed 100644 --- a/src/main/java/com/github/cao/awa/conium/codec/ConiumPacketCodec.kt +++ b/src/main/java/com/github/cao/awa/conium/codec/ConiumPacketCodec.kt @@ -19,7 +19,8 @@ object ConiumPacketCodec { component ) }, - { buf: RegistryByteBuf -> ItemPropertyInjectComponent.decode(buf) }) + { buf: RegistryByteBuf -> ItemPropertyInjectComponent.decode(buf) } + ) @JvmField val ITEM_PROPERTY_INJECT_ACTION: PacketCodec = PacketCodec.ofStatic( @@ -27,16 +28,16 @@ object ConiumPacketCodec { buf.writeByte(action.ordinal) }, { buf: RegistryByteBuf -> - val act = buf.readByte().toInt() + val act: Int = buf.readByte().toInt() if (act >= ItemPropertyInjectAction.entries.size) { throw DecoderException("Unsupported action: '$act'") } ItemPropertyInjectAction.entries[act] - }) + } + ) @JvmField - val ITEM_PROPERTY_INJECT_COMPONENT_LIST: PacketCodec>> = - ITEM_PROPERTY_INJECT_COMPONENT.collect(PacketCodecs.toCollection(CollectionFactor::arrayList)) + val ITEM_PROPERTY_INJECT_COMPONENT_LIST: PacketCodec>> = ITEM_PROPERTY_INJECT_COMPONENT.collect(PacketCodecs.toCollection(CollectionFactor::arrayList)) @JvmField val ITEM_PROPERTY_INJECT_COMPONENT_VALUE: PacketCodec> = @@ -47,5 +48,6 @@ object ConiumPacketCodec { value ) }, - { buf: RegistryByteBuf -> ItemPropertyInjectComponentValue.decode(buf) }) + { buf: RegistryByteBuf -> ItemPropertyInjectComponentValue.decode(buf) } + ) } diff --git a/src/main/java/com/github/cao/awa/conium/component/ConiumComponentTypes.kt b/src/main/java/com/github/cao/awa/conium/component/ConiumComponentTypes.kt index 87edf35..e67758d 100644 --- a/src/main/java/com/github/cao/awa/conium/component/ConiumComponentTypes.kt +++ b/src/main/java/com/github/cao/awa/conium/component/ConiumComponentTypes.kt @@ -1,3 +1,5 @@ +@file:Suppress("unchecked_cast") + package com.github.cao.awa.conium.component import com.github.cao.awa.conium.component.value.ConiumValueCreator @@ -17,7 +19,7 @@ object ConiumComponentTypes { val TEST: ConiumComponentType = register( "test", { builder: ConiumComponentTypeBuilder -> builder.codec(Codec.INT).packetCodec(PacketCodecs.INTEGER) }, - { obj: JsonElement -> obj.asInt } + JsonElement::getAsInt ) fun register(path: String, builderOperator: UnaryOperator>, valueCreator: ConiumValueCreator): ConiumComponentType { diff --git a/src/main/java/com/github/cao/awa/conium/datapack/ConiumJsonDataLoader.kt b/src/main/java/com/github/cao/awa/conium/datapack/ConiumJsonDataLoader.kt index 7883ee0..489f9f8 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/ConiumJsonDataLoader.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/ConiumJsonDataLoader.kt @@ -4,6 +4,7 @@ import com.github.cao.awa.conium.server.ConiumDedicatedServer import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonElement import com.google.gson.JsonParser +import net.minecraft.resource.Resource import net.minecraft.resource.ResourceFinder import net.minecraft.resource.ResourceManager import net.minecraft.resource.SinglePreparationResourceReloader @@ -11,40 +12,39 @@ import net.minecraft.util.Identifier import net.minecraft.util.profiler.Profiler import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger +import java.io.BufferedReader -abstract class ConiumJsonDataLoader(private val dataType: Identifier) : - SinglePreparationResourceReloader>() { +abstract class ConiumJsonDataLoader(private val dataType: Identifier) : SinglePreparationResourceReloader>() { companion object { private val LOGGER: Logger = LogManager.getLogger("ConiumJsonDataLoader") } - override fun prepare(resourceManager: ResourceManager, profiler: Profiler): MutableMap = - CollectionFactor.hashMap().also { - load(resourceManager, this.dataType, it) - } + override fun prepare(resourceManager: ResourceManager, profiler: Profiler): MutableMap = CollectionFactor.hashMap().also { + load(resourceManager, this.dataType, it) + } private fun load( manager: ResourceManager, dataType: Identifier, result: MutableMap ) { - val resourceFinder = ResourceFinder.json(dataType.path) + val resourceFinder: ResourceFinder = ResourceFinder.json(dataType.path) - for ((identifier, value) in resourceFinder.findResources(manager)) { + for ((identifier: Identifier, value: Resource) in resourceFinder.findResources(manager)) { try { - val reader = value.reader + val reader: BufferedReader = value.reader try { - JsonParser.parseReader(reader).let { - result[identifier] = it + JsonParser.parseReader(reader).let { json -> + result[identifier] = json if (ConiumDedicatedServer.initialized) { - ConiumDedicatedServer.onLoadData(dataType, identifier, it.toString()) + ConiumDedicatedServer.onLoadData(dataType, identifier, json.toString()) } } } catch (var14: Throwable) { try { - reader?.close() + reader.close() } catch (var13: Throwable) { var14.addSuppressed(var13) } @@ -52,7 +52,7 @@ abstract class ConiumJsonDataLoader(private val dataType: Identifier) : throw var14 } - reader?.close() + reader.close() } catch (var15: Exception) { LOGGER.error("Couldn't parse data file '{}' from '{}'", resourceFinder.toResourceId(identifier), identifier, var15) } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/block/ConiumBlockManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/block/ConiumBlockManager.kt index 3be3c10..4b8dbf4 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/block/ConiumBlockManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/block/ConiumBlockManager.kt @@ -3,6 +3,8 @@ package com.github.cao.awa.conium.datapack.block import com.github.cao.awa.conium.Conium +import com.github.cao.awa.conium.block.ConiumBlock +import com.github.cao.awa.conium.block.builder.ConiumBlockBuilder import com.github.cao.awa.conium.block.builder.bedrock.BedrockSchemaBlockBuilder import com.github.cao.awa.conium.block.builder.conium.ConiumSchemaBlockBuilder import com.github.cao.awa.conium.datapack.ConiumJsonDataLoader @@ -26,8 +28,7 @@ import net.minecraft.util.profiler.Profiler import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger -class ConiumBlockManager(private val registryLookup: RegistryWrapper.WrapperLookup) : - ConiumJsonDataLoader(ConiumRegistryKeys.BLOCK.value) { +class ConiumBlockManager(private val registryLookup: RegistryWrapper.WrapperLookup) : ConiumJsonDataLoader(ConiumRegistryKeys.BLOCK.value) { companion object { private val LOGGER: Logger = LogManager.getLogger("ConiumBlockManager") } @@ -35,7 +36,7 @@ class ConiumBlockManager(private val registryLookup: RegistryWrapper.WrapperLook override fun apply(prepared: MutableMap, manager: ResourceManager, profiler: Profiler) { resetRegistries() - for ((key, value) in prepared) { + for ((key: Identifier, value: JsonElement) in prepared) { load(key, value as JsonObject) } } @@ -57,17 +58,17 @@ class ConiumBlockManager(private val registryLookup: RegistryWrapper.WrapperLook LOGGER::info ) - val builder = if (json["schema_style"]?.asString == "conium") { + val builder: ConiumBlockBuilder = if (json["schema_style"]?.asString == "conium") { ConiumSchemaBlockBuilder.deserialize(json, this.registryLookup) } else { BedrockSchemaBlockBuilder.deserialize(json, this.registryLookup) } - builder.register { block -> + builder.register { block: ConiumBlock -> val var2: UnmodifiableIterator<*> = block.stateManager.states.iterator() while (var2.hasNext()) { - val blockState = var2.next() as BlockState + val blockState: BlockState = var2.next() as BlockState stateIds.addDynamic(blockState) blockState.initShapeCache() } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/entity/ConiumEntityManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/entity/ConiumEntityManager.kt index 2295eba..fb74217 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/entity/ConiumEntityManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/entity/ConiumEntityManager.kt @@ -34,7 +34,7 @@ class ConiumEntityManager(private val registryLookup: RegistryWrapper.WrapperLoo override fun apply(prepared: MutableMap, manager: ResourceManager, profiler: Profiler) { resetRegistries() - for ((key, value) in prepared) { + for ((key: Identifier, value: JsonElement) in prepared) { load(key, value as JsonObject) } } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInject.kt b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInject.kt index 5ac2184..b1d4982 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInject.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInject.kt @@ -8,15 +8,9 @@ import com.google.gson.JsonObject data class ItemPropertyInject(val target: String, val components: List>) { companion object { @JvmStatic - fun generic(target: String, components: List?>?): ItemPropertyInject { - return ItemPropertyInject(target, Manipulate.cast(components)) - } + fun generic(target: String, components: List>): ItemPropertyInject = ItemPropertyInject(target, Manipulate.cast(components)) - fun deserialize(json: JsonObject): ItemPropertyInject { - val target = json.get("target").asString - val components = ItemPropertyInjectComponent.unverified(json.get("components").asJsonArray) - - return generic(target, components) - } + @JvmStatic + fun deserialize(json: JsonObject): ItemPropertyInject = generic(json["target"].asString, ItemPropertyInjectComponent.unverified(json["components"].asJsonArray)) } } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInjectManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInjectManager.kt index 49c849c..368cd84 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInjectManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/ItemPropertyInjectManager.kt @@ -26,30 +26,32 @@ class ItemPropertyInjectManager : ConiumJsonDataLoader(ConiumRegistryKeys.ITEM_P private val LOGGER: Logger = LogManager.getLogger("ItemPropertyInjectManager") } - private val injects = CollectionFactor.hashMap>>() + private val injects: HashMap>> = CollectionFactor.hashMap() override fun apply(prepared: MutableMap, manager: ResourceManager, profiler: Profiler) { - for ((key, value) in prepared) { - value as JsonObject + for ((key: Identifier, value: JsonElement) in prepared) { + inject(key, value as JsonObject) + } + } - val itemTarget = value["target"].asString + fun inject(identifier: Identifier, json: JsonObject) { + val itemTarget = json["target"].asString - // Use to debug, trace inject details. - Conium.debug( - "Injecting property to item '{}' from '{}'", - { itemTarget }, - key::getNamespace, - LOGGER::info - ) + // Use to debug, trace inject details. + Conium.debug( + "Injecting property to item '{}' from '{}'", + { itemTarget }, + identifier::getNamespace, + LOGGER::info + ) - val injecting: ItemPropertyInject<*> = ItemPropertyInject.deserialize(value.asJsonObject) + val injecting: ItemPropertyInject<*> = ItemPropertyInject.deserialize(json) - val item = Registries.ITEM[Identifier.of(itemTarget)] + val item: Item = Registries.ITEM[Identifier.of(itemTarget)] - this.injects.computeIfAbsent(item) { CollectionFactor.arrayList() } + this.injects.computeIfAbsent(item) { CollectionFactor.arrayList() } - this.injects[item]!!.add(injecting) - } + this.injects[item]!!.add(injecting) } fun injects(item: Item): List> { @@ -59,16 +61,16 @@ class ItemPropertyInjectManager : ConiumJsonDataLoader(ConiumRegistryKeys.ITEM_P fun inject(stack: ItemStack) = injectProperty(stack, injects(stack.item)) fun injectProperty(stack: ItemStack, injects: List>) { - for (inject in injects) { + for (inject: ItemPropertyInject<*> in injects) { injectComponent(stack, inject.components) } } fun injectComponent(stack: ItemStack, injects: List>) { // Inject to current stack. - for (component in injects) { - val value = component.value - val type = component.type + for (component: ItemPropertyInjectComponent<*> in injects) { + val value: ItemPropertyInjectComponentValue<*> = component.value + val type: ComponentType<*> = component.type // Do not append the preset value when the component is present. if (component.action == ItemPropertyInjectAction.SET_PRESET) { @@ -80,8 +82,8 @@ class ItemPropertyInjectManager : ConiumJsonDataLoader(ConiumRegistryKeys.ITEM_P } // When the component is present, do actions. - val currentValue = stack.get(type) - val calculatedValue = ItemPropertyInjectHandler.doHandles(currentValue, value.value, component.action) + val currentValue: Any? = stack.get(type) + val calculatedValue: Any? = ItemPropertyInjectHandler.doHandles(currentValue, value.value, component.action) // Use to debug, trace inject details. Conium.debug( diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponent.kt b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponent.kt index 6b6863b..06f9961 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponent.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponent.kt @@ -6,6 +6,7 @@ import com.github.cao.awa.conium.datapack.inject.item.component.ItemPropertyInje import com.github.cao.awa.sinuatum.manipulate.Manipulate import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonArray +import com.google.gson.JsonElement import com.google.gson.JsonObject import net.minecraft.component.ComponentType import net.minecraft.network.RegistryByteBuf @@ -21,7 +22,7 @@ data class ItemPropertyInjectComponent( companion object { @JvmStatic fun decode(buf: RegistryByteBuf): ItemPropertyInjectComponent<*> { - val value = ConiumPacketCodec.ITEM_PROPERTY_INJECT_COMPONENT_VALUE.decode(buf) + val value: ItemPropertyInjectComponentValue<*> = ConiumPacketCodec.ITEM_PROPERTY_INJECT_COMPONENT_VALUE.decode(buf) return ItemPropertyInjectComponent( value.componentType!!, @@ -41,19 +42,17 @@ data class ItemPropertyInjectComponent( type: ComponentType<*>, action: ItemPropertyInjectAction, value: ItemPropertyInjectComponentValue<*> - ): ItemPropertyInjectComponent { - return ItemPropertyInjectComponent(type, action, value.verified(type)) - } + ): ItemPropertyInjectComponent = ItemPropertyInjectComponent(type, action, value.verified(type)) @JvmStatic fun unverified(json: JsonObject): ItemPropertyInjectComponent { - val type = Registries.DATA_COMPONENT_TYPE[Identifier.of(json["type"].asString)] + val type: ComponentType<*>? = Registries.DATA_COMPONENT_TYPE[Identifier.of(json["type"].asString)] - val action = if (json.has("action")) { + val action: ItemPropertyInjectAction = if (json.has("action")) { ItemPropertyInjectAction.of(json["action"].asString) } else ItemPropertyInjectAction.SET_PRESET - val value = unverified(json["value"]) + val value: ItemPropertyInjectComponentValue<*> = unverified(json["value"]) return verified(Manipulate.cast(type), action, value) } @@ -61,7 +60,7 @@ data class ItemPropertyInjectComponent( @JvmStatic fun unverified(json: JsonArray): List> { val components: MutableList> = CollectionFactor.arrayList() - for (element in json) { + for (element: JsonElement in json) { components.add(unverified(element.asJsonObject)) } return components diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponentValue.kt b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponentValue.kt index ea23385..2f11288 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponentValue.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/component/ItemPropertyInjectComponentValue.kt @@ -10,7 +10,7 @@ data class ItemPropertyInjectComponentValue(val value: X?, val componentType: companion object { @JvmStatic fun decode(buf: RegistryByteBuf): ItemPropertyInjectComponentValue<*> { - val componentType = ComponentType.PACKET_CODEC.decode(buf) + val componentType: ComponentType<*> = ComponentType.PACKET_CODEC.decode(buf) return ItemPropertyInjectComponentValue( componentType.packetCodec.decode(buf), diff --git a/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt index cef69ad..541701c 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/item/ConiumItemManager.kt @@ -23,19 +23,21 @@ import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import java.util.* -class ConiumItemManager(private val registryLookup: RegistryWrapper.WrapperLookup, private val pendingTagLoad: List>) : - ConiumJsonDataLoader(ConiumRegistryKeys.ITEM.value) { +class ConiumItemManager( + private val registryLookup: RegistryWrapper.WrapperLookup, + private val pendingTagLoad: List> +) : ConiumJsonDataLoader(ConiumRegistryKeys.ITEM.value) { companion object { private val LOGGER: Logger = LogManager.getLogger("ConiumItemManager") } - private val fuelRegistry = ConiumFuelRegistry() - val fuels get() = this.fuelRegistry.fuelItems + private val fuelRegistry: ConiumFuelRegistry = ConiumFuelRegistry() + val fuels: Set get() = this.fuelRegistry.fuelItems override fun apply(prepared: MutableMap, manager: ResourceManager, profiler: Profiler) { resetRegistries() - for ((key, value) in prepared) { + for ((key: Identifier, value: JsonElement) in prepared) { load(key, value as JsonObject) } } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/item/fuel/ConiumFuelRegistry.kt b/src/main/java/com/github/cao/awa/conium/datapack/item/fuel/ConiumFuelRegistry.kt index 728d4ce..4576d02 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/item/fuel/ConiumFuelRegistry.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/item/fuel/ConiumFuelRegistry.kt @@ -23,15 +23,13 @@ class ConiumFuelRegistry { this.computedFuels = null } - fun computeFuels(fuels: SequencedSet): SequencedSet { - return this.computedFuels ?: let { - val result = LinkedHashSet() - result.addAll(fuels) - result.addAll(this.fuelItems) + fun computeFuels(fuels: SequencedSet): SequencedSet = this.computedFuels ?: let { + val result: SequencedSet = LinkedHashSet() + result.addAll(fuels) + result.addAll(this.fuelItems) - this.computedFuels = result + this.computedFuels = result - result - } + result } } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/recipe/ConiumRecipeManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/recipe/ConiumRecipeManager.kt index 007064f..ac2ec79 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/recipe/ConiumRecipeManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/recipe/ConiumRecipeManager.kt @@ -5,6 +5,8 @@ import com.github.cao.awa.conium.mixin.recipe.ServerRecipeManagerAccessor import com.github.cao.awa.conium.mixin.recipe.property.RecipePropertySetAccessor import com.github.cao.awa.conium.recipe.ConiumBedrockRecipeBuilder import com.github.cao.awa.sinuatum.util.collection.CollectionFactor +import com.google.gson.JsonElement +import com.google.gson.JsonObject import com.google.gson.JsonParser import com.mojang.serialization.JsonOps import net.minecraft.recipe.* @@ -13,7 +15,9 @@ import net.minecraft.recipe.display.CuttingRecipeDisplay import net.minecraft.recipe.input.RecipeInput import net.minecraft.registry.RegistryKey import net.minecraft.registry.RegistryKeys +import net.minecraft.registry.RegistryOps import net.minecraft.registry.RegistryWrapper.WrapperLookup +import net.minecraft.resource.Resource import net.minecraft.resource.ResourceFinder import net.minecraft.resource.ResourceManager import net.minecraft.resource.featuretoggle.FeatureSet @@ -22,6 +26,7 @@ import net.minecraft.util.profiler.Profiler import net.minecraft.world.World import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger +import java.io.BufferedReader import java.util.* import java.util.function.Consumer import java.util.stream.Collectors @@ -35,10 +40,14 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM RecipePropertySet.SMITHING_ADDITION, SoleIngredientGetter { recipe: Recipe<*> -> if (recipe is SmithingRecipe) recipe.addition() else Optional.empty() } ), - Pair(RecipePropertySet.SMITHING_BASE, - SoleIngredientGetter { recipe: Recipe<*> -> if (recipe is SmithingRecipe) recipe.base() else Optional.empty() }), - Pair(RecipePropertySet.SMITHING_TEMPLATE, - SoleIngredientGetter { recipe: Recipe<*> -> if (recipe is SmithingRecipe) recipe.template() else Optional.empty() }), + Pair( + RecipePropertySet.SMITHING_BASE, + SoleIngredientGetter { recipe: Recipe<*> -> if (recipe is SmithingRecipe) recipe.base() else Optional.empty() } + ), + Pair( + RecipePropertySet.SMITHING_TEMPLATE, + SoleIngredientGetter { recipe: Recipe<*> -> if (recipe is SmithingRecipe) recipe.template() else Optional.empty() } + ), Pair( RecipePropertySet.FURNACE_INPUT, cookingIngredientGetter(RecipeType.SMELTING) @@ -80,7 +89,7 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM private val ingredients: MutableList = ArrayList() override fun accept(recipe: Recipe<*>) { - ingredientGetter.apply(recipe).ifPresent(ingredients::add) + this.ingredientGetter.apply(recipe).ifPresent(this.ingredients::add) } fun build(enabledFeatures: FeatureSet): RecipePropertySet { @@ -90,10 +99,10 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM } private var preparedConiumRecipes: PreparedRecipes = PreparedRecipes.EMPTY - private var coniumPropertySets: Map, RecipePropertySet> = CollectionFactor.hashMap() + private var coniumPropertySets: MutableMap, RecipePropertySet> = CollectionFactor.hashMap() private var coniumStonecutterRecipes: CuttingRecipeDisplay.Grouping = CuttingRecipeDisplay.Grouping.empty() - private var coniumRecipes = listOf() - private var coniumRecipesByKey: Map>, List> = CollectionFactor.hashMap() + private var coniumRecipes: MutableList = CollectionFactor.arrayList() + private var coniumRecipesByKey: MutableMap>, List> = CollectionFactor.hashMap() override fun prepare(resourceManager: ResourceManager, profiler: Profiler): PreparedRecipes { val sortedMap: SortedMap> = TreeMap() @@ -108,36 +117,36 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM } private fun load(manager: ResourceManager, dataType: String, result: MutableMap>) { - val resourceFinder = ResourceFinder.json(dataType) + val resourceFinder: ResourceFinder = ResourceFinder.json(dataType) - for ((key, value) in resourceFinder.findResources(manager)) { - val identifier2 = resourceFinder.toResourceId(key) + for ((identifier: Identifier, value: Resource) in resourceFinder.findResources(manager)) { + val resourceIdentifier: Identifier = resourceFinder.toResourceId(identifier) try { - val reader = value.reader!! + val reader: BufferedReader = value.reader try { - val ops = this.registries.getOps(JsonOps.INSTANCE) - val element = JsonParser.parseReader(reader) + val ops: RegistryOps = this.registries.getOps(JsonOps.INSTANCE) + val element: JsonElement = JsonParser.parseReader(reader) // Parse recipe by vanilla recipe schema. Recipe.CODEC.parse(ops, element).ifSuccess { - check(result.putIfAbsent(identifier2, it) == null) { - "Duplicate data file ignored with ID $identifier2" + check(result.putIfAbsent(resourceIdentifier, it) == null) { + "Duplicate data file ignored with ID $resourceIdentifier" } }.ifError { // If recipe are not vanilla, then it may be a bedrock recipe. - val json = element.asJsonObject + val json: JsonObject = element.asJsonObject try { // Find bedrock recipe and create it. - ConiumBedrockRecipeBuilder.findBedrock(json, this.registries).let { recipes -> + ConiumBedrockRecipeBuilder.findBedrock(json, this.registries).let { recipes: List> -> val standalone: Boolean = recipes.size == 1 for ((index: Int, recipe: Recipe<*>) in recipes.withIndex()) { val id = if (standalone) { - identifier2 + resourceIdentifier } else { - Identifier.of(identifier2.namespace, identifier2.path + "_" + recipe.type.coniumName + "_" + index) + Identifier.of(resourceIdentifier.namespace, resourceIdentifier.path + "_" + recipe.type.coniumName + "_" + index) } check(result.putIfAbsent(id, recipe) == null) { @@ -146,7 +155,7 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM } } } catch (e: Exception) { - LOGGER.error("Couldn't parse data file '{}' from '{}'", identifier2, key, e) + LOGGER.error("Couldn't parse data file '{}' from '{}'", resourceIdentifier, identifier, e) } } } catch (var14: Throwable) { @@ -161,7 +170,7 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM reader.close() } catch (var15: Exception) { - LOGGER.error("Couldn't parse data file '{}' from '{}'", identifier2, key, var15) + LOGGER.error("Couldn't parse data file '{}' from '{}'", resourceIdentifier, identifier, var15) } } } @@ -173,7 +182,7 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM override fun initialize(features: FeatureSet) { val list: MutableList> = ArrayList() - val list2 = SOLE_INGREDIENT_GETTERS.entries + val list2: MutableList = SOLE_INGREDIENT_GETTERS.entries .stream() .map { entry -> PropertySetBuilder( @@ -184,15 +193,15 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM this.preparedConiumRecipes .recipes() .forEach { - val recipe2 = it.value() - if (recipe2.isIgnoredInRecipeBook || !recipe2.ingredientPlacement.hasNoPlacement()) { - list2.forEach { builder -> builder.accept(recipe2) } - if (recipe2 is StonecuttingRecipe && isEnabled(features, recipe2.ingredient()) && recipe2.createResultDisplay().isEnabled(features)) { + val recipe: Recipe<*> = it.value() + if (recipe.isIgnoredInRecipeBook || !recipe.ingredientPlacement.hasNoPlacement()) { + list2.forEach { builder: PropertySetBuilder -> builder.accept(recipe) } + if (recipe is StonecuttingRecipe && isEnabled(features, recipe.ingredient()) && recipe.createResultDisplay().isEnabled(features)) { list.add( CuttingRecipeDisplay.GroupEntry( - recipe2.ingredient(), + recipe.ingredient(), CuttingRecipeDisplay( - recipe2.createResultDisplay(), + recipe.createResultDisplay(), Optional.of(it as RecipeEntry) ) ) @@ -206,7 +215,7 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM Collectors.toUnmodifiableMap( PropertySetBuilder::propertySetKey ) { it.build(features) } - ) as Map, RecipePropertySet> + ) as MutableMap, RecipePropertySet> this.coniumStonecutterRecipes = CuttingRecipeDisplay.Grouping(list) this.coniumRecipes = ServerRecipeManagerAccessor.collectServerRecipes(preparedConiumRecipes.recipes(), features) this.coniumRecipesByKey = coniumRecipes @@ -217,14 +226,14 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM { IdentityHashMap() }, Collectors.toList() ) - ) as Map>, List> + ) as MutableMap>, List> } override fun > getFirstMatch( type: RecipeType, input: I, world: World, recipe: RegistryKey>? ): Optional> { - val recipeEntry = if (recipe != null) this.get(type, recipe) else null + val recipeEntry: RecipeEntry? = if (recipe != null) this.get(type, recipe) else null return this.getFirstMatch(type, input, world, recipeEntry) } @@ -246,18 +255,16 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM * @param type the desired recipe type * @param world the input world */ - override fun > getFirstMatch(type: RecipeType, input: I, world: World): Optional> { - return this.preparedConiumRecipes.find(type, input, world).findFirst() - } + override fun > getFirstMatch(type: RecipeType, input: I, world: World): Optional> = this.preparedConiumRecipes.find( + type, + input, + world + ).findFirst() /** * {@return a recipe with the given {@code id}, or empty if there is no such recipe} */ - override fun get(key: RegistryKey>): Optional> { - return Optional.ofNullable( - this.preparedConiumRecipes[key] - ) - } + override fun get(key: RegistryKey>): Optional> = Optional.ofNullable(this.preparedConiumRecipes[key]) /** * {@return a recipe with the given {@code id} and {@code type}, or empty if there is no such recipe} @@ -265,7 +272,7 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM * @param type the type of the desired recipe */ private fun > get(type: RecipeType, key: RegistryKey>): RecipeEntry? { - val recipeEntry = this.preparedConiumRecipes[key] + val recipeEntry: RecipeEntry<*>? = this.preparedConiumRecipes[key] return if (recipeEntry != null && recipeEntry.value().type == type) { recipeEntry as RecipeEntry } else { @@ -273,21 +280,13 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM } } - override fun getPropertySets(): Map, RecipePropertySet> { - return this.coniumPropertySets - } + override fun getPropertySets(): Map, RecipePropertySet> = this.coniumPropertySets - override fun getStonecutterRecipeForSync(): CuttingRecipeDisplay.Grouping { - return this.stonecutterRecipes - } + override fun getStonecutterRecipeForSync(): CuttingRecipeDisplay.Grouping = this.stonecutterRecipes - override fun getPropertySet(key: RegistryKey): RecipePropertySet { - return propertySets.getOrDefault(key, RecipePropertySet.EMPTY) - } + override fun getPropertySet(key: RegistryKey): RecipePropertySet = propertySets.getOrDefault(key, RecipePropertySet.EMPTY) - override fun getStonecutterRecipes(): CuttingRecipeDisplay.Grouping { - return this.coniumStonecutterRecipes - } + override fun getStonecutterRecipes(): CuttingRecipeDisplay.Grouping = this.coniumStonecutterRecipes /** * {@return all recipes in this manager} @@ -296,16 +295,11 @@ class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeM * The returned set does not update with the manager. Modifications to the * returned set does not affect this manager. */ - override fun values(): Collection> { - return this.preparedConiumRecipes.recipes() - } + override fun values(): Collection> = this.preparedConiumRecipes.recipes() - override fun get(id: NetworkRecipeId): ServerRecipe { - return this.coniumRecipes[id.index] - } + override fun get(id: NetworkRecipeId): ServerRecipe = this.coniumRecipes[id.index] override fun forEachRecipeDisplay(key: RegistryKey>, action: Consumer) { - val list = this.coniumRecipesByKey[key] - list?.forEach { action.accept(it.display) } + this.coniumRecipesByKey[key]?.forEach { action.accept(it.display) } } } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/script/ConiumScriptManager.kt b/src/main/java/com/github/cao/awa/conium/datapack/script/ConiumScriptManager.kt index 3881e0a..5ea3822 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/script/ConiumScriptManager.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/script/ConiumScriptManager.kt @@ -17,13 +17,18 @@ import com.github.cao.awa.sinuatum.resource.loader.ResourceLoader import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.github.cao.awa.sinuatum.util.io.IOUtil import net.minecraft.registry.RegistryKeys -import net.minecraft.resource.* +import net.minecraft.resource.Resource +import net.minecraft.resource.ResourceFinder +import net.minecraft.resource.ResourceManager +import net.minecraft.resource.SinglePreparationResourceReloader import net.minecraft.util.Identifier import net.minecraft.util.profiler.Profiler import org.antlr.v4.runtime.* import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger -import kotlin.script.experimental.api.* +import kotlin.script.experimental.api.EvaluationResult +import kotlin.script.experimental.api.ResultValue +import kotlin.script.experimental.api.ResultWithDiagnostics import kotlin.script.experimental.host.StringScriptSource import kotlin.script.experimental.jvm.dependenciesFromCurrentContext import kotlin.script.experimental.jvm.jvm @@ -43,21 +48,19 @@ import kotlin.script.experimental.jvmhost.createJvmCompilationConfigurationFromT class ConiumScriptManager : SinglePreparationResourceReloader>() { companion object { private val LOGGER: Logger = LogManager.getLogger("ConiumScriptManager") - private val DATA_TYPE = RegistryKeys.getPath(ConiumRegistryKeys.SCRIPT) + private val DATA_TYPE: String = RegistryKeys.getPath(ConiumRegistryKeys.SCRIPT) // Commons script here, all script uses theses script. - private val defaultCommons = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.commons.kts")) - private val defaultBedrockScriptInit = - IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.bedrock.script.init.kts")) - private val defaultBedrockCommons = - IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.bedrock.commons.kts")) + private val defaultCommons: String = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.commons.kts")) + private val defaultBedrockScriptInit: String = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.bedrock.script.init.kts")) + private val defaultBedrockCommons: String = IOUtil.read(ResourceLoader.get("assets/conium/scripts/conium.bedrock.commons.kts")) /** * The 'host' is kotlin scripting host that used to compile and evaluate the kotlin scripts. * * Don't use JSR223 API to evaluates scripts, it will cause unexpected produce env problems! */ - private val host = BasicJvmScriptingHost() + private val host: BasicJvmScriptingHost = BasicJvmScriptingHost() } /** @@ -67,7 +70,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader() + private val exportedScript: MutableMap = CollectionFactor.hashMap() /** * Prepares the intermediate object. @@ -157,14 +160,11 @@ class ConiumScriptManager : SinglePreparationResourceReloader + identifier.path.also { path: String -> if (path.endsWith(".kts")) { // Load script data after. scripts.add(ScriptEval(content, path, "ConiumCommons")) @@ -221,12 +221,12 @@ class ConiumScriptManager : SinglePreparationResourceReloader + return readTypescript(source).let { typescriptFile: TypescriptFile -> // Prepares the typescript AST for next step translating. typescriptFile.prepares() // Translate typescript to conium script (kotlin script with conium API). - val translated = LanguageTranslator.translate( + val translated: String = LanguageTranslator.translate( // Use conium provider to processes something additional features. // See the package 'com.github.cao.awa.conium.script.translate' "conium", @@ -290,8 +290,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader Unit ): ResultWithDiagnostics { // Import scripts to this script. - val content = ScriptExport.import(this.exportedScript, scriptEval.codes, *scriptEval.defaultImports) + val content: String = ScriptExport.import(this.exportedScript, scriptEval.codes, *scriptEval.defaultImports) LOGGER.info( "Evaluating script '{}'", @@ -312,7 +311,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader = host.eval( StringScriptSource(content), // Create compilation configuration that dependencies whole java classpath. // Dependencies whole classpath is necessary, otherwise kotlin script may not be executes anything, @@ -332,7 +331,7 @@ class ConiumScriptManager : SinglePreparationResourceReloader + .let { returnValue: ResultValue -> // When the 'returnValue' is value, then it may be 'ScriptExport'. (returnValue as? ResultValue.Value) ?.let(ResultValue.Value::value) diff --git a/src/main/java/com/github/cao/awa/conium/entity/ConiumEntity.kt b/src/main/java/com/github/cao/awa/conium/entity/ConiumEntity.kt index 92a4f92..e7e980d 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/ConiumEntity.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/ConiumEntity.kt @@ -19,9 +19,7 @@ class ConiumEntity(entityType: EntityType, world: World, private v companion object { @JvmStatic fun createType(builder: ConiumEntityBuilder, settings: ConiumEntitySettingsWithTypeBuilder): EntityType.Builder { - builder.templates.forEach { - it.prepare(settings) - } + builder.templates.forEach { it.prepare(settings) } return settings.builder } @@ -33,13 +31,9 @@ class ConiumEntity(entityType: EntityType, world: World, private v } fun applyTemplates(templates: List) { - templates.forEach { - it.attach(this) - } + templates.forEach { it.attach(this) } - templates.forEach { - it.complete(this) - } + templates.forEach { it.complete(this) } this.customName = Text.of("Test conium entity(${Registries.ENTITY_TYPE.getId(this.type)})") this.isCustomNameVisible = true diff --git a/src/main/java/com/github/cao/awa/conium/entity/attribute/ConiumEntityAttributeRegistry.kt b/src/main/java/com/github/cao/awa/conium/entity/attribute/ConiumEntityAttributeRegistry.kt index 79264bf..2bea8fe 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/attribute/ConiumEntityAttributeRegistry.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/attribute/ConiumEntityAttributeRegistry.kt @@ -10,7 +10,5 @@ object ConiumEntityAttributeRegistry { val attributes: MutableMap, DefaultAttributeContainer> = CollectionFactor.hashMap() @JvmStatic - fun resetAttributes() { - this.attributes.clear() - } + fun resetAttributes() = this.attributes.clear() } diff --git a/src/main/java/com/github/cao/awa/conium/entity/builder/ConiumEntityBuilder.kt b/src/main/java/com/github/cao/awa/conium/entity/builder/ConiumEntityBuilder.kt index 80ac76e..6253218 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/builder/ConiumEntityBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/builder/ConiumEntityBuilder.kt @@ -9,6 +9,7 @@ import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import net.minecraft.entity.EntityType import net.minecraft.entity.SpawnGroup import net.minecraft.util.Identifier +import net.minecraft.world.World abstract class ConiumEntityBuilder(val identifier: Identifier) : ConiumBuilderWithTemplates< ConiumEntityBuilder, @@ -19,7 +20,7 @@ abstract class ConiumEntityBuilder(val identifier: Identifier) : ConiumBuilderWi ) { companion object { fun build(builder: ConiumEntityBuilder): EntityType.Builder { - val type = EntityType.Builder.create({ type, world -> + val type: EntityType.Builder = EntityType.Builder.create({ type: EntityType, world: World -> ConiumEntity( type, world, @@ -27,7 +28,7 @@ abstract class ConiumEntityBuilder(val identifier: Identifier) : ConiumBuilderWi ).also { it.applyTemplates(builder.templates) } }, SpawnGroup.MISC) - builder.groupTemplates.forEach { (name, templates) -> + builder.groupTemplates.forEach { (name: String, templates: MutableList) -> builder.entitySettings.migrate( name, ConiumEntitySettings.create(templates, type) @@ -42,7 +43,7 @@ abstract class ConiumEntityBuilder(val identifier: Identifier) : ConiumBuilderWi } val groupTemplates: MutableMap> = CollectionFactor.hashMap() - val entitySettings = ConiumEntitySettings() + val entitySettings: ConiumEntitySettings = ConiumEntitySettings() fun addTemplates(group: String, templates: MutableList): ConiumEntityBuilder { this.groupTemplates.computeIfAbsent(group) { CollectionFactor.arrayList() }.addAll(templates) diff --git a/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamageEvent.kt b/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamageEvent.kt index c26b050..0b4c539 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamageEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamageEvent.kt @@ -17,12 +17,12 @@ class ConiumEntityDamageEvent : ConiumEvent - noFailure(identity) { - it.arise(world, livingEntity, damageSource, amount) + ).arise { identity: Any, world: World, livingEntity: LivingEntity, damageSource: DamageSource, amount: Float -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, livingEntity, damageSource, amount) } } } diff --git a/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamagedEvent.kt b/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamagedEvent.kt index 2deb7e6..b64db7d 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamagedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/event/damage/ConiumEntityDamagedEvent.kt @@ -17,12 +17,12 @@ class ConiumEntityDamagedEvent : ConiumEvent - noFailure(identity) { - it.arise(world, livingEntity, damageSource, amount) + ).arise { identity: Any, world: World, livingEntity: LivingEntity, damageSource: DamageSource, amount: Float -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, livingEntity, damageSource, amount) } } } diff --git a/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDeadEvent.kt b/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDeadEvent.kt index 95cecea..88cb701 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDeadEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDeadEvent.kt @@ -19,9 +19,9 @@ class ConiumEntityDeadEvent : ConiumEvent - noFailure(identity) { - it.arise(world, livingEntity, damageSource) + ).arise { identity: Any, world: World, livingEntity: LivingEntity, damageSource: DamageSource -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, livingEntity, damageSource) } } } diff --git a/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDieEvent.kt b/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDieEvent.kt index 46155ec..4bbe71c 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDieEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/event/die/ConiumEntityDieEvent.kt @@ -19,9 +19,9 @@ class ConiumEntityDieEvent : ConiumEvent - noFailure(identity) { - it.arise(world, livingEntity, damageSource) + ).arise { identity: Any, world: World, livingEntity: LivingEntity, damageSource: DamageSource -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, livingEntity, damageSource) } } } diff --git a/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickEvent.kt b/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickEvent.kt index 33bc1fe..77e4676 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickEvent.kt @@ -15,9 +15,9 @@ class ConiumEntityTickEvent : ConiumEvent>( ConiumEventArgTypes.ENTITY ).attach( forever(ConiumEventType.ENTITY_TICK) - ).arise { identity, entity -> - noFailure(identity) { - it.arise(entity) + ).arise { identity: Any, entity: Entity -> + noFailure(identity) { parameterSelective -> + parameterSelective(entity) } } } diff --git a/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickedEvent.kt b/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickedEvent.kt index 3225638..1ad6ee9 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickedEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/event/tick/ConiumEntityTickedEvent.kt @@ -15,9 +15,9 @@ class ConiumEntityTickedEvent : ConiumEvent ConiumEventArgTypes.ENTITY ).attach( forever(ConiumEventType.ENTITY_TICKED) - ).arise { identity, entity -> - noFailure(identity) { - it.arise(entity) + ).arise { identity: Any, entity: Entity -> + noFailure(identity) { parameterSelective -> + parameterSelective(entity) } } } diff --git a/src/main/java/com/github/cao/awa/conium/entity/template/ConiumEntityTemplate.kt b/src/main/java/com/github/cao/awa/conium/entity/template/ConiumEntityTemplate.kt index c55c763..c31560a 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/template/ConiumEntityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/template/ConiumEntityTemplate.kt @@ -6,7 +6,7 @@ import com.github.cao.awa.conium.entity.setting.ConiumEntitySettingsWithTypeBuil import com.github.cao.awa.conium.template.ConiumTemplate import net.minecraft.entity.EntityType -abstract class ConiumEntityTemplate(name: String, isClient: Boolean = false) : ConiumTemplate(name, isClient) { +abstract class ConiumEntityTemplate(isClient: Boolean = false, name: String) : ConiumTemplate(isClient, name) { override fun attach(target: ConiumEntity) { // Do nothing. } diff --git a/src/main/java/com/github/cao/awa/conium/entity/template/bedrock/collision/ConiumBedrockEntityCollisionBoxTemplate.kt b/src/main/java/com/github/cao/awa/conium/entity/template/bedrock/collision/ConiumBedrockEntityCollisionBoxTemplate.kt index a9625c6..17f5a72 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/template/bedrock/collision/ConiumBedrockEntityCollisionBoxTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/template/bedrock/collision/ConiumBedrockEntityCollisionBoxTemplate.kt @@ -1,17 +1,23 @@ package com.github.cao.awa.conium.entity.template.bedrock.collision import com.github.cao.awa.conium.entity.template.dimension.ConiumEntityDimensionTemplate +import com.github.cao.awa.conium.template.ConiumTemplate.Companion.notSupported +import com.github.cao.awa.conium.kotlin.extent.json.ifJsonObject import com.github.cao.awa.conium.template.ConiumTemplates.BedrockEntity.COLLISION_BOX import com.google.gson.JsonElement +import com.google.gson.JsonObject import net.minecraft.registry.RegistryWrapper.WrapperLookup object ConiumBedrockEntityCollisionBoxTemplate { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumEntityDimensionTemplate = element.asJsonObject.let { - ConiumEntityDimensionTemplate( - it["width"].asFloat, - it["height"].asFloat, - COLLISION_BOX - ) - } + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumEntityDimensionTemplate = element.ifJsonObject( + { json: JsonObject -> + ConiumEntityDimensionTemplate( + json["width"].asFloat, + json["height"].asFloat, + COLLISION_BOX + ) + }, + notSupported() + )!! } diff --git a/src/main/java/com/github/cao/awa/conium/entity/template/dimension/ConiumEntityDimensionTemplate.kt b/src/main/java/com/github/cao/awa/conium/entity/template/dimension/ConiumEntityDimensionTemplate.kt index 59b48df..01bae9d 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/template/dimension/ConiumEntityDimensionTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/template/dimension/ConiumEntityDimensionTemplate.kt @@ -2,24 +2,29 @@ package com.github.cao.awa.conium.entity.template.dimension import com.github.cao.awa.conium.entity.setting.ConiumEntitySettings import com.github.cao.awa.conium.entity.template.ConiumEntityTemplate +import com.github.cao.awa.conium.template.ConiumTemplate.Companion.notSupported +import com.github.cao.awa.conium.kotlin.extent.json.ifJsonObject import com.github.cao.awa.conium.template.ConiumTemplates.Entity.DIMENSION import com.google.gson.JsonElement import net.minecraft.entity.EntityDimensions import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumEntityDimensionTemplate( +open class ConiumEntityDimensionTemplate( private val width: Float, private val height: Float, name: String = DIMENSION -) : ConiumEntityTemplate(name) { +) : ConiumEntityTemplate(name = name) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumEntityDimensionTemplate = element.asJsonObject.let { - ConiumEntityDimensionTemplate( - it["width"].asFloat, - it["height"].asFloat - ) - } + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumEntityDimensionTemplate = element.ifJsonObject( + { + ConiumEntityDimensionTemplate( + it["width"].asFloat, + it["height"].asFloat + ) + }, + notSupported() + )!! @JvmStatic fun dimensions(width: Float, height: Float): EntityDimensions = EntityDimensions.changing(width, height) diff --git a/src/main/java/com/github/cao/awa/conium/entity/template/pushable/ConiumEntityPushableTemplate.kt b/src/main/java/com/github/cao/awa/conium/entity/template/pushable/ConiumEntityPushableTemplate.kt index ca1dd3e..c24abc8 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/template/pushable/ConiumEntityPushableTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/template/pushable/ConiumEntityPushableTemplate.kt @@ -13,7 +13,7 @@ class ConiumEntityPushableTemplate( private val pushableByPiston: Boolean, private val pushableByFluids: Boolean, name: String -) : ConiumEntityTemplate(name) { +) : ConiumEntityTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup, name: String): ConiumEntityPushableTemplate = element.objectOrBoolean( diff --git a/src/main/java/com/github/cao/awa/conium/entity/template/renderer/model/ConiumEntityModelTemplate.kt b/src/main/java/com/github/cao/awa/conium/entity/template/renderer/model/ConiumEntityModelTemplate.kt index 5a0acd2..384fe88 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/template/renderer/model/ConiumEntityModelTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/template/renderer/model/ConiumEntityModelTemplate.kt @@ -14,7 +14,7 @@ import net.minecraft.util.Identifier class ConiumEntityModelTemplate( private val texturePath: Identifier, private val model: (EntityRendererFactory.Context) -> ConiumEntityModel, -) : ConiumEntityTemplate(MODEL, true) { +) : ConiumEntityTemplate(true, MODEL) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumEntityModelTemplate { diff --git a/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickEvent.kt b/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickEvent.kt index 1da284e..84bf595 100644 --- a/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickEvent.kt @@ -11,10 +11,8 @@ class ConiumServerTickEvent : ConiumEvent>() { override fun requirement(): ConiumEventContext { return requires().attach( forever(ConiumEventType.SERVER_TICK) - ).arise { identity -> - noFailure(identity) { - it.arise() - } + ).arise { identity: Any -> + noFailure(identity, ParameterSelective0::arise) } } } diff --git a/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickTailEvent.kt b/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickTailEvent.kt index 16a6dfb..6d2c2e4 100644 --- a/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickTailEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/event/server/tick/ConiumServerTickTailEvent.kt @@ -11,10 +11,8 @@ class ConiumServerTickTailEvent : ConiumEvent>() { override fun requirement(): ConiumEventContext { return requires().attach( forever(ConiumEventType.SERVER_TICK_TAIL) - ).arise { identity -> - noFailure(identity) { - it.arise() - } + ).arise { identity: Any -> + noFailure(identity, ParameterSelective0::arise) } } } diff --git a/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventArgTypes.kt b/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventArgTypes.kt index a494bf3..f3ab7ef 100644 --- a/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventArgTypes.kt +++ b/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventArgTypes.kt @@ -106,6 +106,9 @@ object ConiumEventArgTypes { @JvmField val DAMAGE_SOURCE: DynamicArgType + @JvmField + val DAMAGE_AMOUNT: DynamicArgType + @JvmField val INT: DynamicArgType @@ -237,6 +240,8 @@ object ConiumEventArgTypes { DAMAGE_SOURCE = arg("damage_source") + DAMAGE_AMOUNT = arg("damage_amount") + INT = arg( "int", transform(::LONG, Long::toInt), diff --git a/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUseOnBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUseOnBlockEvent.kt index bee8b31..93d7e06 100644 --- a/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUseOnBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUseOnBlockEvent.kt @@ -17,12 +17,9 @@ class ConiumItemUseOnBlockEvent : ConiumItemEvent - noFailure(identity) { - it.arise( - world, - context - ) + ).arise { identity: Any, world: ServerWorld, context: ItemUsageContext -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, context) } } } diff --git a/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUsedOnBlockEvent.kt b/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUsedOnBlockEvent.kt index 964b94d..2322cbe 100644 --- a/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUsedOnBlockEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/item/event/use/ConiumItemUsedOnBlockEvent.kt @@ -19,13 +19,9 @@ class ConiumItemUsedOnBlockEvent : ConiumItemEvent - noFailure(identity) { - it.arise( - world, - context, - result - ) + ).arise { identity: Any, world: ServerWorld, context: ItemUsageContext, result: ActionResult -> + noFailure(identity) { parameterSelective -> + parameterSelective(world, context, result) } } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt index ddf456e..d7810f7 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/ConiumItemTemplate.kt @@ -2,12 +2,11 @@ package com.github.cao.awa.conium.item.template import com.github.cao.awa.conium.item.ConiumItem import com.github.cao.awa.conium.template.ConiumTemplate -import com.google.gson.JsonElement import net.minecraft.item.Item import net.minecraft.item.consume.UseAction import net.minecraft.util.Rarity -abstract class ConiumItemTemplate(name: String) : ConiumTemplate(name) { +abstract class ConiumItemTemplate(isClient: Boolean = false, name: String) : ConiumTemplate(isClient, name) { companion object { fun createRarity(name: String): Rarity { return when (name) { @@ -41,12 +40,6 @@ abstract class ConiumItemTemplate(name: String) : ConiumTemplate notSupported(): (JsonElement) -> R = { throw notSupported(it) } - - @Throws(IllegalArgumentException::class) - fun notSupported(jsonElement: JsonElement): IllegalArgumentException = IllegalArgumentException("Not supported syntax: $jsonElement") - } override fun complete(target: ConiumItem) { diff --git a/src/main/java/com/github/cao/awa/conium/item/template/action/ConiumUseActionTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/action/ConiumUseActionTemplate.kt index 2bcc50b..c9e90b4 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/action/ConiumUseActionTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/action/ConiumUseActionTemplate.kt @@ -12,7 +12,7 @@ import net.minecraft.item.Item import net.minecraft.item.consume.UseAction import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumUseActionTemplate(private val useAction: UseAction) : ConiumItemTemplate(USE_ACTION) { +class ConiumUseActionTemplate(private val useAction: UseAction) : ConiumItemTemplate(name = USE_ACTION) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumUseActionTemplate = ConiumUseActionTemplate(createUseAction(element.asString)) diff --git a/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumArmorTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumArmorTemplate.kt index 8192ace..42e509e 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumArmorTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumArmorTemplate.kt @@ -31,7 +31,7 @@ class ConiumArmorTemplate( private val toughness: Double = 0.0, private val knockbackResistance: Double = 0.0, private val enchantmentValue: Int = 0 -) : ConiumWearableTemplate(ARMOR, equipment, defense) { +) : ConiumWearableTemplate(equipment, defense, ARMOR) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumArmorTemplate = element.objectOrString( diff --git a/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumWearableTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumWearableTemplate.kt index 7ba3e7c..f78ceeb 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumWearableTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/armor/ConiumWearableTemplate.kt @@ -28,10 +28,10 @@ import net.minecraft.util.Identifier * @since 1.0.0 */ abstract class ConiumWearableTemplate( - name: String, private val equipment: EquipmentType, - private val defense: Double -) : ConiumItemTemplate(name) { + private val defense: Double, + name: String +) : ConiumItemTemplate(name = name) { companion object { fun createEquipment(name: String): EquipmentType { return when (name) { diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/animation/ConiumBedrockUseAnimationTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/animation/ConiumBedrockUseAnimationTemplate.kt index 840abe3..077ca17 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/animation/ConiumBedrockUseAnimationTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/animation/ConiumBedrockUseAnimationTemplate.kt @@ -13,7 +13,7 @@ import net.minecraft.item.Item import net.minecraft.item.consume.UseAction import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumBedrockUseAnimationTemplate(private val useAction: UseAction) : ConiumItemTemplate(USE_ANIMATION) { +class ConiumBedrockUseAnimationTemplate(private val useAction: UseAction) : ConiumItemTemplate(true, USE_ANIMATION) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockUseAnimationTemplate = element.objectOrString( @@ -35,9 +35,8 @@ class ConiumBedrockUseAnimationTemplate(private val useAction: UseAction) : Coni settings.components.withComponentProvides( DataComponentTypes.CONSUMABLE, withCreateConsumable(), - withComputeUseAction() - ) { - this.useAction - } + withComputeUseAction(), + ::useAction + ) } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/damage/ConiumBedrockDamageTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/damage/ConiumBedrockDamageTemplate.kt index fc932a0..2c7f4eb 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/damage/ConiumBedrockDamageTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/damage/ConiumBedrockDamageTemplate.kt @@ -15,7 +15,7 @@ import net.minecraft.entity.attribute.EntityAttributes import net.minecraft.item.Item import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumBedrockDamageTemplate(private val damage: Double) : ConiumItemTemplate(DAMAGE) { +class ConiumBedrockDamageTemplate(private val damage: Double) : ConiumItemTemplate(name = DAMAGE) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockDamageTemplate = ConiumBedrockDamageTemplate(element.asDouble) diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/destory/ConiumBedrockCanDestroyInCreativeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/destory/ConiumBedrockCanDestroyInCreativeTemplate.kt index 82bc6a6..a9f805f 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/destory/ConiumBedrockCanDestroyInCreativeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/destory/ConiumBedrockCanDestroyInCreativeTemplate.kt @@ -6,8 +6,14 @@ import com.github.cao.awa.conium.kotlin.extent.json.objectOrBoolean import com.github.cao.awa.conium.template.ConiumTemplates.BedrockItem.CAN_DESTROY_IN_CREATIVE import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup +import net.minecraft.util.math.BlockPos +import net.minecraft.item.Item +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.block.Block +import net.minecraft.block.BlockState +import net.minecraft.world.World -class ConiumBedrockCanDestroyInCreativeTemplate(private val canDestroy: Boolean) : ConiumItemTemplate(CAN_DESTROY_IN_CREATIVE) { +class ConiumBedrockCanDestroyInCreativeTemplate(private val canDestroy: Boolean) : ConiumItemTemplate(name = CAN_DESTROY_IN_CREATIVE) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockCanDestroyInCreativeTemplate = element.objectOrBoolean( @@ -24,7 +30,7 @@ class ConiumBedrockCanDestroyInCreativeTemplate(private val canDestroy: Boolean) )!! } - override fun complete(item: ConiumItem) { - item.canMinePredicate = { _, _, _, _, player -> !player.isCreative || this.canDestroy } + override fun complete(target: ConiumItem) { + target.canMinePredicate = { _: Item, _: BlockState, _: World, _: BlockPos, player: PlayerEntity -> !player.isCreative || this.canDestroy } } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/durability/ConiumBedrockDurabilityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/durability/ConiumBedrockDurabilityTemplate.kt index 0899578..40c14d8 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/durability/ConiumBedrockDurabilityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/durability/ConiumBedrockDurabilityTemplate.kt @@ -10,9 +10,9 @@ class ConiumBedrockDurabilityTemplate( durability: Int, damageChance: IntRange = defaultChance ) : ConiumDurabilityTemplate( - DURABILITY, durability, - damageChance + damageChance, + DURABILITY ) { companion object { @JvmStatic diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/food/ConiumBedrockFoodTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/food/ConiumBedrockFoodTemplate.kt index e2fbdfa..57080c7 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/food/ConiumBedrockFoodTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/food/ConiumBedrockFoodTemplate.kt @@ -13,17 +13,16 @@ import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumBedrockFoodTemplate() : ConiumItemTemplate(FOOD) { +class ConiumBedrockFoodTemplate() : ConiumItemTemplate(name = FOOD) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockFoodTemplate = element.createIfJsonObject( { // Create food template. ConiumBedrockFoodTemplate(element.asJsonObject, registryLookup) - } - ) { - throw IllegalArgumentException("minecraft:food must be a JSON object") - }!! + }, + notSupported() + )!! private fun createFoodComponent(template: ConiumBedrockFoodTemplate, jsonObject: JsonObject, registryLookup: WrapperLookup): FoodComponent { FoodComponent.Builder().let { @@ -39,7 +38,7 @@ class ConiumBedrockFoodTemplate() : ConiumItemTemplate(FOOD) { it.alwaysEdible() } - ConiumConsumableTemplate.createConvert(jsonObject, registryLookup, "using_converts_to") { remainder -> + ConiumConsumableTemplate.createConvert(jsonObject, registryLookup, "using_converts_to") { remainder: ItemStack -> template.useRemainder = remainder } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/glint/ConiumBedrockGlintTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/glint/ConiumBedrockGlintTemplate.kt index 999fbbc..7b74cca 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/glint/ConiumBedrockGlintTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/glint/ConiumBedrockGlintTemplate.kt @@ -8,7 +8,7 @@ import net.minecraft.component.DataComponentTypes import net.minecraft.item.Item import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumBedrockGlintTemplate(private val glint: Boolean) : ConiumItemTemplate(GLINT) { +class ConiumBedrockGlintTemplate(private val glint: Boolean) : ConiumItemTemplate(name = GLINT) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockGlintTemplate = element.objectOrBoolean( diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/stack/size/ConiumBedrockMaxStackSizeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/stack/size/ConiumBedrockMaxStackSizeTemplate.kt index cfe6589..86ec693 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/stack/size/ConiumBedrockMaxStackSizeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/stack/size/ConiumBedrockMaxStackSizeTemplate.kt @@ -7,7 +7,7 @@ import com.google.gson.JsonElement import net.minecraft.item.Item import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumBedrockMaxStackSizeTemplate(private val maxStackSize: Int) : ConiumItemTemplate(MAX_STACK_SIZE) { +class ConiumBedrockMaxStackSizeTemplate(private val maxStackSize: Int) : ConiumItemTemplate(name = MAX_STACK_SIZE) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockMaxStackSizeTemplate = element.objectOrInt( diff --git a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/wearable/ConiumBedrockWearableTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/wearable/ConiumBedrockWearableTemplate.kt index 06b9f6c..07f0904 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/bedrock/wearable/ConiumBedrockWearableTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/bedrock/wearable/ConiumBedrockWearableTemplate.kt @@ -20,7 +20,7 @@ import net.minecraft.registry.RegistryWrapper.WrapperLookup * * @since 1.0.0 */ -class ConiumBedrockWearableTemplate(equipment: EquipmentType, protection: Double = 0.0) : ConiumWearableTemplate(WEARABLE, equipment, protection) { +class ConiumBedrockWearableTemplate(equipment: EquipmentType, protection: Double = 0.0) : ConiumWearableTemplate(equipment, protection, WEARABLE) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBedrockWearableTemplate = element.objectOrString( diff --git a/src/main/java/com/github/cao/awa/conium/item/template/consumable/ConiumConsumableTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/consumable/ConiumConsumableTemplate.kt index 39acb88..d8111d9 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/consumable/ConiumConsumableTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/consumable/ConiumConsumableTemplate.kt @@ -18,7 +18,7 @@ import net.minecraft.registry.RegistryOps import net.minecraft.registry.RegistryWrapper.WrapperLookup import net.minecraft.util.Identifier -class ConiumConsumableTemplate(presetConsumableComponent: ConsumableComponent?) : ConiumItemTemplate(CONSUMABLE) { +class ConiumConsumableTemplate(presetConsumableComponent: ConsumableComponent?) : ConiumItemTemplate(name = CONSUMABLE) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumConsumableTemplate = element.objectOrString( diff --git a/src/main/java/com/github/cao/awa/conium/item/template/destory/ConiumCanDestroyInCreativeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/destory/ConiumCanDestroyInCreativeTemplate.kt index 2b8bda2..97db473 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/destory/ConiumCanDestroyInCreativeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/destory/ConiumCanDestroyInCreativeTemplate.kt @@ -5,14 +5,19 @@ import com.github.cao.awa.conium.item.template.ConiumItemTemplate import com.github.cao.awa.conium.template.ConiumTemplates.Item.CAN_DESTROY_IN_CREATIVE import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup +import net.minecraft.item.Item +import net.minecraft.block.BlockState +import net.minecraft.world.World +import net.minecraft.entity.player.PlayerEntity +import net.minecraft.util.math.BlockPos -class ConiumCanDestroyInCreativeTemplate(private val canDestroy: Boolean) : ConiumItemTemplate(CAN_DESTROY_IN_CREATIVE) { +class ConiumCanDestroyInCreativeTemplate(private val canDestroy: Boolean) : ConiumItemTemplate(name = CAN_DESTROY_IN_CREATIVE) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumCanDestroyInCreativeTemplate = ConiumCanDestroyInCreativeTemplate(element.asBoolean) } - override fun complete(item: ConiumItem) { - item.canMinePredicate = { _, _, _, _, player -> !player.isCreative || this.canDestroy } + override fun complete(target: ConiumItem) { + target.canMinePredicate = { _: Item, _: BlockState, _: World, _: BlockPos, player: PlayerEntity -> !player.isCreative || this.canDestroy } } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/durability/ConiumDurabilityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/durability/ConiumDurabilityTemplate.kt index ed41e69..4b9e903 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/durability/ConiumDurabilityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/durability/ConiumDurabilityTemplate.kt @@ -10,7 +10,7 @@ import com.google.gson.JsonObject import net.minecraft.component.DataComponentTypes import net.minecraft.item.Item -open class ConiumDurabilityTemplate(name: String, private val durability: Int, private val damageChance: IntRange) : ConiumItemTemplate(name) { +open class ConiumDurabilityTemplate(private val durability: Int, private val damageChance: IntRange, name: String) : ConiumItemTemplate(name = name) { companion object { val defaultChance = IntRange(100, 100) @@ -32,12 +32,12 @@ open class ConiumDurabilityTemplate(name: String, private val durability: Int, p } } - override fun complete(item: ConiumItem) { + override fun complete(target: ConiumItem) { // Should increments 'USED' stat when an item has durability. - item.shouldPostHit = true + target.shouldPostHit = true // Set durability damage chance. - item.durabilityDamageChance = this.damageChance + target.durabilityDamageChance = this.damageChance } override fun settings(settings: Item.Settings) { diff --git a/src/main/java/com/github/cao/awa/conium/item/template/egg/ConiumSpawnEggTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/egg/ConiumSpawnEggTemplate.kt index 88de521..65bd84a 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/egg/ConiumSpawnEggTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/egg/ConiumSpawnEggTemplate.kt @@ -9,7 +9,7 @@ import net.minecraft.entity.EntityType import net.minecraft.entity.SpawnReason import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumSpawnEggTemplate(private val entityType: EntityType<*>) : ConiumItemTemplate(SPAWN_EGG) { +class ConiumSpawnEggTemplate(private val entityType: EntityType<*>) : ConiumItemTemplate(name = SPAWN_EGG) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumSpawnEggTemplate { diff --git a/src/main/java/com/github/cao/awa/conium/item/template/food/ConiumFoodTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/food/ConiumFoodTemplate.kt index 284b80d..b497fde 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/food/ConiumFoodTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/food/ConiumFoodTemplate.kt @@ -10,7 +10,7 @@ import net.minecraft.component.type.FoodComponents.* import net.minecraft.item.Item import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumFoodTemplate(private val foodComponent: FoodComponent) : ConiumItemTemplate(FOOD) { +class ConiumFoodTemplate(private val foodComponent: FoodComponent) : ConiumItemTemplate(name = FOOD) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumFoodTemplate = element.objectOrString( diff --git a/src/main/java/com/github/cao/awa/conium/item/template/fuel/ConiumFuelTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/fuel/ConiumFuelTemplate.kt index 0f3e61d..d9ccbcd 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/fuel/ConiumFuelTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/fuel/ConiumFuelTemplate.kt @@ -7,13 +7,13 @@ import com.github.cao.awa.conium.template.ConiumTemplates.Item.FUEL import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumFuelTemplate(private val duration: Int, name: String = FUEL) : ConiumItemTemplate(name) { +class ConiumFuelTemplate(private val duration: Int, name: String = FUEL) : ConiumItemTemplate(name = name) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumFuelTemplate = ConiumFuelTemplate(element.asInt) } - override fun complete(item: ConiumItem) { - Conium.coniumItemManager!!.addFuel(item, this.duration) + override fun complete(target: ConiumItem) { + Conium.coniumItemManager!!.addFuel(target, this.duration) } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/glint/ConiumGlintTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/glint/ConiumGlintTemplate.kt index a7a0f7e..c6607bb 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/glint/ConiumGlintTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/glint/ConiumGlintTemplate.kt @@ -7,7 +7,7 @@ import net.minecraft.component.DataComponentTypes import net.minecraft.item.Item import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumGlintTemplate(private val glint: Boolean) : ConiumItemTemplate(GLINT) { +class ConiumGlintTemplate(private val glint: Boolean) : ConiumItemTemplate(name = GLINT) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumGlintTemplate = ConiumGlintTemplate(element.asBoolean) diff --git a/src/main/java/com/github/cao/awa/conium/item/template/rarity/ConiumRarityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/rarity/ConiumRarityTemplate.kt index 98096c1..5b2121a 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/rarity/ConiumRarityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/rarity/ConiumRarityTemplate.kt @@ -8,10 +8,10 @@ import net.minecraft.item.Item.Settings import net.minecraft.registry.RegistryWrapper.WrapperLookup import net.minecraft.util.Rarity -open class ConiumRarityTemplate(name: String, private val rarity: Rarity) : ConiumItemTemplate(name) { +open class ConiumRarityTemplate(private val rarity: Rarity, name: String) : ConiumItemTemplate(name = name) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup, name: String = Item.RARITY): ConiumRarityTemplate = ConiumRarityTemplate(name, createRarity(element.asString)) + fun create(element: JsonElement, registryLookup: WrapperLookup, name: String = Item.RARITY): ConiumRarityTemplate = ConiumRarityTemplate(createRarity(element.asString), name) @JvmStatic fun createBedrock(element: JsonElement, registryLookup: WrapperLookup): ConiumRarityTemplate = create(element, registryLookup, BedrockItem.RARITY) diff --git a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumCommonRarityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumCommonRarityTemplate.kt index a5abbe1..ffcb9b8 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumCommonRarityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumCommonRarityTemplate.kt @@ -7,7 +7,7 @@ import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup import net.minecraft.util.Rarity -class ConiumCommonRarityTemplate : ConiumRarityTemplate(COMMON_RARITY, Rarity.COMMON) { +class ConiumCommonRarityTemplate : ConiumRarityTemplate(Rarity.COMMON, COMMON_RARITY) { companion object { fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumCommonRarityTemplate = element.createIfJsonObject(::ConiumCommonRarityTemplate, notSupported())!! } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumEpicRarityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumEpicRarityTemplate.kt index 932779d..7c83ff1 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumEpicRarityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumEpicRarityTemplate.kt @@ -7,7 +7,7 @@ import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup import net.minecraft.util.Rarity -class ConiumEpicRarityTemplate : ConiumRarityTemplate(EPIC_RARITY, Rarity.EPIC) { +class ConiumEpicRarityTemplate : ConiumRarityTemplate(Rarity.EPIC, EPIC_RARITY) { companion object { fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumEpicRarityTemplate = element.createIfJsonObject(::ConiumEpicRarityTemplate, notSupported())!! } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumRareRarityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumRareRarityTemplate.kt index bf1382c..0d35fbb 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumRareRarityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumRareRarityTemplate.kt @@ -7,7 +7,7 @@ import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup import net.minecraft.util.Rarity -class ConiumRareRarityTemplate : ConiumRarityTemplate(RARE_RARITY, Rarity.RARE) { +class ConiumRareRarityTemplate : ConiumRarityTemplate(Rarity.RARE, RARE_RARITY) { companion object { fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumRareRarityTemplate = element.createIfJsonObject(::ConiumRareRarityTemplate, notSupported())!! } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumUncommonRarityTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumUncommonRarityTemplate.kt index 4002f97..038f2ef 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumUncommonRarityTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/rarity/epic/ConiumUncommonRarityTemplate.kt @@ -7,7 +7,7 @@ import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup import net.minecraft.util.Rarity -class ConiumUncommonRarityTemplate : ConiumRarityTemplate(UNCOMMON_RARITY, Rarity.UNCOMMON) { +class ConiumUncommonRarityTemplate : ConiumRarityTemplate(Rarity.UNCOMMON, UNCOMMON_RARITY) { companion object { fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumUncommonRarityTemplate = element.createIfJsonObject(::ConiumUncommonRarityTemplate, notSupported())!! } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/stack/count/ConiumStackMaxCountTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/stack/count/ConiumStackMaxCountTemplate.kt index 0a5fac1..c712aa9 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/stack/count/ConiumStackMaxCountTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/stack/count/ConiumStackMaxCountTemplate.kt @@ -6,7 +6,7 @@ import com.google.gson.JsonElement import net.minecraft.item.Item import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumStackMaxCountTemplate(private val stackMaxCount: Int) : ConiumItemTemplate(STACK_MAX_COUNT) { +class ConiumStackMaxCountTemplate(private val stackMaxCount: Int) : ConiumItemTemplate(name = STACK_MAX_COUNT) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumStackMaxCountTemplate = ConiumStackMaxCountTemplate(validateStackSize(element.asInt)) diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/ConiumItemToolTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/ConiumItemToolTemplate.kt index 3f87570..fae3743 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/ConiumItemToolTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/ConiumItemToolTemplate.kt @@ -6,6 +6,7 @@ import com.github.cao.awa.conium.item.template.durability.ConiumDurabilityTempla import com.github.cao.awa.conium.kotlin.extent.json.ifJsonObject import com.github.cao.awa.conium.template.ConiumTemplates.Item.TOOL import com.google.gson.JsonElement +import com.google.gson.JsonObject import net.minecraft.block.Block import net.minecraft.item.Item import net.minecraft.item.ToolMaterial @@ -16,7 +17,6 @@ import net.minecraft.registry.tag.TagKey import net.minecraft.util.Identifier open class ConiumItemToolTemplate( - name: String, private val material: ToolMaterial?, private val effectiveBlocks: TagKey = BlockTags.AIR, private val attackDamage: Float = -1F, @@ -24,23 +24,42 @@ open class ConiumItemToolTemplate( private val durability: Int = -1, private val isWeapon: Boolean = false, private val damageChance: IntRange = ConiumDurabilityTemplate.defaultChance, -) : ConiumItemTemplate(name) { + name: String +) : ConiumItemTemplate(name = name) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: RegistryWrapper.WrapperLookup): ConiumItemToolTemplate = element.ifJsonObject({ - ConiumItemToolTemplate( - TOOL, - createMaterial(it["material"].asString), - it["effective_blocks"]?.asString?.let(::createEffectiveBlocks) ?: BlockTags.AIR, - it["attack_damage"]?.asFloat ?: -1F, - it["attack_speed"]?.asFloat ?: -1F, - it["durability"]?.asInt ?: -1, - it["is_weapon"]?.asBoolean ?: false, - ConiumDurabilityTemplate.createChance(it) + fun create(element: JsonElement, registryLookup: RegistryWrapper.WrapperLookup): ConiumItemToolTemplate = element.ifJsonObject( + { + createWith(it, TOOL, ::ConiumItemToolTemplate) + }, + notSupported() + )!! + + fun createWith( + it: JsonObject, + name: String, + creator: (ToolMaterial, TagKey, Float, Float, Int, Boolean, IntRange, String) -> T, + material: (JsonObject) -> ToolMaterial = { createMaterial(it["material"].asString) }, + effectiveBlocks: (JsonObject) -> TagKey = { it["effective_blocks"]?.asString?.let(::createEffectiveBlocks) ?: BlockTags.AIR }, + attackDamage: (JsonObject) -> Float = { it["attack_damage"]?.asFloat ?: -1F }, + attackSpeed: (JsonObject) -> Float = { it["attack_speed"]?.asFloat ?: -1F }, + durability: (JsonObject) -> Int = { it["durability"]?.asInt ?: -1 }, + isWeapon: (JsonObject) -> Boolean = { it["is_weapon"]?.asBoolean ?: false }, + damageChance: (JsonObject) -> IntRange = { ConiumDurabilityTemplate.createChance(it)} + ): T { + return creator( + material(it), + effectiveBlocks(it), + attackDamage(it), + attackSpeed(it), + durability(it), + isWeapon(it), + damageChance(it), + name ) - }, notSupported())!! + } - private fun createMaterial(name: String): ToolMaterial { + fun createMaterial(name: String): ToolMaterial { return when (name) { "wooden", "wood" -> ToolMaterial.WOOD "stone" -> ToolMaterial.STONE @@ -52,17 +71,15 @@ open class ConiumItemToolTemplate( } } - private fun createEffectiveBlocks(name: String): TagKey { - return TagKey.of(RegistryKeys.BLOCK, Identifier.of(name)) - } + fun createEffectiveBlocks(name: String): TagKey = TagKey.of(RegistryKeys.BLOCK, Identifier.of(name)) } - override fun complete(item: ConiumItem) { + override fun complete(target: ConiumItem) { // Item is tool, post hit to increments 'USED' stat data. - item.shouldPostHit = true + target.shouldPostHit = true // Set durability damage chance. - item.durabilityDamageChance = this.damageChance + target.durabilityDamageChance = this.damageChance } override fun settings(settings: Item.Settings) { diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemAxeTemplate.kt index d14d9fb..8d905ec 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemAxeTemplate.kt @@ -1,28 +1,56 @@ package com.github.cao.awa.conium.item.template.tool.axe +import com.github.cao.awa.conium.item.template.durability.ConiumDurabilityTemplate import com.github.cao.awa.conium.item.template.tool.ConiumItemToolTemplate +import com.github.cao.awa.conium.kotlin.extent.innate.changeIfIs +import com.github.cao.awa.conium.kotlin.extent.json.ifJsonObject +import com.github.cao.awa.conium.template.ConiumTemplates.Item.TOOL +import com.google.gson.JsonElement +import net.minecraft.block.Block import net.minecraft.item.ToolMaterial +import net.minecraft.registry.RegistryWrapper import net.minecraft.registry.tag.BlockTags +import net.minecraft.registry.tag.TagKey open class ConiumItemAxeTemplate( - name: String, material: ToolMaterial, attackDamage: Float, - attackSpeed: Float + attackSpeed: Float, + isWeapon: Boolean = false, + damageChance: IntRange = ConiumDurabilityTemplate.defaultChance, + effectiveBlocks: TagKey = BlockTags.AXE_MINEABLE, + durability: Int = -1, + name: String ) : ConiumItemToolTemplate( - name, material, - BlockTags.AXE_MINEABLE, + effectiveBlocks, attackDamage, - attackSpeed + attackSpeed, + durability.changeIfIs(-1) { material.durability }, + isWeapon, + damageChance, + name ) { companion object { -// @JvmStatic -// fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemPickaxeTemplate { -// if (element is JsonObject) { -// return ConiumItemPickaxeTemplate() -// } -// throw IllegalArgumentException("Not supported syntax: $element") -// } + @JvmStatic + fun create(element: JsonElement, registryLookup: RegistryWrapper.WrapperLookup): ConiumItemAxeTemplate = element.ifJsonObject( + { + createWith( + it, + TOOL, + { material: ToolMaterial, + effectiveBlocks: TagKey, + attackDamage: Float, + attackSpeed: Float, durability: Int, + isWeapon: Boolean, + damageChance: IntRange, + name: String -> + ConiumItemAxeTemplate(material, attackDamage, attackSpeed, isWeapon, damageChance, effectiveBlocks, durability, name) + }, + effectiveBlocks = { BlockTags.AXE_MINEABLE } + ) + }, + notSupported() + )!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemDiamondAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemDiamondAxeTemplate.kt index 04d9e32..41d6121 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemDiamondAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemDiamondAxeTemplate.kt @@ -7,15 +7,13 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemDiamondAxeTemplate : ConiumItemAxeTemplate( - DIAMOND_AXE, ToolMaterial.DIAMOND, 5.0F, - -3.0F + -3.0F, + name = DIAMOND_AXE, ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemDiamondAxeTemplate = element.createIfJsonObject(::ConiumItemDiamondAxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemDiamondAxeTemplate = element.createIfJsonObject(::ConiumItemDiamondAxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemGoldenAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemGoldenAxeTemplate.kt index 3a86a5b..bcf009a 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemGoldenAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemGoldenAxeTemplate.kt @@ -7,15 +7,13 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemGoldenAxeTemplate : ConiumItemAxeTemplate( - GOLDEN_AXE, ToolMaterial.GOLD, 6.0F, - -3.0F + -3.0F, + name = GOLDEN_AXE ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemGoldenAxeTemplate = element.createIfJsonObject(::ConiumItemGoldenAxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemGoldenAxeTemplate = element.createIfJsonObject(::ConiumItemGoldenAxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemIronAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemIronAxeTemplate.kt index 6b2ffa3..e130b61 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemIronAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemIronAxeTemplate.kt @@ -7,15 +7,13 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemIronAxeTemplate : ConiumItemAxeTemplate( - IRON_AXE, ToolMaterial.IRON, 6.0F, - -3.1F + -3.1F, + name = IRON_AXE ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemIronAxeTemplate = element.createIfJsonObject(::ConiumItemIronAxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemIronAxeTemplate = element.createIfJsonObject(::ConiumItemIronAxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemNetheriteAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemNetheriteAxeTemplate.kt index 544764c..00e9563 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemNetheriteAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemNetheriteAxeTemplate.kt @@ -7,15 +7,13 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemNetheriteAxeTemplate : ConiumItemAxeTemplate( - NETHERITE_AXE, ToolMaterial.NETHERITE, 5F, - -3.0F + -3.0F, + name = NETHERITE_AXE ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemNetheriteAxeTemplate = element.createIfJsonObject(::ConiumItemNetheriteAxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemNetheriteAxeTemplate = element.createIfJsonObject(::ConiumItemNetheriteAxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemStoneAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemStoneAxeTemplate.kt index 11d65c7..ae06cf5 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemStoneAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemStoneAxeTemplate.kt @@ -7,15 +7,13 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemStoneAxeTemplate : ConiumItemAxeTemplate( - STONE_AXE, ToolMaterial.STONE, 7.0F, - -3.2F + -3.2F, + name = STONE_AXE, ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemStoneAxeTemplate = element.createIfJsonObject(::ConiumItemStoneAxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemStoneAxeTemplate = element.createIfJsonObject(::ConiumItemStoneAxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemWoodenAxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemWoodenAxeTemplate.kt index c5d2820..d359598 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemWoodenAxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/axe/ConiumItemWoodenAxeTemplate.kt @@ -7,15 +7,13 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemWoodenAxeTemplate : ConiumItemAxeTemplate( - WOODEN_AXE, ToolMaterial.WOOD, 6.0F, - -3.2F + -3.2F, + name = WOODEN_AXE ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemWoodenAxeTemplate = element.createIfJsonObject(::ConiumItemWoodenAxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemWoodenAxeTemplate = element.createIfJsonObject(::ConiumItemWoodenAxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemDiamondPickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemDiamondPickaxeTemplate.kt index 7b2d27d..2419e83 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemDiamondPickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemDiamondPickaxeTemplate.kt @@ -7,13 +7,11 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemDiamondPickaxeTemplate : ConiumItemPickaxeTemplate( - DIAMOND_PICKAXE, - ToolMaterial.DIAMOND + ToolMaterial.DIAMOND, + name = DIAMOND_PICKAXE, ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemDiamondPickaxeTemplate = element.createIfJsonObject(::ConiumItemDiamondPickaxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemDiamondPickaxeTemplate = element.createIfJsonObject(::ConiumItemDiamondPickaxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemGoldenPickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemGoldenPickaxeTemplate.kt index bd2799b..1287911 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemGoldenPickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemGoldenPickaxeTemplate.kt @@ -7,13 +7,11 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemGoldenPickaxeTemplate : ConiumItemPickaxeTemplate( - GOLDEN_PICKAXE, - ToolMaterial.GOLD + ToolMaterial.GOLD, + name = GOLDEN_PICKAXE ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemGoldenPickaxeTemplate = element.createIfJsonObject(::ConiumItemGoldenPickaxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemGoldenPickaxeTemplate = element.createIfJsonObject(::ConiumItemGoldenPickaxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemIronPickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemIronPickaxeTemplate.kt index a6d0b7e..bd47179 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemIronPickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemIronPickaxeTemplate.kt @@ -7,13 +7,11 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemIronPickaxeTemplate : ConiumItemPickaxeTemplate( - IRON_PICKAXE, - ToolMaterial.IRON + ToolMaterial.IRON, + name = IRON_PICKAXE, ) { companion object { @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemIronPickaxeTemplate = element.createIfJsonObject(::ConiumItemIronPickaxeTemplate) { - throw IllegalArgumentException("Not supported syntax: $it") - }!! + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemIronPickaxeTemplate = element.createIfJsonObject(::ConiumItemIronPickaxeTemplate, notSupported())!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemNetheritePickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemNetheritePickaxeTemplate.kt index e807471..f142ff2 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemNetheritePickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemNetheritePickaxeTemplate.kt @@ -7,8 +7,8 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemNetheritePickaxeTemplate : ConiumItemPickaxeTemplate( - NETHERITE_PICKAXE, - ToolMaterial.NETHERITE + ToolMaterial.NETHERITE, + name = NETHERITE_PICKAXE ) { companion object { @JvmStatic diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemPickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemPickaxeTemplate.kt index 49bb12f..d4227dd 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemPickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemPickaxeTemplate.kt @@ -1,23 +1,56 @@ package com.github.cao.awa.conium.item.template.tool.pickaxe +import com.github.cao.awa.conium.item.template.durability.ConiumDurabilityTemplate import com.github.cao.awa.conium.item.template.tool.ConiumItemToolTemplate +import com.github.cao.awa.conium.kotlin.extent.innate.changeIfIs +import com.github.cao.awa.conium.kotlin.extent.json.ifJsonObject +import com.github.cao.awa.conium.template.ConiumTemplates.Item.TOOL +import com.google.gson.JsonElement +import net.minecraft.block.Block import net.minecraft.item.ToolMaterial +import net.minecraft.registry.RegistryWrapper import net.minecraft.registry.tag.BlockTags +import net.minecraft.registry.tag.TagKey -open class ConiumItemPickaxeTemplate(name: String, material: ToolMaterial) : ConiumItemToolTemplate( - name, +open class ConiumItemPickaxeTemplate( + material: ToolMaterial, + attackDamage: Float = 1.0F, + attackSpeed: Float = -2.8F, + isWeapon: Boolean = false, + damageChance: IntRange = ConiumDurabilityTemplate.defaultChance, + effectiveBlocks: TagKey = BlockTags.PICKAXE_MINEABLE, + durability: Int = -1, + name: String +) : ConiumItemToolTemplate( material, - BlockTags.PICKAXE_MINEABLE, - 1.0F, - -2.8F + effectiveBlocks, + attackDamage, + attackSpeed, + durability.changeIfIs(-1) { material.durability }, + isWeapon, + damageChance, + name ) { companion object { -// @JvmStatic -// fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemPickaxeTemplate { -// if (element is JsonObject) { -// return ConiumItemPickaxeTemplate() -// } -// throw IllegalArgumentException("Not supported syntax: $element") -// } + @JvmStatic + fun create(element: JsonElement, registryLookup: RegistryWrapper.WrapperLookup): ConiumItemPickaxeTemplate = element.ifJsonObject( + { + createWith( + it, + TOOL, + { material: ToolMaterial, + effectiveBlocks: TagKey, + attackDamage: Float, + attackSpeed: Float, durability: Int, + isWeapon: Boolean, + damageChance: IntRange, + name: String -> + ConiumItemPickaxeTemplate(material, attackDamage, attackSpeed, isWeapon, damageChance, effectiveBlocks, durability, name) + }, + effectiveBlocks = { BlockTags.PICKAXE_MINEABLE } + ) + }, + notSupported() + )!! } } diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemStonePickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemStonePickaxeTemplate.kt index 445089e..83b9dc4 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemStonePickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemStonePickaxeTemplate.kt @@ -7,8 +7,8 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemStonePickaxeTemplate : ConiumItemPickaxeTemplate( - STONE_PICKAXE, - ToolMaterial.STONE + ToolMaterial.STONE, + name = STONE_PICKAXE, ) { companion object { @JvmStatic diff --git a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemWoodenPickaxeTemplate.kt b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemWoodenPickaxeTemplate.kt index b8b0d7a..c5cb0fc 100644 --- a/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemWoodenPickaxeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/item/template/tool/pickaxe/ConiumItemWoodenPickaxeTemplate.kt @@ -7,8 +7,8 @@ import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumItemWoodenPickaxeTemplate : ConiumItemPickaxeTemplate( - WOODEN_PICKAXE, - ToolMaterial.WOOD + ToolMaterial.WOOD, + name = WOODEN_PICKAXE ) { companion object { @JvmStatic diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt index 9acac0e..92f2d23 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumBlockKotlinExtents.kt @@ -14,11 +14,11 @@ fun ConiumBlockBuilder.register(afterAction: (ConiumBlock) -> Unit) { afterAction( Blocks.register( blockKeyOf(this.identifier), - { + { settings -> build( ConiumBlockSettings.create( this.templates, - it + settings ) ) }, @@ -27,6 +27,4 @@ fun ConiumBlockBuilder.register(afterAction: (ConiumBlock) -> Unit) { ) } -fun blockKeyOf(id: Identifier): RegistryKey { - return RegistryKey.of(RegistryKeys.BLOCK, id) -} +fun blockKeyOf(id: Identifier): RegistryKey = RegistryKey.of(RegistryKeys.BLOCK, id) diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentsExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentsExtents.kt index c8936b4..dacc51d 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentsExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentsExtents.kt @@ -11,4 +11,8 @@ import net.minecraft.registry.entry.RegistryEntry */ val AttributeModifiersComponent.entries: MutableList get() = this.modifiers as MutableList -fun AttributeModifiersComponent.add(attribute: RegistryEntry, modifier: EntityAttributeModifier, slot: AttributeModifierSlot) = this.entries.add(AttributeModifiersComponent.Entry(attribute, modifier, slot)) +fun AttributeModifiersComponent.add( + attribute: RegistryEntry, + modifier: EntityAttributeModifier, + slot: AttributeModifierSlot +): Boolean = this.entries.add(AttributeModifiersComponent.Entry(attribute, modifier, slot)) diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/entity/ConiumEntityKotlinExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/entity/ConiumEntityKotlinExtents.kt index b3468fa..903da60 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/entity/ConiumEntityKotlinExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/entity/ConiumEntityKotlinExtents.kt @@ -1,5 +1,6 @@ package com.github.cao.awa.conium.kotlin.extent.entity +import com.github.cao.awa.conium.entity.ConiumEntity import com.github.cao.awa.conium.entity.attribute.ConiumEntityAttributeRegistry import com.github.cao.awa.conium.entity.builder.ConiumEntityBuilder import com.github.cao.awa.conium.entity.metadata.ConiumEntityMetadata @@ -18,11 +19,11 @@ var Entity.dimensions: EntityDimensions get() = this.accessor.dimensions() set(value) = this.accessor.dimensions(value) -val Entity.accessor get() = this as EntityAccessor +val Entity.accessor: EntityAccessor get() = this as EntityAccessor fun ConiumEntityBuilder.register(callback: (ConiumEntityMetadata) -> Unit = { }) { - build().also { entityType -> - val type = registerEntity(this.identifier, entityType) + build().also { builder: EntityType.Builder -> + val type: EntityType = registerEntity(this.identifier, builder) callback( ConiumEntityMetadata(type, this.entitySettings) ) @@ -32,14 +33,8 @@ fun ConiumEntityBuilder.register(callback: (ConiumEntityMetadata) -> Unit = { }) } } -private fun keyOf(id: Identifier): RegistryKey> { - return RegistryKey.of(RegistryKeys.ENTITY_TYPE, id) -} +private fun keyOf(id: Identifier): RegistryKey> = RegistryKey.of(RegistryKeys.ENTITY_TYPE, id) -fun registerEntity(id: Identifier, type: EntityType.Builder): EntityType { - return registerEntity(keyOf(id), type) -} +fun registerEntity(id: Identifier, type: EntityType.Builder): EntityType = registerEntity(keyOf(id), type) -fun registerEntity(key: RegistryKey>, type: EntityType.Builder): EntityType { - return Registry.register(Registries.ENTITY_TYPE, key, type.build(key)) -} +fun registerEntity(key: RegistryKey>, type: EntityType.Builder): EntityType = Registry.register(Registries.ENTITY_TYPE, key, type.build(key)) diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/innate/ConiumInnate.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/innate/ConiumInnate.kt index 18c7802..06de691 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/innate/ConiumInnate.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/innate/ConiumInnate.kt @@ -7,3 +7,10 @@ inline fun T.asIt(): T = this inline fun T.isIt(): Boolean { return asIt() != null && T::class.java.isInstance(this) } + +inline fun T.changeIfIs(value: T, creator: (T) -> T): T { + if (value == this) { + return creator(value) + } + return this +} \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt index 330b8e4..0888e3c 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/item/ConiumItemKotlinExtents.kt @@ -36,9 +36,7 @@ fun ConiumBlockBuilder.registerBlockItem(block: ConiumBlock, settingsProvider: ( } } -fun itemKeyOf(id: Identifier): RegistryKey { - return RegistryKey.of(RegistryKeys.ITEM, id) -} +fun itemKeyOf(id: Identifier): RegistryKey = RegistryKey.of(RegistryKeys.ITEM, id) val Item.Settings.components: ComponentMap.Builder get() = (this as ItemSettingsAccessor).components diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/recipe/ConiumRecipeTypeKotlinExtends.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/recipe/ConiumRecipeTypeKotlinExtends.kt index 4490904..8e2b17d 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/recipe/ConiumRecipeTypeKotlinExtends.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/recipe/ConiumRecipeTypeKotlinExtends.kt @@ -2,7 +2,7 @@ package com.github.cao.awa.conium.kotlin.extent.recipe import net.minecraft.recipe.RecipeType -val RecipeType<*>.coniumName +val RecipeType<*>.coniumName: String get() = when (this) { RecipeType.SMELTING -> "smelting" RecipeType.BLASTING -> "blasting" diff --git a/src/main/java/com/github/cao/awa/conium/network/ConiumPacketRegistry.kt b/src/main/java/com/github/cao/awa/conium/network/ConiumPacketRegistry.kt index 717522a..1830b94 100644 --- a/src/main/java/com/github/cao/awa/conium/network/ConiumPacketRegistry.kt +++ b/src/main/java/com/github/cao/awa/conium/network/ConiumPacketRegistry.kt @@ -50,17 +50,13 @@ class ConiumPacketRegistry { } fun

registerClientConfigurationReceiver(id: Id

) { - ClientConfigurationNetworking.registerGlobalReceiver(id) { packet, context -> - try { - packet.arising(context.client(), null, context.responseSender(), context.networkHandler()) - } catch (e: Exception) { - e.printStackTrace() - } + ClientConfigurationNetworking.registerGlobalReceiver(id) { packet: P, context: ClientConfigurationNetworking.Context -> + packet.arising(context.client(), null, context.responseSender(), context.networkHandler()) } } fun

registerClientPlayReceiver(id: Id

) { - ClientPlayNetworking.registerGlobalReceiver(id) { packet, context -> + ClientPlayNetworking.registerGlobalReceiver(id) { packet: P, context: ClientPlayNetworking.Context -> packet.arising(context.client(), context.player(), context.responseSender(), context.player().networkHandler) } } @@ -86,13 +82,13 @@ class ConiumPacketRegistry { } fun

registerServerConfigurationReceiver(id: Id

) { - ServerConfigurationNetworking.registerGlobalReceiver(id) { packet, context -> + ServerConfigurationNetworking.registerGlobalReceiver(id) { packet: P, context: ServerConfigurationNetworking.Context -> packet.arising(context.server(), null, context.responseSender(), context.networkHandler()) } } fun

registerServerPlayReceiver(id: Id

) { - ServerPlayNetworking.registerGlobalReceiver(id) { packet, context -> + ServerPlayNetworking.registerGlobalReceiver(id) { packet: P, context: ServerPlayNetworking.Context -> packet.arising(context.server(), context.player(), context.responseSender(), context.player().networkHandler) } } diff --git a/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt b/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt index cfa1bc1..28ae304 100644 --- a/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt +++ b/src/main/java/com/github/cao/awa/conium/network/packet/client/configuration/registry/SynchronizeRegistryPayload.kt @@ -70,21 +70,21 @@ class SynchronizeRegistryPayload : ConiumClientConfigurationPacket(IDENTIFIER) { Conium.pendingDatapack.datapacks.let { datapacks -> datapacks[ConiumRegistryKeys.ITEM.value]?.let { datapack -> - for ((identifier, content) in datapack.contents) { + for ((identifier: Identifier, content: String) in datapack.contents) { Conium.coniumItemManager!!.resetRegistries() Conium.coniumItemManager!!.load(identifier, JsonParser.parseString(content).asJsonObject) } } datapacks[ConiumRegistryKeys.BLOCK.value]?.let { datapack -> - for ((identifier, content) in datapack.contents) { + for ((identifier: Identifier, content: String) in datapack.contents) { Conium.coniumBlockManager!!.resetRegistries() Conium.coniumBlockManager!!.load(identifier, JsonParser.parseString(content).asJsonObject) } } datapacks[ConiumRegistryKeys.ENTITY.value]?.let { datapack -> - for ((identifier, content) in datapack.contents) { + for ((identifier: Identifier, content: String) in datapack.contents) { Conium.coniumEntityManager!!.resetRegistries() Conium.coniumEntityManager!!.load(identifier, JsonParser.parseString(content).asJsonObject) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/type/DynamicArgTypeBuilder.kt b/src/main/java/com/github/cao/awa/conium/parameter/type/DynamicArgTypeBuilder.kt index 8834275..1b73836 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/type/DynamicArgTypeBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/type/DynamicArgTypeBuilder.kt @@ -1,3 +1,5 @@ +@file:Suppress("unchecked_cast", "unused") + package com.github.cao.awa.conium.parameter.type import com.github.cao.awa.conium.parameter.DynamicArgType diff --git a/src/main/java/com/github/cao/awa/conium/random/ConiumRandom.kt b/src/main/java/com/github/cao/awa/conium/random/ConiumRandom.kt index dab65d7..b5834ba 100644 --- a/src/main/java/com/github/cao/awa/conium/random/ConiumRandom.kt +++ b/src/main/java/com/github/cao/awa/conium/random/ConiumRandom.kt @@ -4,7 +4,5 @@ import net.minecraft.util.math.random.Random object ConiumRandom { @JvmStatic - fun tryChance(chance: IntRange, random: Random): Boolean { - return random.nextBetween(chance.first, chance.last) == 0 - } + fun tryChance(chance: IntRange, random: Random): Boolean = random.nextBetween(chance.first, chance.last) == 0 } diff --git a/src/main/java/com/github/cao/awa/conium/recipe/ConiumBedrockRecipeBuilder.kt b/src/main/java/com/github/cao/awa/conium/recipe/ConiumBedrockRecipeBuilder.kt index 73b26b4..1f59a33 100644 --- a/src/main/java/com/github/cao/awa/conium/recipe/ConiumBedrockRecipeBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/recipe/ConiumBedrockRecipeBuilder.kt @@ -18,28 +18,24 @@ class ConiumBedrockRecipeBuilder : ConiumBuilderWithTemplates< ::build ) { companion object { - private val bedrockRecipes = listOf( + private val bedrockRecipes: List = listOf( RECIPE_SHAPED, RECIPE_SHAPELESS, RECIPE_FURNACE, ) @JvmStatic - fun create(template: ConiumRecipeTemplate>): ConiumBedrockRecipeBuilder { - return ConiumBedrockRecipeBuilder().apply { - addTemplate(template) - } - } + fun create(template: ConiumRecipeTemplate>): ConiumBedrockRecipeBuilder = ConiumBedrockRecipeBuilder().apply { addTemplate(template) } @JvmStatic fun findBedrock(jsonObject: JsonObject, registryLookup: WrapperLookup): List> { - for (bedrockRecipe in this.bedrockRecipes) { + for (bedrockRecipe: String in this.bedrockRecipes) { jsonObject[bedrockRecipe]?.asJsonObject?.let { return ConiumTemplate.deserializeRecipeTemplate(bedrockRecipe, it, registryLookup).fold( - { template -> + { template: ConiumRecipeTemplate> -> create(template).build() } - ) { thr -> + ) { thr: Throwable -> throw IllegalArgumentException("Unable to deserialize bedrock recipe: $it", thr) } } diff --git a/src/main/java/com/github/cao/awa/conium/recipe/template/ConiumRecipeTemplate.kt b/src/main/java/com/github/cao/awa/conium/recipe/template/ConiumRecipeTemplate.kt index 40a661f..61c133d 100644 --- a/src/main/java/com/github/cao/awa/conium/recipe/template/ConiumRecipeTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/recipe/template/ConiumRecipeTemplate.kt @@ -10,10 +10,10 @@ import net.minecraft.recipe.Recipe import net.minecraft.registry.Registries import net.minecraft.util.Identifier -abstract class ConiumRecipeTemplate>(name: String) : ConiumTemplate(name) { +abstract class ConiumRecipeTemplate>(name: String) : ConiumTemplate(name = name) { companion object { fun createItem(jsonObject: JsonObject, name: String): ItemStack { - return jsonObject[name]!!.let { result -> + return jsonObject[name]!!.let { result: JsonElement -> val count: Int val resultItemName: String @@ -25,24 +25,18 @@ abstract class ConiumRecipeTemplate>(name: String) : ConiumTemplat resultItemName = result.asString } - val item = Registries.ITEM.get(Identifier.of(resultItemName)) - ItemStack( - item, + Registries.ITEM.get(Identifier.of(resultItemName)), count ) } } fun createItemNoData(jsonObject: JsonObject, name: String): ItemStack { - return jsonObject[name]!!.let { result -> - val item = Registries.ITEM.get(Identifier.of(result.asString)) - - ItemStack( - item, - 1 - ) - } + return ItemStack( + Registries.ITEM.get(Identifier.of(jsonObject[name]!!.asString)), + 1 + ) } fun createIngredient(element: JsonElement): Ingredient { @@ -66,11 +60,11 @@ abstract class ConiumRecipeTemplate>(name: String) : ConiumTemplat lateinit var group: String lateinit var result: ItemStack - override fun attach(item: T) { + override fun attach(target: T) { } - override fun complete(item: T) { + override fun complete(target: T) { } } diff --git a/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/furnace/ConiumBedrockRecipeFurnaceTemplate.kt b/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/furnace/ConiumBedrockRecipeFurnaceTemplate.kt index 54da68a..e7d997c 100644 --- a/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/furnace/ConiumBedrockRecipeFurnaceTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/furnace/ConiumBedrockRecipeFurnaceTemplate.kt @@ -5,13 +5,14 @@ import com.github.cao.awa.conium.template.ConiumTemplates.BedrockRecipe.RECIPE_F import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonElement import com.google.gson.JsonObject +import net.minecraft.item.ItemStack import net.minecraft.recipe.* import net.minecraft.recipe.book.CookingRecipeCategory import net.minecraft.registry.RegistryWrapper.WrapperLookup class ConiumBedrockRecipeFurnaceTemplate : ConiumRecipeTemplate>(RECIPE_FURNACE) { companion object { - private val furnaceTypes = mapOf( + private val furnaceTypes: Map AbstractCookingRecipe> = mapOf( Pair("furnace", ::SmeltingRecipe), Pair("blast_furnace", ::BlastingRecipe), Pair("smoker", ::SmokingRecipe), @@ -38,8 +39,8 @@ class ConiumBedrockRecipeFurnaceTemplate : ConiumRecipeTemplate>(RECIP override fun results(): List> { return CollectionFactor.arrayList>().also { - for (tag in this.tags) { - furnaceTypes[tag]?.let { recipe -> + for (tag: String in this.tags) { + furnaceTypes[tag]?.let { recipe: (String, CookingRecipeCategory, Ingredient, ItemStack, Float, Int) -> AbstractCookingRecipe -> it.add( recipe( this.group, diff --git a/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/shape/ConiumBedrockRecipeShapedTemplate.kt b/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/shape/ConiumBedrockRecipeShapedTemplate.kt index 1ffbe83..f931b90 100644 --- a/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/shape/ConiumBedrockRecipeShapedTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/recipe/template/bedrock/shape/ConiumBedrockRecipeShapedTemplate.kt @@ -20,12 +20,12 @@ class ConiumBedrockRecipeShapedTemplate : ConiumRecipeTemplate(REC return ConiumBedrockRecipeShapedTemplate().also { createBasic(jsonObject, it) }.also { - it.keys = jsonObject["key"]!!.let { keys -> - val ingredients = CollectionFactor.hashMap() + it.keys = jsonObject["key"]!!.let { keys: JsonElement -> + val ingredients: MutableMap = CollectionFactor.hashMap() keys as JsonObject - for ((key, ingredient) in keys.entrySet()) { + for ((key: String, ingredient: JsonElement) in keys.entrySet()) { ingredients[key.toCharArray()[0]] = ingredient.let(::createIngredient) } diff --git a/src/main/java/com/github/cao/awa/conium/registry/ConiumRegistryKeys.kt b/src/main/java/com/github/cao/awa/conium/registry/ConiumRegistryKeys.kt index 81d63f6..7aa3624 100644 --- a/src/main/java/com/github/cao/awa/conium/registry/ConiumRegistryKeys.kt +++ b/src/main/java/com/github/cao/awa/conium/registry/ConiumRegistryKeys.kt @@ -25,7 +25,5 @@ object ConiumRegistryKeys { @JvmStatic val ENTITY: RegistryKey> = of("entity") - private fun of(id: String): RegistryKey> { - return RegistryKey.ofRegistry(Identifier.of("conium", id)) - } + private fun of(id: String): RegistryKey> = RegistryKey.ofRegistry(Identifier.of("conium", id)) } diff --git a/src/main/java/com/github/cao/awa/conium/script/ScriptExport.kt b/src/main/java/com/github/cao/awa/conium/script/ScriptExport.kt index 34f36e5..4ddfb17 100644 --- a/src/main/java/com/github/cao/awa/conium/script/ScriptExport.kt +++ b/src/main/java/com/github/cao/awa/conium/script/ScriptExport.kt @@ -20,7 +20,7 @@ class ScriptExport( fun import(exported: Map, code: String, vararg defaultImports: String): String { this.exported = exported - val builder = StringBuilder() + val builder: StringBuilder = StringBuilder() val importing: MutableSet = CollectionFactor.hashSet() @@ -32,9 +32,9 @@ class ScriptExport( importing.addAll(it.substring(it.indexOf(":") + 1).split(",").toSet().map(String::trim)) } - for (sourceName in importing) { + for (sourceName: String in importing) { exported[sourceName]?.let { - for (import in it.imports) { + for (import: String in it.imports) { builder.append(import) builder.append("\n") } @@ -45,9 +45,8 @@ class ScriptExport( sharedFields(it) - for (fieldEntry in it.fields) { - val field = fieldEntry.value - builder.append(field.toStatement(sourceName)) + for ((_, value: SharedField) in it.fields) { + builder.append(value.toStatement(sourceName)) } } } @@ -59,7 +58,7 @@ class ScriptExport( @JvmStatic fun accessExportedField(instance: Any, name: String, fieldName: String): T? { - val result = this.exported?.get(name)?.fields?.get(fieldName) + val result: SharedField? = this.exported?.get(name)?.fields?.get(fieldName) result ?: return null diff --git a/src/main/java/com/github/cao/awa/conium/script/kts/ConiumScript.kt b/src/main/java/com/github/cao/awa/conium/script/kts/ConiumScript.kt index 0077313..8ed448a 100644 --- a/src/main/java/com/github/cao/awa/conium/script/kts/ConiumScript.kt +++ b/src/main/java/com/github/cao/awa/conium/script/kts/ConiumScript.kt @@ -3,14 +3,12 @@ package com.github.cao.awa.conium.script.kts import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import kotlin.script.experimental.annotations.KotlinScript -@KotlinScript( - fileExtension = "kts" -) +@KotlinScript(fileExtension = "kts") abstract class ConiumScript fun clearDuplicateImports(script: String): String { - val imports = CollectionFactor.hashSet() - val scriptLines = CollectionFactor.linkedList() + val imports: MutableSet = CollectionFactor.hashSet() + val scriptLines: MutableList = CollectionFactor.linkedList() script.lines().forEach { if (it.startsWith("import ")) { imports.add(it) @@ -19,14 +17,14 @@ fun clearDuplicateImports(script: String): String { } } - val builder = StringBuilder() + val builder: StringBuilder = StringBuilder() - for (import in imports) { + for (import: String in imports) { builder.append(import) builder.append("\n") } - for (scriptLine in scriptLines) { + for (scriptLine: String in scriptLines) { builder.append(scriptLine) builder.append("\n") } @@ -35,7 +33,7 @@ fun clearDuplicateImports(script: String): String { } fun filterImports(script: String): Set { - val imports = CollectionFactor.hashSet() + val imports: MutableSet = CollectionFactor.hashSet() script.lines().forEach { if (it.startsWith("import ")) { imports.add(it) diff --git a/src/main/java/com/github/cao/awa/conium/script/translate/ConiumScriptTranslator.kt b/src/main/java/com/github/cao/awa/conium/script/translate/ConiumScriptTranslator.kt index 7742d05..470b0ca 100644 --- a/src/main/java/com/github/cao/awa/conium/script/translate/ConiumScriptTranslator.kt +++ b/src/main/java/com/github/cao/awa/conium/script/translate/ConiumScriptTranslator.kt @@ -1,17 +1,17 @@ package com.github.cao.awa.conium.script.translate -import com.github.cao.awa.conium.script.translate.kts.file.`object`.anonymous.ConiumTypescriptAnonymousObjectTranslator +import com.github.cao.awa.conium.script.translate.kts.file.obj.anonymous.ConiumTypescriptAnonymousObjectTranslator import com.github.cao.awa.conium.script.translate.kts.file.statement.variable.ConiumTypescriptDefineVariableTranslator import com.github.cao.awa.language.translator.builtin.typescript.translate.element.TypescriptTranslateElement import com.github.cao.awa.language.translator.translate.LanguageTranslator import com.github.cao.awa.language.translator.translate.lang.TranslateTarget import com.github.cao.awa.language.translator.translate.tree.LanguageAst -abstract class ConiumScriptTranslator : LanguageTranslator() { +abstract class ConiumScriptTranslator : LanguageTranslator() { companion object { fun postRegister() { // Most of the cases, generic provider is great, - // but generic doesn't translating anonymous object, conium will impls it. + // but generic doesn't translate anonymous object, conium will impls it. registerKotlinScript( "conium", TypescriptTranslateElement.ANONYMOUS_OBJECT, diff --git a/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/object/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt b/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/obj/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt similarity index 71% rename from src/main/java/com/github/cao/awa/conium/script/translate/kts/file/object/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt rename to src/main/java/com/github/cao/awa/conium/script/translate/kts/file/obj/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt index 7af84d3..c0c797e 100644 --- a/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/object/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt +++ b/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/obj/anonymous/ConiumTypescriptAnonymousObjectTranslator.kt @@ -1,17 +1,18 @@ -package com.github.cao.awa.conium.script.translate.kts.file.`object`.anonymous +package com.github.cao.awa.conium.script.translate.kts.file.obj.anonymous import com.github.cao.awa.conium.script.translate.ConiumScriptTranslator import com.github.cao.awa.language.translator.builtin.typescript.translate.base.file.`object`.anonymous.TypescriptAnonymousObjectTranslator import com.github.cao.awa.language.translator.builtin.typescript.translate.element.TypescriptTranslateElement import com.github.cao.awa.language.translator.builtin.typescript.tree.`object`.anonymous.TypescriptAnonymousObject +import com.github.cao.awa.language.translator.builtin.typescript.tree.result.TypescriptResultStatement class ConiumTypescriptAnonymousObjectTranslator : ConiumScriptTranslator(), TypescriptAnonymousObjectTranslator { override fun translate(builder: StringBuilder, ast: TypescriptAnonymousObject) { builder.append("BedrockScriptAnonymousObjectMap()") - ast.params().values().forEach { (key, value) -> - builder.append(".add(\"$key\",") - postTranslate(TypescriptTranslateElement.STATEMENT, value) + ast.params().values().forEach { (name: String, statement: TypescriptResultStatement) -> + builder.append(".add(\"$name\",") + postTranslate(TypescriptTranslateElement.STATEMENT, statement) builder.append(")") } } diff --git a/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/statement/variable/ConiumTypescriptDefineVariableTranslator.kt b/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/statement/variable/ConiumTypescriptDefineVariableTranslator.kt index a5eb53d..d8c7f01 100644 --- a/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/statement/variable/ConiumTypescriptDefineVariableTranslator.kt +++ b/src/main/java/com/github/cao/awa/conium/script/translate/kts/file/statement/variable/ConiumTypescriptDefineVariableTranslator.kt @@ -7,8 +7,7 @@ import com.github.cao.awa.language.translator.builtin.typescript.tree.statement. import com.github.cao.awa.language.translator.builtin.typescript.tree.statement.invoke.access.TypescriptInvokeAccessElement import com.github.cao.awa.language.translator.builtin.typescript.tree.statement.variable.TypescriptDefineVariable -class ConiumTypescriptDefineVariableTranslator : ConiumScriptTranslator(), - TypescriptDefineVariableTranslator { +class ConiumTypescriptDefineVariableTranslator : ConiumScriptTranslator(), TypescriptDefineVariableTranslator { override fun translate(builder: StringBuilder, ast: TypescriptDefineVariable) { if (ast.isFinal) { builder.append("val ") diff --git a/src/main/java/com/github/cao/awa/conium/script/typescript/TypescriptPrototype.kt b/src/main/java/com/github/cao/awa/conium/script/typescript/TypescriptPrototype.kt index 47d87a9..8ce5276 100644 --- a/src/main/java/com/github/cao/awa/conium/script/typescript/TypescriptPrototype.kt +++ b/src/main/java/com/github/cao/awa/conium/script/typescript/TypescriptPrototype.kt @@ -1,7 +1,10 @@ package com.github.cao.awa.conium.script.typescript import com.github.cao.awa.conium.parameter.ParameterSelective2 +import org.jetbrains.annotations.ApiStatus +@ApiStatus.Internal +@ApiStatus.Experimental class TypescriptPrototype(private val delegate: T) { // Test callable val yyy: ParameterSelective2 = ParameterSelective2 { p1, p2 -> diff --git a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplate.kt b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplate.kt index 5d80cef..daadbca 100644 --- a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplate.kt @@ -17,7 +17,7 @@ import org.apache.logging.log4j.Logger import java.util.* import kotlin.reflect.KClass -abstract class ConiumTemplate(private val name: String, val isClient: Boolean = false) { +abstract class ConiumTemplate(val isClient: Boolean = false, private val name: String) { companion object { private val LOGGER: Logger = LogManager.getLogger("ConiumTemplate") private val templates: MutableMap = CollectionFactor.hashMap() @@ -141,6 +141,11 @@ abstract class ConiumTemplate(private val name: String, val isClient: Bool // Attention to duration, this duration value in bedrock is seconds instead of ticks in bedrock. fun secondsToTicks(duration: Float): Int = (duration * 20).toInt() + + fun notSupported(): (JsonElement) -> R = { throw notSupported(it) } + + @Throws(IllegalArgumentException::class) + fun notSupported(jsonElement: JsonElement): IllegalArgumentException = IllegalArgumentException("Not supported syntax: $jsonElement") } // This contexts will be set in deserializing templates, do not set it again in feature. diff --git a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplateFactor.kt b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplateFactor.kt index 292ebf2..718dd2b 100644 --- a/src/main/java/com/github/cao/awa/conium/template/ConiumTemplateFactor.kt +++ b/src/main/java/com/github/cao/awa/conium/template/ConiumTemplateFactor.kt @@ -4,11 +4,7 @@ import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup fun interface ConiumTemplateFactor { - fun createResult(element: JsonElement, registryLookup: WrapperLookup): Result> { - return runCatching { - create(element, registryLookup) - } - } + fun createResult(element: JsonElement, registryLookup: WrapperLookup): Result> = runCatching { create(element, registryLookup) } fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumTemplate<*, *> }