diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 109814e8..504dce9e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,4 +38,3 @@ jobs: files: | build/libs/!(*-@(dev-all|sources|javadoc)).jar - build/libs/*-@(dev-all|sources|javadocs).jar diff --git a/gradle.properties b/gradle.properties index 92c8259a..b03ec233 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx2G # Mod Properties -modVersion = 1.3.5 +modVersion = 1.3.6 mavenGroup = com.github.quiltservertools modId = ledger modName = Ledger diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b82aa23a..9355b415 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/libs.versions.toml b/libs.versions.toml index 5836b88c..26ab10aa 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,17 +1,17 @@ [versions] -minecraft = "1.21" -yarn-mappings = "1.21+build.1" -fabric-loader = "0.15.11" +minecraft = "1.21.3" +yarn-mappings = "1.21.3+build.2" +fabric-loader = "0.16.8" -fabric-api = "0.100.1+1.21" +fabric-api = "0.107.0+1.21.3" # Kotlin kotlin = "2.0.0" # Also modrinth version in gradle.properties fabric-kotlin = "1.11.0+kotlin.2.0.0" -fabric-permissions = "0.3.1" -translations = "2.3.1+1.21-pre2" +fabric-permissions = "0.3.3" +translations = "2.4.0+1.21.2-rc1" exposed = "0.46.0" sqlite-jdbc = "3.44.1.0" @@ -48,7 +48,7 @@ wdmcf = { module = "me.bymartrixx:wdmcf", version.ref = "wdmcf" } [plugins] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detect" } -loom = { id = "fabric-loom", version = "1.6.+" } +loom = { id = "fabric-loom", version = "1.7.+" } git_hooks = { id = "com.github.jakemarsden.git-hooks", version = "0.0.2" } # https://github.com/johnrengelman/shadow/issues/894 shadow = { id = "io.github.goooler.shadow", version = "8.1.7" } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java index eeb6518d..3ebc620d 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java @@ -3,32 +3,31 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.PlayerCausable; import com.github.quiltservertools.ledger.utility.Sources; +import java.util.function.BiConsumer; import net.minecraft.block.AbstractBlock; import net.minecraft.block.BlockState; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; import net.minecraft.world.explosion.Explosion; 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 java.util.function.BiConsumer; - @Mixin(AbstractBlock.class) public abstract class AbstractBlockMixin { @Inject( method = "onExploded", at = @At( - value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z" + value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z" ) ) - private void ledgerBlockExplodeCallback(BlockState blockState, World world, BlockPos blockPos, Explosion explosion, BiConsumer biConsumer, CallbackInfo ci) { + private void ledgerBlockExplodeCallback(BlockState state, ServerWorld world, BlockPos pos, Explosion explosion, BiConsumer stackMerger, CallbackInfo ci) { LivingEntity entity; if (explosion.getCausingEntity() instanceof PlayerCausable playerCausable && playerCausable.getCausingPlayer() != null) { entity = playerCausable.getCausingPlayer(); @@ -45,9 +44,9 @@ private void ledgerBlockExplodeCallback(BlockState blockState, World world, Bloc BlockBreakCallback.EVENT.invoker().breakBlock( world, - blockPos, - blockState, - world.getBlockEntity(blockPos) != null ? world.getBlockEntity(blockPos) : null, + pos, + state, + world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null, source, entity instanceof PlayerEntity player ? player : null ); 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 7f1870b0..77957150 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java @@ -23,7 +23,10 @@ public BlockItemMixin(Settings settings) { @Inject( method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", - at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ActionResult;success(Z)Lnet/minecraft/util/ActionResult;") + at = @At( + value = "FIELD", + target = "Lnet/minecraft/util/ActionResult;SUCCESS:Lnet/minecraft/util/ActionResult$Success;" + ) ) public void ledgerPlayerPlaceBlockCallback(ItemPlacementContext context, CallbackInfoReturnable cir) { World world = context.getWorld(); 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/BucketItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/BucketItemMixin.java index c335a9c0..a8d446ba 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BucketItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BucketItemMixin.java @@ -10,9 +10,8 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.fluid.Fluid; import net.minecraft.item.BucketItem; -import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -73,7 +72,7 @@ private void logWaterlog(PlayerEntity player, World world, BlockPos pos, BlockHi } @Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/stat/Stat;)V", ordinal = 0)) - private void logFluidPickup(World world, PlayerEntity player, Hand hand, CallbackInfoReturnable> cir, @Local(ordinal = 0) BlockPos pos, @Local BlockState blockState) { + private void logFluidPickup(World world, PlayerEntity player, Hand hand, CallbackInfoReturnable cir, @Local(ordinal = 0) BlockPos pos, @Local BlockState blockState) { if (blockState.getBlock() instanceof Waterloggable) { BlockChangeCallback.EVENT.invoker().changeBlock( world, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/CampfireBlockEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/CampfireBlockEntityMixin.java index 44691d92..51909477 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/CampfireBlockEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/CampfireBlockEntityMixin.java @@ -4,8 +4,11 @@ import com.github.quiltservertools.ledger.utility.Sources; import net.minecraft.block.BlockState; import net.minecraft.block.entity.CampfireBlockEntity; +import net.minecraft.recipe.CampfireCookingRecipe; +import net.minecraft.recipe.ServerRecipeManager; +import net.minecraft.recipe.input.SingleStackRecipeInput; +import net.minecraft.server.world.ServerWorld; 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; @@ -16,7 +19,7 @@ public abstract class CampfireBlockEntityMixin { @Inject(method = "litServerTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ItemScatterer;spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) - private static void logCampfireRemoveItem(World world, BlockPos pos, BlockState state, CampfireBlockEntity campfire, CallbackInfo ci) { + private static void logCampfireRemoveItem(ServerWorld world, BlockPos pos, BlockState state, CampfireBlockEntity campfire, ServerRecipeManager.MatchGetter matchGetter, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, world.getBlockState(pos), campfire, world.getBlockEntity(pos), Sources.REMOVE); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionImplMixin.java similarity index 77% rename from src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionImplMixin.java index e71e42e4..52cf4d4b 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionImplMixin.java @@ -4,16 +4,16 @@ import com.github.quiltservertools.ledger.utility.PlayerCausable; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import it.unimi.dsi.fastutil.objects.ObjectListIterator; +import java.util.List; import net.minecraft.block.AbstractFireBlock; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.registry.Registries; +import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.explosion.Explosion; +import net.minecraft.world.explosion.ExplosionImpl; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -22,11 +22,11 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(Explosion.class) -public abstract class ExplosionMixin { +@Mixin(ExplosionImpl.class) +public abstract class ExplosionImplMixin { @Shadow @Final - private World world; + private ServerWorld world; @Shadow public abstract @Nullable LivingEntity getCausingEntity(); @@ -37,14 +37,13 @@ public abstract class ExplosionMixin { private Entity entity; @Inject( - method = "affectWorld", + method = "createFire", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z" + target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z" ) ) - private void ledgerExplosionFireCallback(boolean particles, CallbackInfo ci, - @Local ObjectListIterator affectedBlocks, @Local BlockPos blockPos) { + private void ledgerExplosionFireCallback(List positions, CallbackInfo ci, @Local BlockPos blockPos) { BlockState blockState = AbstractFireBlock.getState(world, blockPos); LivingEntity entity; diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java index accd681e..eefee657 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java @@ -6,7 +6,7 @@ import net.minecraft.component.type.JukeboxPlayableComponent; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; -import net.minecraft.util.ItemActionResult; +import net.minecraft.util.ActionResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -22,7 +22,7 @@ public abstract class JukeboxPlayableComponentMixin { @Inject(method = "tryPlayStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/JukeboxBlockEntity;setStack(Lnet/minecraft/item/ItemStack;)V")) - private static void ledgerPlayerInsertMusicDisc(World world, BlockPos pos, ItemStack itemStack, PlayerEntity player, CallbackInfoReturnable cir) { + private static void ledgerPlayerInsertMusicDisc(World world, BlockPos pos, ItemStack itemStack, PlayerEntity player, CallbackInfoReturnable cir) { BlockState blockState = world.getBlockState(pos); BlockChangeCallback.EVENT.invoker().changeBlock( 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/blocks/CakeBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CakeBlockMixin.java index c78dc1f6..d116adac 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CakeBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CakeBlockMixin.java @@ -9,7 +9,6 @@ import net.minecraft.state.property.IntProperty; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -62,7 +61,7 @@ private static void ledgerLogCakeEatAndRemove( target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER)) private void ledgerLogCakeAddCandle( - ItemStack itemStack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable cir) { + ItemStack itemStack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock( player.getWorld(), pos, 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 09e62653..98b5daed 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 @@ -11,8 +11,8 @@ import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.item.ItemStack; import net.minecraft.state.property.BooleanProperty; +import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; -import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -35,7 +35,7 @@ public abstract class CampfireBlockMixin { @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/util/Identifier;)V") ) - public void logCampfireAddItem(ItemStack itemStack, BlockState blockState, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable cir, @Local BlockEntity oldBlockEntity) { + public void logCampfireAddItem(ItemStack itemStack, BlockState blockState, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult blockHitResult, CallbackInfoReturnable cir, @Local BlockEntity oldBlockEntity) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, world.getBlockState(pos), oldBlockEntity, world.getBlockEntity(pos), Sources.INSERT, player); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DoorBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DoorBlockMixin.java index 72e07366..2c627b56 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DoorBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DoorBlockMixin.java @@ -11,6 +11,7 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.block.WireOrientation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -31,7 +32,7 @@ public void logDoorInteraction(BlockState state, World world, BlockPos pos, Play } @Inject(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logRedstoneDoorInteraction(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify, CallbackInfo ci) { + public void logRedstoneDoorInteraction(BlockState state, World world, BlockPos pos, Block sourceBlock, WireOrientation wireOrientation, boolean notify, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, state.cycle(OPEN), null, null, Sources.REDSTONE); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FenceGateBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FenceGateBlockMixin.java index 5fb7f3fd..206dc4a3 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FenceGateBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FenceGateBlockMixin.java @@ -11,6 +11,7 @@ import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.block.WireOrientation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -31,7 +32,7 @@ public void logFenceGateInteraction(BlockState state, World world, BlockPos pos, } @Inject(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logRedstoneFenceGateInteraction(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify, CallbackInfo ci) { + public void logRedstoneFenceGateInteraction(BlockState state, World world, BlockPos pos, Block sourceBlock, WireOrientation wireOrientation, boolean notify, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, state.cycle(OPEN), null, null, Sources.REDSTONE); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LilyPadBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LilyPadBlockMixin.java index b1f101fb..dce70b01 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LilyPadBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LilyPadBlockMixin.java @@ -6,7 +6,7 @@ import net.minecraft.block.LilyPadBlock; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.BoatEntity; +import net.minecraft.entity.vehicle.AbstractBoatEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -18,7 +18,7 @@ public abstract class LilyPadBlockMixin { @Inject(method = "onEntityCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z")) private void ledgerLogLilyPadBreak(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) { - BoatEntity boat = (BoatEntity) entity; + AbstractBoatEntity boat = (AbstractBoatEntity) entity; if (boat.getFirstPassenger() instanceof PlayerEntity player) { BlockBreakCallback.EVENT.invoker().breakBlock(world, new BlockPos(pos), state, null, Sources.VEHICLE, player); } else { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapdoorBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapdoorBlockMixin.java index f14af511..d2047f48 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapdoorBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapdoorBlockMixin.java @@ -9,6 +9,7 @@ import net.minecraft.state.property.BooleanProperty; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraft.world.block.WireOrientation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -28,7 +29,7 @@ public void logTrapdoorInteraction(BlockState state, World world, BlockPos pos, } @Inject(method = "neighborUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logTrapdoorRedstoneInteraction(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify, CallbackInfo ci) { + public void logTrapdoorRedstoneInteraction(BlockState state, World world, BlockPos pos, Block sourceBlock, WireOrientation wireOrientation, boolean notify, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, state.cycle(OPEN), null, null, Sources.REDSTONE); } } 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 340a0ea1..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;)Lnet/minecraft/world/explosion/Explosion;")) - 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/PlayerEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerEntityMixin.java similarity index 63% rename from src/main/java/com/github/quiltservertools/ledger/mixin/entities/PlayerEntityMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerEntityMixin.java index f121a672..1770b0da 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/PlayerEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerEntityMixin.java @@ -1,19 +1,20 @@ package com.github.quiltservertools.ledger.mixin.entities; import com.github.quiltservertools.ledger.callbacks.ItemDropCallback; +import com.llamalad7.mixinextras.sugar.Local; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; 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; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin { - @Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setPickupDelay(I)V"), locals = LocalCapture.CAPTURE_FAILEXCEPTION) - private void logPlayerItemDrop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable cir, double d, ItemEntity itemEntity) { +@Mixin(ServerPlayerEntity.class) +public abstract class ServerPlayerEntityMixin { + @Inject(method = "dropPlayerItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setPickupDelay(I)V")) + private void logPlayerItemDrop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable cir, @Local ItemEntity itemEntity) { PlayerEntity player = (PlayerEntity) (Object) this; ItemDropCallback.EVENT.invoker().drop(itemEntity, player); } 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 360f7e15..34bf7844 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt @@ -8,7 +8,6 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException 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 @@ -26,7 +25,7 @@ class EntityChangeActionType : AbstractActionType() { override fun getTranslationType(): String { val item = getStack(DynamicRegistryManager.EMPTY).item - return if (item is BlockItem && item !is AliasedBlockItem) { + return if (item is BlockItem) { "block" } else { "item" @@ -68,7 +67,7 @@ class EntityChangeActionType : AbstractActionType() { text.append(Text.literal(" ").append(Text.translatable("text.ledger.action_message.with")).append(" ")) text.append( Text.translatable( - stack.translationKey + stack.item.translationKey ).setStyle(TextColorPallet.secondaryVariant).styled { it.withHoverEvent( HoverEvent( 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 a0924f88..6a99d681 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt @@ -5,6 +5,7 @@ import com.github.quiltservertools.ledger.utility.UUID import com.github.quiltservertools.ledger.utility.getWorld import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity +import net.minecraft.entity.SpawnReason import net.minecraft.nbt.StringNbtReader import net.minecraft.registry.Registries import net.minecraft.server.MinecraftServer @@ -20,10 +21,10 @@ 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) as LivingEntity?)!! + val entity: LivingEntity = (entityType.get().create(world, SpawnReason.COMMAND) as LivingEntity?)!! entity.readNbt(StringNbtReader.parse(extraData)) entity.health = entity.defaultMaxHealth.toFloat() entity.velocity = Vec3d.ZERO @@ -51,9 +52,9 @@ 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)!! + val entity = entityType.get().create(world, SpawnReason.COMMAND)!! entity.readNbt(StringNbtReader.parse(extraData)) entity.velocity = Vec3d.ZERO entity.fireTicks = 0 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..9073733f 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt @@ -15,29 +15,19 @@ 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 -import net.minecraft.registry.Registries import net.minecraft.server.MinecraftServer import net.minecraft.server.command.ServerCommandSource import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.server.world.ServerWorld import net.minecraft.text.HoverEvent import net.minecraft.text.Text -import net.minecraft.util.Util 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) { - "block" - } else { - "item" - } - } + // Not used + override fun getTranslationType(): String = "item" private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties( extraData, @@ -49,12 +39,7 @@ abstract class ItemChangeActionType : AbstractActionType() { val stack = getStack(source.server) return "${stack.count} ".literal().append( - Text.translatable( - Util.createTranslationKey( - getTranslationType(), - objectIdentifier - ) - ) + stack.itemName ).setStyle(TextColorPallet.secondaryVariant).styled { it.withHoverEvent( HoverEvent( 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..6f939707 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt @@ -8,27 +8,18 @@ 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 import net.minecraft.server.MinecraftServer import net.minecraft.server.command.ServerCommandSource import net.minecraft.text.HoverEvent import net.minecraft.text.Text -import net.minecraft.util.Util +// TODO remove duplication from ItemPickUpActionType and ItemDropActionType open class ItemDropActionType : AbstractActionType() { override val identifier = "item-drop" - override fun getTranslationType(): String { - val item = Registries.ITEM.get(objectIdentifier) - return if (item is BlockItem && item !is AliasedBlockItem) { - "block" - } else { - "item" - } - } + // Not used + override fun getTranslationType(): String = "item" private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties( extraData, @@ -40,12 +31,7 @@ open class ItemDropActionType : AbstractActionType() { val stack = getStack(source.server) return "${stack.count} ".literal().append( - Text.translatable( - Util.createTranslationKey( - getTranslationType(), - objectIdentifier - ) - ) + stack.itemName ).setStyle(TextColorPallet.secondaryVariant).styled { it.withHoverEvent( HoverEvent( 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..075ca8f4 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt @@ -8,27 +8,17 @@ 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 import net.minecraft.server.MinecraftServer import net.minecraft.server.command.ServerCommandSource import net.minecraft.text.HoverEvent import net.minecraft.text.Text -import net.minecraft.util.Util open class ItemPickUpActionType : AbstractActionType() { override val identifier = "item-pick-up" - override fun getTranslationType(): String { - val item = Registries.ITEM.get(objectIdentifier) - return if (item is BlockItem && item !is AliasedBlockItem) { - "block" - } else { - "item" - } - } + // Not used + override fun getTranslationType(): String = "item" private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties( extraData, @@ -40,12 +30,7 @@ open class ItemPickUpActionType : AbstractActionType() { val stack = getStack(source.server) return "${stack.count} ".literal().append( - Text.translatable( - Util.createTranslationKey( - getTranslationType(), - objectIdentifier - ) - ) + stack.itemName ).setStyle(TextColorPallet.secondaryVariant).styled { it.withHoverEvent( HoverEvent( 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 a5af6aad..09f831a9 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, @@ -248,7 +254,7 @@ object ActionFactory { action.oldObjectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) if (itemStack != null) { - action.extraData = itemStack.encode(world.registryManager)?.asString() + action.extraData = itemStack.toNbtAllowEmpty(world.registryManager)?.asString() } action.oldObjectState = oldEntityTags.asString() action.objectState = entity.writeNbt(NbtCompound())?.asString() diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ObjectParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ObjectParameter.kt index a7772a33..1952660a 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ObjectParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ObjectParameter.kt @@ -54,9 +54,9 @@ class ObjectParameter : SimpleParameter>() { return if (builder.remaining.startsWith("#")) { CommandSource.suggestIdentifiers( mutableListOf().apply { - addAll(Registries.BLOCK.streamTags().map { it.id }.toList()) - addAll(Registries.ITEM.streamTags().map { it.id }.toList()) - addAll(Registries.ENTITY_TYPE.streamTags().map { it.id }.toList()) + addAll(Registries.BLOCK.streamTags().map { it.tag.id }.toList()) + addAll(Registries.ITEM.streamTags().map { it.tag.id }.toList()) + addAll(Registries.ENTITY_TYPE.streamTags().map { it.tag.id }.toList()) }, builder.createOffset(builder.start + 1) ) 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 4fc652b9..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) + 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..82712b4f 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.network.ServerPlayerEntity import net.minecraft.util.ActionResult import net.minecraft.util.Hand import net.minecraft.util.hit.BlockHitResult @@ -49,11 +50,10 @@ private fun onUseBlock( hand: Hand, blockHitResult: BlockHitResult ): ActionResult { - if (player.isInspecting() && hand == Hand.MAIN_HAND) { + if (player is ServerPlayerEntity && player.isInspecting() && hand == Hand.MAIN_HAND) { player.commandSource.inspectBlock(blockHitResult.blockPos.offset(blockHitResult.side)) return ActionResult.SUCCESS } - return ActionResult.PASS } @@ -64,13 +64,10 @@ private fun onBlockAttack( pos: BlockPos, direction: Direction ): ActionResult { - if (world.isClient) return ActionResult.PASS - - if (player.isInspecting()) { + if (player is ServerPlayerEntity && player.isInspecting()) { player.commandSource.inspectBlock(pos) return ActionResult.SUCCESS } - return ActionResult.PASS } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/SearchC2SPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/SearchC2SPacket.kt index 23a82d11..5723a08b 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/SearchC2SPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/SearchC2SPacket.kt @@ -10,7 +10,6 @@ import com.github.quiltservertools.ledger.network.packet.response.ResponseConten import com.github.quiltservertools.ledger.network.packet.response.ResponseS2CPacket import com.github.quiltservertools.ledger.utility.MessageUtils import com.github.quiltservertools.ledger.utility.TextColorPallet -import com.github.quiltservertools.ledger.utility.launchMain import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking 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 097c0c2e..138c9d83 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt @@ -15,6 +15,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 @@ -134,8 +135,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 e0ba58be..f5110fbe 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/fabric.mod.json b/src/main/resources/fabric.mod.json index 567ca7d4..b008499e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,10 +26,10 @@ "ledger.mixins.json" ], "depends": { - "fabricloader": ">=0.15.10", + "fabricloader": ">=0.16.2", "fabric": ">=${fabricApi}", "fabric-language-kotlin": ">=${fabricKotlin}", - "minecraft": ">=${minecraft}" + "minecraft": ">=1.21.2" }, "breaks": { "cardboard": "*" diff --git a/src/main/resources/ledger.mixins.json b/src/main/resources/ledger.mixins.json index 3707605d..f9077a96 100644 --- a/src/main/resources/ledger.mixins.json +++ b/src/main/resources/ledger.mixins.json @@ -12,7 +12,7 @@ "CampfireBlockEntityMixin", "DoubleInventoryMixin", "DyeItemMixin", - "ExplosionMixin", + "ExplosionImplMixin", "FillCommandMixin", "FlintAndSteelItemMixin", "FrostWalkerEnchantmentMixin", @@ -84,11 +84,11 @@ "entities.ItemFrameEntityMixin", "entities.LightningEntityMixin", "entities.LivingEntityMixin", - "entities.PlayerEntityMixin", + "entities.ServerPlayerEntityMixin", "entities.RavagerEntityMixin", "entities.SheepEntityMixin", "entities.SnowGolemEntityMixin", - "entities.VillagerEntityMixin", + "entities.MobEntityMixin", "entities.WolfEntityMixin", "entities.silverfish.CallForHelpGoalMixin", "entities.silverfish.WanderAndInfestGoalMixin",