diff --git a/libs.versions.toml b/libs.versions.toml index 87d332c3..bbba01bf 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,9 +1,9 @@ [versions] -minecraft = "24w34a" -yarn-mappings = "24w34a+build.3" -fabric-loader = "0.16.2" +minecraft = "24w39a" +yarn-mappings = "24w39a+build.8" +fabric-loader = "0.16.5" -fabric-api = "0.102.3+1.21.2" +fabric-api = "0.105.1+1.21.2" # Kotlin kotlin = "2.0.0" diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java index 2127ea3d..77957150 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java @@ -25,7 +25,7 @@ public BlockItemMixin(Settings settings) { method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", at = @At( value = "FIELD", - target = "Lnet/minecraft/util/ActionResult;SUCCESS_SERVER:Lnet/minecraft/util/ActionResult$Success;" + target = "Lnet/minecraft/util/ActionResult;SUCCESS:Lnet/minecraft/util/ActionResult$Success;" ) ) public void ledgerPlayerPlaceBlockCallback(ItemPlacementContext context, CallbackInfoReturnable cir) { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/BucketDispenserBehaviorMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/BucketDispenserBehaviorMixin.java index e12f6b37..2136813b 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BucketDispenserBehaviorMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BucketDispenserBehaviorMixin.java @@ -15,7 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(targets = "net/minecraft/block/dispenser/DispenserBehavior$16") +@Mixin(targets = "net/minecraft/block/dispenser/DispenserBehavior$13") public abstract class BucketDispenserBehaviorMixin extends ItemDispenserBehavior { @Inject( diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java index f9c1dc56..6cf914f8 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java @@ -16,13 +16,10 @@ @Mixin(NetherPortal.class) public abstract class NetherPortalMixin { - @Shadow - @Final - private WorldAccess world; - @Inject(method = "method_30488", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldAccess;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logPortalPlacement(BlockState state, BlockPos pos, CallbackInfo ci) { - if (this.world instanceof ServerWorld world) { + @Inject(method = "method_64315", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldAccess;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) + private static void logPortalPlacement(WorldAccess worldAccess, BlockState state, BlockPos pos, CallbackInfo ci) { + if (worldAccess instanceof ServerWorld world) { BlockPlaceCallback.EVENT.invoker().place(world, pos.toImmutable(), state, null, Sources.PORTAL); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandEntityMixin.java index 87ebbb6d..a255a2ca 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandEntityMixin.java @@ -44,15 +44,15 @@ private void ledgerArmorStandInteract(PlayerEntity player, EquipmentSlot slot, I } } - @Inject(method = "updateHealth", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;kill()V")) + @Inject(method = "updateHealth", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;kill(Lnet/minecraft/server/world/ServerWorld;)V")) private void ledgerArmorStandKill(ServerWorld world, DamageSource damageSource, float amount, CallbackInfo ci) { LivingEntity entity = (LivingEntity) (Object) this; EntityKillCallback.EVENT.invoker().kill(entity.getWorld(), entity.getBlockPos(), entity, damageSource); } - @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;kill()V")) - private void ledgerArmorStandKill(DamageSource source, float amount, CallbackInfoReturnable cir) { + @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;kill(Lnet/minecraft/server/world/ServerWorld;)V")) + private void ledgerArmorStandKill(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable cir) { LivingEntity entity = (LivingEntity) (Object) this; - EntityKillCallback.EVENT.invoker().kill(entity.getWorld(), entity.getBlockPos(), entity, source); + EntityKillCallback.EVENT.invoker().kill(world, entity.getBlockPos(), entity, source); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalEntityMixin.java index 3056ab2c..5d1cd72a 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalEntityMixin.java @@ -5,6 +5,7 @@ import net.minecraft.entity.decoration.EndCrystalEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.server.world.ServerWorld; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -23,8 +24,8 @@ public PlayerEntity getCausingPlayer() { return causingPlayer; } - @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;createExplosion(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/damage/DamageSource;Lnet/minecraft/world/explosion/ExplosionBehavior;DDDFZLnet/minecraft/world/World$ExplosionSourceType;)V")) - public void correctEndCrystalEntitySource(DamageSource source, float amount, CallbackInfoReturnable cir) { + @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;createExplosion(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/damage/DamageSource;Lnet/minecraft/world/explosion/ExplosionBehavior;DDDFZLnet/minecraft/world/World$ExplosionSourceType;)V")) + public void correctEndCrystalEntitySource(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable cir) { if (source.getSource() instanceof PlayerEntity player) { this.causingPlayer = player; } else if (source.getSource() instanceof ProjectileEntity projectile && projectile.getOwner() instanceof PlayerEntity player) { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonEntityMixin.java index 28c4169c..ec46b718 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonEntityMixin.java @@ -1,7 +1,9 @@ package com.github.quiltservertools.ledger.mixin.entities; import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.entity.boss.dragon.EnderDragonEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.registry.Registries; import net.minecraft.util.math.Box; @@ -14,10 +16,15 @@ @Mixin(EnderDragonEntity.class) public abstract class EnderDragonEntityMixin { - @Inject(method = "destroyBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void logEnderDragonBreakingBlocks(Box box, CallbackInfoReturnable cir, int i, int j, int k, int l, int m, int n, boolean bl, boolean bl2, int o, int p, int q, BlockPos blockPos) { + @Inject( + method = "destroyBlocks", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/world/ServerWorld;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + ) + ) + private void logEnderDragonBreakingBlocks(ServerWorld world, Box box, CallbackInfoReturnable cir, @Local BlockPos blockPos) { EnderDragonEntity entity = (EnderDragonEntity) (Object) this; - World world = entity.getEntityWorld(); BlockBreakCallback.EVENT.invoker().breakBlock(world, blockPos, world.getBlockState(blockPos), world.getBlockEntity(blockPos), Registries.ENTITY_TYPE.getId(entity.getType()).getPath()); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameEntityMixin.java index b7b7c5cc..a44c696a 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameEntityMixin.java @@ -9,6 +9,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import org.jetbrains.annotations.Nullable; @@ -35,7 +36,7 @@ private void ledgerLogOldEntity(PlayerEntity player, Hand hand, CallbackInfoRetu } @Inject(method = "dropHeldStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setHeldItemStack(Lnet/minecraft/item/ItemStack;)V")) - private void ledgerLogOldEntity2(@Nullable Entity entityActor, boolean alwaysDrop, CallbackInfo ci) { + private void ledgerLogOldEntity2(ServerWorld world, Entity entityActor, boolean dropSelf, CallbackInfo ci) { if (entityActor == null) { return; } @@ -51,7 +52,7 @@ private void ledgerItemFrameEquip(PlayerEntity player, Hand hand, CallbackInfoRe } @Inject(method = "dropHeldStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setHeldItemStack(Lnet/minecraft/item/ItemStack;)V")) - private void ledgerItemFrameRemove(@Nullable Entity entityActor, boolean alwaysDrop, CallbackInfo ci) { + private void ledgerItemFrameRemove(ServerWorld world, Entity entityActor, boolean dropSelf, CallbackInfo ci) { ItemStack entityStack = this.getHeldItemStack(); if (entityStack.isEmpty() || entityActor == null) { return; @@ -66,8 +67,8 @@ private void ledgerItemFrameRotate(PlayerEntity player, Hand hand, CallbackInfoR EntityModifyCallback.EVENT.invoker().modify(player.getWorld(), entity.getBlockPos(), oldEntityTags, entity, null, player, Sources.ROTATE); } - @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/AbstractDecorationEntity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z")) - private void ledgerItemFrameKill(DamageSource source, float amount, CallbackInfoReturnable cir) { + @Inject(method = "damage", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/AbstractDecorationEntity;damage(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/entity/damage/DamageSource;F)Z")) + private void ledgerItemFrameKill(ServerWorld world, DamageSource source, float amount, CallbackInfoReturnable cir) { Entity entity = (Entity) (Object) this; EntityKillCallback.EVENT.invoker().kill(entity.getWorld(), entity.getBlockPos(), entity, source); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java index 268c10b2..1ab58f67 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java @@ -1,6 +1,7 @@ package com.github.quiltservertools.ledger.mixin.entities; import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.block.BlockState; import net.minecraft.entity.LightningEntity; import net.minecraft.registry.Registries; @@ -13,15 +14,31 @@ @Mixin(LightningEntity.class) public abstract class LightningEntityMixin { - @Inject(method = "spawnFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER, ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void logFirePlacedByLightningBolt(int spreadAttempts, CallbackInfo ci, BlockPos blockPos, BlockState blockState) { + @Inject( + method = "spawnFire", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", + ordinal = 0, + shift = At.Shift.AFTER + ) + ) + private void logFirePlacedByLightningBolt(int spreadAttempts, CallbackInfo ci, @Local BlockPos blockPos, @Local BlockState blockState) { LightningEntity entity = (LightningEntity) (Object) this; BlockPlaceCallback.EVENT.invoker().place(entity.getEntityWorld(), blockPos, blockState, null, Registries.ENTITY_TYPE.getId(entity.getType()).getPath()); } - @Inject(method = "spawnFire", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER, ordinal = 1), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void logFirePlacedByLightningBolt(int spreadAttempts, CallbackInfo ci, BlockPos blockPos, BlockState blockState, int i, BlockPos blockPos2) { + @Inject( + method = "spawnFire", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", + ordinal = 1, + shift = At.Shift.AFTER + ) + ) + private void logFirePlacedByLightningBoltSpread(int spreadAttempts, CallbackInfo ci, @Local(ordinal = 1) BlockPos blockPos, @Local BlockState blockState) { LightningEntity entity = (LightningEntity) (Object) this; - BlockPlaceCallback.EVENT.invoker().place(entity.getEntityWorld(), blockPos2, blockState, null, Registries.ENTITY_TYPE.getId(entity.getType()).getPath()); + BlockPlaceCallback.EVENT.invoker().place(entity.getEntityWorld(), blockPos, blockState, null, Registries.ENTITY_TYPE.getId(entity.getType()).getPath()); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobEntityMixin.java new file mode 100644 index 00000000..17edf2e2 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobEntityMixin.java @@ -0,0 +1,27 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.listeners.EntityCallbackListenerKt; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.SpawnReason; +import net.minecraft.entity.conversion.EntityConversionContext; +import net.minecraft.entity.mob.MobEntity; +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(MobEntity.class) +public abstract class MobEntityMixin { + @Inject( + method = "convertTo(Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/conversion/EntityConversionContext;Lnet/minecraft/entity/SpawnReason;Lnet/minecraft/entity/conversion/EntityConversionContext$Finalizer;)Lnet/minecraft/entity/mob/MobEntity;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/mob/MobEntity;discard()V" + ) + ) + private void ledgerEntityConversion(EntityType entityType, EntityConversionContext context, SpawnReason reason, EntityConversionContext.Finalizer finalizer, CallbackInfoReturnable cir) { + MobEntity entity = (MobEntity) (Object) this; + EntityCallbackListenerKt.onKill(entity.getWorld(), entity.getBlockPos(), entity, Sources.CONVERSION); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerEntityMixin.java index e8339af2..334de335 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerEntityMixin.java @@ -11,7 +11,7 @@ @Mixin(RavagerEntity.class) public abstract class RavagerEntityMixin { - @ModifyArgs(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z")) + @ModifyArgs(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z")) public void logRavagerBreakingLeaves(Args args) { BlockPos pos = args.get(0); var world = ((RavagerEntity) (Object) this).getWorld(); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepEntityMixin.java index 9fffbdad..9b69ef75 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepEntityMixin.java @@ -19,13 +19,13 @@ public abstract class SheepEntityMixin { @Unique private NbtCompound oldEntityTags; - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;sheared(Lnet/minecraft/sound/SoundCategory;)V")) + @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;sheared(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/sound/SoundCategory;Lnet/minecraft/item/ItemStack;)V")) private void ledgerLogOldEntity(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { LivingEntity entity = (LivingEntity) (Object) this; oldEntityTags = entity.writeNbt(new NbtCompound()); } - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;sheared(Lnet/minecraft/sound/SoundCategory;)V", shift = At.Shift.AFTER)) + @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;sheared(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/sound/SoundCategory;Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) private void ledgerSheepWoolShear(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { LivingEntity entity = (LivingEntity) (Object) this; EntityModifyCallback.EVENT.invoker().modify(player.getWorld(), entity.getBlockPos(), oldEntityTags, entity, null, player, Sources.SHEAR); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemEntityMixin.java index 64e4d844..a3a3cacf 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemEntityMixin.java @@ -3,6 +3,7 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; import com.github.quiltservertools.ledger.utility.Sources; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.block.BlockState; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.passive.SnowGolemEntity; @@ -17,25 +18,24 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(SnowGolemEntity.class) public abstract class SnowGolemEntityMixin { @Unique private NbtCompound oldEntityTags; - @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - public void logSnowGolemSnow(CallbackInfo ci, BlockState blockState, int i, int j, int k, int l, BlockPos blockPos) { + @Inject(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER)) + public void logSnowGolemSnow(CallbackInfo ci, @Local BlockState blockState, @Local BlockPos blockPos) { BlockPlaceCallback.EVENT.invoker().place(((LivingEntity) (Object) this).getWorld(), blockPos, blockState, null, Sources.SNOW_GOLEM); } - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SnowGolemEntity;sheared(Lnet/minecraft/sound/SoundCategory;)V")) + @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SnowGolemEntity;sheared(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/sound/SoundCategory;Lnet/minecraft/item/ItemStack;)V")) private void ledgerOldEntity(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { LivingEntity entity = (LivingEntity) (Object) this; oldEntityTags = entity.writeNbt(new NbtCompound()); } - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SnowGolemEntity;sheared(Lnet/minecraft/sound/SoundCategory;)V", shift = At.Shift.AFTER)) + @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SnowGolemEntity;sheared(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/sound/SoundCategory;Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) private void ledgerSnowGolemPumpkinShear(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { LivingEntity entity = (LivingEntity) (Object) this; EntityModifyCallback.EVENT.invoker().modify(player.getWorld(), entity.getBlockPos(), oldEntityTags, entity, null, player, Sources.SHEAR); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/VillagerEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/VillagerEntityMixin.java deleted file mode 100644 index cc5fbf8a..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/VillagerEntityMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.EntityKillCallback; -import net.minecraft.entity.LightningEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.VillagerEntity; -import net.minecraft.server.world.ServerWorld; -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; - -@Mixin(VillagerEntity.class) -public abstract class VillagerEntityMixin { - @Inject(method = "onStruckByLightning", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;spawnEntityAndPassengers(Lnet/minecraft/entity/Entity;)V")) - private void ledgerVillagerToWitch(ServerWorld world, LightningEntity lightning, CallbackInfo ci) { - LivingEntity entity = (LivingEntity) (Object) this; - EntityKillCallback.EVENT.invoker().kill(entity.getWorld(), entity.getBlockPos(), entity, world.getDamageSources().lightningBolt()); - } -} diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockChangeActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockChangeActionType.kt index 33f44578..d45151e9 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockChangeActionType.kt @@ -6,11 +6,14 @@ import com.github.quiltservertools.ledger.utility.NbtUtils import com.github.quiltservertools.ledger.utility.TextColorPallet import com.github.quiltservertools.ledger.utility.getWorld import com.github.quiltservertools.ledger.utility.literal +import net.minecraft.block.Block import net.minecraft.block.BlockState import net.minecraft.block.Blocks import net.minecraft.nbt.StringNbtReader import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket import net.minecraft.registry.Registries +import net.minecraft.registry.RegistryEntryLookup +import net.minecraft.registry.RegistryKeys import net.minecraft.server.MinecraftServer import net.minecraft.server.command.ServerCommandSource import net.minecraft.server.network.ServerPlayerEntity @@ -24,7 +27,7 @@ open class BlockChangeActionType : AbstractActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - world?.setBlockState(pos, oldBlockState()) + world?.setBlockState(pos, oldBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) world?.getBlockEntity(pos)?.read(StringNbtReader.parse(extraData), server.registryManager) world?.chunkManager?.markForUpdate(pos) @@ -33,7 +36,9 @@ open class BlockChangeActionType : AbstractActionType() { override fun previewRollback(preview: Preview, player: ServerPlayerEntity) { if (player.world.registryKey.value == world) { - player.networkHandler.sendPacket(BlockUpdateS2CPacket(pos, oldBlockState())) + player.networkHandler.sendPacket( + BlockUpdateS2CPacket(pos, oldBlockState(player.world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) + ) preview.positions.add(pos) } } @@ -41,14 +46,16 @@ open class BlockChangeActionType : AbstractActionType() { override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world) - world?.setBlockState(pos, newBlockState()) + world?.setBlockState(pos, newBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) return true } override fun previewRestore(preview: Preview, player: ServerPlayerEntity) { if (player.world.registryKey.value == world) { - player.networkHandler.sendPacket(BlockUpdateS2CPacket(pos, newBlockState())) + player.networkHandler.sendPacket( + BlockUpdateS2CPacket(pos, newBlockState(player.world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) + ) preview.positions.add(pos) } } @@ -93,28 +100,30 @@ open class BlockChangeActionType : AbstractActionType() { return text } - fun oldBlockState() = checkForBlockState( + fun oldBlockState(blockLookup: RegistryEntryLookup) = checkForBlockState( oldObjectIdentifier, oldObjectState?.let { NbtUtils.blockStateFromProperties( StringNbtReader.parse(it), - oldObjectIdentifier + oldObjectIdentifier, + blockLookup ) } ) - fun newBlockState() = checkForBlockState( + fun newBlockState(blockLookup: RegistryEntryLookup) = checkForBlockState( objectIdentifier, objectState?.let { NbtUtils.blockStateFromProperties( StringNbtReader.parse(it), - objectIdentifier + objectIdentifier, + blockLookup ) } ) private fun checkForBlockState(identifier: Identifier, checkState: BlockState?): BlockState { - val block = Registries.BLOCK.getOrEmpty(identifier) + val block = Registries.BLOCK.getOptionalValue(identifier) if (block.isEmpty) { logWarn("Unknown block $identifier") return Blocks.AIR.defaultState diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockPlaceActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockPlaceActionType.kt index c6c0c9d1..cb3bf74a 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockPlaceActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockPlaceActionType.kt @@ -4,6 +4,7 @@ import com.github.quiltservertools.ledger.utility.TextColorPallet import com.github.quiltservertools.ledger.utility.getWorld import com.github.quiltservertools.ledger.utility.literal import net.minecraft.nbt.StringNbtReader +import net.minecraft.registry.RegistryKeys import net.minecraft.server.MinecraftServer import net.minecraft.server.command.ServerCommandSource import net.minecraft.text.HoverEvent @@ -15,21 +16,23 @@ class BlockPlaceActionType : BlockChangeActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - world?.setBlockState(pos, oldBlockState()) + world?.setBlockState(pos, oldBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) - return true + return world != null } override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val state = newBlockState() - world?.setBlockState(pos, state) - if (state.hasBlockEntity()) { - world?.getBlockEntity(pos)?.read(StringNbtReader.parse(extraData), server.registryManager) + if (world != null) { + val state = newBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK)) + world.setBlockState(pos, state) + if (state.hasBlockEntity()) { + world.getBlockEntity(pos)?.read(StringNbtReader.parse(extraData), server.registryManager) + } } - return true + return world != null } override fun getObjectMessage(source: ServerCommandSource): Text = Text.translatable( diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt index 5aa20e77..7be09d35 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt @@ -7,7 +7,6 @@ import com.github.quiltservertools.ledger.utility.literal import net.minecraft.entity.LivingEntity import net.minecraft.entity.decoration.AbstractDecorationEntity import net.minecraft.entity.decoration.ItemFrameEntity -import net.minecraft.item.AliasedBlockItem import net.minecraft.item.BlockItem import net.minecraft.item.ItemStack import net.minecraft.nbt.StringNbtReader @@ -24,7 +23,7 @@ class EntityChangeActionType : AbstractActionType() { override fun getTranslationType(): String { val item = Registries.ITEM.get(Identifier.of(extraData)) - return if (item is BlockItem && item !is AliasedBlockItem) { + return if (item is BlockItem) { "block" } else { "item" diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt index 5012c7df..6a99d681 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt @@ -21,7 +21,7 @@ class EntityKillActionType : AbstractActionType() { override fun previewRollback(preview: Preview, player: ServerPlayerEntity) { val world = player.server.getWorld(world) - val entityType = Registries.ENTITY_TYPE.getOrEmpty(objectIdentifier) + val entityType = Registries.ENTITY_TYPE.getOptionalValue(objectIdentifier) if (entityType.isEmpty) return val entity: LivingEntity = (entityType.get().create(world, SpawnReason.COMMAND) as LivingEntity?)!! @@ -52,7 +52,7 @@ class EntityKillActionType : AbstractActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val entityType = Registries.ENTITY_TYPE.getOrEmpty(objectIdentifier) + val entityType = Registries.ENTITY_TYPE.getOptionalValue(objectIdentifier) if (entityType.isPresent) { val entity = entityType.get().create(world, SpawnReason.COMMAND)!! entity.readNbt(StringNbtReader.parse(extraData)) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt index f4d1e782..bd769989 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt @@ -15,7 +15,6 @@ import net.minecraft.block.LecternBlock import net.minecraft.block.entity.ChestBlockEntity import net.minecraft.block.entity.LecternBlockEntity import net.minecraft.inventory.Inventory -import net.minecraft.item.AliasedBlockItem import net.minecraft.item.BlockItem import net.minecraft.item.ItemStack import net.minecraft.item.Items @@ -32,7 +31,7 @@ import net.minecraft.util.math.BlockPos abstract class ItemChangeActionType : AbstractActionType() { override fun getTranslationType(): String { val item = Registries.ITEM.get(objectIdentifier) - return if (item is BlockItem && item !is AliasedBlockItem) { + return if (item is BlockItem) { "block" } else { "item" diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt index 4c1882df..ab76c865 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt @@ -8,7 +8,6 @@ import com.github.quiltservertools.ledger.utility.literal import net.minecraft.entity.Entity import net.minecraft.entity.EntityType import net.minecraft.entity.ItemEntity -import net.minecraft.item.AliasedBlockItem import net.minecraft.item.BlockItem import net.minecraft.nbt.StringNbtReader import net.minecraft.registry.Registries @@ -23,7 +22,7 @@ open class ItemDropActionType : AbstractActionType() { override fun getTranslationType(): String { val item = Registries.ITEM.get(objectIdentifier) - return if (item is BlockItem && item !is AliasedBlockItem) { + return if (item is BlockItem) { "block" } else { "item" diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt index 69ddd238..64444631 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt @@ -8,7 +8,6 @@ import com.github.quiltservertools.ledger.utility.literal import net.minecraft.entity.Entity import net.minecraft.entity.EntityType import net.minecraft.entity.ItemEntity -import net.minecraft.item.AliasedBlockItem import net.minecraft.item.BlockItem import net.minecraft.nbt.StringNbtReader import net.minecraft.registry.Registries @@ -23,7 +22,7 @@ open class ItemPickUpActionType : AbstractActionType() { override fun getTranslationType(): String { val item = Registries.ITEM.get(objectIdentifier) - return if (item is BlockItem && item !is AliasedBlockItem) { + return if (item is BlockItem) { "block" } else { "item" diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionFactory.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionFactory.kt index 212b8fbe..93a47ab6 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionFactory.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionFactory.kt @@ -193,7 +193,7 @@ object ActionFactory { action.world = world.registryKey.value action.objectIdentifier = Registries.ITEM.getId(stack.item) action.sourceName = source - action.extraData = stack.encode(world.registryManager)?.asString() + action.extraData = stack.toNbtAllowEmpty(world.registryManager)?.asString() } fun entityKillAction(world: World, pos: BlockPos, entity: Entity, cause: DamageSource): EntityKillActionType { @@ -217,6 +217,12 @@ object ActionFactory { return action } + fun entityKillAction(world: World, pos: BlockPos, entity: Entity, source: String): EntityKillActionType { + val action = EntityKillActionType() + setEntityData(action, pos, world, entity, source) + return action + } + private fun setEntityData( action: ActionType, pos: BlockPos, diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/TeleportCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/TeleportCommand.kt index 664bf772..7c08883c 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/TeleportCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/TeleportCommand.kt @@ -32,8 +32,17 @@ object TeleportCommand : BuildableCommand { private fun teleport(context: Context, world: ServerWorld, posArg: PosArgument): Int { val player = context.source.playerOrThrow - val pos = posArg.toAbsolutePos(context.source) - player.teleport(world, pos.x, pos.y, pos.z, player.yaw, player.pitch, true) + val pos = posArg.toAbsoluteBlockPos(context.source) + player.teleport( + world, + pos.x.toDouble(), + pos.y.toDouble(), + pos.z.toDouble(), + emptySet(), + player.yaw, + player.pitch, + true + ) return 1 } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/EntityCallbackListener.kt b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/EntityCallbackListener.kt index 3818d69d..bb11ac21 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/EntityCallbackListener.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/EntityCallbackListener.kt @@ -27,6 +27,17 @@ private fun onKill( ) } +fun onKill( + world: World, + pos: BlockPos, + entity: Entity, + source: String +) { + ActionQueueService.addToQueue( + ActionFactory.entityKillAction(world, pos, entity, source) + ) +} + private fun onModify( world: World, pos: BlockPos, diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/PlayerEventListener.kt b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/PlayerEventListener.kt index 595ad5df..b1685932 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/PlayerEventListener.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/PlayerEventListener.kt @@ -22,6 +22,7 @@ import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.ItemPlacementContext import net.minecraft.server.MinecraftServer import net.minecraft.server.network.ServerPlayNetworkHandler +import net.minecraft.server.world.ServerWorld import net.minecraft.util.ActionResult import net.minecraft.util.Hand import net.minecraft.util.hit.BlockHitResult @@ -50,7 +51,7 @@ private fun onUseBlock( blockHitResult: BlockHitResult ): ActionResult { if (player.isInspecting() && hand == Hand.MAIN_HAND) { - player.commandSource.inspectBlock(blockHitResult.blockPos.offset(blockHitResult.side)) + player.getCommandSource(world as ServerWorld?).inspectBlock(blockHitResult.blockPos.offset(blockHitResult.side)) return ActionResult.SUCCESS } @@ -67,7 +68,7 @@ private fun onBlockAttack( if (world.isClient) return ActionResult.PASS if (player.isInspecting()) { - player.commandSource.inspectBlock(pos) + player.getCommandSource(world as ServerWorld?).inspectBlock(pos) return ActionResult.SUCCESS } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt index b771d3d6..c58c78f3 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt @@ -16,6 +16,7 @@ import net.minecraft.block.enums.ChestType import net.minecraft.block.enums.DoubleBlockHalf import net.minecraft.entity.player.PlayerEntity import net.minecraft.server.command.ServerCommandSource +import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.text.Text import net.minecraft.util.Formatting import net.minecraft.util.math.BlockBox @@ -135,8 +136,8 @@ private fun getOtherBedPart(state: BlockState, pos: BlockPos): BlockPos { } } -suspend fun PlayerEntity.getInspectResults(pos: BlockPos): SearchResults { - val source = this.commandSource +suspend fun ServerPlayerEntity.getInspectResults(pos: BlockPos): SearchResults { + val source = this.getCommandSource(this.serverWorld) val params = ActionSearchParams.build { bounds = BlockBox(pos) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/NbtUtils.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/NbtUtils.kt index 346139f5..d48aea22 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/NbtUtils.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/NbtUtils.kt @@ -1,6 +1,7 @@ package com.github.quiltservertools.ledger.utility import com.mojang.serialization.Dynamic +import net.minecraft.block.Block import net.minecraft.block.BlockState import net.minecraft.datafixer.Schemas import net.minecraft.datafixer.TypeReferences @@ -10,7 +11,7 @@ import net.minecraft.nbt.NbtElement import net.minecraft.nbt.NbtHelper import net.minecraft.nbt.NbtOps import net.minecraft.nbt.StringNbtReader -import net.minecraft.registry.Registries +import net.minecraft.registry.RegistryEntryLookup import net.minecraft.registry.RegistryWrapper import net.minecraft.util.Identifier @@ -37,11 +38,15 @@ object NbtUtils { } } - fun blockStateFromProperties(tag: NbtCompound, name: Identifier): BlockState { + fun blockStateFromProperties( + tag: NbtCompound, + name: Identifier, + blockLookup: RegistryEntryLookup + ): BlockState { val stateTag = NbtCompound() stateTag.putString("Name", name.toString()) stateTag.put(PROPERTIES, tag) - return NbtHelper.toBlockState(Registries.BLOCK.readOnlyWrapper, stateTag) + return NbtHelper.toBlockState(blockLookup, stateTag) } fun itemFromProperties(tag: String?, name: Identifier, registries: RegistryWrapper.WrapperLookup): ItemStack { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/Sources.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/Sources.kt index 1e464082..6d92767e 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/Sources.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/Sources.kt @@ -35,5 +35,6 @@ object Sources { const val SHEAR = "shear" const val DYE = "dye" const val STATUE = "statue" + const val CONVERSION = "conversion" const val UNKNOWN = "unknown" } diff --git a/src/main/resources/ledger.mixins.json b/src/main/resources/ledger.mixins.json index bc4f66d4..f9077a96 100644 --- a/src/main/resources/ledger.mixins.json +++ b/src/main/resources/ledger.mixins.json @@ -88,7 +88,7 @@ "entities.RavagerEntityMixin", "entities.SheepEntityMixin", "entities.SnowGolemEntityMixin", - "entities.VillagerEntityMixin", + "entities.MobEntityMixin", "entities.WolfEntityMixin", "entities.silverfish.CallForHelpGoalMixin", "entities.silverfish.WanderAndInfestGoalMixin",