Skip to content

Commit 07a2f02

Browse files
authored
Block-Change & Block-Place things logged (QuiltServerTools#127)
* cake eating * Candle logging & finding the methods for cauldrons * caudron logging, could do with some polish * AAAAAAAAAAAAAAAAAAAAAAAAAAA * Cake Candle place logged, Water Bottle on empty cauldron logged * Fix Powdered Snow -> Water when on fire entity is cooled off * Anvil use damage logging * Jukebox Logging. notes on why beds and other multi blocks rollback unreliably * Removal of unneeded imports * Grass,Dirt Part, Mycelium, -> Dirt trample logging etc, farmland can Dry out instead of trample, Endcrystal player source added for bows * should have been removed * probs needs to ensure the projectile is owned by a player * Kinda fix sponge logging, Correct block on placement & change log Break water logs are out of order from placement however. * Use ModifyArgs in SpongeBlock * Scaffolding placing (with correct pos) & breaking logging * Upward Pointed dripstone gravity logging, Campfire interactions logging * untested but i think this should work * method names * move cauldron stuff to own folder fix dripstone and precipitate logs * incomplete: removal of console logs. sponges still have logic issues other general jank needs to be sorted still. sponges are very jank * tidy up, onblockadded still out of order * sponges should work correctly now. * revert blockitem place. * extra info for block place * Ran thru reformatter & other code clean up * Ran thru reformatter & other code clean up * more code clean up * sponge comments, remove campfire manual cast, use already stored pos in blockitem * variable naming & using modifyargs * ModifyArgs for FallingBlockEntity & ItemScatter. Fix off by 1 index for anvil args
1 parent 5fd57b5 commit 07a2f02

37 files changed

+822
-70
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.quiltservertools.ledger.mixin;
2+
3+
import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
4+
import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback;
5+
import com.github.quiltservertools.ledger.utility.Sources;
6+
import net.minecraft.block.BlockState;
7+
import net.minecraft.entity.player.PlayerEntity;
8+
import net.minecraft.screen.AnvilScreenHandler;
9+
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.world.World;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.ModifyArgs;
15+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
16+
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
17+
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
18+
19+
@Mixin(AnvilScreenHandler.class)
20+
public abstract class AnvilScreenHandlerMixin {
21+
22+
@Inject(method = "method_24922",
23+
at = @At(value = "INVOKE",
24+
target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
25+
private static void ledgerLogAnvilBreak(PlayerEntity player, World world, BlockPos pos, CallbackInfo ci) {
26+
BlockBreakCallback.EVENT.invoker().breakBlock(
27+
world,
28+
pos,
29+
world.getBlockState(pos),
30+
null,
31+
Sources.DECAY,
32+
player);
33+
}
34+
35+
@ModifyArgs(method = "method_24922",
36+
at = @At(value = "INVOKE",
37+
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
38+
private static void ledgerLogAnvilChange(Args args, PlayerEntity player, World world, BlockPos pos) {
39+
BlockState newBlockState = args.get(1);
40+
BlockChangeCallback.EVENT.invoker().changeBlock(
41+
world,
42+
pos,
43+
world.getBlockState(pos),
44+
newBlockState,
45+
world.getBlockEntity(pos),
46+
null,
47+
Sources.DECAY,
48+
player);
49+
}
50+
}

src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback;
44
import com.github.quiltservertools.ledger.utility.Sources;
5-
import net.minecraft.block.BlockState;
5+
import net.minecraft.entity.player.PlayerEntity;
66
import net.minecraft.item.BlockItem;
77
import net.minecraft.item.Item;
88
import net.minecraft.item.ItemPlacementContext;
99
import net.minecraft.util.ActionResult;
10+
import net.minecraft.util.math.BlockPos;
11+
import net.minecraft.world.World;
1012
import org.spongepowered.asm.mixin.Mixin;
1113
import org.spongepowered.asm.mixin.injection.At;
1214
import org.spongepowered.asm.mixin.injection.Inject;
1315
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1416

1517
@Mixin(BlockItem.class)
1618
public abstract class BlockItemMixin extends Item {
19+
1720
public BlockItemMixin(Settings settings) {
1821
super(settings);
1922
}
@@ -24,15 +27,16 @@ public BlockItemMixin(Settings settings) {
2427
cancellable = true
2528
)
2629
public void ledgerPlayerPlaceBlockCallback(ItemPlacementContext context, CallbackInfoReturnable<ActionResult> cir) {
27-
BlockState blockState = context.getWorld().getBlockState(context.getBlockPos());
28-
30+
World world = context.getWorld();
31+
BlockPos pos = context.getBlockPos();
32+
PlayerEntity player = context.getPlayer();
2933
BlockPlaceCallback.EVENT.invoker().place(
30-
context.getWorld(),
31-
context.getBlockPos(),
32-
blockState,
33-
context.getWorld().getBlockEntity(context.getBlockPos()) != null ? context.getWorld().getBlockEntity(context.getBlockPos()) : null,
34-
context.getPlayer() == null ? Sources.REDSTONE : Sources.PLAYER,
35-
context.getPlayer()
34+
world,
35+
pos,
36+
world.getBlockState(pos),
37+
world.getBlockEntity(pos),
38+
player == null ? Sources.REDSTONE : Sources.PLAYER,
39+
player
3640
);
3741
}
3842
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.quiltservertools.ledger.mixin;
2+
3+
import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback;
4+
import com.github.quiltservertools.ledger.utility.Sources;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.block.entity.CampfireBlockEntity;
7+
import net.minecraft.util.math.BlockPos;
8+
import net.minecraft.world.World;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(CampfireBlockEntity.class)
15+
public abstract class CampfireBlockEntityMixin {
16+
17+
@Inject(method = "litServerTick", at = @At(value = "INVOKE",
18+
target = "Lnet/minecraft/util/ItemScatterer;spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER))
19+
private static void logCampfireRemoveItem(World world, BlockPos pos, BlockState state, CampfireBlockEntity campfire, CallbackInfo ci) {
20+
BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, world.getBlockState(pos), campfire, world.getBlockEntity(pos), Sources.REMOVE);
21+
}
22+
23+
}

src/main/java/com/github/quiltservertools/ledger/mixin/DoubleInventoryMixin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.github.quiltservertools.ledger.mixin;
22

3+
import com.github.quiltservertools.ledger.actionutils.DoubleInventoryHelper;
34
import net.minecraft.inventory.DoubleInventory;
45
import net.minecraft.inventory.Inventory;
56
import org.jetbrains.annotations.NotNull;
67
import org.spongepowered.asm.mixin.Final;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Shadow;
9-
import com.github.quiltservertools.ledger.actionutils.DoubleInventoryHelper;
1010

1111
@Mixin(DoubleInventory.class)
1212
public abstract class DoubleInventoryMixin implements DoubleInventoryHelper {

src/main/java/com/github/quiltservertools/ledger/mixin/EndCrystalEntityMixin.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.minecraft.entity.damage.DamageSource;
55
import net.minecraft.entity.decoration.EndCrystalEntity;
66
import net.minecraft.entity.player.PlayerEntity;
7+
import net.minecraft.entity.projectile.ProjectileEntity;
78
import org.spongepowered.asm.mixin.Mixin;
89
import org.spongepowered.asm.mixin.Unique;
910
import org.spongepowered.asm.mixin.injection.At;
@@ -26,7 +27,9 @@ public PlayerEntity getCausingPlayer() {
2627
public void correctEndCrystalEntitySource(Args args, DamageSource source, float amount) {
2728
if (source.getSource() instanceof PlayerEntity player) {
2829
this.causingPlayer = player;
29-
args.set(0, (EndCrystalEntity) (Object) this);
30+
} else if (source.getSource() instanceof ProjectileEntity projectile && projectile.getOwner() instanceof PlayerEntity player) {
31+
this.causingPlayer = player;
3032
}
33+
args.set(0, (EndCrystalEntity) (Object) this);
3134
}
3235
}

src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionMixin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.github.quiltservertools.ledger.utility.Sources;
66
import com.mojang.datafixers.util.Pair;
77
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
8-
import java.util.Iterator;
98
import net.minecraft.block.Block;
109
import net.minecraft.block.BlockState;
1110
import net.minecraft.entity.Entity;
@@ -27,6 +26,8 @@
2726
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
2827
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
2928

29+
import java.util.Iterator;
30+
3031
@Mixin(Explosion.class)
3132
public abstract class ExplosionMixin {
3233
@Shadow

src/main/java/com/github/quiltservertools/ledger/mixin/FallingBlockEntityMixin.java

+14-17
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,40 @@
77
import net.minecraft.block.BlockState;
88
import net.minecraft.entity.FallingBlockEntity;
99
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.world.World;
1011
import org.spongepowered.asm.mixin.Mixin;
1112
import org.spongepowered.asm.mixin.Shadow;
1213
import org.spongepowered.asm.mixin.injection.At;
1314
import org.spongepowered.asm.mixin.injection.Inject;
15+
import org.spongepowered.asm.mixin.injection.ModifyArgs;
1416
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1517
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
18+
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
1619

1720
@Mixin(FallingBlockEntity.class)
1821
public abstract class FallingBlockEntityMixin {
1922
@Shadow
2023
private BlockState block;
2124

22-
@Inject(
25+
@ModifyArgs(
2326
method = "tick",
2427
at = @At(
2528
value = "INVOKE",
26-
target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"
27-
),
28-
locals = LocalCapture.CAPTURE_FAILEXCEPTION
29-
)
30-
private void ledgerBlockFallInvoker(CallbackInfo ci, Block block, BlockPos blockPos) {
29+
target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
30+
private void ledgerBlockFallInvoker(Args args) {
3131
FallingBlockEntity entity = (FallingBlockEntity) (Object) this;
32-
33-
BlockBreakCallback.EVENT.invoker().breakBlock(entity.world, blockPos, this.block, this.block.hasBlockEntity() ? entity.world.getBlockEntity(blockPos) : null, Sources.GRAVITY);
32+
BlockPos pos = args.get(0);
33+
BlockBreakCallback.EVENT.invoker().breakBlock(entity.world, pos, this.block, this.block.hasBlockEntity() ? entity.world.getBlockEntity(pos) : null, Sources.GRAVITY);
3434
}
3535

36-
@Inject(
36+
@ModifyArgs(
3737
method = "tick",
3838
at = @At(
39-
value = "INVOKE_ASSIGN",
40-
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"
41-
),
42-
locals = LocalCapture.CAPTURE_FAILEXCEPTION
43-
)
44-
private void ledgerBlockLandInvoker(CallbackInfo ci, Block block, BlockPos blockPos) {
39+
value = "INVOKE",
40+
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z"))
41+
private void ledgerBlockLandInvoker(Args args) {
4542
FallingBlockEntity entity = (FallingBlockEntity) (Object) this;
46-
47-
BlockPlaceCallback.EVENT.invoker().place(entity.world, blockPos, this.block, null, Sources.GRAVITY);
43+
BlockPos pos = args.get(0);
44+
BlockPlaceCallback.EVENT.invoker().place(entity.world, pos, this.block, null, Sources.GRAVITY);
4845
}
4946
}

src/main/java/com/github/quiltservertools/ledger/mixin/FlintAndSteelItemMixin.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ public void log(Args args, ItemUsageContext context) {
3232
}
3333
} else {
3434
if (player != null) {
35-
BlockPlaceCallback.EVENT.invoker().place( world, pos, state, be, Sources.FIRE, player);
35+
BlockPlaceCallback.EVENT.invoker().place(world, pos, state, be, Sources.FIRE, player);
3636
} else {
37-
BlockPlaceCallback.EVENT.invoker().place( world, pos, state, be, Sources.FIRE);
37+
BlockPlaceCallback.EVENT.invoker().place(world, pos, state, be, Sources.FIRE);
3838
}
3939
}
4040
}

src/main/java/com/github/quiltservertools/ledger/mixin/ItemScattererMixin.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@
1111
import org.spongepowered.asm.mixin.Mixin;
1212
import org.spongepowered.asm.mixin.injection.At;
1313
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.ModifyArg;
15+
import org.spongepowered.asm.mixin.injection.ModifyArgs;
1416
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1517
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
18+
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
1619

1720
@Mixin(ItemScatterer.class)
1821
public abstract class ItemScattererMixin {
19-
@Inject(
22+
23+
@ModifyArgs(
2024
method = "spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/inventory/Inventory;)V",
21-
at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;getStack(I)Lnet/minecraft/item/ItemStack;"),
22-
locals = LocalCapture.CAPTURE_FAILEXCEPTION
23-
)
24-
private static void ledgerTrackContainerBreakRemove(World world, double x, double y, double z, Inventory inventory, CallbackInfo ci, int i) {
25-
ItemStack stack = inventory.getStack(i);
25+
at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;getStack(I)Lnet/minecraft/item/ItemStack;"))
26+
private static void ledgerTrackContainerBreakRemove(Args args, World world, double x, double y, double z, Inventory inventory) {
27+
ItemStack stack = inventory.getStack(args.get(0));
2628

2729
if (!stack.isEmpty() && inventory instanceof LocationalInventory locationalInventory) {
2830
ItemRemoveCallback.EVENT.invoker().remove(stack, locationalInventory.getLocation(), (ServerWorld) world, Sources.BROKE, null);
2931
}
3032
}
31-
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.github.quiltservertools.ledger.mixin;
2+
3+
import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback;
4+
import com.github.quiltservertools.ledger.utility.Sources;
5+
import net.minecraft.block.BlockState;
6+
import net.minecraft.item.ItemUsageContext;
7+
import net.minecraft.item.MusicDiscItem;
8+
import net.minecraft.util.ActionResult;
9+
import net.minecraft.util.math.BlockPos;
10+
import net.minecraft.world.World;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.Inject;
14+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
15+
16+
import static net.minecraft.block.JukeboxBlock.HAS_RECORD;
17+
18+
19+
@Mixin(MusicDiscItem.class)
20+
public abstract class MusicDiscItemMixin {
21+
22+
@Inject(method = "useOnBlock", at = @At(value = "INVOKE",
23+
target = "Lnet/minecraft/block/JukeboxBlock;setRecord(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/item/ItemStack;)V"))
24+
public void ledgerPlayerInsertMusicDisc(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
25+
World world = context.getWorld();
26+
BlockPos pos = context.getBlockPos();
27+
BlockState blockState = world.getBlockState(pos);
28+
29+
BlockChangeCallback.EVENT.invoker().changeBlock(
30+
world,
31+
pos,
32+
blockState.with(HAS_RECORD, false),
33+
blockState,
34+
null,
35+
world.getBlockEntity(pos),
36+
Sources.INTERACT,
37+
context.getPlayer());
38+
}
39+
}

src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantPartBlockMixin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
44
import com.github.quiltservertools.ledger.utility.Sources;
5-
import java.util.Random;
65
import net.minecraft.block.AbstractPlantPartBlock;
76
import net.minecraft.block.BlockState;
87
import net.minecraft.server.world.ServerWorld;
@@ -12,6 +11,8 @@
1211
import org.spongepowered.asm.mixin.injection.Inject;
1312
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1413

14+
import java.util.Random;
15+
1516
@Mixin(AbstractPlantPartBlock.class)
1617
public abstract class AbstractPlantPartBlockMixin {
1718
@Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))

src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantStemBlockMixin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback;
44
import com.github.quiltservertools.ledger.utility.Sources;
5-
import java.util.Random;
65
import net.minecraft.block.AbstractPlantStemBlock;
76
import net.minecraft.block.BlockState;
87
import net.minecraft.server.world.ServerWorld;
@@ -12,6 +11,8 @@
1211
import org.spongepowered.asm.mixin.injection.ModifyArgs;
1312
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
1413

14+
import java.util.Random;
15+
1516
@Mixin(AbstractPlantStemBlock.class)
1617
public abstract class AbstractPlantStemBlockMixin {
1718
@ModifyArgs(method = "grow", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))

src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooBlockMixin.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback;
44
import com.github.quiltservertools.ledger.utility.Sources;
5-
import java.util.Random;
65
import net.minecraft.block.BambooBlock;
76
import net.minecraft.block.BlockState;
87
import net.minecraft.server.world.ServerWorld;
@@ -12,6 +11,8 @@
1211
import org.spongepowered.asm.mixin.injection.Inject;
1312
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1413

14+
import java.util.Random;
15+
1516
@Mixin(BambooBlock.class)
1617
public abstract class BambooBlockMixin {
1718
@Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))

0 commit comments

Comments
 (0)