Skip to content

Commit

Permalink
Update loom version to '1.9.2'.
Browse files Browse the repository at this point in the history
Add events support: 'ITEM_INVENTORY_TICK', 'ITEM_INVENTORY_TICKED', 'ITEM_STACK_CLICK', 'ITEM_STACK_CLICKED'.
Add context args: 'CURSOR_STACK', 'CLICK_TYPE', 'SLOT', 'SLOT_NUMBER', 'SELECT_STATUS'.
Update version id to '1.0.0-alpha7'.
  • Loading branch information
cao-awa committed Dec 12, 2024
1 parent 4a4355b commit 079c6fe
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 20 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ Conium lets you complete your mods only using datapacks.

Conium has configured whole project, just clone the repository, and reload project then run the gradle task ```remapJar```.

| Requirement | Version | Notes |
|------------:|:------------:|:----------------------------------:|
| Java | 21!! | Only 21 can be use |
| Gradle | 8.11 | 8.11 or other could be use |
| Kotlin | 2.1.0!! | Only 2.1.0 can be use |
| Fabric loom | 1.9-SNAPSHOT | 1.9-SNAPSHOT or other could be use |
| Minecraft | 1.21.4!! | Only 1.21.4 can be use |
| Requirement | Version | Notes |
|------------:|:--------:|:---------------------------:|
| Java | 21!! | Only 21 can be use |
| Gradle | 8.11 | 8.11 or other could be use |
| Kotlin | 2.1.0!! | Only 2.1.0 can be use |
| Fabric loom | 1.9.2 | 1.9.2 or other could be use |
| Minecraft | 1.21.4!! | Only 1.21.4 can be use |

## Data driven

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id "fabric-loom" version "1.9-SNAPSHOT"
id "fabric-loom" version "1.9.2"
id "maven-publish"
id 'com.github.ben-manes.versions' version '+'
id "org.jetbrains.kotlin.jvm" version "2.1.0"
Expand Down
4 changes: 4 additions & 0 deletions document/script/kotlin/event/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
| ITEM_USED_ON_ENTITY | Trigger when an item used on an entity | ALL | true | * | Item |
| ITEM_USAGE_TICK | Trigger when an item usage ticking | ALL | true | ``ITEM_USAGE_TICKED`` | Item |
| ITEM_USAGE_TICKED | Trigger when an item usage ticked | ALL | true | * | Item |
| ITEM_INVENTORY_TICK | Trigger when an item ticking in inventory | ALL | true | ``ITEM_INVENTORY_TICKED`` | Item |
| ITEM_INVENTORY_TICKED | Trigger when an item ticked in inventory | ALL | true | * | Item |
| ITEM_STACK_CLICK | Trigger when an item stack clicking in inventory | ALL | true | ``ITEM_STACK_CLICKED`` | Item |
| ITEM_STACK_CLICKED | Trigger when an item stack clicked in inventory | 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 |
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs = -Xmx4G
# Mod Properties
mod_version = 1.0.0-alpha6
mod_version = 1.0.0-alpha7
maven_group = com.github.cao.awa
archives_base_name = conium
# Fabric Properties
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/com/github/cao/awa/conium/Conium.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Conium : ModInitializer {
val isClient: Boolean get() = ConiumClient.initialized

@JvmField
var VERSION = "1.0.0-alpha6"
var VERSION = "1.0.0-alpha7"

@JvmField
var LANGUAGE_TRANSLATOR_VERSION: String = LanguageTranslator.getVersion()
Expand Down Expand Up @@ -191,9 +191,9 @@ class Conium : ModInitializer {
// Initialize for events
ConiumEvent.init()
ConiumEvent.events().let { events ->
LOGGER.info("Loaded {} events", events.size)
LOGGER.info("Loaded {} conium events", events.size)
debug(
"Loaded {} events: {}",
"Loaded {} conium events: {}",
events::size,
{ events },
LOGGER::info
Expand Down Expand Up @@ -237,13 +237,5 @@ class Conium : ModInitializer {
LOGGER::info
)
}

LOGGER.info("Loaded {} conium events", ConiumEvent.count())
debug(
"Loaded {} conium events: {}",
{ ConiumEvent.count() },
{ ConiumEvent.events() },
LOGGER::info
)
}
}
33 changes: 33 additions & 0 deletions src/main/java/com/github/cao/awa/conium/event/ConiumEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ import com.github.cao.awa.conium.event.server.tick.ConiumServerTickEvent
import com.github.cao.awa.conium.event.server.tick.ConiumServerTickTailEvent
import com.github.cao.awa.conium.event.trigger.ListTriggerable
import com.github.cao.awa.conium.event.type.ConiumEventType
import com.github.cao.awa.conium.item.event.stack.click.ConiumItemStackClickEvent
import com.github.cao.awa.conium.item.event.stack.click.ConiumItemStackClickedEvent
import com.github.cao.awa.conium.item.event.tick.inventory.ConiumItemInventoryTickEvent
import com.github.cao.awa.conium.item.event.tick.inventory.ConiumItemInventoryTickedEvent
import com.github.cao.awa.conium.item.event.use.block.ConiumItemUseOnBlockEvent
import com.github.cao.awa.conium.item.event.use.block.ConiumItemUsedOnBlockEvent
import com.github.cao.awa.conium.item.event.use.entity.ConiumItemUseOnEntityEvent
Expand All @@ -42,10 +46,13 @@ import com.github.cao.awa.conium.item.event.use.usage.ConiumItemUsageTickEvent
import com.github.cao.awa.conium.item.event.use.usage.ConiumItemUsageTickedEvent
import com.github.cao.awa.conium.parameter.ParameterSelective
import com.github.cao.awa.sinuatum.util.collection.CollectionFactor
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import java.util.*

abstract class ConiumEvent<P : ParameterSelective>(val eventType: ConiumEventType<*>) : ListTriggerable<P>() {
companion object {
private val LOGGER: Logger = LogManager.getLogger("ConiumEvent")
private val events: MutableMap<ConiumEventType<*>, ConiumEvent<*>> = CollectionFactor.hashMap()
private val foreverContext: MutableMap<ConiumEventType<*>, MutableList<ConiumEventContext<*>>> = CollectionFactor.hashMap()

Expand All @@ -67,6 +74,18 @@ abstract class ConiumEvent<P : ParameterSelective>(val eventType: ConiumEventTyp
@JvmField
val itemUsageTickedEvent: ConiumItemUsageTickedEvent = ConiumItemUsageTickedEvent()

@JvmField
val itemStackClickEvent: ConiumItemStackClickEvent = ConiumItemStackClickEvent()

@JvmField
val itemStackClickedEvent: ConiumItemStackClickedEvent = ConiumItemStackClickedEvent()

@JvmField
val itemInventoryTickEvent: ConiumItemInventoryTickEvent = ConiumItemInventoryTickEvent()

@JvmField
val itemInventoryTickedEvent: ConiumItemInventoryTickedEvent = ConiumItemInventoryTickedEvent()

@JvmField
val serverTick: ConiumServerTickEvent = ConiumServerTickEvent()

Expand Down Expand Up @@ -257,6 +276,18 @@ abstract class ConiumEvent<P : ParameterSelective>(val eventType: ConiumEventTyp
}

private fun register() {
events[this.eventType]?.let { event: ConiumEvent<*> ->
if (!shouldForceOverride()) {
throw IllegalStateException("The event type '${this.eventType.name}' already registered as '${event.javaClass.name}', '${this.javaClass.name}' cannot override it")
} else {
LOGGER.info(
"The event type '{}' already registered as '{}', '{}' force override it now",
this.eventType.name,
event.javaClass.name,
this.javaClass.name
)
}
}
events[this.eventType] = this
}

Expand All @@ -271,4 +302,6 @@ abstract class ConiumEvent<P : ParameterSelective>(val eventType: ConiumEventTyp
open fun attach() {
// No default attaches.
}

open fun shouldForceOverride(): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import net.minecraft.item.Item
import net.minecraft.item.ItemPlacementContext
import net.minecraft.item.ItemStack
import net.minecraft.item.ItemUsageContext
import net.minecraft.screen.slot.Slot
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.ClickType
import net.minecraft.util.Hand
import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.math.BlockPos
Expand All @@ -44,6 +46,21 @@ object ConiumEventArgTypes {
@JvmField
val ITEM_STACK: DynamicArgType<ItemStack>

@JvmField
val CURSOR_STACK: DynamicArgType<ItemStack>

@JvmField
val CLICK_TYPE: DynamicArgType<ClickType>

@JvmField
val SLOT: DynamicArgType<Slot>

@JvmField
val SLOT_NUMBER: DynamicArgType<Int>

@JvmField
val SELECT_STATUS: DynamicArgType<Boolean>

@JvmField
val HAND: DynamicArgType<Hand>

Expand Down Expand Up @@ -144,6 +161,16 @@ object ConiumEventArgTypes {
transform(::ITEM_PLACEMENT_CONTEXT, ItemPlacementContext::getStack)
)

CURSOR_STACK = arg("cursor_stack")

CLICK_TYPE = arg("click_type")

SLOT = arg("slot")

SLOT_NUMBER = arg("slot_number")

SELECT_STATUS = arg("select_status")

HAND = arg(
"hand",
transform(::ITEM_USAGE_CONTEXT, ItemUsageContext::getHand)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class ConiumEventType<I : Any>(val name: String, val identityType: KClass<I>) {
@JvmField
val ITEM_USAGE_TICKED: ConiumEventType<Item> = ConiumEventType("item_usage_tick", Item::class)

@JvmField
val ITEM_INVENTORY_TICK: ConiumEventType<Item> = ConiumEventType("item_inventory_tick", Item::class)

@JvmField
val ITEM_INVENTORY_TICKED: ConiumEventType<Item> = ConiumEventType("item_inventory_ticked", Item::class)

@JvmField
val ITEM_STACK_CLICK: ConiumEventType<Item> = ConiumEventType("item_stack_click", Item::class)

@JvmField
val ITEM_STACK_CLICKED: ConiumEventType<Item> = ConiumEventType("item_stack_clicked", Item::class)

@JvmField
val ITEM_USE_ON_BLOCK: ConiumEventType<Item> = ConiumEventType("item_use_on_block", Item::class)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.cao.awa.conium.item.event.stack.click

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.item.event.ConiumItemEvent
import com.github.cao.awa.conium.parameter.ParameterSelective
import com.github.cao.awa.conium.parameter.ParameterSelective5
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot
import net.minecraft.util.ClickType

class ConiumItemStackClickEvent : ConiumItemEvent<ParameterSelective5<Boolean, PlayerEntity, ItemStack, ItemStack, ClickType, Slot>>(ConiumEventType.ITEM_STACK_CLICK) {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.PLAYER,
ConiumEventArgTypes.ITEM_STACK,
ConiumEventArgTypes.CURSOR_STACK,
ConiumEventArgTypes.CLICK_TYPE,
ConiumEventArgTypes.SLOT,
).arise { identity: Any, player: PlayerEntity, itemStack: ItemStack, cursorStack: ItemStack, clickType: ClickType, slot: Slot ->
noFailure(identity) { parameterSelective ->
parameterSelective(player, itemStack, cursorStack, clickType, slot)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.cao.awa.conium.item.event.stack.click

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.item.event.ConiumItemEvent
import com.github.cao.awa.conium.parameter.ParameterSelective
import com.github.cao.awa.conium.parameter.ParameterSelective4
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemStack
import net.minecraft.screen.slot.Slot
import net.minecraft.util.ClickType

class ConiumItemStackClickedEvent : ConiumItemEvent<ParameterSelective4<Boolean, PlayerEntity, ItemStack, ClickType, Slot>>(ConiumEventType.ITEM_STACK_CLICKED) {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.PLAYER,
ConiumEventArgTypes.ITEM_STACK,
ConiumEventArgTypes.CLICK_TYPE,
ConiumEventArgTypes.SLOT
).arise { identity: Any, player: PlayerEntity, itemStack: ItemStack, clickType: ClickType, slot: Slot ->
noFailure(identity) { parameterSelective ->
parameterSelective(player, itemStack, clickType, slot)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.cao.awa.conium.item.event.tick.inventory

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.item.event.ConiumItemEvent
import com.github.cao.awa.conium.parameter.ParameterSelective
import com.github.cao.awa.conium.parameter.ParameterSelective5
import net.minecraft.entity.Entity
import net.minecraft.item.ItemStack
import net.minecraft.world.World

class ConiumItemInventoryTickEvent : ConiumItemEvent<ParameterSelective5<Boolean, World, Entity, ItemStack, Int, Boolean>>(ConiumEventType.ITEM_INVENTORY_TICK) {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.WORLD,
ConiumEventArgTypes.ENTITY,
ConiumEventArgTypes.ITEM_STACK,
ConiumEventArgTypes.SLOT_NUMBER,
ConiumEventArgTypes.SELECT_STATUS,
).arise { identity: Any, world: World, entity: Entity, itemStack: ItemStack, slotNumber: Int, selectStatus: Boolean ->
noFailure(identity) { parameterSelective ->
parameterSelective(world, entity, itemStack, slotNumber, selectStatus)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.github.cao.awa.conium.item.event.tick.inventory

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.item.event.ConiumItemEvent
import com.github.cao.awa.conium.parameter.ParameterSelective
import com.github.cao.awa.conium.parameter.ParameterSelective5
import net.minecraft.entity.Entity
import net.minecraft.item.ItemStack
import net.minecraft.world.World

class ConiumItemInventoryTickedEvent : ConiumItemEvent<ParameterSelective5<Boolean, World, Entity, ItemStack, Int, Boolean>>(ConiumEventType.ITEM_INVENTORY_TICKED) {
override fun requirement(): ConiumEventContext<out ParameterSelective> {
return requires(
ConiumEventArgTypes.WORLD,
ConiumEventArgTypes.ENTITY,
ConiumEventArgTypes.ITEM_STACK,
ConiumEventArgTypes.SLOT_NUMBER,
ConiumEventArgTypes.SELECT_STATUS,
).arise { identity: Any, world: World, entity: Entity, itemStack: ItemStack, slotNumber: Int, selectStatus: Boolean ->
noFailure(identity) { parameterSelective ->
parameterSelective(world, entity, itemStack, slotNumber, selectStatus)
}
}
}
}
Loading

0 comments on commit 079c6fe

Please sign in to comment.