Skip to content

Commit

Permalink
Update documents and event args.
Browse files Browse the repository at this point in the history
  • Loading branch information
cao-awa committed Nov 19, 2024
1 parent 541db9e commit 8ecd03d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 45 deletions.
36 changes: 18 additions & 18 deletions document/script/kotlin/event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

## Event types

| 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<*> |
| Key | Notes | Environment | Cancelable | Cascade events | Input instance |
|-------------------:|:--------------------------------------:|------------:|-----------:|--------------------------------------:|:---------------:|
| SERVER_TICK | Trigger in every server tick | SERVER | false | Too many events | MinecraftServer |
| SERVER_TICK_TAIL | Trigger in every server tick completed | SERVER | false | * | MinecraftServer |
| ITEM_USE_ON_BLOCK | Trigger when an item use on a block | ALL | true | * | Item |
| ITEM_USED_ON_BLOCK | Trigger when an item used 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

Expand Down Expand Up @@ -83,9 +85,7 @@ if you are finding not rarely used parameters, then you need read the ```ConiumE

### SERVER_TICK

| Key | Transform from |
|-------:|:--------------:|
| SERVER | * |
### SERVER_TICK_TAIL

### ITEM_USE_ON_BLOCK

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ package com.github.cao.awa.conium.event.server.tick
import com.github.cao.awa.conium.event.ConiumEvent
import com.github.cao.awa.conium.event.context.ConiumEventContext
import com.github.cao.awa.conium.event.context.ConiumEventContextBuilder.requires
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.ParameterSelective1
import net.minecraft.server.MinecraftServer
import com.github.cao.awa.conium.parameter.ParameterSelective0

class ConiumServerTickEvent : ConiumEvent<ParameterSelective1<Boolean, MinecraftServer>>() {
class ConiumServerTickEvent : ConiumEvent<ParameterSelective0<Boolean>>() {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.SERVER,
).attach(
return requires().attach(
forever(ConiumEventType.SERVER_TICK)
).arise { identity, server ->
).arise { identity ->
noFailure(identity) {
it.arise(server)
it.arise()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@ package com.github.cao.awa.conium.event.server.tick
import com.github.cao.awa.conium.event.ConiumEvent
import com.github.cao.awa.conium.event.context.ConiumEventContext
import com.github.cao.awa.conium.event.context.ConiumEventContextBuilder.requires
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.ParameterSelective1
import net.minecraft.server.MinecraftServer
import com.github.cao.awa.conium.parameter.ParameterSelective0

class ConiumServerTickTailEvent : ConiumEvent<ParameterSelective1<Boolean, MinecraftServer>>() {
class ConiumServerTickTailEvent : ConiumEvent<ParameterSelective0<Boolean>>() {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.SERVER,
).attach(
return requires().attach(
forever(ConiumEventType.SERVER_TICK_TAIL)
).arise { identity, server ->
).arise { identity ->
noFailure(identity) {
it.arise(server)
it.arise()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public void tickStart(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
// Request the server ticking context.
ConiumEventContext<?> tickingContext = ConiumEvent.request(ConiumEventType.SERVER_TICK);

tickingContext.put(ConiumEventArgTypes.SERVER, cast());

if (tickingContext.presaging(this)) {
tickingContext.arising(this);
}
Expand All @@ -38,15 +36,8 @@ public void tickTail(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
// Request the server ticked context.
ConiumEventContext<?> tickedContext = ConiumEvent.request(ConiumEventType.SERVER_TICK_TAIL);

tickedContext.put(ConiumEventArgTypes.SERVER, cast());

if (tickedContext.presaging(this)) {
tickedContext.arising(this);
}
}

@Unique
private MinecraftServer cast() {
return (MinecraftServer) (Object) this;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/conium/scripts/conium.commons.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import com.github.cao.awa.conium.event.type.ConiumEventArgTypes.BLOCK_HIT_RESULT
import com.github.cao.awa.conium.event.type.ConiumEventArgTypes.ACTION_RESULT

import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.SERVER_TICK
import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.SERVER_TICK_TAIL
import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.ITEM_USE_ON_BLOCK
import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.ITEM_USED_ON_BLOCK
import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.BREAKING_BLOCK
import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.BREAK_BLOCK
import com.github.cao.awa.conium.event.type.ConiumEventType.Companion.BROKEN_BLOCK
Expand Down

0 comments on commit 8ecd03d

Please sign in to comment.