Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ These are the currently logged action types:
- block-change
- item-insert
- item-remove
- entity-killed
- entity-killed
- entity-mount
- entity-dismount
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.quiltservertools.ledger.mixin;

import com.github.quiltservertools.ledger.callbacks.EntityMountCallback;
import com.github.quiltservertools.ledger.utility.HandlerWithContext;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -28,4 +30,14 @@ public void addPositionContext(NamedScreenHandlerFactory factory, CallbackInfoRe
}
}

@Inject(method = "startRiding", at = @At(value = "RETURN"))
public void onPlayerStartedRiding(Entity entity, boolean force, CallbackInfoReturnable<Boolean> cir) {
ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;

if (!cir.getReturnValue()) {
return;
}

EntityMountCallback.EVENT.invoker().mount(entity, player);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.github.quiltservertools.ledger.mixin.entities;

import com.github.quiltservertools.ledger.callbacks.EntityDismountCallback;
import com.github.quiltservertools.ledger.callbacks.EntityKillCallback;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -21,4 +24,15 @@ private void ledgerEntityKillInvoker(DamageSource source, CallbackInfo ci) {
entity.getWorld(), entity.getBlockPos(), entity, source
);
}

@Inject(method = "onDismounted", at = @At("RETURN"))
private void onEntityDismount(Entity vehicle, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;

if (!(entity instanceof PlayerEntity player)) {
return;
}

EntityDismountCallback.EVENT.invoker().dismount(vehicle, player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.quiltservertools.ledger.actions

class EntityDismountActionType : AbstractActionType() {
override val identifier = "entity-dismount"

override fun getTranslationType() = "entity"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.quiltservertools.ledger.actions

class EntityMountActionType : AbstractActionType() {
override val identifier = "entity-mount"

override fun getTranslationType() = "entity"
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import com.github.quiltservertools.ledger.actions.BlockBreakActionType
import com.github.quiltservertools.ledger.actions.BlockChangeActionType
import com.github.quiltservertools.ledger.actions.BlockPlaceActionType
import com.github.quiltservertools.ledger.actions.EntityChangeActionType
import com.github.quiltservertools.ledger.actions.EntityDismountActionType
import com.github.quiltservertools.ledger.actions.EntityKillActionType
import com.github.quiltservertools.ledger.actions.EntityMountActionType
import com.github.quiltservertools.ledger.actions.ItemDropActionType
import com.github.quiltservertools.ledger.actions.ItemInsertActionType
import com.github.quiltservertools.ledger.actions.ItemPickUpActionType
Expand Down Expand Up @@ -207,10 +209,12 @@ object ActionFactory {
setEntityData(action, pos, world, entity, Sources.PLAYER)
action.sourceProfile = killer.gameProfile
}

killer != null -> {
val source = Registries.ENTITY_TYPE.getId(killer.type).path
setEntityData(action, pos, world, entity, source)
}

else -> {
setEntityData(action, pos, world, entity, cause.name)
}
Expand Down Expand Up @@ -268,4 +272,46 @@ object ActionFactory {

return action
}

fun entityMountAction(
entity: Entity,
player: PlayerEntity,
): EntityMountActionType {
val world = entity.world

val action = EntityMountActionType()

action.pos = entity.blockPos
action.world = world.registryKey.value
action.objectIdentifier = Registries.ENTITY_TYPE.getId(entity.type)
action.oldObjectIdentifier = Registries.ENTITY_TYPE.getId(entity.type)

action.objectState = entity.writeNbt(NbtCompound())?.toString()
action.sourceName = Sources.PLAYER

action.sourceProfile = player.gameProfile

return action
}

fun entityDismountAction(
entity: Entity,
player: PlayerEntity,
): EntityDismountActionType {
val world = entity.world

val action = EntityDismountActionType()

action.pos = entity.blockPos
action.world = world.registryKey.value
action.objectIdentifier = Registries.ENTITY_TYPE.getId(entity.type)
action.oldObjectIdentifier = Registries.ENTITY_TYPE.getId(entity.type)

action.objectState = entity.writeNbt(NbtCompound())?.toString()
action.sourceName = Sources.PLAYER

action.sourceProfile = player.gameProfile

return action
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.quiltservertools.ledger.callbacks

import net.fabricmc.fabric.api.event.Event
import net.fabricmc.fabric.api.event.EventFactory
import net.minecraft.entity.Entity
import net.minecraft.entity.player.PlayerEntity

fun interface EntityDismountCallback {
fun dismount(entity: Entity, playerEntity: PlayerEntity)

companion object {
@JvmField
val EVENT: Event<EntityDismountCallback> =
EventFactory.createArrayBacked(EntityDismountCallback::class.java) { listeners ->
EntityDismountCallback { entity, player ->
for (listener in listeners) {
listener.dismount(entity, player)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.quiltservertools.ledger.callbacks

import net.fabricmc.fabric.api.event.Event
import net.fabricmc.fabric.api.event.EventFactory
import net.minecraft.entity.Entity
import net.minecraft.entity.player.PlayerEntity

fun interface EntityMountCallback {
fun mount(entity: Entity, playerEntity: PlayerEntity)

companion object {
@JvmField
val EVENT: Event<EntityMountCallback> =
EventFactory.createArrayBacked(EntityMountCallback::class.java) { listeners ->
EntityMountCallback { entity, player ->
for (listener in listeners) {
listener.mount(entity, player)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.github.quiltservertools.ledger.listeners

import com.github.quiltservertools.ledger.Ledger
import com.github.quiltservertools.ledger.actionutils.ActionFactory
import com.github.quiltservertools.ledger.callbacks.EntityDismountCallback
import com.github.quiltservertools.ledger.callbacks.EntityMountCallback
import com.github.quiltservertools.ledger.callbacks.ItemDropCallback
import com.github.quiltservertools.ledger.callbacks.ItemPickUpCallback
import com.github.quiltservertools.ledger.database.ActionQueueService
Expand All @@ -17,6 +19,7 @@ import net.fabricmc.fabric.api.networking.v1.PacketSender
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntity
import net.minecraft.entity.Entity
import net.minecraft.entity.ItemEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.ItemPlacementContext
Expand All @@ -38,6 +41,8 @@ fun registerPlayerListeners() {
UseBlockCallback.EVENT.register(::onUseBlock)
ItemPickUpCallback.EVENT.register(::onItemPickUp)
ItemDropCallback.EVENT.register(::onItemDrop)
EntityMountCallback.EVENT.register(::onEntityMount)
EntityDismountCallback.EVENT.register(::onEntityDismount)
}

fun onLeave(handler: ServerPlayNetworkHandler, server: MinecraftServer) {
Expand Down Expand Up @@ -127,3 +132,17 @@ private fun onItemDrop(
) {
ActionQueueService.addToQueue(ActionFactory.itemDropAction(entity, player))
}

private fun onEntityMount(
entity: Entity,
playerEntity: PlayerEntity,
) {
ActionQueueService.addToQueue(ActionFactory.entityMountAction(entity, playerEntity))
}

private fun onEntityDismount(
entity: Entity,
playerEntity: PlayerEntity,
) {
ActionQueueService.addToQueue(ActionFactory.entityDismountAction(entity, playerEntity))
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ object ActionRegistry {
registerActionType { ItemDropActionType() }
registerActionType { EntityKillActionType() }
registerActionType { EntityChangeActionType() }
registerActionType { EntityMountActionType() }
registerActionType { EntityDismountActionType() }
}

fun getType(id: String) = actionTypes[id]
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/data/ledger/lang/en_gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"text.ledger.action.item-drop": "dropped",
"text.ledger.action.entity-kill": "killed",
"text.ledger.action.entity-change": "changed",
"text.ledger.action.entity-mount": "mounted",
"text.ledger.action.entity-dismount": "dismounted",

"text.ledger.network.protocols_mismatched": "Protocol versions mismatched: client mod is Ledger protocol version %d and the client version is %d",
"text.ledger.network.no_mod_info": "Unable to determine mod information for your client mod",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/data/ledger/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"text.ledger.action.item-drop": "dropped",
"text.ledger.action.entity-kill": "killed",
"text.ledger.action.entity-change": "changed",
"text.ledger.action.entity-mount": "mounted",
"text.ledger.action.entity-dismount": "dismounted",

"text.ledger.parameter.action.description": "Filter by type of performed action.",
"text.ledger.parameter.after.description": "Filter by time (after the provided time).",
Expand Down