diff --git a/document/script/kotlin/event/README.md b/document/script/kotlin/event/README.md index 1a82bd0..b096bb3 100644 --- a/document/script/kotlin/event/README.md +++ b/document/script/kotlin/event/README.md @@ -2,21 +2,32 @@ ## Event types -| Key | Notes | Environment | Cancelable | -|------------------:|:-----------------------------------:|------------:|-----------:| -| SERVER_TICK | Trigger in every server tick | SERVER | false | -| ITEM_USE_ON_BLOCK | Trigger when an item use on a block | ALL | true | -| BREAKING_BLOCK | Trigger when breaking block | ALL | true | -| BREAK_BLOCK | Trigger when broking block | SERVER | true | -| BROKEN_BLOCK | Trigger when broken block | ALL | false | -| PLACE_BLOCK | Trigger when placing block | ALL | true | -| PLACED_BLOCK | Trigger when block placed | ALL | false | -| USE_BLOCK | Trigger when using block | ALL | true | -| USED_BLOCK | Trigger when block used | ALL | false | -| ENTITY_DAMAGE | Trigger when entity damaging | ALL | true | -| ENTITY_DAMAGED | Trigger when entity damaged | ALL | false | -| ENTITY_DIE | Trigger when entity dying | ALL | true | -| ENTITY_DIED | Trigger when entity died | ALL | false | +| Key | Notes | Environment | Cancelable | Cascade events | +|------------------:|:-----------------------------------:|------------:|-----------:|--------------------------------------:| +| SERVER_TICK | Trigger in every server tick | SERVER | false | * | +| ITEM_USE_ON_BLOCK | Trigger when an item use on a block | ALL | true | * | +| BREAKING_BLOCK | Trigger when breaking block | ALL | true | ```BREAK_BLOCK``` ```BROKEN_BLOCK``` | +| BREAK_BLOCK | Trigger when broking block | SERVER | true | ```BROKEN_BLOCK``` | +| BROKEN_BLOCK | Trigger when broken block | ALL | false | * | +| PLACE_BLOCK | Trigger when placing block | ALL | true | ```PLACED_BLOCK``` | +| PLACED_BLOCK | Trigger when block placed | ALL | false | * | +| USE_BLOCK | Trigger when using block | ALL | true | ```USED_BLOCK``` | +| USED_BLOCK | Trigger when block used | ALL | false | * | +| ENTITY_DAMAGE | Trigger when entity damaging | ALL | true | ```ENTITY_DAMAGED``` | +| ENTITY_DAMAGED | Trigger when entity damaged | ALL | false | * | +| ENTITY_DIE | Trigger when entity dying | ALL | true | ```ENTITY_DEAD``` | +| ENTITY_DIED | Trigger when entity died | ALL | false | * | + +### Cascade events +Cascade events are one or more events that only can happen when the preceding event is successful. + +For example, the ```BREAKING_BLOCK``` event occurs when a player starting mining a block, normally, it takes time for the player to destroy the block, and only then can ```BREAK_BLOCK``` event occur, followed by the ```BROKEN_BLOCK``` event.\ +The ```BREAK_BLOCK``` and ```BROKEN_BLOCK``` events cannot happen if ```BREAKING_BLOCK``` event is canceled or failed. + +In summary, cascade events is one or more events that depends on certain preceding events. + +Remember, all cascade event of the event cannot happen when you are canceling a event!\ +Includes all ```arising``` and ```presaging``` context of cascaded events and ```arising``` context of this event. ## Context args diff --git a/src/main/java/com/github/cao/awa/conium/Conium.kt b/src/main/java/com/github/cao/awa/conium/Conium.kt index 5c6ad41..85e1eda 100644 --- a/src/main/java/com/github/cao/awa/conium/Conium.kt +++ b/src/main/java/com/github/cao/awa/conium/Conium.kt @@ -16,7 +16,6 @@ import com.github.cao.awa.language.translator.translate.lang.element.TranslateEl import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import net.fabricmc.api.ModInitializer import org.apache.logging.log4j.LogManager -import org.jetbrains.annotations.NotNull import java.util.function.Supplier class Conium : ModInitializer { diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt b/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt index d1f041e..c42d15e 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/BedrockScriptApi.kt @@ -1,3 +1,3 @@ package com.github.cao.awa.conium.bedrock -annotation class BedrockScriptApi() +annotation class BedrockScriptApi diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt b/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt index 67876b9..bb2bfb2 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/event/context/item/use/BedrockItemUseOnEventContext.kt @@ -2,20 +2,20 @@ package com.github.cao.awa.conium.bedrock.event.context.item.use import com.github.cao.awa.conium.bedrock.BedrockScriptApi import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade -import com.github.cao.awa.conium.bedrock.world.BedrockWorld import com.github.cao.awa.conium.bedrock.event.context.BedrockEventContext import com.github.cao.awa.conium.bedrock.item.stack.BedrockItemStack import com.github.cao.awa.conium.bedrock.item.stack.toBedrock +import com.github.cao.awa.conium.bedrock.world.BedrockWorld import com.github.cao.awa.conium.bedrock.world.toBedrock import net.minecraft.item.ItemUsageContext @BedrockScriptApi @BedrockScriptApiFacade("ItemUseOnBeforeEvent", "ItemUseOnAfterEvent") -class BedrockItemUseOnEventContext(source: Any, val world: BedrockWorld, val itemStack: BedrockItemStack): BedrockEventContext(source) { +class BedrockItemUseOnEventContext(source: Any, val world: BedrockWorld, val itemStack: BedrockItemStack) : BedrockEventContext(source) { override fun world(): BedrockWorld = this.world } -fun ItemUsageContext.toBedrock(scriptSource: Any): BedrockItemUseOnEventContext{ +fun ItemUsageContext.toBedrock(scriptSource: Any): BedrockItemUseOnEventContext { val context = BedrockItemUseOnEventContext( scriptSource, this.world.toBedrock(), 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 3cd4ef4..93c3800 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 @@ -2,13 +2,13 @@ package com.github.cao.awa.conium.bedrock.script import com.github.cao.awa.conium.bedrock.BedrockScriptApi import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade -import com.github.cao.awa.conium.event.type.DynamicArgType +import com.github.cao.awa.conium.parameter.DynamicArgType import com.github.cao.awa.conium.parameter.type.DynamicArgTypeBuilder.arg import com.github.cao.awa.sinuatum.util.collection.CollectionFactor @BedrockScriptApi @BedrockScriptApiFacade("anonymous object") -open class BedrockScriptAnonymousObjectMap: Iterable> { +open class BedrockScriptAnonymousObjectMap : Iterable> { private val map = CollectionFactor.hashMap() fun add(key: String, value: Any?): BedrockScriptAnonymousObjectMap { 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 d771364..77ae8bb 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 @@ -3,7 +3,6 @@ package com.github.cao.awa.conium.bedrock.system import com.github.cao.awa.catheter.receptacle.IntegerReceptacle import com.github.cao.awa.conium.bedrock.BedrockScriptApi import com.github.cao.awa.conium.bedrock.system.task.ConiumTask -import com.github.cao.awa.conium.bedrock.world.BedrockWorld import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import net.minecraft.server.MinecraftServer 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 e30c326..6e0ca68 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 @@ -5,7 +5,7 @@ import com.github.cao.awa.conium.bedrock.world.player.delegate.BedrockPlayerDele import net.minecraft.world.World @BedrockScriptApi -open class BedrockWorld(private val delegate: World): AbstractBedrockWorld() { +open class BedrockWorld(private val delegate: World) : AbstractBedrockWorld() { companion object { val DUMMY = DummyBedrockWorld() } diff --git a/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt b/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt index ce7c079..ef86e7c 100644 --- a/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt +++ b/src/main/java/com/github/cao/awa/conium/bedrock/world/dimension/BedrockDimensionLocation.kt @@ -5,6 +5,4 @@ import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade @BedrockScriptApi @BedrockScriptApiFacade("DimensionLocation") -class BedrockDimensionLocation { - -} +class BedrockDimensionLocation 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 01dca78..a7e2e7d 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 @@ -33,7 +33,7 @@ class ConiumBlock(settings: Settings) : Block(settings), BlockColorProvider { } var color: Int = 0 - var outlineShape : VoxelShape = VoxelShapes.fullCube() + var outlineShape: VoxelShape = VoxelShapes.fullCube() override fun getColor(state: BlockState?, world: BlockRenderView?, pos: BlockPos?, tintIndex: Int): Int = this.color diff --git a/src/main/java/com/github/cao/awa/conium/block/builder/ConiumBlockBuilder.kt b/src/main/java/com/github/cao/awa/conium/block/builder/ConiumBlockBuilder.kt index 2a58226..8b55c9c 100644 --- a/src/main/java/com/github/cao/awa/conium/block/builder/ConiumBlockBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/block/builder/ConiumBlockBuilder.kt @@ -2,12 +2,8 @@ package com.github.cao.awa.conium.block.builder import com.github.cao.awa.conium.block.ConiumBlock import com.github.cao.awa.conium.block.template.ConiumBlockTemplate -import com.github.cao.awa.conium.item.ConiumItem -import com.github.cao.awa.conium.item.template.ConiumItemTemplate -import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import net.minecraft.block.AbstractBlock import net.minecraft.block.Block -import net.minecraft.item.Item import net.minecraft.util.Identifier abstract class ConiumBlockBuilder(val identifier: Identifier) { diff --git a/src/main/java/com/github/cao/awa/conium/block/builder/bedrock/BedrockSchemaBlockBuilder.kt b/src/main/java/com/github/cao/awa/conium/block/builder/bedrock/BedrockSchemaBlockBuilder.kt index b1d3036..6cdd1a0 100644 --- a/src/main/java/com/github/cao/awa/conium/block/builder/bedrock/BedrockSchemaBlockBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/block/builder/bedrock/BedrockSchemaBlockBuilder.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonObject import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier -class BedrockSchemaBlockBuilder(identifier: Identifier): ConiumBlockBuilder(identifier) { +class BedrockSchemaBlockBuilder(identifier: Identifier) : ConiumBlockBuilder(identifier) { companion object { @JvmStatic fun deserialize(json: JsonObject, registryLookup: RegistryWrapper.WrapperLookup): BedrockSchemaBlockBuilder { diff --git a/src/main/java/com/github/cao/awa/conium/block/builder/conium/ConiumSchemaBlockBuilder.kt b/src/main/java/com/github/cao/awa/conium/block/builder/conium/ConiumSchemaBlockBuilder.kt index 9f52678..f65b0d5 100644 --- a/src/main/java/com/github/cao/awa/conium/block/builder/conium/ConiumSchemaBlockBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/block/builder/conium/ConiumSchemaBlockBuilder.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonObject import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier -class ConiumSchemaBlockBuilder(identifier: Identifier): ConiumBlockBuilder(identifier) { +class ConiumSchemaBlockBuilder(identifier: Identifier) : ConiumBlockBuilder(identifier) { companion object { @JvmStatic fun deserialize(json: JsonObject, registryLookup: RegistryWrapper.WrapperLookup): ConiumSchemaBlockBuilder { 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 8130d7f..335c5bf 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 @@ -6,7 +6,6 @@ import com.github.cao.awa.conium.event.context.ConiumEventContextBuilder.require 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.ParameterSelective -import com.github.cao.awa.conium.parameter.ParameterSelective3 import com.github.cao.awa.conium.parameter.ParameterSelective4 import net.minecraft.block.AbstractBlock.AbstractBlockState import net.minecraft.entity.player.PlayerEntity 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 e87f056..b6f2998 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 @@ -8,9 +8,7 @@ import com.github.cao.awa.conium.event.type.ConiumEventType import com.github.cao.awa.conium.parameter.ParameterSelective import com.github.cao.awa.conium.parameter.ParameterSelective5 import net.minecraft.block.AbstractBlock.AbstractBlockState -import net.minecraft.entity.LivingEntity import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.ItemStack import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos import net.minecraft.world.World diff --git a/src/main/java/com/github/cao/awa/conium/block/template/bedrock/collision/ConiumBedrockBlockCollisionBoxTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/bedrock/collision/ConiumBedrockBlockCollisionBoxTemplate.kt index a04d018..3d76286 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/bedrock/collision/ConiumBedrockBlockCollisionBoxTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/bedrock/collision/ConiumBedrockBlockCollisionBoxTemplate.kt @@ -9,22 +9,22 @@ import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup object ConiumBedrockBlockCollisionBoxTemplate { - @JvmStatic - fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockCollisionTemplate = element.objectOrBoolean( - { - // Create the custom cubed block. - createWithCubed(COLLISION_BOX) { cubed -> - // Push all int to cubed array. - it["origin"].asJsonArray.let { - // Bedrock base offset is '-8', make it be conium offset '0'. - cubed(it[0].asInt + 8) - cubed(it[1].asInt) - cubed(it[2].asInt + 8) - } - it["size"].asJsonArray.eachInt(cubed) + @JvmStatic + fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumBlockCollisionTemplate = element.objectOrBoolean( + { + // Create the custom cubed block. + createWithCubed(COLLISION_BOX) { cubed -> + // Push all int to cubed array. + it["origin"].asJsonArray.let { + // Bedrock base offset is '-8', make it be conium offset '0'. + cubed(it[0].asInt + 8) + cubed(it[1].asInt) + cubed(it[2].asInt + 8) } - }, - // Create the full cubed block when origin and size not specified. - { ConiumBlockCollisionTemplate(it, 0, 0, 0, 16, 16, 16, COLLISION_BOX) } - )!! + it["size"].asJsonArray.eachInt(cubed) + } + }, + // Create the full cubed block when origin and size not specified. + { ConiumBlockCollisionTemplate(it, 0, 0, 0, 16, 16, 16, COLLISION_BOX) } + )!! } diff --git a/src/main/java/com/github/cao/awa/conium/block/template/bedrock/light/ConiumBedrockLightEmissionTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/bedrock/light/ConiumBedrockLightEmissionTemplate.kt index e2cf30b..a942d71 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/bedrock/light/ConiumBedrockLightEmissionTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/bedrock/light/ConiumBedrockLightEmissionTemplate.kt @@ -1,8 +1,8 @@ package com.github.cao.awa.conium.block.template.bedrock.light -import com.github.cao.awa.conium.template.ConiumTemplates.BedrockBlock.LIGHT_EMISSION import com.github.cao.awa.conium.block.template.luminance.ConiumLuminanceTemplate import com.github.cao.awa.conium.block.template.luminance.ConiumLuminanceTemplate.Companion.validateLuminance +import com.github.cao.awa.conium.template.ConiumTemplates.BedrockBlock.LIGHT_EMISSION import com.google.gson.JsonElement import net.minecraft.registry.RegistryWrapper.WrapperLookup diff --git a/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumBedrockMapColorTemplate.kt b/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumBedrockMapColorTemplate.kt index 4b99bde..fcee39b 100644 --- a/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumBedrockMapColorTemplate.kt +++ b/src/main/java/com/github/cao/awa/conium/block/template/map/ConiumBedrockMapColorTemplate.kt @@ -1,6 +1,5 @@ package com.github.cao.awa.conium.block.template.map -import com.github.cao.awa.conium.block.template.map.ConiumMapColorTemplate import com.github.cao.awa.conium.kotlin.extent.block.parseAndFindColor import com.github.cao.awa.conium.template.ConiumTemplates.BedrockBlock.MAP_COLOR import com.google.gson.JsonElement 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 a7b807a..ce8d61d 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) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumHardnessTemplate = ConiumHardnessTemplate(element.asFloat) 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 db56f7c..8a43ac6 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 @@ -1,11 +1,8 @@ package com.github.cao.awa.conium.datapack -import com.github.cao.awa.conium.registry.ConiumRegistryKeys import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonElement import com.google.gson.JsonParser -import net.minecraft.registry.RegistryKeys -import net.minecraft.resource.Resource import net.minecraft.resource.ResourceFinder import net.minecraft.resource.ResourceManager import net.minecraft.resource.SinglePreparationResourceReloader 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 372aa0c..9a78181 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 @@ -7,14 +7,15 @@ import com.github.cao.awa.conium.datapack.ConiumJsonDataLoader import com.github.cao.awa.conium.event.ConiumEvent import com.github.cao.awa.conium.extend.ConiumDynamicIdList import com.github.cao.awa.conium.extend.ConiumDynamicRegistry -import com.github.cao.awa.conium.item.builder.bedrock.BedrockSchemaItemBuilder import com.github.cao.awa.conium.kotlin.extent.block.register -import com.github.cao.awa.conium.kotlin.extent.item.register import com.github.cao.awa.conium.kotlin.extent.item.registerBlockItem import com.github.cao.awa.conium.registry.ConiumRegistryKeys import com.github.cao.awa.sinuatum.manipulate.Manipulate import com.google.common.collect.UnmodifiableIterator -import com.google.gson.* +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import com.google.gson.JsonElement +import com.google.gson.JsonObject import net.minecraft.block.Block import net.minecraft.block.BlockState import net.minecraft.registry.Registries 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 8170151..47c6b92 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 @@ -13,7 +13,8 @@ import com.github.cao.awa.conium.extend.ConiumDynamicRegistry import com.github.cao.awa.conium.kotlin.extent.entity.register import com.github.cao.awa.conium.registry.ConiumRegistryKeys import com.github.cao.awa.sinuatum.util.collection.CollectionFactor -import com.google.gson.* +import com.google.gson.JsonElement +import com.google.gson.JsonObject import net.minecraft.registry.Registries import net.minecraft.registry.RegistryKeys import net.minecraft.registry.RegistryWrapper 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 b0454ad..0cfebdd 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 @@ -9,13 +9,14 @@ import com.github.cao.awa.conium.datapack.inject.item.component.ItemPropertyInje import com.github.cao.awa.conium.registry.ConiumRegistryKeys import com.github.cao.awa.sinuatum.manipulate.Manipulate import com.github.cao.awa.sinuatum.util.collection.CollectionFactor -import com.google.gson.* +import com.google.gson.JsonElement +import com.google.gson.JsonObject import net.minecraft.component.ComponentType import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.registry.Registries import net.minecraft.registry.RegistryKeys -import net.minecraft.resource.* +import net.minecraft.resource.ResourceManager import net.minecraft.util.Identifier import net.minecraft.util.profiler.Profiler import org.apache.logging.log4j.LogManager diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/ItemPropertyInjectAction.kt b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/ItemPropertyInjectAction.kt index 8b2f3da..8c5a3cc 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/ItemPropertyInjectAction.kt +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/ItemPropertyInjectAction.kt @@ -1,7 +1,5 @@ package com.github.cao.awa.conium.datapack.inject.item.action -import com.mojang.serialization.DataResult - enum class ItemPropertyInjectAction { SET, SET_PRESET, diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/ItemPropertyInjectHandler.java b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/ItemPropertyInjectHandler.java index 5e39e04..4c32153 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/ItemPropertyInjectHandler.java +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/ItemPropertyInjectHandler.java @@ -1,12 +1,12 @@ package com.github.cao.awa.conium.datapack.inject.item.action.handler; +import com.github.cao.awa.conium.datapack.inject.item.action.ItemPropertyInjectAction; import com.github.cao.awa.conium.datapack.inject.item.action.handler.math.ItemPropertyInjectAddHandler; import com.github.cao.awa.conium.datapack.inject.item.action.handler.math.ItemPropertyInjectDivideHandler; import com.github.cao.awa.conium.datapack.inject.item.action.handler.math.ItemPropertyInjectMinusHandler; import com.github.cao.awa.conium.datapack.inject.item.action.handler.math.ItemPropertyInjectMultiplyHandler; import com.github.cao.awa.conium.datapack.inject.item.action.handler.set.ItemPropertyInjectSetHandler; import com.github.cao.awa.sinuatum.manipulate.Manipulate; -import com.github.cao.awa.conium.datapack.inject.item.action.ItemPropertyInjectAction; import com.github.cao.awa.sinuatum.manipulate.QuickManipulate; import com.github.cao.awa.sinuatum.util.collection.CollectionFactor; @@ -23,8 +23,6 @@ public abstract class ItemPropertyInjectHandler { handlers.put(ItemPropertyInjectAction.MULTIPLY, new ItemPropertyInjectMultiplyHandler<>()); }); - public abstract T doHandle(T source, T value); - public static X doHandles(X first, X second, ItemPropertyInjectAction action) { if (first.getClass() == second.getClass() && handlers.containsKey(action)) { return Manipulate.cast(handlers.get(action).doHandle(Manipulate.cast(first), Manipulate.cast(second))); @@ -32,4 +30,6 @@ public static X doHandles(X first, X second, ItemPropertyInjectAction action throw new IllegalArgumentException("No handler registered for " + action); } } + + public abstract T doHandle(T source, T value); } diff --git a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/math/typed/NumberHandler.java b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/math/typed/NumberHandler.java index 48a338c..010d758 100644 --- a/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/math/typed/NumberHandler.java +++ b/src/main/java/com/github/cao/awa/conium/datapack/inject/item/action/handler/math/typed/NumberHandler.java @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.datapack.inject.item.action.handler.math.typed; -import com.github.cao.awa.sinuatum.manipulate.Manipulate; import com.github.cao.awa.conium.datapack.inject.item.action.ItemPropertyInjectAction; +import com.github.cao.awa.sinuatum.manipulate.Manipulate; import com.github.cao.awa.sinuatum.manipulate.QuickManipulate; import com.github.cao.awa.sinuatum.util.collection.CollectionFactor; @@ -17,8 +17,6 @@ public abstract class NumberHandler { handlers.put(BigInteger.class, new BigIntegerNumberHandler()); }); - public abstract T doHandle(T first, T second, ItemPropertyInjectAction action); - public static X doHandles(Number first, Number second, ItemPropertyInjectAction action) { if (first.getClass() == second.getClass() && handlers.containsKey(first.getClass())) { return Manipulate.cast(handlers.get(first.getClass()).doHandle(Manipulate.cast(first), Manipulate.cast(second), action)); @@ -26,4 +24,6 @@ public static X doHandles(Number first, Number second, ItemPr throw new IllegalArgumentException("Unsupported number type: " + first.getClass() + " and " + second.getClass()); } } + + public abstract T doHandle(T first, T second, ItemPropertyInjectAction action); } 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 250c5ba..02a1b59 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 @@ -5,11 +5,12 @@ import com.github.cao.awa.conium.datapack.ConiumJsonDataLoader import com.github.cao.awa.conium.datapack.item.fuel.ConiumFuelRegistry import com.github.cao.awa.conium.event.ConiumEvent import com.github.cao.awa.conium.extend.ConiumDynamicRegistry -import com.github.cao.awa.conium.item.builder.conium.ConiumSchemaItemBuilder import com.github.cao.awa.conium.item.builder.bedrock.BedrockSchemaItemBuilder +import com.github.cao.awa.conium.item.builder.conium.ConiumSchemaItemBuilder import com.github.cao.awa.conium.kotlin.extent.item.register import com.github.cao.awa.conium.registry.ConiumRegistryKeys -import com.google.gson.* +import com.google.gson.JsonElement +import com.google.gson.JsonObject import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.registry.Registries @@ -21,7 +22,7 @@ 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.util.SequencedSet +import java.util.* class ConiumItemManager(private val registryLookup: RegistryWrapper.WrapperLookup, private val pendingTagLoad: List>) : ConiumJsonDataLoader(RegistryKeys.getPath(ConiumRegistryKeys.ITEM)) { 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 a4f37f7..728d4ce 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 @@ -1,7 +1,7 @@ package com.github.cao.awa.conium.datapack.item.fuel -import com.github.cao.awa.sinuatum.util.collection.CollectionFactor -import it.unimi.dsi.fastutil.objects.* +import it.unimi.dsi.fastutil.objects.Object2IntMap +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap import net.minecraft.item.Item import net.minecraft.item.ItemStack import java.util.* 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 545958b..b2684fc 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,7 +5,6 @@ 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.JsonObject import com.google.gson.JsonParser import com.mojang.serialization.JsonOps import net.minecraft.recipe.* @@ -26,7 +25,6 @@ import org.apache.logging.log4j.Logger import java.util.* import java.util.function.Consumer import java.util.stream.Collectors -import kotlin.jvm.optionals.getOrNull class ConiumRecipeManager(private val registries: WrapperLookup) : ServerRecipeManager(registries) { companion object { diff --git a/src/main/java/com/github/cao/awa/conium/entity/builder/bedrock/BedrockSchemaEntityBuilder.kt b/src/main/java/com/github/cao/awa/conium/entity/builder/bedrock/BedrockSchemaEntityBuilder.kt index 630733c..0688027 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/builder/bedrock/BedrockSchemaEntityBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/builder/bedrock/BedrockSchemaEntityBuilder.kt @@ -1,10 +1,8 @@ package com.github.cao.awa.conium.entity.builder.bedrock import com.github.cao.awa.conium.entity.builder.ConiumEntityBuilder -import com.github.cao.awa.conium.entity.template.ConiumEntityTemplate import com.github.cao.awa.conium.template.ConiumTemplate import com.github.cao.awa.sinuatum.manipulate.Manipulate -import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonObject import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier diff --git a/src/main/java/com/github/cao/awa/conium/entity/builder/conium/ConiumSchemaEntityBuilder.kt b/src/main/java/com/github/cao/awa/conium/entity/builder/conium/ConiumSchemaEntityBuilder.kt index 459fbe5..b2e84fe 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/builder/conium/ConiumSchemaEntityBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/builder/conium/ConiumSchemaEntityBuilder.kt @@ -1,10 +1,8 @@ package com.github.cao.awa.conium.entity.builder.conium import com.github.cao.awa.conium.entity.builder.ConiumEntityBuilder -import com.github.cao.awa.conium.entity.template.ConiumEntityTemplate import com.github.cao.awa.conium.template.ConiumTemplate import com.github.cao.awa.sinuatum.manipulate.Manipulate -import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonObject import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier diff --git a/src/main/java/com/github/cao/awa/conium/entity/renderer/model/ConiumEntityModel.kt b/src/main/java/com/github/cao/awa/conium/entity/renderer/model/ConiumEntityModel.kt index 2461957..ff4180f 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/renderer/model/ConiumEntityModel.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/renderer/model/ConiumEntityModel.kt @@ -1,7 +1,6 @@ package com.github.cao.awa.conium.entity.renderer.model import com.github.cao.awa.conium.entity.renderer.state.ConiumEntityRenderState -import com.github.cao.awa.conium.kotlin.extent.json.jsonArray import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.google.gson.JsonArray import com.google.gson.JsonElement diff --git a/src/main/java/com/github/cao/awa/conium/entity/renderer/state/ConiumEntityRenderState.kt b/src/main/java/com/github/cao/awa/conium/entity/renderer/state/ConiumEntityRenderState.kt index 8a4b62f..0ef6e41 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/renderer/state/ConiumEntityRenderState.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/renderer/state/ConiumEntityRenderState.kt @@ -2,7 +2,6 @@ package com.github.cao.awa.conium.entity.renderer.state import net.fabricmc.api.EnvType import net.fabricmc.api.Environment -import net.minecraft.client.render.entity.state.EntityRenderState import net.minecraft.client.render.entity.state.LivingEntityRenderState @Environment(EnvType.CLIENT) diff --git a/src/main/java/com/github/cao/awa/conium/entity/setting/ConiumEntitySettings.kt b/src/main/java/com/github/cao/awa/conium/entity/setting/ConiumEntitySettings.kt index 3a48d1b..0b27a96 100644 --- a/src/main/java/com/github/cao/awa/conium/entity/setting/ConiumEntitySettings.kt +++ b/src/main/java/com/github/cao/awa/conium/entity/setting/ConiumEntitySettings.kt @@ -9,9 +9,9 @@ import net.minecraft.block.piston.PistonBehavior import net.minecraft.client.render.entity.EntityRenderer import net.minecraft.client.render.entity.EntityRendererFactory import net.minecraft.client.render.entity.model.EntityModel -import net.minecraft.entity.EntityType import net.minecraft.entity.Entity import net.minecraft.entity.EntityDimensions +import net.minecraft.entity.EntityType import net.minecraft.entity.LivingEntity import net.minecraft.util.Identifier diff --git a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt index ee647c9..609b350 100644 --- a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt +++ b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContext.kt @@ -1,6 +1,6 @@ package com.github.cao.awa.conium.event.context -import com.github.cao.awa.conium.event.type.DynamicArgType +import com.github.cao.awa.conium.parameter.DynamicArgType import com.github.cao.awa.conium.parameter.DynamicArgs import com.github.cao.awa.conium.parameter.ParameterSelective import com.github.cao.awa.sinuatum.util.collection.CollectionFactor @@ -79,7 +79,7 @@ class ConiumEventContext

( } fun arising(identity: Any): Boolean { - var success = this.dynamicArgs.arising(identity, this.args, this.ariseTrigger!!) as Boolean + var success = this.dynamicArgs.arising(identity, this.args, this.ariseTrigger!!) for (attach in this.attaches) { if (attach.hasArising()) { val attachSuccess = attach.resetArgs(this.args) diff --git a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt index a96e176..b49c7c9 100644 --- a/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/event/context/ConiumEventContextBuilder.kt @@ -1,7 +1,6 @@ package com.github.cao.awa.conium.event.context import com.github.cao.awa.conium.event.ConiumEvent -import com.github.cao.awa.conium.event.type.DynamicArgType import com.github.cao.awa.conium.event.type.ConiumEventType import com.github.cao.awa.conium.parameter.* 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 822bdb2..8c77830 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 @@ -1,24 +1,24 @@ package com.github.cao.awa.conium.event.type +import com.github.cao.awa.conium.parameter.DynamicArgType import com.github.cao.awa.conium.parameter.DynamicArgsBuilder -import net.minecraft.block.BlockState -import net.minecraft.client.network.ClientPlayerEntity -import net.minecraft.client.world.ClientWorld -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.ItemUsageContext -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.server.world.ServerWorld -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World import com.github.cao.awa.conium.parameter.type.DynamicArgTypeBuilder.arg import net.minecraft.block.AbstractBlock.AbstractBlockState +import net.minecraft.client.network.ClientPlayerEntity +import net.minecraft.client.world.ClientWorld import net.minecraft.entity.LivingEntity import net.minecraft.entity.damage.DamageSource +import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.ItemPlacementContext import net.minecraft.item.ItemStack +import net.minecraft.item.ItemUsageContext import net.minecraft.server.MinecraftServer +import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.world.ServerWorld import net.minecraft.util.ActionResult import net.minecraft.util.hit.BlockHitResult +import net.minecraft.util.math.BlockPos +import net.minecraft.world.World object ConiumEventArgTypes { @JvmField diff --git a/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventType.kt b/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventType.kt index 6ed7231..f0b2a49 100644 --- a/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventType.kt +++ b/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventType.kt @@ -1,8 +1,8 @@ package com.github.cao.awa.conium.event.type -import com.github.cao.awa.conium.mixin.server.interaction.ServerPlayerInteractionManagerMixin -import com.github.cao.awa.conium.mixin.client.interaction.ClientPlayerInteractionManagerMixin import com.github.cao.awa.conium.mixin.block.BlockStateMixin +import com.github.cao.awa.conium.mixin.client.interaction.ClientPlayerInteractionManagerMixin +import com.github.cao.awa.conium.mixin.server.interaction.ServerPlayerInteractionManagerMixin enum class ConiumEventType { SERVER_TICK, diff --git a/src/main/java/com/github/cao/awa/conium/event/type/DynamicArgType.kt b/src/main/java/com/github/cao/awa/conium/event/type/DynamicArgType.kt deleted file mode 100644 index f8dc931..0000000 --- a/src/main/java/com/github/cao/awa/conium/event/type/DynamicArgType.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.cao.awa.conium.event.type - -import com.github.cao.awa.conium.parameter.DynamicArgs - -class DynamicArgType(val key: String, vararg val dynamicArgs: DynamicArgs<*, T?>?) { - constructor(key: String) : this(key, null) -} diff --git a/src/main/java/com/github/cao/awa/conium/extend/ConiumDynamicIdList.java b/src/main/java/com/github/cao/awa/conium/extend/ConiumDynamicIdList.java index 269979a..4fa85f0 100644 --- a/src/main/java/com/github/cao/awa/conium/extend/ConiumDynamicIdList.java +++ b/src/main/java/com/github/cao/awa/conium/extend/ConiumDynamicIdList.java @@ -10,5 +10,6 @@ default void clearDynamic() { default void addDynamic(T value) { conium$add(value); } + void conium$add(T value); } diff --git a/src/main/java/com/github/cao/awa/conium/item/builder/ConiumItemBuilder.kt b/src/main/java/com/github/cao/awa/conium/item/builder/ConiumItemBuilder.kt index 3b09bf7..d26e966 100644 --- a/src/main/java/com/github/cao/awa/conium/item/builder/ConiumItemBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/item/builder/ConiumItemBuilder.kt @@ -2,7 +2,6 @@ package com.github.cao.awa.conium.item.builder import com.github.cao.awa.conium.item.ConiumItem import com.github.cao.awa.conium.item.template.ConiumItemTemplate -import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import net.minecraft.item.Item interface ConiumItemBuilder { diff --git a/src/main/java/com/github/cao/awa/conium/item/builder/conium/ConiumSchemaItemBuilder.kt b/src/main/java/com/github/cao/awa/conium/item/builder/conium/ConiumSchemaItemBuilder.kt index 472b135..2fcce55 100644 --- a/src/main/java/com/github/cao/awa/conium/item/builder/conium/ConiumSchemaItemBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/item/builder/conium/ConiumSchemaItemBuilder.kt @@ -9,7 +9,7 @@ import com.google.gson.JsonObject import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier -class ConiumSchemaItemBuilder(val identifier: Identifier): ConiumItemBuilder { +class ConiumSchemaItemBuilder(val identifier: Identifier) : ConiumItemBuilder { companion object { @JvmStatic fun deserialize(json: JsonObject, registryLookup: RegistryWrapper.WrapperLookup): ConiumSchemaItemBuilder { diff --git a/src/main/java/com/github/cao/awa/conium/item/event/ConiumItemEvent.kt b/src/main/java/com/github/cao/awa/conium/item/event/ConiumItemEvent.kt index c4bfca8..e1fde65 100644 --- a/src/main/java/com/github/cao/awa/conium/item/event/ConiumItemEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/item/event/ConiumItemEvent.kt @@ -2,8 +2,5 @@ package com.github.cao.awa.conium.item.event import com.github.cao.awa.conium.event.ConiumEvent import com.github.cao.awa.conium.parameter.ParameterSelective -import net.minecraft.item.Item -abstract class ConiumItemEvent: ConiumEvent

() { - -} +abstract class ConiumItemEvent

: ConiumEvent

() 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 b4cd3af..ddf456e 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 @@ -6,7 +6,6 @@ import com.google.gson.JsonElement import net.minecraft.item.Item import net.minecraft.item.consume.UseAction import net.minecraft.util.Rarity -import kotlin.jvm.Throws abstract class ConiumItemTemplate(name: String) : ConiumTemplate(name) { companion object { 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 06bc8bb..fc932a0 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 @@ -1,8 +1,8 @@ package com.github.cao.awa.conium.item.template.bedrock.damage import com.github.cao.awa.conium.item.template.ConiumItemTemplate -import com.github.cao.awa.conium.kotlin.extent.component.withComputeAttributeModifiers import com.github.cao.awa.conium.kotlin.extent.component.withComponent +import com.github.cao.awa.conium.kotlin.extent.component.withComputeAttributeModifiers import com.github.cao.awa.conium.kotlin.extent.component.withCreateAttributeModifiers import com.github.cao.awa.conium.kotlin.extent.item.components import com.github.cao.awa.conium.template.ConiumTemplates.BedrockItem.DAMAGE 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 075b7a0..ed41e69 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 @@ -6,12 +6,9 @@ import com.github.cao.awa.conium.kotlin.extent.component.withComponent import com.github.cao.awa.conium.kotlin.extent.component.withComputeTool import com.github.cao.awa.conium.kotlin.extent.component.withCreateTool import com.github.cao.awa.conium.kotlin.extent.item.components -import com.github.cao.awa.conium.template.ConiumTemplates -import com.google.gson.JsonElement import com.google.gson.JsonObject import net.minecraft.component.DataComponentTypes import net.minecraft.item.Item -import net.minecraft.registry.RegistryWrapper.WrapperLookup open class ConiumDurabilityTemplate(name: String, private val durability: Int, private val damageChance: IntRange) : ConiumItemTemplate(name) { companion object { 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 b1e1241..e807471 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 @@ -6,10 +6,10 @@ import com.google.gson.JsonElement import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumItemNetheritePickaxeTemplate: ConiumItemPickaxeTemplate( +class ConiumItemNetheritePickaxeTemplate : ConiumItemPickaxeTemplate( NETHERITE_PICKAXE, ToolMaterial.NETHERITE -){ +) { companion object { @JvmStatic fun create(element: JsonElement, registryLookup: WrapperLookup): ConiumItemNetheritePickaxeTemplate = element.createIfJsonObject(::ConiumItemNetheritePickaxeTemplate, 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 fcd473b..445089e 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 @@ -6,7 +6,7 @@ import com.google.gson.JsonElement import net.minecraft.item.ToolMaterial import net.minecraft.registry.RegistryWrapper.WrapperLookup -class ConiumItemStonePickaxeTemplate: ConiumItemPickaxeTemplate( +class ConiumItemStonePickaxeTemplate : ConiumItemPickaxeTemplate( STONE_PICKAXE, ToolMaterial.STONE ) { 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 13e698c..8de4f06 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 @@ -2,8 +2,6 @@ package com.github.cao.awa.conium.kotlin.extent.block 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 net.minecraft.block.AbstractBlock import net.minecraft.block.Block import net.minecraft.block.Blocks diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumMapColorKotlinExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumMapColorKotlinExtents.kt index 05bae71..0128b24 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumMapColorKotlinExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/block/ConiumMapColorKotlinExtents.kt @@ -39,4 +39,4 @@ fun findColor(code: Int): MapColor { return last } - fun parseColor(string: String): Int = string.substring(1).toLong(16).toInt() \ No newline at end of file +fun parseColor(string: String): Int = string.substring(1).toLong(16).toInt() \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentMapExtents.kt b/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentMapExtents.kt index 3c976cc..8706b96 100644 --- a/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentMapExtents.kt +++ b/src/main/java/com/github/cao/awa/conium/kotlin/extent/component/ConiumComponentMapExtents.kt @@ -27,7 +27,7 @@ val ComponentMap.Builder.components: Reference2ObjectMap, Any> * * @since 1.0.0 */ -fun ComponentMap.Builder.withComponent( +fun ComponentMap.Builder.withComponent( type: ComponentType, creator: () -> T, compute: Pair<(T) -> Y, (Y) -> T>, @@ -64,7 +64,7 @@ fun ComponentMap.Builder.withComponent( * * @since 1.0.0 */ -fun ComponentMap.Builder.withComponentProvides( +fun ComponentMap.Builder.withComponentProvides( type: ComponentType, creator: () -> T, compute: (T, Y) -> T, @@ -94,7 +94,7 @@ fun ComponentMap.Builder.withComponentProvides( * * @since 1.0.0 */ -fun ComponentMap.Builder.withComponent(type: ComponentType, creator: () -> T, callback: (T) -> Unit): ComponentMap.Builder { +fun ComponentMap.Builder.withComponent(type: ComponentType, creator: () -> T, callback: (T) -> Unit): ComponentMap.Builder { // Ensure value is present, then operate it, put back to make it still presents in next acquired. this.components[type] = getOrCreate(type, creator).also(callback) @@ -102,7 +102,7 @@ fun ComponentMap.Builder.withComponent(type: ComponentType, creator: } // Let the component rebuild and put it back to components map when the target component type is present. -fun ComponentMap.Builder.rebuild(type: ComponentType, creator: (T) -> T): ComponentMap.Builder { +fun ComponentMap.Builder.rebuild(type: ComponentType, creator: (T) -> T): ComponentMap.Builder { (this.components[type] as? T)?.let { this.components[type] = creator(it) } @@ -111,7 +111,7 @@ fun ComponentMap.Builder.rebuild(type: ComponentType, creator: (T) - } // Operates the component when the target component type is present. -fun ComponentMap.Builder.acquire(type: ComponentType, creator: (T) -> Unit, callback: (T) -> Unit = { }): ComponentMap.Builder { +fun ComponentMap.Builder.acquire(type: ComponentType, creator: (T) -> Unit, callback: (T) -> Unit = { }): ComponentMap.Builder { (this.components[type] as? T)?.let { creator(it) callback(it) 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 c8b4869..b3468fa 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,6 +1,5 @@ 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 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 a12f711..d78801b 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 @@ -2,9 +2,8 @@ package com.github.cao.awa.conium.kotlin.extent.item 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.conium.ConiumSchemaBlockBuilder -import com.github.cao.awa.conium.item.builder.conium.ConiumSchemaItemBuilder import com.github.cao.awa.conium.item.builder.bedrock.BedrockSchemaItemBuilder +import com.github.cao.awa.conium.item.builder.conium.ConiumSchemaItemBuilder import com.github.cao.awa.conium.kotlin.extent.registry.tags import com.github.cao.awa.conium.mixin.item.setting.ItemSettingsAccessor import com.github.cao.awa.sinuatum.util.collection.CollectionFactor diff --git a/src/main/java/com/github/cao/awa/conium/mixin/block/BlockItemMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/block/BlockItemMixin.java index e97a776..9e42dfc 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/block/BlockItemMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/block/BlockItemMixin.java @@ -25,14 +25,11 @@ public class BlockItemMixin { * Inject to {@code place} to trigger event {@code PLACE_BLOCK}. * * @param context the placement context - * + * @author cao_awa * @see ConiumEventType#PLACE_BLOCK * @see com.github.cao.awa.conium.block.event.place.ConiumPlaceBlockEvent ConiumPlaceBlockEvent * @see com.github.cao.awa.conium.block.event.place.ConiumPlacedBlockEvent ConiumPlacedBlockEvent * @see BlockItemMixin#placedBlock - * - * @author cao_awa - * * @since 1.0.0 */ @Inject( @@ -59,20 +56,17 @@ public void placeBlock(ItemPlacementContext context, CallbackInfoReturnable implements ConiumDynamicIdList { - @Shadow public abstract void add(T value); - - @Shadow @Final private List list; - @Shadow @Final private Reference2IntMap idMap; - @Shadow private int nextId; @Unique private final List dynamicList = CollectionFactor.arrayList(); + @Shadow + @Final + private List list; + @Shadow + @Final + private Reference2IntMap idMap; + @Shadow + private int nextId; + + @Shadow + public abstract void add(T value); @Override public void conium$clearDynamic() { diff --git a/src/main/java/com/github/cao/awa/conium/mixin/component/map/builder/ComponentMapBuilderAccessor.java b/src/main/java/com/github/cao/awa/conium/mixin/component/map/builder/ComponentMapBuilderAccessor.java index 3a006dd..b3f32e4 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/component/map/builder/ComponentMapBuilderAccessor.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/component/map/builder/ComponentMapBuilderAccessor.java @@ -3,7 +3,6 @@ import it.unimi.dsi.fastutil.objects.Reference2ObjectMap; import net.minecraft.component.ComponentMap; import net.minecraft.component.ComponentType; -import net.minecraft.item.Item; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; diff --git a/src/main/java/com/github/cao/awa/conium/mixin/datapack/DataPackContentsMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/datapack/DataPackContentsMixin.java index be5b2f0..25d60e5 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/datapack/DataPackContentsMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/datapack/DataPackContentsMixin.java @@ -10,7 +10,10 @@ import com.github.cao.awa.conium.mixin.recipe.ServerRecipeManagerAccessor; import com.github.cao.awa.sinuatum.util.collection.CollectionFactor; import net.minecraft.recipe.ServerRecipeManager; -import net.minecraft.registry.*; +import net.minecraft.registry.CombinedDynamicRegistries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryWrapper; +import net.minecraft.registry.ServerDynamicRegistryType; import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceReloader; import net.minecraft.resource.featuretoggle.FeatureSet; @@ -18,7 +21,10 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.util.Unit; import org.slf4j.Logger; -import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -31,14 +37,15 @@ @Mixin(DataPackContents.class) public abstract class DataPackContentsMixin { + @Shadow + @Final + private static CompletableFuture COMPLETED_UNIT; + @Shadow + @Final + private static Logger LOGGER; @Shadow @Final private ServerRecipeManager recipeManager; - - @Shadow public abstract List getContents(); - - @Shadow @Final private static CompletableFuture COMPLETED_UNIT; - @Shadow @Final private static Logger LOGGER; @Unique private ItemPropertyInjectManager itemPropertyInjectManager; @Unique @@ -50,6 +57,29 @@ public abstract class DataPackContentsMixin { @Unique private ConiumScriptManager scriptManager; + @Inject(method = "reload", at = @At(value = "RETURN")) + private static void reload( + ResourceManager resourceManager, + CombinedDynamicRegistries dynamicRegistries, + List> pendingTagLoads, + FeatureSet enabledFeatures, + CommandManager.RegistrationEnvironment environment, + int functionPermissionLevel, + Executor prepareExecutor, + Executor applyExecutor, + CallbackInfoReturnable> cir + ) { + // Do callbacks when completed reloading. + cir.getReturnValue().whenComplete(((dataPackContents, throwable) -> { + for (Runnable reloadCallback : Conium.reloadCallbacks) { + reloadCallback.run(); + } + })); + } + + @Shadow + public abstract List getContents(); + @Inject( method = "", at = @At("RETURN") @@ -90,24 +120,4 @@ public void contents(CallbackInfoReturnable> cir) { reloaderList.add(this.scriptManager); cir.setReturnValue(reloaderList); } - - @Inject(method = "reload", at = @At(value = "RETURN")) - private static void reload( - ResourceManager resourceManager, - CombinedDynamicRegistries dynamicRegistries, - List> pendingTagLoads, - FeatureSet enabledFeatures, - CommandManager.RegistrationEnvironment environment, - int functionPermissionLevel, - Executor prepareExecutor, - Executor applyExecutor, - CallbackInfoReturnable> cir - ) { - // Do callbacks when completed reloading. - cir.getReturnValue().whenComplete(((dataPackContents, throwable) -> { - for (Runnable reloadCallback : Conium.reloadCallbacks) { - reloadCallback.run(); - } - })); - } } diff --git a/src/main/java/com/github/cao/awa/conium/mixin/entity/EntityAccessor.java b/src/main/java/com/github/cao/awa/conium/mixin/entity/EntityAccessor.java index face98a..944eff7 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/entity/EntityAccessor.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/entity/EntityAccessor.java @@ -9,6 +9,7 @@ public interface EntityAccessor { @Accessor("dimensions") EntityDimensions dimensions(); + @Accessor("dimensions") void dimensions(EntityDimensions dimensions); } diff --git a/src/main/java/com/github/cao/awa/conium/mixin/item/ItemMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/item/ItemMixin.java index 0a33332..009631c 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/item/ItemMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/item/ItemMixin.java @@ -1,12 +1,7 @@ package com.github.cao.awa.conium.mixin.item; import net.minecraft.item.Item; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Item.class) public class ItemMixin { diff --git a/src/main/java/com/github/cao/awa/conium/mixin/item/stack/ItemStackMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/item/stack/ItemStackMixin.java index ff6b481..673983b 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/item/stack/ItemStackMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/item/stack/ItemStackMixin.java @@ -6,7 +6,10 @@ import com.github.cao.awa.conium.event.context.ConiumEventContext; import com.github.cao.awa.conium.event.type.ConiumEventArgTypes; import com.github.cao.awa.conium.event.type.ConiumEventType; -import net.minecraft.component.*; +import net.minecraft.component.ComponentHolder; +import net.minecraft.component.ComponentType; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.MergedComponentMap; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; @@ -31,13 +34,13 @@ @Mixin(ItemStack.class) public abstract class ItemStackMixin implements ComponentHolder { - @Shadow - public abstract Item getItem(); - @Shadow @Final MergedComponentMap components; + @Shadow + public abstract Item getItem(); + @Unique private ItemStack cast() { return (ItemStack) (Object) this; diff --git a/src/main/java/com/github/cao/awa/conium/mixin/recipe/ServerRecipeManagerAccessor.java b/src/main/java/com/github/cao/awa/conium/mixin/recipe/ServerRecipeManagerAccessor.java index 17ab5ba..eab218e 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/recipe/ServerRecipeManagerAccessor.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/recipe/ServerRecipeManagerAccessor.java @@ -16,6 +16,11 @@ @Mixin(ServerRecipeManager.class) public interface ServerRecipeManagerAccessor { + @Invoker("collectServerRecipes") + static List collectServerRecipes(Iterable> recipes, FeatureSet enabledFeatures) { + throw new AssertionError(); + } + @Accessor RegistryWrapper.WrapperLookup getRegistries(); @@ -27,9 +32,4 @@ public interface ServerRecipeManagerAccessor { @Accessor("recipesByKey") Map>, List> getRecipesByKey(); - - @Invoker("collectServerRecipes") - static List collectServerRecipes(Iterable> recipes, FeatureSet enabledFeatures) { - throw new AssertionError(); - } } diff --git a/src/main/java/com/github/cao/awa/conium/mixin/registry/RegistryEntryReferenceMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/registry/RegistryEntryReferenceMixin.java index 99ae10e..a1f9074 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/registry/RegistryEntryReferenceMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/registry/RegistryEntryReferenceMixin.java @@ -14,10 +14,13 @@ public interface RegistryEntryReferenceMixin { @Invoker("setRegistryKey") void registryKey(RegistryKey registryKey); + @Accessor("tags") Set> getTags(); + @Invoker("setTags") void tags(Collection> tags); + @Invoker("setValue") void value(T value); } diff --git a/src/main/java/com/github/cao/awa/conium/mixin/registry/SimpleRegistryMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/registry/SimpleRegistryMixin.java index abb978e..a138ee2 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/registry/SimpleRegistryMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/registry/SimpleRegistryMixin.java @@ -9,7 +9,10 @@ import it.unimi.dsi.fastutil.objects.ObjectList; import it.unimi.dsi.fastutil.objects.Reference2IntMap; import it.unimi.dsi.fastutil.objects.Reference2IntOpenHashMap; -import net.minecraft.registry.*; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryEntryLookup; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.SimpleRegistry; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.entry.RegistryEntryInfo; import net.minecraft.registry.entry.RegistryEntryList; @@ -18,7 +21,10 @@ import net.minecraft.util.Util; import net.minecraft.util.math.random.Random; import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.*; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Redirect; @@ -46,10 +52,10 @@ public abstract class SimpleRegistryMixin implements ConiumDynamicRegistry { private final List> dynamicRawIdToEntry = CollectionFactor.arrayList(); @Unique private final Map, RegistryEntryInfo> dynamicKeyToEntryInfo = new IdentityHashMap<>(); - + @Unique + private final Map, RegistryEntryList.Named> dynamicTags = new IdentityHashMap<>(); @Shadow private boolean frozen; - @Shadow @Final private Map> idToEntry; @@ -68,7 +74,6 @@ public abstract class SimpleRegistryMixin implements ConiumDynamicRegistry { @Shadow @Final private Map, RegistryEntryInfo> keyToEntryInfo; - @Shadow private Lifecycle lifecycle; @@ -78,21 +83,14 @@ public abstract class SimpleRegistryMixin implements ConiumDynamicRegistry { @Shadow protected abstract RegistryEntryList.Named createNamedEntryList(TagKey tag); - @Unique - private final Map, RegistryEntryList.Named> dynamicTags = new IdentityHashMap<>(); - - @Shadow - @Final - private Map, RegistryEntryList.Named> tags; - @Shadow abstract RegistryEntryList.Named getTag(TagKey key); - @Shadow abstract RegistryEntry.Reference getOrCreateEntry(RegistryKey key); - - @Shadow public abstract void resetTagEntries(); + @Shadow + abstract RegistryEntry.Reference getOrCreateEntry(RegistryKey key); - @Shadow public abstract Optional> getOptional(RegistryKey key); + @Shadow + public abstract void resetTagEntries(); @Inject( method = "add", @@ -241,12 +239,6 @@ public Object getByKey(Map instance, Object o) { return orEntry((RegistryKey) o); } - @Unique - @Nullable - private static T getValue(@Nullable RegistryEntry.Reference entry) { - return entry != null ? entry.value() : null; - } - @Inject( method = "get(I)Ljava/lang/Object;", at = @At("RETURN"), @@ -487,7 +479,7 @@ public void resetTagEntries(CallbackInfo ci) { cancellable = true ) public void getOptional(RegistryKey key, CallbackInfoReturnable>> cir) { - cir.setReturnValue(orRegistryOptional(key)); + cir.setReturnValue(orRegistryOptional(key)); } @Unique diff --git a/src/main/java/com/github/cao/awa/conium/mixin/renderer/entity/EntityRenderDispatcherMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/renderer/entity/EntityRenderDispatcherMixin.java index 10eccc8..7fecc28 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/renderer/entity/EntityRenderDispatcherMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/renderer/entity/EntityRenderDispatcherMixin.java @@ -12,7 +12,8 @@ @Mixin(EntityRenderDispatcher.class) public abstract class EntityRenderDispatcherMixin { - @Shadow public abstract EntityRenderer getRenderer(T entity); + @Shadow + public abstract EntityRenderer getRenderer(T entity); @Inject( method = "shouldRender", diff --git a/src/main/java/com/github/cao/awa/conium/mixin/server/MinecraftServerMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/server/MinecraftServerMixin.java index 77b1a1e..45efae6 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/server/MinecraftServerMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/server/MinecraftServerMixin.java @@ -5,7 +5,6 @@ import com.github.cao.awa.conium.event.type.ConiumEventArgTypes; import com.github.cao.awa.conium.event.type.ConiumEventType; import net.minecraft.server.MinecraftServer; -import net.minecraft.util.ActionResult; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/java/com/github/cao/awa/conium/mixin/server/interaction/ServerPlayerInteractionManagerMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/server/interaction/ServerPlayerInteractionManagerMixin.java index 822f957..ea28fe9 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/server/interaction/ServerPlayerInteractionManagerMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/server/interaction/ServerPlayerInteractionManagerMixin.java @@ -7,7 +7,6 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.OperatorBlock; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.item.ItemStack; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerInteractionManager; @@ -23,13 +22,17 @@ @Mixin(ServerPlayerInteractionManager.class) public abstract class ServerPlayerInteractionManagerMixin { - @Shadow protected ServerWorld world; + @Shadow + protected ServerWorld world; - @Shadow @Final protected ServerPlayerEntity player; + @Shadow + @Final + protected ServerPlayerEntity player; + @Shadow + private GameMode gameMode; - @Shadow public abstract boolean isCreative(); - - @Shadow private GameMode gameMode; + @Shadow + public abstract boolean isCreative(); @Inject( method = "tryBreakBlock", diff --git a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgType.kt b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgType.kt new file mode 100644 index 0000000..19fd734 --- /dev/null +++ b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgType.kt @@ -0,0 +1,3 @@ +package com.github.cao.awa.conium.parameter + +class DynamicArgType(val key: String, vararg val dynamicArgs: DynamicArgs<*, T?>?) \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgs.kt b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgs.kt index 2893dd2..6a231fb 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgs.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgs.kt @@ -1,9 +1,28 @@ package com.github.cao.awa.conium.parameter -import com.github.cao.awa.conium.event.type.DynamicArgType import com.github.cao.awa.sinuatum.util.collection.CollectionFactor import com.mojang.datafixers.util.Function3 +/** + * Dynamic args is a data collecting and varying solution, it required arguments by dynamic arg types, and collect the real arguments to trigger. + * + * Dynamic args instance should create by [DynamicArgsBuilder], don't create the instance with trigger manually. + * + * @see ParameterSelective + * @see DynamicArgsBuilder + * @see DynamicArgType + * @see DynamicArgsLifecycle + * + * @param P the type of ``ParameterSelective`` + * @param R result value of the dynamic args + * @param trigger the trigger that called in arising + * @param args required arguments, lazy supply a dynamic arg type + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ class DynamicArgs

( private val trigger: Function3, Any?>, P, R>, vararg args: () -> DynamicArgType<*> @@ -12,8 +31,8 @@ class DynamicArgs

( private var lifecycle: DynamicArgsLifecycle = DynamicArgsLifecycle.ONCE constructor(trigger: Function3, Any?>, P, R>, vararg args: DynamicArgType<*>) : this(trigger, *args.map { - val getter: () -> DynamicArgType<*> = { it } - getter + // Vary 'DynamicArgType<*>' to '() -> DynamicArgType<*>' + { it } }.toList().toTypedArray()) constructor(trigger: Function3, Any?>, P, R>) : this(trigger, *mutableListOf<() -> DynamicArgType<*>>().toTypedArray()) @@ -27,23 +46,47 @@ class DynamicArgs

( return this } + /** + * + * @param identity a unique identity instance + * @param sources source context arguments + * + * @see ParameterSelective + * @see DynamicArgsBuilder + * @see DynamicArgType + * + * @return the new context arguments that trying to fills required arguments instance + * + * @author cao_awa + * @author 草二号机 + * + * @since 1.0.0 + */ private fun varyArgs(identity: Any, sources: MutableMap, Any?>): Map, Any?> { val args = CollectionFactor.hashMap, Any?>() + // Find required arguments from context arguments (manually putted to map). for (arg in sources) { arg.value.let { + // Only varying argument type to real argument instance. if (it is DynamicArgType<*>) { - for (dynamic in it.dynamicArgs) { - val result = dynamic?.runCatching { + // Dynamic args has multiple varying methods, find until found or no more method can trys. + for (dynamicVarying in it.dynamicArgs) { + // Run the dynamic vary. + val result = dynamicVarying?.runCatching { + // Arise the dynamic args, it will continues to vary args or got a value. arising(identity, sources, null) }?.getOrNull() + // When result found, stop dynamic args varying. if (result != null) { + // And put to arguments map. args[arg.key] = result break } } } else { + // The real instance should directly put to arguments map. args[arg.key] = it } } @@ -52,16 +95,36 @@ class DynamicArgs

( return args } + /** + * @param identity a unique identity instance + * @param args context arguments + * @param p the ``ParameterSelective`` instance + * + * @see ParameterSelective + * @see DynamicArgsBuilder + * @see DynamicArgType + * + * @return expected return value instance + * + * @author cao_awa + * + * @since 1.0.0 + */ fun arising(identity: Any, args: MutableMap, Any?>, p: P?): R { + // When 'ParameterSelective' instance is null, means this dynamic args won't got more args, it should got a value. if (p == null) { + // Do trigger directly, no vary args. return this.trigger.apply(identity, args, null) } + // Vary args to got more completed arguments. + // Put 'queryArg'(DynamicArgType<*>) to source arguments map, it will vary to other value in next step varying. for (queryArg in this.queryArgs) { if (!args.containsKey(queryArg)) { args[queryArg] = queryArg } } + // Do vary and trigger. return this.trigger.apply(identity, varyArgs(identity, args), p) } } \ No newline at end of file diff --git a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsBuilder.kt b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsBuilder.kt index 001e720..926ed75 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsBuilder.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsBuilder.kt @@ -1,7 +1,5 @@ package com.github.cao.awa.conium.parameter -import com.github.cao.awa.conium.event.type.DynamicArgType - class DynamicArgsBuilder { companion object { @JvmStatic 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 364c2d9..8834275 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,6 +1,6 @@ package com.github.cao.awa.conium.parameter.type -import com.github.cao.awa.conium.event.type.DynamicArgType +import com.github.cao.awa.conium.parameter.DynamicArgType import com.github.cao.awa.conium.parameter.DynamicArgs import com.github.cao.awa.sinuatum.util.collection.CollectionFactor 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 b60288e..64d78d2 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 @@ -2,9 +2,9 @@ package com.github.cao.awa.conium.recipe import com.github.cao.awa.conium.recipe.template.ConiumRecipeTemplate import com.github.cao.awa.conium.template.ConiumTemplate +import com.github.cao.awa.conium.template.ConiumTemplates.BedrockRecipe.RECIPE_FURNACE import com.github.cao.awa.conium.template.ConiumTemplates.BedrockRecipe.RECIPE_SHAPED import com.github.cao.awa.conium.template.ConiumTemplates.BedrockRecipe.RECIPE_SHAPELESS -import com.github.cao.awa.conium.template.ConiumTemplates.BedrockRecipe.RECIPE_FURNACE import com.google.gson.JsonObject import net.minecraft.recipe.Recipe import net.minecraft.registry.RegistryWrapper.WrapperLookup 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 5fdc77b..40a661f 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 @@ -53,7 +53,7 @@ abstract class ConiumRecipeTemplate>(name: String) : ConiumTemplat } } - fun > createBasic(jsonObject: JsonObject, template: T, resultName: String = "result") { + fun > createBasic(jsonObject: JsonObject, template: T, resultName: String = "result") { template.identifier = Identifier.of(jsonObject["description"].asJsonObject["identifier"].asString) template.result = createItem(jsonObject, resultName) diff --git a/src/main/java/com/github/cao/awa/conium/registry/ConiumDynamicTagLookup.java b/src/main/java/com/github/cao/awa/conium/registry/ConiumDynamicTagLookup.java index 5327f4c..7c2fe1a 100644 --- a/src/main/java/com/github/cao/awa/conium/registry/ConiumDynamicTagLookup.java +++ b/src/main/java/com/github/cao/awa/conium/registry/ConiumDynamicTagLookup.java @@ -1,6 +1,5 @@ package com.github.cao.awa.conium.registry; -import net.minecraft.registry.SimpleRegistry; import net.minecraft.registry.entry.RegistryEntryList; import net.minecraft.registry.tag.TagKey; 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 abeca10..81d63f6 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 @@ -12,12 +12,16 @@ import net.minecraft.util.Identifier object ConiumRegistryKeys { @JvmStatic val ITEM_PROPERTY_INJECT: RegistryKey>> = of("property/item") + @JvmStatic val SCRIPT: RegistryKey> = of("script") + @JvmStatic val ITEM: RegistryKey> = of("item") + @JvmStatic val BLOCK: RegistryKey> = of("block") + @JvmStatic val ENTITY: RegistryKey> = of("entity") diff --git a/src/main/java/com/github/cao/awa/conium/registry/DynamicTagLookup.java b/src/main/java/com/github/cao/awa/conium/registry/DynamicTagLookup.java index fd4549a..913e5c5 100644 --- a/src/main/java/com/github/cao/awa/conium/registry/DynamicTagLookup.java +++ b/src/main/java/com/github/cao/awa/conium/registry/DynamicTagLookup.java @@ -1,6 +1,5 @@ package com.github.cao.awa.conium.registry; -import net.minecraft.registry.SimpleRegistry; import net.minecraft.registry.entry.RegistryEntryList; import net.minecraft.registry.tag.TagKey; 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 a17b221..34f36e5 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 @@ -1,8 +1,5 @@ package com.github.cao.awa.conium.script -import com.github.cao.awa.conium.bedrock.system.AbstractBedrockSystem -import com.github.cao.awa.conium.bedrock.system.BedrockSystem -import com.github.cao.awa.conium.parameter.ParameterSelective0 import com.github.cao.awa.conium.parameter.ParameterSelective1 import com.github.cao.awa.conium.script.field.SharedField import com.github.cao.awa.conium.script.field.SharedFieldByJvm @@ -66,7 +63,7 @@ class ScriptExport( result ?: return null - if(result is SharedFieldByJvm<*>) { + if (result is SharedFieldByJvm<*>) { return Manipulate.cast((result.value as ParameterSelective1<*, Any>).arise(instance)) } diff --git a/src/main/java/com/github/cao/awa/conium/script/eval/ScriptEval.kt b/src/main/java/com/github/cao/awa/conium/script/eval/ScriptEval.kt index 9d8c875..1941120 100644 --- a/src/main/java/com/github/cao/awa/conium/script/eval/ScriptEval.kt +++ b/src/main/java/com/github/cao/awa/conium/script/eval/ScriptEval.kt @@ -1,5 +1,3 @@ package com.github.cao.awa.conium.script.eval -class ScriptEval(val codes: String, val source: String, vararg val defaultImports: String) { - -} +class ScriptEval(val codes: String, val source: String, vararg val defaultImports: String) diff --git a/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByJvm.kt b/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByJvm.kt index 83f907f..9b8850c 100644 --- a/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByJvm.kt +++ b/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByJvm.kt @@ -3,7 +3,7 @@ package com.github.cao.awa.conium.script.field import com.github.cao.awa.conium.parameter.ParameterSelective1 import kotlin.reflect.KClass -class SharedFieldByJvm(val type: KClass<*>, val name: String, val value: ParameterSelective1): SharedField() { +class SharedFieldByJvm(val type: KClass<*>, val name: String, val value: ParameterSelective1) : SharedField() { override fun toStatement(exportName: String): String { val builder = StringBuilder() diff --git a/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByStatement.kt b/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByStatement.kt index 5ddca71..d9c0df0 100644 --- a/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByStatement.kt +++ b/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldByStatement.kt @@ -1,5 +1,5 @@ package com.github.cao.awa.conium.script.field -class SharedFieldByStatement(private val statement: String): SharedField() { - override fun toStatement(exportName: String): String = this.statement + "\n" +class SharedFieldByStatement(private val statement: String) : SharedField() { + override fun toStatement(exportName: String): String = "${this.statement}\n" } diff --git a/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldHandler.kt b/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldHandler.kt index 96328cd..5caa371 100644 --- a/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldHandler.kt +++ b/src/main/java/com/github/cao/awa/conium/script/field/SharedFieldHandler.kt @@ -1,20 +1,18 @@ package com.github.cao.awa.conium.script.field -import com.github.cao.awa.conium.parameter.ParameterSelective0 import com.github.cao.awa.conium.parameter.ParameterSelective1 import com.github.cao.awa.conium.script.ScriptExport import com.github.cao.awa.sinuatum.util.collection.CollectionFactor -import java.util.HashMap import kotlin.reflect.KClass class SharedFieldHandler { - val fields: HashMap = CollectionFactor.hashMap() + private val fields: HashMap = CollectionFactor.hashMap() operator fun invoke(name: String, type: KClass, value: ParameterSelective1) { this.fields[name] = SharedFieldByJvm(type, name, value) } - operator fun invoke(name: String, statement:String) { + operator fun invoke(name: String, statement: String) { this.fields[name] = SharedFieldByStatement(statement) } 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 7e3e845..a5eb53d 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 @@ -26,7 +26,7 @@ class ConiumTypescriptDefineVariableTranslator : ConiumScriptTranslator