From 950e8a95a9f3fce0b91aaa0d6e74ac5342bc0644 Mon Sep 17 00:00:00 2001 From: yitzy299 <66269211+yitzy299@users.noreply.github.com> Date: Thu, 24 Feb 2022 16:59:16 +0100 Subject: [PATCH] Fix mixin crashes & bump version to 1.2.3 (#155) Co-authored-by: yitzy299 --- docs/actions.md | 1 + gradle.properties | 2 +- .../ledger/mixin/FallingBlockEntityMixin.java | 7 +++---- .../mixin/blocks/CampfireBlockMixin.java | 12 ++++++----- .../ledger/mixin/blocks/CandleBlockMixin.java | 20 ++++++++++--------- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/docs/actions.md b/docs/actions.md index 0d2b769a..f55f0363 100644 --- a/docs/actions.md +++ b/docs/actions.md @@ -4,6 +4,7 @@ These are the currently logged action types: - block-break - block-place +- block-change - item-insert - item-remove - entity-killed \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 056e5bb4..3b8d2d1a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx1G # Mod Properties -modVersion = 1.2.2 +modVersion = 1.2.3 mavenGroup = com.github.quiltservertools modId = ledger modName = Ledger diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/FallingBlockEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/FallingBlockEntityMixin.java index 8ee35099..39f35fb7 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/FallingBlockEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/FallingBlockEntityMixin.java @@ -22,15 +22,14 @@ public abstract class FallingBlockEntityMixin { @Shadow private BlockState block; - @ModifyArgs( + @Inject( method = "tick", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - private void ledgerBlockFallInvoker(Args args) { + private void ledgerBlockFallInvoker(CallbackInfo ci) { FallingBlockEntity entity = (FallingBlockEntity) (Object) this; - BlockPos pos = args.get(0); - BlockBreakCallback.EVENT.invoker().breakBlock(entity.world, pos, this.block, this.block.hasBlockEntity() ? entity.world.getBlockEntity(pos) : null, Sources.GRAVITY); + BlockBreakCallback.EVENT.invoker().breakBlock(entity.world, entity.getBlockPos(), this.block, this.block.hasBlockEntity() ? entity.world.getBlockEntity(entity.getBlockPos()) : null, Sources.GRAVITY); } @ModifyArgs( diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CampfireBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CampfireBlockMixin.java index 2736ef08..eadcf5ea 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CampfireBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CampfireBlockMixin.java @@ -41,11 +41,13 @@ public void logCampfireAddItem(BlockState blockState, World world, BlockPos pos, @Inject(method = "extinguish", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldAccess;emitGameEvent(Lnet/minecraft/entity/Entity;Lnet/minecraft/world/event/GameEvent;Lnet/minecraft/util/math/BlockPos;)V")) - private static void logCampfireExtinguish(Entity entity, WorldAccess world, BlockPos pos, BlockState blockState, CallbackInfo ci) { - if (entity instanceof PlayerEntity player) { - BlockChangeCallback.EVENT.invoker().changeBlock((World) world, pos, blockState, blockState.with(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH, player); - } else { - BlockChangeCallback.EVENT.invoker().changeBlock((World) world, pos, blockState, blockState.with(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH); + private static void logCampfireExtinguish(Entity entity, WorldAccess worldAccess, BlockPos pos, BlockState blockState, CallbackInfo ci) { + if (worldAccess instanceof World world) { + if (entity instanceof PlayerEntity player) { + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, blockState.with(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH, player); + } else { + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, blockState.with(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH); + } } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java index a2c2de8a..46239304 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java @@ -26,15 +26,17 @@ public abstract class CandleBlockMixin { public static BooleanProperty LIT; @Inject(method = "extinguish", at = @At(value = "RETURN")) - private static void ledgerLogCandleExtinguish(PlayerEntity player, BlockState state, WorldAccess world, BlockPos pos, CallbackInfo ci) { - BlockChangeCallback.EVENT.invoker().changeBlock( - (World) world, - pos, - state, - state.with(LIT, !state.get(LIT)), - null, - null, - Sources.EXTINGUISH, player); + private static void ledgerLogCandleExtinguish(PlayerEntity player, BlockState state, WorldAccess worldAccess, BlockPos pos, CallbackInfo ci) { + if (worldAccess instanceof World world) { + BlockChangeCallback.EVENT.invoker().changeBlock( + world, + pos, + state, + state.with(LIT, !state.get(LIT)), + null, + null, + Sources.EXTINGUISH, player); + } } @Inject(method = "onProjectileHit", at = @At(value = "RETURN"))