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
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.daqem.grieflogger.event.block;

import dev.architectury.event.EventResult;
import dev.architectury.event.events.common.BlockEvent;
import dev.architectury.event.events.common.InteractionEvent;

public class BlockEvents {

public static void registerEvents() {
BlockEvent.BREAK.register(BreakBlockEvent::breakBlock);
BlockEvent.PLACE.register(PlaceBlockEvent::placeBlock);
BlockEvent.PLACE.register(((level, blockPos, blockState, entity) -> {
PlaceBlockEvent.placeBlock(level, blockPos, blockState, entity);
return EventResult.pass();
}));
InteractionEvent.LEFT_CLICK_BLOCK.register((player, hand, pos, direction) -> LeftClickBlockEvent.leftClickBlock(player, hand, pos, direction).asMinecraft());
InteractionEvent.RIGHT_CLICK_BLOCK.register((player, hand, pos, direction) -> RightClickBlockEvent.rightClickBlock(player, hand, pos, direction).asMinecraft());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

import com.daqem.grieflogger.model.action.BlockAction;
import com.daqem.grieflogger.player.GriefLoggerServerPlayer;
import dev.architectury.event.EventResult;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

public class PlaceBlockEvent {

public static EventResult placeBlock(Level level, BlockPos pos, BlockState state, Entity placer) {
public static void placeBlock(Level level, BlockPos pos, BlockState state, Entity placer) {
if (placer instanceof GriefLoggerServerPlayer serverPlayer) {
LogBlockEvent.logBlock(serverPlayer, level, state, pos, BlockAction.PLACE_BLOCK);
}
return EventResult.pass();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@
@Mixin(BucketItem.class)
public class MixinBucketItem {

@Inject(
method = "emptyContents",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z",
shift = At.Shift.AFTER
)
)
private void onLiquidPlaced(LivingEntity livingEntity, Level level, BlockPos blockPos, BlockHitResult blockHitResult, CallbackInfoReturnable<Boolean> cir) {
if (livingEntity instanceof ServerPlayer serverPlayer) {
PlaceBlockEvent.placeBlock(level, blockPos, level.getBlockState(blockPos), serverPlayer);
}
}

@Inject(
method = "use",
at = @At(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.daqem.grieflogger.fabric.mixin;

import com.daqem.grieflogger.event.block.PlaceBlockEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BucketItem.class)
public class MixinBucketItem {

@Inject(
method = "emptyContents",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z",
shift = At.Shift.AFTER
)
)
private void onLiquidPlaced(LivingEntity livingEntity, Level level, BlockPos blockPos, BlockHitResult blockHitResult, CallbackInfoReturnable<Boolean> cir) {
if (livingEntity instanceof ServerPlayer serverPlayer) {
PlaceBlockEvent.placeBlock(level, blockPos, level.getBlockState(blockPos), serverPlayer);
}
}
}
3 changes: 2 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
]
},
"mixins": [
"grieflogger-common.mixins.json"
"grieflogger-common.mixins.json",
"grieflogger-fabric.mixins.json"
],
"depends": {
"fabric": "*",
Expand Down
14 changes: 14 additions & 0 deletions fabric/src/main/resources/grieflogger-fabric.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "com.daqem.grieflogger.fabric.mixin",
"compatibilityLevel": "JAVA_21",
"minVersion": "0.8",
"client": [
],
"mixins": [
"MixinBucketItem"
],
"injectors": {
"defaultRequire": 1
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ maven_group=com.daqem
archives_base_name=grieflogger

# Project
mod_version=1.2.7-1.21.6
mod_version=1.2.8-1.21.6
mod_id=grieflogger
mod_name=GriefLogger
mod_description=A mod that logs all player interactions with blocks and entities and stores them in a database.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.daqem.grieflogger.neoforge.mixin;

import com.daqem.grieflogger.event.block.PlaceBlockEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(BucketItem.class)
public class MixinBucketItem {

@Inject(
method = "emptyContents(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/phys/BlockHitResult;Lnet/minecraft/world/item/ItemStack;)Z",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z",
shift = At.Shift.AFTER
)
)
private void onLiquidPlaced(LivingEntity livingEntity, Level level, BlockPos blockPos, BlockHitResult blockHitResult, ItemStack itemStack, CallbackInfoReturnable<Boolean> cir) {
if (livingEntity instanceof ServerPlayer serverPlayer) {
PlaceBlockEvent.placeBlock(level, blockPos, level.getBlockState(blockPos), serverPlayer);
}
}
}
5 changes: 4 additions & 1 deletion neoforge/src/main/resources/META-INF/neoforge.mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ ordering = "AFTER"
side = "SERVER"

[[mixins]]
config = "grieflogger-common.mixins.json"
config = "grieflogger-common.mixins.json"

[[mixins]]
config = "grieflogger-neoforge.mixins.json"
14 changes: 14 additions & 0 deletions neoforge/src/main/resources/grieflogger-neoforge.mixins.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"required": true,
"package": "com.daqem.grieflogger.neoforge.mixin",
"compatibilityLevel": "JAVA_21",
"minVersion": "0.8",
"client": [
],
"mixins": [
"MixinBucketItem"
],
"injectors": {
"defaultRequire": 1
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ include 'common'
include 'fabric'
include 'neoforge'

rootProject.name = "GriefLogger 1.21.5"
rootProject.name = "GriefLogger 1.21.6"
Loading