Skip to content

Commit

Permalink
Clear imports and reformat codes.
Browse files Browse the repository at this point in the history
More documents completing.
  • Loading branch information
cao-awa committed Nov 16, 2024
1 parent 4380993 commit 0a10d85
Show file tree
Hide file tree
Showing 82 changed files with 299 additions and 266 deletions.
41 changes: 26 additions & 15 deletions document/script/kotlin/event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/github/cao/awa/conium/Conium.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.github.cao.awa.conium.bedrock

annotation class BedrockScriptApi()
annotation class BedrockScriptApi
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<MutableMap.MutableEntry<String, Any?>> {
open class BedrockScriptAnonymousObjectMap : Iterable<MutableMap.MutableEntry<String, Any?>> {
private val map = CollectionFactor.hashMap<String, Any?>()

fun add(key: String, value: Any?): BedrockScriptAnonymousObjectMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ import com.github.cao.awa.conium.bedrock.BedrockScriptApiFacade

@BedrockScriptApi
@BedrockScriptApiFacade("DimensionLocation")
class BedrockDimensionLocation {

}
class BedrockDimensionLocation
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
)!!
}
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -23,13 +23,13 @@ public abstract class ItemPropertyInjectHandler<T> {
handlers.put(ItemPropertyInjectAction.MULTIPLY, new ItemPropertyInjectMultiplyHandler<>());
});

public abstract T doHandle(T source, T value);

public static <X> 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)));
} else {
throw new IllegalArgumentException("No handler registered for " + action);
}
}

public abstract T doHandle(T source, T value);
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -17,13 +17,13 @@ public abstract class NumberHandler<T extends Number> {
handlers.put(BigInteger.class, new BigIntegerNumberHandler());
});

public abstract T doHandle(T first, T second, ItemPropertyInjectAction action);

public static <X extends Number> 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));
} else {
throw new IllegalArgumentException("Unsupported number type: " + first.getClass() + " and " + second.getClass());
}
}

public abstract T doHandle(T first, T second, ItemPropertyInjectAction action);
}
Loading

0 comments on commit 0a10d85

Please sign in to comment.