From 11c543e8c540d17eb9d8490b60845af5d5dddec3 Mon Sep 17 00:00:00 2001 From: cao-awa Date: Mon, 18 Nov 2024 16:53:55 +0800 Subject: [PATCH] The 'identity' of event context that input to 'arising' and 'presaging' have actual type now. --- document/script/kotlin/event/README.md | 31 ++-- .../cao/awa/conium/event/ConiumEvent.kt | 12 +- .../context/ConiumEventContextBuilder.kt | 81 ++++++---- .../awa/conium/event/type/ConiumEventType.kt | 147 ++++++++++-------- .../conium/mixin/block/BlockStateMixin.java | 18 ++- .../mixin/entity/LivingEntityMixin.java | 25 ++- .../mixin/item/stack/ItemStackMixin.java | 7 +- .../conium/parameter/ParameterSelective.kt | 6 +- .../conium/parameter/ParameterSelective0.kt | 8 +- .../conium/parameter/ParameterSelective1.kt | 8 +- .../conium/parameter/ParameterSelective2.kt | 8 +- .../conium/parameter/ParameterSelective3.kt | 8 +- .../conium/parameter/ParameterSelective4.kt | 8 +- .../conium/parameter/ParameterSelective5.kt | 8 +- .../conium/parameter/ParameterSelective6.kt | 8 +- .../conium/parameter/ParameterSelective7.kt | 8 +- .../conium/parameter/ParameterSelective8.kt | 8 +- 17 files changed, 237 insertions(+), 162 deletions(-) diff --git a/document/script/kotlin/event/README.md b/document/script/kotlin/event/README.md index b096bb3..a824e82 100644 --- a/document/script/kotlin/event/README.md +++ b/document/script/kotlin/event/README.md @@ -2,23 +2,24 @@ ## Event types -| 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 | * | +| Key | Notes | Environment | Cancelable | Cascade events | Input instance | +|------------------:|:-----------------------------------:|------------:|-----------:|--------------------------------------:|:---------------:| +| SERVER_TICK | Trigger in every server tick | SERVER | false | * | MinecraftServer | +| ITEM_USE_ON_BLOCK | Trigger when an item use on a block | ALL | true | * | Item | +| BREAKING_BLOCK | Trigger when breaking block | ALL | true | ```BREAK_BLOCK``` ```BROKEN_BLOCK``` | Block | +| BREAK_BLOCK | Trigger when broking block | SERVER | true | ```BROKEN_BLOCK``` | Block | +| BROKEN_BLOCK | Trigger when broken block | ALL | false | * | Block | +| PLACE_BLOCK | Trigger when placing block | ALL | true | ```PLACED_BLOCK``` | Block | +| PLACED_BLOCK | Trigger when block placed | ALL | false | * | Block | +| USE_BLOCK | Trigger when using block | ALL | true | ```USED_BLOCK``` | Block | +| USED_BLOCK | Trigger when block used | ALL | false | * | Block | +| ENTITY_DAMAGE | Trigger when entity damaging | ALL | true | ```ENTITY_DAMAGED``` | EntityType<*> | +| ENTITY_DAMAGED | Trigger when entity damaged | ALL | false | * | EntityType<*> | +| ENTITY_DIE | Trigger when entity dying | ALL | true | ```ENTITY_DEAD``` | EntityType<*> | +| ENTITY_DIED | Trigger when entity died | ALL | false | * | EntityType<*> | ### 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.\ diff --git a/src/main/java/com/github/cao/awa/conium/event/ConiumEvent.kt b/src/main/java/com/github/cao/awa/conium/event/ConiumEvent.kt index f25df42..2c616fa 100644 --- a/src/main/java/com/github/cao/awa/conium/event/ConiumEvent.kt +++ b/src/main/java/com/github/cao/awa/conium/event/ConiumEvent.kt @@ -22,8 +22,8 @@ import java.util.* abstract class ConiumEvent

: ListTriggerable

() { companion object { - private val events: MutableMap> = CollectionFactor.hashMap() - private val foreverContext: MutableMap>> = CollectionFactor.hashMap() + private val events: MutableMap, ConiumEvent<*>> = CollectionFactor.hashMap() + private val foreverContext: MutableMap, MutableList>> = CollectionFactor.hashMap() @JvmField val itemUseOnBlockEvent = ConiumItemUseOnBlockEvent() @@ -70,20 +70,20 @@ abstract class ConiumEvent

: ListTriggerable

() { * @param type the type of event */ @JvmStatic - fun request(type: ConiumEventType): ConiumEventContext { + fun request(type: ConiumEventType<*>): ConiumEventContext { return this.events[type]!!.requirement() } @JvmStatic - fun > findEvent(type: ConiumEventType): X { + fun > findEvent(type: ConiumEventType<*>): X { return this.events[type] as X } - fun forever(eventType: ConiumEventType, context: ConiumEventContext<*>) { + fun forever(eventType: ConiumEventType<*>, context: ConiumEventContext<*>) { this.foreverContext.computeIfAbsent(eventType) { CollectionFactor.arrayList() }.add(context) } - fun forever(eventType: ConiumEventType): MutableList> = this.foreverContext[eventType] ?: Collections.emptyList() + fun forever(eventType: ConiumEventType<*>): MutableList> = this.foreverContext[eventType] ?: Collections.emptyList() fun resetForever() { this.foreverContext.clear() 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 b49c7c9..f33da9b 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,6 +1,7 @@ package com.github.cao.awa.conium.event.context import com.github.cao.awa.conium.event.ConiumEvent +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.* @@ -89,9 +90,9 @@ object ConiumEventContextBuilder { @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, - arising: ParameterSelective1 = ParameterSelective1 { _ -> true } + fun request( + eventType: ConiumEventType, + arising: ParameterSelective1 = ParameterSelective1 { _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires(true).lifecycle(DynamicArgsLifecycle.FOREVER) @@ -99,17 +100,19 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { + (it as? I)?.let(arising::arise) ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, - arising: ParameterSelective2 = ParameterSelective2 { _, _ -> true } + arising: ParameterSelective2 = ParameterSelective2 { _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -120,18 +123,20 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1 -> + (i as? I)?.let { arising.arise(it, p1) } ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, arg2: DynamicArgType, - arising: ParameterSelective3 = ParameterSelective3 { _, _, _ -> true } + arising: ParameterSelective3 = ParameterSelective3 { _, _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -143,19 +148,21 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1, p2 -> + (i as? I)?.let { arising.arise(it, p1, p2) } ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, arg2: DynamicArgType, arg3: DynamicArgType, - arising: ParameterSelective4 = ParameterSelective4 { _, _, _, _ -> true } + arising: ParameterSelective4 = ParameterSelective4 { _, _, _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -168,20 +175,22 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1, p2, p3 -> + (i as? I)?.let { arising(it, p1, p2, p3) } ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, arg2: DynamicArgType, arg3: DynamicArgType, arg4: DynamicArgType, - arising: ParameterSelective5 = ParameterSelective5 { _, _, _, _, _ -> true } + arising: ParameterSelective5 = ParameterSelective5 { _, _, _, _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -195,21 +204,23 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1, p2, p3, p4 -> + (i as? I)?.let { arising.arise(it, p1, p2, p3, p4) } ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, arg2: DynamicArgType, arg3: DynamicArgType, arg4: DynamicArgType, arg5: DynamicArgType, - arising: ParameterSelective6 = ParameterSelective6 { _, _, _, _, _, _ -> true } + arising: ParameterSelective6 = ParameterSelective6 { _, _, _, _, _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -224,22 +235,24 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1, p2, p3, p4, p5 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5) } ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, arg2: DynamicArgType, arg3: DynamicArgType, arg4: DynamicArgType, arg5: DynamicArgType, arg6: DynamicArgType, - arising: ParameterSelective7 = ParameterSelective7 { _, _, _, _, _, _, _ -> true } + arising: ParameterSelective7 = ParameterSelective7 { _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -255,15 +268,17 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1, p2, p3, p4, p5, p6 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6) } ?: true + } return context } @JvmStatic @SuppressWarnings("UNCHECKED_CAST") - fun request( - eventType: ConiumEventType, + fun request( + eventType: ConiumEventType, arg1: DynamicArgType, arg2: DynamicArgType, arg3: DynamicArgType, @@ -271,7 +286,7 @@ object ConiumEventContextBuilder { arg5: DynamicArgType, arg6: DynamicArgType, arg7: DynamicArgType, - arising: ParameterSelective8 = ParameterSelective8 { _, _, _, _, _, _, _, _ -> true } + arising: ParameterSelective8 = ParameterSelective8 { _, _, _, _, _, _, _, _ -> true } ): ConiumEventContext> { val context = ConiumEventContext( DynamicArgsBuilder.requires( @@ -288,7 +303,9 @@ object ConiumEventContextBuilder { ConiumEvent.forever(eventType, context) - context.arise(arising) + context.arise { i, p1, p2, p3, p4, p5, p6, p7 -> + (i as? I)?.let { arising(it, p1, p2, p3, p4, p5, p6, p7) } ?: true + } return context } 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 f0b2a49..6cdc37e 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 @@ -3,75 +3,98 @@ package com.github.cao.awa.conium.event.type 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 +import net.minecraft.block.Block +import net.minecraft.entity.EntityType +import net.minecraft.item.Item +import net.minecraft.server.MinecraftServer -enum class ConiumEventType { - SERVER_TICK, +class ConiumEventType { + companion object { + @JvmField + val SERVER_TICK: ConiumEventType = ConiumEventType() - ITEM_USE_ON_BLOCK, + @JvmField + val ITEM_USE_ON_BLOCK: ConiumEventType = ConiumEventType() - // Block. - /** - * The event where that block is be mining. - * - * This event is cancelable. - * - * @see BlockStateMixin.breakingBlock - * - * @author cao_awa - * - * @since 1.0.0 - */ - BREAKING_BLOCK, + // Block. + /** + * The event where that block is be mining. + * + * This event is cancelable. + * + * @see BlockStateMixin.breakingBlock + * + * @author cao_awa + * + * @since 1.0.0 + */ + @JvmField + val BREAKING_BLOCK: ConiumEventType = ConiumEventType() - /** - * The event where that block is be breaking. - * - * This event is cancelable. - * - * ``This event is only for server side`` - * - * @see ServerPlayerInteractionManagerMixin.tryBreakBlock - * - * @author cao_awa - * - * @since 1.0.0 - */ - BREAK_BLOCK, + /** + * The event where that block is be breaking. + * + * This event is cancelable. + * + * ``This event is only for server side`` + * + * @see ServerPlayerInteractionManagerMixin.tryBreakBlock + * + * @author cao_awa + * + * @since 1.0.0 + */ + @JvmField + val BREAK_BLOCK: ConiumEventType = ConiumEventType() - /** - * The event where that block is be mined. - * - * This event is not cancelable. - * - * @see ServerPlayerInteractionManagerMixin.tryBreakBlock - * @see ClientPlayerInteractionManagerMixin.breakBlock - * - * @author cao_awa - * - * @since 1.0.0 - */ - BROKEN_BLOCK, - PLACE_BLOCK, - PLACED_BLOCK, + /** + * The event where that block is be mined. + * + * This event is not cancelable. + * + * @see ServerPlayerInteractionManagerMixin.tryBreakBlock + * @see ClientPlayerInteractionManagerMixin.breakBlock + * + * @author cao_awa + * + * @since 1.0.0 + */ + @JvmField + val BROKEN_BLOCK: ConiumEventType = ConiumEventType() - USE_BLOCK, - USED_BLOCK, + @JvmField + val PLACE_BLOCK: ConiumEventType = ConiumEventType() - // Entity. - ENTITY_DAMAGE, - ENTITY_DAMAGED, + @JvmField + val PLACED_BLOCK: ConiumEventType = ConiumEventType() - /** - * The event where that entity was dying. - * - * @since 1.0.0 - */ - ENTITY_DIE, + @JvmField + val USE_BLOCK: ConiumEventType = ConiumEventType() - /** - * The event where that entity was died. - * - * @since 1.0.0 - */ - ENTITY_DEAD, + @JvmField + val USED_BLOCK: ConiumEventType = ConiumEventType() + + // Entity. + @JvmField + val ENTITY_DAMAGE: ConiumEventType> = ConiumEventType() + + @JvmField + val ENTITY_DAMAGED: ConiumEventType> = ConiumEventType() + + /** + * The event where that entity was dying. + * + * @since 1.0.0 + */ + @JvmField + val ENTITY_DIE: ConiumEventType> = ConiumEventType() + + /** + * The event where that entity was died. + * + * @since 1.0.0 + */ + @JvmField + val ENTITY_DEAD: ConiumEventType> = ConiumEventType() + } } diff --git a/src/main/java/com/github/cao/awa/conium/mixin/block/BlockStateMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/block/BlockStateMixin.java index 7cc77e8..637411d 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/block/BlockStateMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/block/BlockStateMixin.java @@ -13,6 +13,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; +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; @@ -30,6 +31,8 @@ public void breakingBlock(World world, BlockPos pos, PlayerEntity player, Callba AbstractBlock.AbstractBlockState self = cast(); + Block block = self.getBlock(); + // Fill the context args. eventContext.put(ConiumEventArgTypes.WORLD, world); @@ -38,8 +41,8 @@ public void breakingBlock(World world, BlockPos pos, PlayerEntity player, Callba eventContext.put(ConiumEventArgTypes.BLOCK_POS, pos); eventContext.put(ConiumEventArgTypes.BLOCK_STATE, self); - if (eventContext.presaging(self)) { - eventContext.arising(self); + if (eventContext.presaging(block)) { + eventContext.arising(block); } else { // Cancel this event when presaging was rejected the event. ci.cancel(); @@ -57,6 +60,8 @@ public ActionResult useBlock(Block instance, BlockState blockState, World world, ConiumEventContext usingContext = ConiumEvent.request(ConiumEventType.USE_BLOCK); ConiumEventContext usedContext = ConiumEvent.request(ConiumEventType.USED_BLOCK); + Block block = blockState.getBlock(); + // Fill the context args. usingContext.put(ConiumEventArgTypes.WORLD, world); @@ -68,15 +73,15 @@ public ActionResult useBlock(Block instance, BlockState blockState, World world, usedContext.inherit(usingContext); - if (usingContext.presaging(blockState)) { - usingContext.arising(blockState); + if (usingContext.presaging(block)) { + usingContext.arising(block); ActionResult result = ((AbstractBlockMixin) instance).invokeOnUse(blockState, world, blockPos, playerEntity, blockHitResult); usedContext.put(ConiumEventArgTypes.ACTION_RESULT, result); - if (usedContext.presaging(blockState)) { - usedContext.arising(blockState); + if (usedContext.presaging(block)) { + usedContext.arising(block); } return result; @@ -86,6 +91,7 @@ public ActionResult useBlock(Block instance, BlockState blockState, World world, } } + @Unique private AbstractBlock.AbstractBlockState cast() { return (AbstractBlock.AbstractBlockState) (Object) this; } diff --git a/src/main/java/com/github/cao/awa/conium/mixin/entity/LivingEntityMixin.java b/src/main/java/com/github/cao/awa/conium/mixin/entity/LivingEntityMixin.java index 80bf2c3..6c604cc 100644 --- a/src/main/java/com/github/cao/awa/conium/mixin/entity/LivingEntityMixin.java +++ b/src/main/java/com/github/cao/awa/conium/mixin/entity/LivingEntityMixin.java @@ -4,6 +4,7 @@ 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.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.damage.DamageSource; import net.minecraft.server.world.ServerWorld; @@ -32,6 +33,8 @@ public void damage(ServerWorld world, DamageSource damageSource, float amount, C LivingEntity self = cast(); + EntityType type = self.getType(); + // Fill the context args. eventContext.put(ConiumEventArgTypes.WORLD, world); @@ -39,9 +42,9 @@ public void damage(ServerWorld world, DamageSource damageSource, float amount, C eventContext.put(ConiumEventArgTypes.LIVING_ENTITY, self); eventContext.put(ConiumEventArgTypes.FLOAT, amount); - if (eventContext.presaging(self)) { + if (eventContext.presaging(type)) { // Only presaging state is true can be continues. - eventContext.arising(self); + eventContext.arising(type); } else { // Cancel this event when presaging was rejected the event. cir.setReturnValue(false); @@ -58,6 +61,8 @@ public void damaged(ServerWorld world, DamageSource damageSource, float amount, LivingEntity self = cast(); + EntityType type = self.getType(); + // Fill the context args. eventContext.put(ConiumEventArgTypes.WORLD, world); @@ -66,8 +71,8 @@ public void damaged(ServerWorld world, DamageSource damageSource, float amount, eventContext.put(ConiumEventArgTypes.FLOAT, amount); // The entity damaged event is not cancelable, only arising the context. - if (eventContext.presaging(self)) { - eventContext.arising(self); + if (eventContext.presaging(type)) { + eventContext.arising(type); } } @@ -82,13 +87,15 @@ public void dying(DamageSource damageSource, CallbackInfo ci) { LivingEntity self = cast(); + EntityType type = self.getType(); + // Fill the context args. eventContext.put(ConiumEventArgTypes.DAMAGE_SOURCE, damageSource); eventContext.put(ConiumEventArgTypes.LIVING_ENTITY, self); - if (eventContext.presaging(self)) { + if (eventContext.presaging(type)) { // Only presaging state is true can be continues. - eventContext.arising(self); + eventContext.arising(type); } else { // Cancel this event when presaging was rejected the event. ci.cancel(); @@ -105,13 +112,15 @@ public void dead(DamageSource damageSource, CallbackInfo ci) { LivingEntity self = cast(); + EntityType type = self.getType(); + // Fill the context args. eventContext.put(ConiumEventArgTypes.DAMAGE_SOURCE, damageSource); eventContext.put(ConiumEventArgTypes.LIVING_ENTITY, self); // The entity dead event is not cancelable, only arising the context. - if (eventContext.presaging(self)) { - eventContext.arising(self); + if (eventContext.presaging(type)) { + eventContext.arising(type); } } } 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 673983b..ec440a4 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 @@ -101,9 +101,12 @@ public ActionResult handleUseOnBlock(Item instance, ItemUsageContext context) { ActionResult result = ActionResult.FAIL; - if (eventContext.presaging(this)) { + if (eventContext.presaging(instance)) { result = instance.useOnBlock(context); - if (!eventContext.arising(this) && result != ActionResult.FAIL) { + + eventContext.put(ConiumEventArgTypes.ACTION_RESULT, result); + + if (!eventContext.arising(instance) && result != ActionResult.FAIL) { result = ActionResult.PASS; } } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt index 41df425..bb9334a 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective.kt @@ -1,5 +1,3 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter -public interface ParameterSelective { - -} +interface ParameterSelective diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective0.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective0.kt index dfe0e63..3d9f312 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective0.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective0.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective0 extends ParameterSelective { - R arise(); +fun interface ParameterSelective0 : ParameterSelective { + fun arise(): R + + operator fun invoke() = arise() } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective1.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective1.kt index 56ccfdf..4e09a06 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective1.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective1.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective1 extends ParameterSelective { - R arise(P p1); +fun interface ParameterSelective1 : ParameterSelective { + fun arise(p1: P): R + + operator fun invoke(p1: P) = arise(p1) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective2.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective2.kt index 472fa63..76658d7 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective2.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective2.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective2 extends ParameterSelective { - R arise(P1 p1, P2 p2); +fun interface ParameterSelective2 : ParameterSelective { + fun arise(p1: P1, p2: P2): R + + operator fun invoke(p1: P1, p2: P2) = arise(p1, p2) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective3.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective3.kt index dcd927f..54903b9 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective3.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective3.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective3 extends ParameterSelective { - R arise(P1 p1, P2 p2, P3 p3); +fun interface ParameterSelective3 : ParameterSelective { + fun arise(p1: P1, p2: P2, p3: P3): R + + operator fun invoke(p1: P1, p2: P2, p3: P3) = arise(p1, p2, p3) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective4.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective4.kt index ab10051..4cc6a45 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective4.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective4.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective4 extends ParameterSelective { - R arise(P1 p1, P2 p2, P3 p3, P4 p4); +fun interface ParameterSelective4 : ParameterSelective { + fun arise(p1: P1, p2: P2, p3: P3, p4: P4): R + + operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4) = arise(p1, p2, p3, p4) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective5.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective5.kt index 04eb571..2d7692e 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective5.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective5.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective5 extends ParameterSelective { - R arise(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5); +fun interface ParameterSelective5 : ParameterSelective { + fun arise(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5): R + + operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) = arise(p1, p2, p3, p4, p5) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective6.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective6.kt index 79618a3..a8ac46e 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective6.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective6.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective6 extends ParameterSelective { - R arise(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6); +fun interface ParameterSelective6 : ParameterSelective { + fun arise(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6): R + + operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) = arise(p1, p2, p3, p4, p5, p6) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective7.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective7.kt index 32c8b20..14eb1b7 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective7.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective7.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective7 extends ParameterSelective { - R arise(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7); +fun interface ParameterSelective7 : ParameterSelective { + fun arise(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7): R + + operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) = arise(p1, p2, p3, p4, p5, p6, p7) } diff --git a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective8.kt b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective8.kt index 1e43816..3b999fa 100644 --- a/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective8.kt +++ b/src/main/java/com/github/cao/awa/conium/parameter/ParameterSelective8.kt @@ -1,6 +1,8 @@ -package com.github.cao.awa.conium.parameter; +package com.github.cao.awa.conium.parameter @FunctionalInterface -public interface ParameterSelective8 extends ParameterSelective { - R arise(P1 p1, P2 p2, P3 p3, P4 p4, P5 p5, P6 p6, P7 p7, P8 p8); +fun interface ParameterSelective8 : ParameterSelective { + fun arise(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8): R + + operator fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) = arise(p1, p2, p3, p4, p5, p6, p7, p8) }