summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/keuin/blame/EventHandler.java10
-rw-r--r--src/main/java/com/keuin/blame/adapter/handler/PlaceBlockHandler.java10
-rw-r--r--src/main/java/com/keuin/blame/data/LogEntryFactory.java15
-rw-r--r--src/main/java/com/keuin/blame/mixin/BlockPlaceMixin.java6
-rw-r--r--src/main/java/com/keuin/blame/mixin/FrostWalkerPlaceMixin.java30
5 files changed, 53 insertions, 18 deletions
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<PlaceBlockHandler> 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<PlacedBlockCrite
@Inject(at = @At(value = "HEAD"), method = "trigger")
public void trigger(ServerPlayerEntity player, BlockPos blockPos, ItemStack stack, CallbackInfo ci) {
- PlaceBlockHandler.EVENT.invoker().onPlayerPlaceBlock(
+ PlaceBlockHandler.EVENT.invoker().onEntityPlaceBlock(
player.world,
player,
- blockPos,
- player.world.getBlockState(blockPos),
- player.world.getBlockEntity(blockPos)
+ blockPos
);
}
} \ No newline at end of file
diff --git a/src/main/java/com/keuin/blame/mixin/FrostWalkerPlaceMixin.java b/src/main/java/com/keuin/blame/mixin/FrostWalkerPlaceMixin.java
new file mode 100644
index 0000000..d8d93db
--- /dev/null
+++ b/src/main/java/com/keuin/blame/mixin/FrostWalkerPlaceMixin.java
@@ -0,0 +1,30 @@
+package com.keuin.blame.mixin;
+
+import com.keuin.blame.adapter.handler.PlaceBlockHandler;
+import net.minecraft.block.BlockState;
+import net.minecraft.enchantment.FrostWalkerEnchantment;
+import net.minecraft.entity.LivingEntity;
+import net.minecraft.util.math.BlockPos;
+import net.minecraft.world.World;
+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.CallbackInfo;
+import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
+
+@Mixin(FrostWalkerEnchantment.class)
+public abstract class FrostWalkerPlaceMixin {
+
+ @Inject(locals = LocalCapture.CAPTURE_FAILSOFT,
+ at = @At(value = "INVOKE",
+ target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"),
+ method = "freezeWater")
+ private static void applyMovementEffectsMixin(LivingEntity entity, World world, BlockPos blockPos, int level,
+ CallbackInfo ci, BlockState blockState3) {
+ PlaceBlockHandler.EVENT.invoker().onEntityPlaceBlock(
+ world,
+ entity,
+ blockPos
+ );
+ }
+}