Skip to content

Commit

Permalink
Add events support: 'BREAKING_BLOCK', 'BROKEN_BLOCK', 'ENTITY_DAMAGE'…
Browse files Browse the repository at this point in the history
…, 'ENTITY_DAMAGED', 'ENTITY_DIE', 'ENTITY_DEAD'.

Better feature for 'DynamicArgs'.
More documents completing.
  • Loading branch information
cao-awa committed Nov 16, 2024
1 parent 564741a commit 4380993
Show file tree
Hide file tree
Showing 32 changed files with 1,070 additions and 159 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,15 +404,15 @@ Currently, supported these components of items:

## Conium script APIs

Documents are not done yet.
See the [Conium scripting](./document/script/kotlin/README.md).

## Bedrock script APIs

Not completed bedrock script APIs supports now, only framework able to runs the sample.

### Grammars

About typescript grammar, supported by 'language-translator': [Typescript supports](https://github.com/cao-awa/language-translator/tree/main/doc/typescript)
About typescript grammar, supported by ```language-translator``` or called ```fluxia```: [Typescript supports](https://github.com/cao-awa/language-translator/tree/main/doc/typescript)

### APIs

Expand Down
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ loom {
}
}

runClient {
args("--username", "cao_awa")
}

// Add the datagenned files into the jar.
sourceSets {
main {
Expand Down
73 changes: 47 additions & 26 deletions document/script/kotlin/event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

## Event types

| Key | Notes |
|------------------:|:-----------------------------------:|
| SERVER_TICK | Trigger in every server tick |
| ITEM_USE_ON_BLOCK | Trigger when an item use on a block |
| BREAK_BLOCK | Trigger when breaking block |
| PLACE_BLOCK | Trigger when placing block |
| PLACED_BLOCK | Trigger when block placed |
| USE_BLOCK | Trigger when using block |
| USED_BLOCK | Trigger when block used |
| 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 |

## Context args

Expand All @@ -22,28 +28,28 @@ For example:
request(
// This is the event type.
PLACE_BLOCK,
// This is the conext args.
// This is the context args.
SERVER_WORLD,
// This also.
BLOCK_POS,
// This also.
ITEM_STACK
) { _, world, pos, stack ->
// When you defines how many context args in 'request',
// then you must defines they in arising context as consistent order and quantity.
// then you must define them in arising context as consistent order and quantity.
true
}

request(
// This is the event type.
PLACE_BLOCK,
// This is the conext args.
// This is the context args.
SERVER_WORLD,
// This also.
ITEM_STACK
) { _, world, stack ->
// Here missing 'BLOCK_POS', so arising context also must missing it.
// Arising context should match to 'request' required args.
// Here missing 'BLOCK_POS', so arising context also must miss it to match requiring args.
// Arising context should match the required arguments for 'request'.
true
}
```
Expand All @@ -58,34 +64,49 @@ This is the ```DynamicArgs``` transform(or adapter) mechanism, dynamic args use
For details, see [ConiumEventArgTypes](/src/main/java/com/github/cao/awa/conium/event/type/ConiumEventArgTypes.kt) and [DynamicArgsBuilder#transform](/src/main/java/com/github/cao/awa/conium/parameter/DynamicArgsBuilder.kt).

If required arg is still unable to found when the dynamic args for-each to all other args and runs all transform presets,\
then this ```request``` of this event will not be arising, because the parameters of arising and presaging don't receive null value.
then this ```request``` of this event will not be arising, because the parameters of ```arising``` and ```presaging``` don't receive null value.

Avoid the trouble of guessing yourself, all args possible to uses for every event is here, \
if you are finding not rarely used parameters, then you need read the ```ConiumEventArgTypes```.

### SERVER_TICK

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

### ITEM_USE_ON_BLOCK

### BREAKING_BLOCK

### BREAK_BLOCK

### PLACE_BLOCK
### BROKEN_BLOCK

```ITEM_PLACEMENT_CONTEXT``` ()
### PLACE_BLOCK

```WORLD``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```SERVER_WORLD``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```CLIENT_WORLD``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```ITEM_STACK``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```PLAYER``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```SERVER_PLAYER``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```CLIENT_PLAYER``` (transform from ```ITEM_PLACEMENT_CONTEXT```) \
```BLOCK_POS``` (transform from ```ITEM_PLACEMENT_CONTEXT```)
| Key | Transform from | Environment |
|-----------------------:|:----------------------:|------------:|
| ITEM_PLACEMENT_CONTEXT | * | ALL |
| WORLD | ITEM_PLACEMENT_CONTEXT | ALL |
| SERVER_WORLD | ITEM_PLACEMENT_CONTEXT | SERVER |
| CLIENT_WORLD | ITEM_PLACEMENT_CONTEXT | CLIENT |
| ITEM_STACK | ITEM_PLACEMENT_CONTEXT | ALL |
| PLAYER | ITEM_PLACEMENT_CONTEXT | ALL |
| SERVER_PLAYER | ITEM_PLACEMENT_CONTEXT | SERVER |
| CLIENT_PLAYER | ITEM_PLACEMENT_CONTEXT | CLIENT |
| BLOCK_POS | ITEM_PLACEMENT_CONTEXT | ALL |

### PLACED_BLOCK

### USE_BLOCK

### USED_BLOCK

### ENTITY_DAMAGE

### ENTITY_DAMAGED

### ENTITY_DIE

### ENTITY_DIED
31 changes: 29 additions & 2 deletions sample/datapacks/tests/data/awa/script/conium_fools_day.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import net.minecraft.server.network.ServerPlayerEntity
import java.util.*
import net.minecraft.util.math.Vec3d

val random = Random()

request(
SERVER_TICK,
SERVER
) { _, server ->
val random = Random()

server.worlds.forEach { world ->
world.iterateEntities().forEach { entity ->
if (entity != null && entity !is ServerPlayerEntity) {
Expand All @@ -34,6 +34,15 @@ request(
true
}

request(
PLACE_BLOCK,
SERVER_WORLD
) { _, world ->
println(world)

true
}

// Let blue bed explosion!
request(
USE_BLOCK,
Expand All @@ -48,3 +57,21 @@ request(

true
}

request(
ENTITY_DIE,
LIVING_ENTITY
).presage { _, entity ->
println("${entity} dying")

false
}

request(
ENTITY_DEAD,
LIVING_ENTITY
) { _, entity ->
println("${entity} dead")

true
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ class BedrockBeforeEvents {
val EVENTS = BedrockBeforeEvents()
}

@BedrockScriptApi
val itemUseOn = BedrockItemUseOnBeforeEvent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import com.github.cao.awa.conium.parameter.ParameterSelective1
@BedrockScriptApi
@BedrockScriptApiFacade("ItemUseOnBeforeEventSignal")
class BedrockItemUseOnBeforeEvent {
@BedrockScriptApi
fun subscribe(action: ParameterSelective1<Unit, BedrockItemUseOnEventContext>) {
val currentPosting = BedrockEventContext.currentPosting!!

println("$currentPosting subscribing to item use on")

ConiumEventContextBuilder.request(
ConiumEventType.ITEM_USE_ON_BLOCK,
ConiumEventArgTypes.ITEM_USAGE_CONTEXT
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.github.cao.awa.conium.block.event.breaking

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.ParameterSelective4
import net.minecraft.block.AbstractBlock.AbstractBlockState
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World

class ConiumBreakingBlockEvent : ConiumEvent<ParameterSelective4<Boolean, World, PlayerEntity, BlockPos, AbstractBlockState>>() {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.WORLD,
ConiumEventArgTypes.PLAYER,
ConiumEventArgTypes.BLOCK_POS,
ConiumEventArgTypes.BLOCK_STATE
).attach(
forever(ConiumEventType.BREAKING_BLOCK)
).arise { identity, world, player, blockPos, state ->
noFailure(identity) {
it.arise(world, player, blockPos, state)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.cao.awa.conium.block.event.breaking

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.ParameterSelective3
import com.github.cao.awa.conium.parameter.ParameterSelective4
import net.minecraft.block.AbstractBlock.AbstractBlockState
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.util.math.BlockPos
import net.minecraft.world.World

class ConiumBrokenBlockEvent : ConiumEvent<ParameterSelective4<Boolean, World, PlayerEntity, BlockPos, AbstractBlockState>>() {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.WORLD,
ConiumEventArgTypes.PLAYER,
ConiumEventArgTypes.BLOCK_POS,
ConiumEventArgTypes.BLOCK_STATE
).attach(
forever(ConiumEventType.BROKEN_BLOCK)
).arise { identity, world, player, blockPos, state ->
noFailure(identity) {
it.arise(world, player, blockPos, state)
}
}
}
}
Loading

0 comments on commit 4380993

Please sign in to comment.