From f655118067835b272579f89fc84d163239a01f4f Mon Sep 17 00:00:00 2001 From: Keuin Date: Sun, 22 Aug 2021 19:02:12 +0800 Subject: Logs frost walker block placement. --- src/main/java/com/keuin/blame/EventHandler.java | 10 +++++--- .../blame/adapter/handler/PlaceBlockHandler.java | 10 +++----- .../java/com/keuin/blame/data/LogEntryFactory.java | 15 ++++++++--- .../com/keuin/blame/mixin/BlockPlaceMixin.java | 6 ++--- .../keuin/blame/mixin/FrostWalkerPlaceMixin.java | 30 ++++++++++++++++++++++ src/main/resources/blame.mixins.json | 3 ++- 6 files changed, 55 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/keuin/blame/mixin/FrostWalkerPlaceMixin.java diff --git a/src/main/java/com/keuin/blame/EventHandler.java b/src/main/java/com/keuin/blame/EventHandler.java index fb2df2f..ae67363 100644 --- a/src/main/java/com/keuin/blame/EventHandler.java +++ b/src/main/java/com/keuin/blame/EventHandler.java @@ -68,18 +68,20 @@ public class EventHandler implements AttackEntityHandler, PlaceBlockHandler, Bre } @Override - public void onPlayerPlaceBlock(World world, PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity) { + public void onEntityPlaceBlock(World world, LivingEntity livingEntity, BlockPos blockPos) { + var blockState = world.getBlockState(blockPos); + var blockEntity = world.getBlockEntity(blockPos); String blockId = Registry.BLOCK.getId(blockState.getBlock()).toString(); String worldString = MinecraftUtil.worldToString(world); - LogEntry entry = LogEntryFactory.playerWithBlock( - playerEntity, + LogEntry entry = LogEntryFactory.entityWithBlock( + livingEntity, worldString, blockId, blockPos, worldString, ActionType.BLOCK_PLACE ); - SubmitWorker.INSTANCE.submit(entry); + SubmitWorker.INSTANCE.submit(entry); } @Override diff --git a/src/main/java/com/keuin/blame/adapter/handler/PlaceBlockHandler.java b/src/main/java/com/keuin/blame/adapter/handler/PlaceBlockHandler.java index fa5bab5..cf4e674 100644 --- a/src/main/java/com/keuin/blame/adapter/handler/PlaceBlockHandler.java +++ b/src/main/java/com/keuin/blame/adapter/handler/PlaceBlockHandler.java @@ -2,9 +2,7 @@ package com.keuin.blame.adapter.handler; import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.EventFactory; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.LivingEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; @@ -12,11 +10,11 @@ import org.jetbrains.annotations.Nullable; public interface PlaceBlockHandler { Event EVENT = EventFactory.createArrayBacked(PlaceBlockHandler.class, - (listeners) -> (world, playerEntity, blockPos, blockState, blockEntity) -> { + (listeners) -> (world, playerEntity, blockPos) -> { for (PlaceBlockHandler listener : listeners) { - listener.onPlayerPlaceBlock(world, playerEntity, blockPos, blockState, blockEntity); + listener.onEntityPlaceBlock(world, playerEntity, blockPos); } }); - void onPlayerPlaceBlock(World world, @Nullable PlayerEntity playerEntity, BlockPos blockPos, BlockState blockState, BlockEntity blockEntity); + void onEntityPlaceBlock(World world, @Nullable LivingEntity livingEntity, BlockPos blockPos); } diff --git a/src/main/java/com/keuin/blame/data/LogEntryFactory.java b/src/main/java/com/keuin/blame/data/LogEntryFactory.java index c7be5a5..f21fc7b 100644 --- a/src/main/java/com/keuin/blame/data/LogEntryFactory.java +++ b/src/main/java/com/keuin/blame/data/LogEntryFactory.java @@ -3,17 +3,24 @@ package com.keuin.blame.data; import com.keuin.blame.data.entry.LogEntry; import com.keuin.blame.data.enums.ActionType; import com.keuin.blame.data.enums.ObjectType; +import com.keuin.blame.util.MinecraftUtil; +import net.minecraft.block.entity.EndGatewayBlockEntity; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; +import net.minecraft.util.registry.Registry; + +import java.util.Objects; public class LogEntryFactory { - public static LogEntry playerWithBlock(PlayerEntity player, String playerWorld, String blockId, Vec3i blockPos, String blockWorld, ActionType actionType) { - Vec3d playerPos = player.getPos(); + public static LogEntry entityWithBlock(LivingEntity livingEntity, String playerWorld, String blockId, Vec3i blockPos, String blockWorld, ActionType actionType) { + Vec3d playerPos = livingEntity.getPos(); return new LogEntry( System.currentTimeMillis(), - player.getName().asString(), - player.getUuid(), + livingEntity.getName().asString(), + livingEntity.getUuid(), new WorldPos(playerWorld, playerPos.x, playerPos.y, playerPos.z), actionType, ObjectType.BLOCK, diff --git a/src/main/java/com/keuin/blame/mixin/BlockPlaceMixin.java b/src/main/java/com/keuin/blame/mixin/BlockPlaceMixin.java index adee24c..3052c5c 100644 --- a/src/main/java/com/keuin/blame/mixin/BlockPlaceMixin.java +++ b/src/main/java/com/keuin/blame/mixin/BlockPlaceMixin.java @@ -19,12 +19,10 @@ public abstract class BlockPlaceMixin extends AbstractCriterion