diff --git a/build.gradle.kts b/build.gradle.kts index 2edf3c96..95be69bf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -60,7 +60,7 @@ dependencies { // Fabric minecraft(libs.minecraft) - mappings(variantOf(libs.yarn.mappings) { classifier("v2") }) + mappings(loom.officialMojangMappings()) modImplementation(libs.fabric.loader) // Fabric API diff --git a/gradle.properties b/gradle.properties index 9ecd8ceb..da19cdb3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ kotlin.code.style=official org.gradle.jvmargs=-Xmx2G # Mod Properties -modVersion = 1.3.17 +modVersion = 1.3.18 mavenGroup = com.github.quiltservertools modId = ledger modName = Ledger diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a84e188..23449a2b 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-9.0.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/libs.versions.toml b/libs.versions.toml index 2aaf440f..e9f5af24 100644 --- a/libs.versions.toml +++ b/libs.versions.toml @@ -1,16 +1,15 @@ [versions] -minecraft = "1.21.10" -yarn-mappings = "1.21.10+build.2" -fabric-loader = "0.17.2" +minecraft = "1.21.11-rc2" +fabric-loader = "0.18.1" -fabric-api = "0.135.0+1.21.10" +fabric-api = "0.139.4+1.21.11" # Kotlin kotlin = "2.2.0" # Also modrinth version in gradle.properties fabric-kotlin = "1.13.4+kotlin.2.2.0" -fabric-permissions = "0.5.0" +fabric-permissions = "0.6.0-patbox" translations = "2.5.2+1.21.9-pre3" exposed = "1.0.0-rc-2" @@ -22,7 +21,6 @@ detekt = "1.23.8" [libraries] minecraft = { module = "net.minecraft:minecraft", version.ref = "minecraft" } -yarn-mappings = { module = "net.fabricmc:yarn", version.ref = "yarn-mappings" } fabric-loader = { module = "net.fabricmc:fabric-loader", version.ref = "fabric-loader" } fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fabric-api" } @@ -45,5 +43,5 @@ detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", [plugins] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } -loom = { id = "fabric-loom", version = "1.11.+" } +loom = { id = "fabric-loom", version = "1.14.+" } git_hooks = { id = "com.github.jakemarsden.git-hooks", version = "0.0.2" } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java deleted file mode 100644 index 3ebc620d..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractBlockMixin.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -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.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; - -@Mixin(AbstractBlock.class) -public abstract class AbstractBlockMixin { - - @Inject( - method = "onExploded", - at = @At( - value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z" - ) - ) - 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(); - } else { - entity = explosion.getCausingEntity(); - } - - String source; - if (explosion.getEntity() != null && !(explosion.getEntity() instanceof PlayerEntity)) { - source = Registries.ENTITY_TYPE.getId(explosion.getEntity().getType()).getPath(); - } else { - source = Sources.EXPLOSION; - } - - BlockBreakCallback.EVENT.invoker().breakBlock( - world, - 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/ScreenHandlerMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractContainerMenuMixin.java similarity index 63% rename from src/main/java/com/github/quiltservertools/ledger/mixin/ScreenHandlerMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/AbstractContainerMenuMixin.java index 1b2d3505..700fbc2b 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ScreenHandlerMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/AbstractContainerMenuMixin.java @@ -10,16 +10,16 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.Registries; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; -import net.minecraft.screen.slot.SlotActionType; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.inventory.ClickType; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; @@ -29,46 +29,46 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(ScreenHandler.class) -public abstract class ScreenHandlerMixin implements HandlerWithContext { +@Mixin(AbstractContainerMenu.class) +public abstract class AbstractContainerMenuMixin implements HandlerWithContext { @Unique Map changedStacks = new HashMap<>(); @Unique - private ServerPlayerEntity player = null; + private ServerPlayer player = null; @Unique private BlockPos pos = null; @Inject(method = "addSlot", at = @At(value = "HEAD")) private void ledgerGiveSlotHandlerReference(Slot slot, CallbackInfoReturnable cir) { - ((HandledSlot) slot).setHandler((ScreenHandler) (Object) this); + ((HandledSlot) slot).setHandler((AbstractContainerMenu) (Object) this); } - @Inject(method = "onButtonClick", at = @At(value = "HEAD")) - private void ledgerButtonClickGetPlayer(PlayerEntity player, int id, CallbackInfoReturnable cir) { - this.player = (ServerPlayerEntity) player; + @Inject(method = "clickMenuButton", at = @At(value = "HEAD")) + private void ledgerButtonClickGetPlayer(Player player, int id, CallbackInfoReturnable cir) { + this.player = (ServerPlayer) player; } - @Inject(method = "internalOnSlotClick", at = @At(value = "HEAD")) - private void internalOnSlotClickGetPlayer(int slotIndex, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { - this.player = (ServerPlayerEntity) player; + @Inject(method = "doClick", at = @At(value = "HEAD")) + private void internalOnSlotClickGetPlayer(int slotIndex, int button, ClickType actionType, Player player, CallbackInfo ci) { + this.player = (ServerPlayer) player; } - @Inject(method = "onSlotClick", at = @At(value = "HEAD")) - private void ledgerSlotClickGetPlayer(int slotIndex, int button, SlotActionType actionType, PlayerEntity player, CallbackInfo ci) { - this.player = (ServerPlayerEntity) player; + @Inject(method = "clicked", at = @At(value = "HEAD")) + private void ledgerSlotClickGetPlayer(int slotIndex, int button, ClickType actionType, Player player, CallbackInfo ci) { + this.player = (ServerPlayer) player; } - @Inject(method = "dropInventory", at = @At(value = "HEAD")) - private void ledgerDropInventoryGetPlayer(PlayerEntity player, Inventory inventory, CallbackInfo ci) { - this.player = (ServerPlayerEntity) player; + @Inject(method = "clearContainer", at = @At(value = "HEAD")) + private void ledgerDropInventoryGetPlayer(Player player, Container inventory, CallbackInfo ci) { + this.player = (ServerPlayer) player; } - @Inject(method = "onClosed", at = @At(value = "RETURN")) - private void ledgerCloseScreenLogChanges(PlayerEntity player, CallbackInfo ci) { - if (!player.getEntityWorld().isClient() && pos != null) { + @Inject(method = "removed", at = @At(value = "RETURN")) + private void ledgerCloseScreenLogChanges(Player player, CallbackInfo ci) { + if (!player.level().isClientSide() && pos != null) { for (var pair : changedStacks.keySet()) { - ItemStack stack = new ItemStack(Registries.ITEM.getEntry(pair.getItem()), 1, pair.getChanges()); + ItemStack stack = new ItemStack(BuiltInRegistries.ITEM.wrapAsHolder(pair.getItem()), 1, pair.getChanges()); if (stack.isEmpty()) { continue; } @@ -76,17 +76,17 @@ private void ledgerCloseScreenLogChanges(PlayerEntity player, CallbackInfo ci) { int countAbs = Math.abs(count); List splitStacks = new ArrayList<>(); while (countAbs > 0) { - ItemStack addStack = stack.copyWithCount(Math.min(countAbs, stack.getMaxCount())); + ItemStack addStack = stack.copyWithCount(Math.min(countAbs, stack.getMaxStackSize())); splitStacks.add(addStack); countAbs -= addStack.getCount(); } if (count > 0) { for (ItemStack splitStack : splitStacks) { - ItemInsertCallback.EVENT.invoker().insert(splitStack, pos, (ServerWorld) player.getEntityWorld(), Sources.PLAYER, (ServerPlayerEntity) player); + ItemInsertCallback.EVENT.invoker().insert(splitStack, pos, (ServerLevel) player.level(), Sources.PLAYER, (ServerPlayer) player); } } else { for (ItemStack splitStack : splitStacks) { - ItemRemoveCallback.EVENT.invoker().remove(splitStack, pos, (ServerWorld) player.getEntityWorld(), Sources.PLAYER, (ServerPlayerEntity) player); + ItemRemoveCallback.EVENT.invoker().remove(splitStack, pos, (ServerLevel) player.level(), Sources.PLAYER, (ServerPlayer) player); } } } @@ -95,7 +95,7 @@ private void ledgerCloseScreenLogChanges(PlayerEntity player, CallbackInfo ci) { @Nullable @Override - public ServerPlayerEntity getPlayer() { + public ServerPlayer getPlayer() { return player; } @@ -114,7 +114,7 @@ public void setPos(@NotNull BlockPos pos) { public void onStackChanged(@NotNull ItemStack old, @NotNull ItemStack itemStack, @NotNull BlockPos pos) { if (old.isEmpty() && !itemStack.isEmpty()) { // Add item - var key = new ItemData(itemStack.getItem(), itemStack.getComponentChanges()); + var key = new ItemData(itemStack.getItem(), itemStack.getComponentsPatch()); if (changedStacks.containsKey(key)) { changedStacks.put(key, changedStacks.get(key) + itemStack.getCount()); } else { @@ -122,7 +122,7 @@ public void onStackChanged(@NotNull ItemStack old, @NotNull ItemStack itemStack, } } else if (!old.isEmpty() && itemStack.isEmpty()) { // Remove item - var key = new ItemData(old.getItem(), old.getComponentChanges()); + var key = new ItemData(old.getItem(), old.getComponentsPatch()); if (changedStacks.containsKey(key)) { changedStacks.put(key, changedStacks.get(key) - old.getCount()); } else { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/AnvilScreenHandlerMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/AnvilMenuMixin.java similarity index 63% rename from src/main/java/com/github/quiltservertools/ledger/mixin/AnvilScreenHandlerMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/AnvilMenuMixin.java index d4c9b0fc..8bd9ad1d 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/AnvilScreenHandlerMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/AnvilMenuMixin.java @@ -3,11 +3,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.AnvilScreenHandler; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.AnvilMenu; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -15,13 +15,13 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -@Mixin(AnvilScreenHandler.class) -public abstract class AnvilScreenHandlerMixin { +@Mixin(AnvilMenu.class) +public abstract class AnvilMenuMixin { @Inject(method = "method_24922", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - private static void ledgerLogAnvilBreak(PlayerEntity player, World world, BlockPos pos, CallbackInfo ci) { + target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + private static void ledgerLogAnvilBreak(Player player, Level world, BlockPos pos, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock( world, pos, @@ -33,8 +33,8 @@ private static void ledgerLogAnvilBreak(PlayerEntity player, World world, BlockP @ModifyArgs(method = "method_24922", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static void ledgerLogAnvilChange(Args args, PlayerEntity player, World world, BlockPos pos) { + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static void ledgerLogAnvilChange(Args args, Player player, Level world, BlockPos pos) { BlockState newBlockState = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock( world, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/AxeItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/AxeItemMixin.java index 7f290105..f02d6dfa 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/AxeItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/AxeItemMixin.java @@ -2,12 +2,12 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AxeItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.AxeItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -15,13 +15,13 @@ @Mixin(AxeItem.class) public abstract class AxeItemMixin { - @ModifyArgs(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logAxeUsage(Args args, ItemUsageContext context) { - World world = context.getWorld(); - BlockPos pos = context.getBlockPos(); + @ModifyArgs(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logAxeUsage(Args args, UseOnContext context) { + Level world = context.getLevel(); + BlockPos pos = context.getClickedPos(); BlockState oldState = world.getBlockState(pos); BlockState newState = args.get(1); - PlayerEntity player = context.getPlayer(); + Player player = context.getPlayer(); if (player != null) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, player); } else { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/BaseContainerBlockEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/BaseContainerBlockEntityMixin.java new file mode 100644 index 00000000..04becaa5 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BaseContainerBlockEntityMixin.java @@ -0,0 +1,23 @@ +package com.github.quiltservertools.ledger.mixin; + +import com.github.quiltservertools.ledger.actionutils.LocationalInventory; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.core.BlockPos; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(BaseContainerBlockEntity.class) +public abstract class BaseContainerBlockEntityMixin extends BlockEntity implements LocationalInventory { + public BaseContainerBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { + super(type, pos, state); + } + + @NotNull + @Override + public BlockPos getLocation() { + return this.worldPosition; + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockBehaviourMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockBehaviourMixin.java new file mode 100644 index 00000000..b2f3bd25 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockBehaviourMixin.java @@ -0,0 +1,55 @@ +package com.github.quiltservertools.ledger.mixin; + +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.world.level.block.state.BlockBehaviour; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.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; + +@Mixin(BlockBehaviour.class) +public abstract class BlockBehaviourMixin { + + @Inject( + method = "onExplosionHit", + at = @At( + value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z" + ) + ) + private void ledgerBlockExplodeCallback(BlockState state, ServerLevel world, BlockPos pos, Explosion explosion, BiConsumer stackMerger, CallbackInfo ci) { + LivingEntity entity; + if (explosion.getIndirectSourceEntity() instanceof PlayerCausable playerCausable && playerCausable.getCausingPlayer() != null) { + entity = playerCausable.getCausingPlayer(); + } else { + entity = explosion.getIndirectSourceEntity(); + } + + String source; + if (explosion.getDirectSourceEntity() != null && !(explosion.getDirectSourceEntity() instanceof Player)) { + source = BuiltInRegistries.ENTITY_TYPE.getKey(explosion.getDirectSourceEntity().getType()).getPath(); + } else { + source = Sources.EXPLOSION; + } + + BlockBreakCallback.EVENT.invoker().breakBlock( + world, + pos, + state, + world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null, + source, + entity instanceof Player 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 77957150..fec60ea1 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockItemMixin.java @@ -2,13 +2,13 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.InteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,21 +17,21 @@ @Mixin(BlockItem.class) public abstract class BlockItemMixin extends Item { - public BlockItemMixin(Settings settings) { + public BlockItemMixin(Properties settings) { super(settings); } @Inject( - method = "place(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/util/ActionResult;", + method = "place(Lnet/minecraft/world/item/context/BlockPlaceContext;)Lnet/minecraft/world/InteractionResult;", at = @At( value = "FIELD", - target = "Lnet/minecraft/util/ActionResult;SUCCESS:Lnet/minecraft/util/ActionResult$Success;" + target = "Lnet/minecraft/world/InteractionResult;SUCCESS:Lnet/minecraft/world/InteractionResult$Success;" ) ) - public void ledgerPlayerPlaceBlockCallback(ItemPlacementContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - BlockPos pos = context.getBlockPos(); - PlayerEntity player = context.getPlayer(); + public void ledgerPlayerPlaceBlockCallback(BlockPlaceContext context, CallbackInfoReturnable cir) { + Level world = context.getLevel(); + BlockPos pos = context.getClickedPos(); + Player player = context.getPlayer(); BlockPlaceCallback.EVENT.invoker().place( world, pos, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockMixin.java index c603066d..39ce8e5d 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BlockMixin.java @@ -3,11 +3,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,11 +16,11 @@ @Mixin(Block.class) public abstract class BlockMixin { @Inject( - method = "replace(Lnet/minecraft/block/BlockState;Lnet/minecraft/block/BlockState;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;II)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldAccess;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;I)Z")) - private static void ledgerTryLogSupportedBlockBreak(BlockState state, BlockState newState, WorldAccess worldAccess, BlockPos pos, int flags, int maxUpdateDepth, CallbackInfo ci) { - if (worldAccess instanceof World world) { - BlockBreakCallback.EVENT.invoker().breakBlock(world, pos.toImmutable(), state, state.hasBlockEntity() ? world.getBlockEntity(pos) : null, Sources.GRAVITY); + method = "updateOrDestroy(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;II)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelAccessor;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;I)Z")) + private static void ledgerTryLogSupportedBlockBreak(BlockState state, BlockState newState, LevelAccessor worldAccess, BlockPos pos, int flags, int maxUpdateDepth, CallbackInfo ci) { + if (worldAccess instanceof Level world) { + BlockBreakCallback.EVENT.invoker().breakBlock(world, pos.immutable(), state, state.hasBlockEntity() ? world.getBlockEntity(pos) : null, Sources.GRAVITY); } } } 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 d85a71d7..c6548a85 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BucketDispenserBehaviorMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BucketDispenserBehaviorMixin.java @@ -4,32 +4,32 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.dispenser.ItemDispenserBehavior; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPointer; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.dispenser.BlockSource; +import net.minecraft.core.BlockPos; 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(targets = "net/minecraft/block/dispenser/DispenserBehavior$11") -public abstract class BucketDispenserBehaviorMixin extends ItemDispenserBehavior { +@Mixin(targets = "net.minecraft.core.dispenser.DispenseItemBehavior$5") +public abstract class BucketDispenserBehaviorMixin extends DefaultDispenseItemBehavior { @Inject( - method = "dispenseSilently", + method = "execute", at = @At( value = "INVOKE", - target = "Lnet/minecraft/block/FluidDrainable;tryDrainFluid(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/item/ItemStack;", + target = "Lnet/minecraft/world/level/block/BucketPickup;pickupBlock(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/item/ItemStack;", shift = At.Shift.AFTER ) ) - private void logFluidPickup(BlockPointer pointer, ItemStack stack, CallbackInfoReturnable cir, @Local(argsOnly = true) ItemStack itemStack, @Local BlockPos pos, @Local BlockState blockState) { - var world = pointer.world(); + private void logFluidPickup(BlockSource pointer, ItemStack stack, CallbackInfoReturnable cir, @Local(argsOnly = true) ItemStack itemStack, @Local BlockPos pos, @Local BlockState blockState) { + var world = pointer.level(); if (!itemStack.isEmpty()) { - if (!blockState.getFluidState().isEmpty() || blockState.isOf(Blocks.POWDER_SNOW)) { + if (!blockState.getFluidState().isEmpty() || blockState.is(Blocks.POWDER_SNOW)) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, blockState, world.getBlockEntity(pos), Sources.REDSTONE); } else { BlockChangeCallback.EVENT.invoker().changeBlock( 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 baf17021..74bf64a4 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/BucketItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/BucketItemMixin.java @@ -5,17 +5,17 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.Waterloggable; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.item.BucketItem; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.world.item.BucketItem; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -27,35 +27,35 @@ public abstract class BucketItemMixin { @Shadow @Final - private Fluid fluid; + private Fluid content; - @Inject(method = "placeFluid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - private void logFluidBreak(LivingEntity user, World world, BlockPos pos, BlockHitResult hitResult, CallbackInfoReturnable cir) { + @Inject(method = "emptyContents", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + private void logFluidBreak(LivingEntity user, Level world, BlockPos pos, BlockHitResult hitResult, CallbackInfoReturnable cir) { var blockstate = world.getBlockState(pos); - if (!blockstate.isAir() && user instanceof PlayerEntity player) { + if (!blockstate.isAir() && user instanceof Player player) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, world.getBlockState(pos), world.getBlockEntity(pos), Sources.FLUID, player); } } - @Inject(method = "placeFluid", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/BucketItem;playEmptyingSound(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;)V")) - private void logFluidPlace(LivingEntity user, World world, BlockPos pos, BlockHitResult hitResult, CallbackInfoReturnable cir) { - if (user instanceof PlayerEntity player) { - BlockPlaceCallback.EVENT.invoker().place(world, pos, this.fluid.getDefaultState().getBlockState(), null, player); + @Inject(method = "emptyContents", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/BucketItem;playEmptySound(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;)V")) + private void logFluidPlace(LivingEntity user, Level world, BlockPos pos, BlockHitResult hitResult, CallbackInfoReturnable cir) { + if (user instanceof Player player) { + BlockPlaceCallback.EVENT.invoker().place(world, pos, this.content.defaultFluidState().createLegacyBlock(), null, player); } else { - BlockPlaceCallback.EVENT.invoker().place(world, pos, this.fluid.getDefaultState().getBlockState(), null, Sources.REDSTONE); + BlockPlaceCallback.EVENT.invoker().place(world, pos, this.content.defaultFluidState().createLegacyBlock(), null, Sources.REDSTONE); } } @Inject( - method = "placeFluid", + method = "emptyContents", at = @At( value = "INVOKE", - target = "Lnet/minecraft/item/BucketItem;playEmptyingSound(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;)V", + target = "Lnet/minecraft/world/item/BucketItem;playEmptySound(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;)V", ordinal = 0 ) ) - private void logWaterlog(LivingEntity user, World world, BlockPos pos, BlockHitResult hitResult, CallbackInfoReturnable cir, @Local BlockState blockState) { - if (user instanceof PlayerEntity player) { + private void logWaterlog(LivingEntity user, Level world, BlockPos pos, BlockHitResult hitResult, CallbackInfoReturnable cir, @Local BlockState blockState) { + if (user instanceof Player player) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, @@ -78,9 +78,9 @@ private void logWaterlog(LivingEntity user, World world, BlockPos pos, BlockHitR } } - @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) { - if (blockState.getBlock() instanceof Waterloggable) { + @Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;awardStat(Lnet/minecraft/stats/Stat;)V", ordinal = 0)) + private void logFluidPickup(Level world, Player player, InteractionHand hand, CallbackInfoReturnable cir, @Local(ordinal = 0) BlockPos pos, @Local BlockState blockState) { + if (blockState.getBlock() instanceof SimpleWaterloggedBlock) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, 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 51909477..038d3ef9 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/CampfireBlockEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/CampfireBlockEntityMixin.java @@ -2,13 +2,13 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; 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.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.CampfireBlockEntity; +import net.minecraft.world.item.crafting.CampfireCookingRecipe; +import net.minecraft.world.item.crafting.RecipeManager; +import net.minecraft.world.item.crafting.SingleRecipeInput; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,9 +17,9 @@ @Mixin(CampfireBlockEntity.class) 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(ServerWorld world, BlockPos pos, BlockState state, CampfireBlockEntity campfire, ServerRecipeManager.MatchGetter matchGetter, CallbackInfo ci) { + @Inject(method = "cookTick", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/Containers;dropItemStack(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) + private static void logCampfireRemoveItem(ServerLevel world, BlockPos pos, BlockState state, CampfireBlockEntity campfire, RecipeManager.CachedCheck 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/ChestBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/ChestBlockMixin.java index c51484e5..31d808de 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ChestBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/ChestBlockMixin.java @@ -1,29 +1,29 @@ package com.github.quiltservertools.ledger.mixin; import com.github.quiltservertools.ledger.utility.HandlerWithContext; -import net.minecraft.block.entity.ChestBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.screen.ScreenHandler; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -@Mixin(targets = "net/minecraft/block/ChestBlock$2$1") +@Mixin(targets = "net.minecraft.world.level.block.ChestBlock$2$1") public abstract class ChestBlockMixin { @Shadow - ChestBlockEntity field_17358; + ChestBlockEntity val$first; @Inject( - method = "createMenu(ILnet/minecraft/entity/player/PlayerInventory;Lnet/minecraft/entity/player/PlayerEntity;)Lnet/minecraft/screen/ScreenHandler;", + method = "createMenu(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/inventory/AbstractContainerMenu;", at = @At("RETURN") ) - private void addPositionContext(int i, PlayerInventory playerInventory, PlayerEntity playerEntity, CallbackInfoReturnable cir) { - ScreenHandler screenHandler = cir.getReturnValue(); + private void addPositionContext(int i, Inventory playerInventory, Player playerEntity, CallbackInfoReturnable cir) { + AbstractContainerMenu screenHandler = cir.getReturnValue(); if (screenHandler != null) { - ((HandlerWithContext) screenHandler).setPos(this.field_17358.getPos()); + ((HandlerWithContext) screenHandler).setPos(this.val$first.getBlockPos()); } } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/CompoundContainerMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/CompoundContainerMixin.java new file mode 100644 index 00000000..fbff64cd --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/CompoundContainerMixin.java @@ -0,0 +1,26 @@ +package com.github.quiltservertools.ledger.mixin; + +import com.github.quiltservertools.ledger.actionutils.DoubleInventoryHelper; +import net.minecraft.world.CompoundContainer; +import net.minecraft.world.Container; +import org.jetbrains.annotations.NotNull; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(CompoundContainer.class) +public abstract class CompoundContainerMixin implements DoubleInventoryHelper { + @Shadow + @Final + private Container container1; + + @Shadow + @Final + private Container container2; + + @NotNull + @Override + public Container getInventory(int slot) { + return slot >= this.container1.getContainerSize() ? this.container2 : this.container1; + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/ItemScattererMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/ContainersMixin.java similarity index 56% rename from src/main/java/com/github/quiltservertools/ledger/mixin/ItemScattererMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/ContainersMixin.java index ff4b9d14..088e040c 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ItemScattererMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/ContainersMixin.java @@ -3,27 +3,27 @@ import com.github.quiltservertools.ledger.actionutils.LocationalInventory; import com.github.quiltservertools.ledger.callbacks.ItemRemoveCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ItemScatterer; -import net.minecraft.world.World; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.Containers; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -@Mixin(ItemScatterer.class) -public abstract class ItemScattererMixin { +@Mixin(Containers.class) +public abstract class ContainersMixin { @ModifyArgs( - method = "spawn(Lnet/minecraft/world/World;DDDLnet/minecraft/inventory/Inventory;)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;getStack(I)Lnet/minecraft/item/ItemStack;")) - private static void ledgerTrackContainerBreakRemove(Args args, World world, double x, double y, double z, Inventory inventory) { - ItemStack stack = inventory.getStack(args.get(0)); + method = "dropContents(Lnet/minecraft/world/level/Level;DDDLnet/minecraft/world/Container;)V", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Container;getItem(I)Lnet/minecraft/world/item/ItemStack;")) + private static void ledgerTrackContainerBreakRemove(Args args, Level world, double x, double y, double z, Container inventory) { + ItemStack stack = inventory.getItem(args.get(0)); if (!stack.isEmpty() && inventory instanceof LocationalInventory locationalInventory) { - ItemRemoveCallback.EVENT.invoker().remove(stack, locationalInventory.getLocation(), (ServerWorld) world, Sources.BROKE, null); + ItemRemoveCallback.EVENT.invoker().remove(stack, locationalInventory.getLocation(), (ServerLevel) world, Sources.BROKE, null); } } } \ No newline at end of file diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/CopperGolemGiveMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/CopperGolemGiveMixin.java index 9be0ecc7..814c7172 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/CopperGolemGiveMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/CopperGolemGiveMixin.java @@ -2,23 +2,23 @@ import com.github.quiltservertools.ledger.callbacks.ItemDropCallback; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.ai.brain.task.TargetUtil; -import net.minecraft.entity.passive.CopperGolemEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.Vec3d; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.behavior.BehaviorUtils; +import net.minecraft.world.entity.animal.golem.CopperGolem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.phys.Vec3; 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(TargetUtil.class) +@Mixin(BehaviorUtils.class) public class CopperGolemGiveMixin { - @Inject(method = "give(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;spawnEntity(Lnet/minecraft/entity/Entity;)Z")) - private static void onItemGiven(LivingEntity entity, ItemStack stack, Vec3d targetLocation, Vec3d velocityFactor, float yOffset, CallbackInfo ci, @Local ItemEntity itemEntity) { - if (entity instanceof CopperGolemEntity) { + @Inject(method = "throwItem(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/phys/Vec3;Lnet/minecraft/world/phys/Vec3;F)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;addFreshEntity(Lnet/minecraft/world/entity/Entity;)Z")) + private static void onItemGiven(LivingEntity entity, ItemStack stack, Vec3 targetLocation, Vec3 velocityFactor, float yOffset, CallbackInfo ci, @Local ItemEntity itemEntity) { + if (entity instanceof CopperGolem) { ItemDropCallback.EVENT.invoker().drop(itemEntity, entity); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/DoubleInventoryMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/DoubleInventoryMixin.java deleted file mode 100644 index 25d5f337..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/DoubleInventoryMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -import com.github.quiltservertools.ledger.actionutils.DoubleInventoryHelper; -import net.minecraft.inventory.DoubleInventory; -import net.minecraft.inventory.Inventory; -import org.jetbrains.annotations.NotNull; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; - -@Mixin(DoubleInventory.class) -public abstract class DoubleInventoryMixin implements DoubleInventoryHelper { - @Shadow - @Final - private Inventory first; - - @Shadow - @Final - private Inventory second; - - @NotNull - @Override - public Inventory getInventory(int slot) { - return slot >= this.first.size() ? this.second : this.first; - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/DyeItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/DyeItemMixin.java index cbb7171a..1199ebd3 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/DyeItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/DyeItemMixin.java @@ -3,13 +3,13 @@ import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; import com.github.quiltservertools.ledger.utility.NbtUtils; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.DyeItem; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.DyeItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -19,15 +19,15 @@ @Mixin(DyeItem.class) public abstract class DyeItemMixin { @Unique - private NbtCompound oldEntityTags; + private CompoundTag oldEntityTags; - @Inject(method = "useOnEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;setColor(Lnet/minecraft/util/DyeColor;)V")) - private void ledgerOldEntity(ItemStack stack, PlayerEntity player, LivingEntity entity, Hand hand, CallbackInfoReturnable cir) { + @Inject(method = "interactLivingEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/sheep/Sheep;setColor(Lnet/minecraft/world/item/DyeColor;)V")) + private void ledgerOldEntity(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand, CallbackInfoReturnable cir) { oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); } - @Inject(method = "useOnEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;setColor(Lnet/minecraft/util/DyeColor;)V", shift = At.Shift.AFTER)) - private void ledgerPlayerDyeSheep(ItemStack stack, PlayerEntity player, LivingEntity entity, Hand hand, CallbackInfoReturnable cir) { - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, stack, player, Sources.DYE); + @Inject(method = "interactLivingEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/sheep/Sheep;setColor(Lnet/minecraft/world/item/DyeColor;)V", shift = At.Shift.AFTER)) + private void ledgerPlayerDyeSheep(ItemStack stack, Player player, LivingEntity entity, InteractionHand hand, CallbackInfoReturnable cir) { + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, stack, player, Sources.DYE); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/FillCommandMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/FillCommandMixin.java index ea70d655..a4d8da4f 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/FillCommandMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/FillCommandMixin.java @@ -4,17 +4,17 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.pattern.CachedBlockPosition; -import net.minecraft.command.argument.BlockStateArgument; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.command.FillCommand; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockBox; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.pattern.BlockInWorld; +import net.minecraft.commands.arguments.blocks.BlockInput; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.server.commands.FillCommand; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.levelgen.structure.BoundingBox; +import net.minecraft.core.BlockPos; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -27,32 +27,32 @@ @Mixin(FillCommand.class) public abstract class FillCommandMixin { @Inject( - method = "execute", + method = "fillBlocks", at = @At( value = "INVOKE", - target = "Lnet/minecraft/command/argument/BlockStateArgument;setBlockState(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;I)Z" + target = "Lnet/minecraft/commands/arguments/blocks/BlockInput;place(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;I)Z" ) ) private static void logFillChanges( - ServerCommandSource source, - BlockBox range, - BlockStateArgument block, + CommandSourceStack source, + BoundingBox range, + BlockInput block, @Coerce Object mode, - Predicate filter, + Predicate filter, boolean strict, CallbackInfoReturnable cir, @Local BlockPos pos) { - ServerWorld world = source.getWorld(); + ServerLevel world = source.getLevel(); BlockState oldState = world.getBlockState(pos); BlockEntity oldBlockEntity = world.getBlockEntity(pos); - BlockState newState = block.getBlockState(); + BlockState newState = block.getState(); Entity entity = source.getEntity(); - PlayerEntity player = entity instanceof PlayerEntity ? (PlayerEntity) entity : null; + Player player = entity instanceof Player ? (Player) entity : null; if (!oldState.isAir()) { - BlockBreakCallback.EVENT.invoker().breakBlock(world, pos.toImmutable(), oldState, oldBlockEntity, Sources.COMMAND, player); + BlockBreakCallback.EVENT.invoker().breakBlock(world, pos.immutable(), oldState, oldBlockEntity, Sources.COMMAND, player); } - BlockPlaceCallback.EVENT.invoker().place(world, pos.toImmutable(), newState, null, Sources.COMMAND, player); + BlockPlaceCallback.EVENT.invoker().place(world, pos.immutable(), newState, null, Sources.COMMAND, player); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/FlintAndSteelItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/FlintAndSteelItemMixin.java index 3613faf7..c84004f4 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/FlintAndSteelItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/FlintAndSteelItemMixin.java @@ -3,10 +3,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.item.FlintAndSteelItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.FlintAndSteelItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.core.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -14,21 +14,21 @@ @Mixin(FlintAndSteelItem.class) public abstract class FlintAndSteelItemMixin { - @ModifyArgs(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void log(Args args, ItemUsageContext context) { + @ModifyArgs(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void log(Args args, UseOnContext context) { BlockState state = args.get(1); BlockPos pos = args.get(0); var player = context.getPlayer(); - var world = context.getWorld(); + var world = context.getLevel(); var oldState = world.getBlockState(pos); var be = world.getBlockEntity(pos); if (oldState.getBlock().equals(state.getBlock())) { // Block types are the same, log interaction if (player != null) { - BlockChangeCallback.EVENT.invoker().changeBlock(context.getWorld(), pos, oldState, state, be, be, player); + BlockChangeCallback.EVENT.invoker().changeBlock(context.getLevel(), pos, oldState, state, be, be, player); } else { - BlockChangeCallback.EVENT.invoker().changeBlock(context.getWorld(), pos, oldState, state, be, be, Sources.FIRE); + BlockChangeCallback.EVENT.invoker().changeBlock(context.getLevel(), pos, oldState, state, be, be, Sources.FIRE); } } else { if (player != null) { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/FrostWalkerEnchantmentMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/FrostWalkerEnchantmentMixin.java index 8f284809..199fbd34 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/FrostWalkerEnchantmentMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/FrostWalkerEnchantmentMixin.java @@ -2,29 +2,29 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.enchantment.EnchantmentEffectContext; -import net.minecraft.enchantment.effect.entity.ReplaceDiskEnchantmentEffect; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.enchantment.EnchantedItemInUse; +import net.minecraft.world.item.enchantment.effects.ReplaceDisk; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.Vec3; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -@Mixin(ReplaceDiskEnchantmentEffect.class) +@Mixin(ReplaceDisk.class) public abstract class FrostWalkerEnchantmentMixin { - @ModifyArgs(method = "apply", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - private void logFrostWalkerPlacement(Args args, ServerWorld world, int level, EnchantmentEffectContext context, Entity entity, Vec3d vec3d) { + @ModifyArgs(method = "apply", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + private void logFrostWalkerPlacement(Args args, ServerLevel world, int level, EnchantedItemInUse context, Entity entity, Vec3 vec3d) { // Frosted ice block is hardcoded in target class BlockPos pos = args.get(0); BlockState state = args.get(1); - pos = pos.toImmutable(); + pos = pos.immutable(); // TODO 1.21 - Datapacks can use this. The source might need to be renamed BlockPlaceCallback.EVENT.invoker().place(world, pos, state, null, Sources.FROST_WALKER, - entity instanceof PlayerEntity ? (PlayerEntity) entity : null); + entity instanceof Player ? (Player) entity : null); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/HoeItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/HoeItemMixin.java index c735cd76..efaba6da 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/HoeItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/HoeItemMixin.java @@ -2,10 +2,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.item.HoeItem; -import net.minecraft.item.ItemConvertible; -import net.minecraft.item.ItemUsageContext; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.HoeItem; +import net.minecraft.world.level.ItemLike; +import net.minecraft.world.item.context.UseOnContext; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -16,22 +16,22 @@ public abstract class HoeItemMixin { // These unmapped methods are lambda expressions used by the game for hoe uses @Inject(method = "method_36984", at = @At("HEAD")) - private static void logHoeInteraction(BlockState state, ItemUsageContext context, CallbackInfo ci) { + private static void logHoeInteraction(BlockState state, UseOnContext context, CallbackInfo ci) { log(state, context); } @Inject(method = "method_36986", at = @At("HEAD")) - private static void logHoeInteraction(BlockState state, ItemConvertible itemConvertible, ItemUsageContext context, CallbackInfo ci) { + private static void logHoeInteraction(BlockState state, ItemLike itemConvertible, UseOnContext context, CallbackInfo ci) { log(state, context); } @Unique - private static void log(BlockState state, ItemUsageContext context) { + private static void log(BlockState state, UseOnContext context) { var player = context.getPlayer(); if (player != null) { - BlockChangeCallback.EVENT.invoker().changeBlock(context.getWorld(), context.getBlockPos(), context.getWorld().getBlockState(context.getBlockPos()), state, null, null, player); + BlockChangeCallback.EVENT.invoker().changeBlock(context.getLevel(), context.getClickedPos(), context.getLevel().getBlockState(context.getClickedPos()), state, null, null, player); } else { - BlockChangeCallback.EVENT.invoker().changeBlock(context.getWorld(), context.getBlockPos(), context.getWorld().getBlockState(context.getBlockPos()), state, null, null, Sources.INTERACT); + BlockChangeCallback.EVENT.invoker().changeBlock(context.getLevel(), context.getClickedPos(), context.getLevel().getBlockState(context.getClickedPos()), state, null, null, Sources.INTERACT); } } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/HoneycombItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/HoneycombItemMixin.java index a0d1a480..18d1ca81 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/HoneycombItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/HoneycombItemMixin.java @@ -3,12 +3,12 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.HoneycombItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.HoneycombItem; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -16,8 +16,8 @@ @Mixin(HoneycombItem.class) public abstract class HoneycombItemMixin { - @ModifyArgs(method = "method_34719", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static void logCopperWaxing(Args args, @Local World world, @Local PlayerEntity player) { + @ModifyArgs(method = "method_34719", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static void logCopperWaxing(Args args, @Local Level world, @Local Player player) { BlockPos pos = args.get(0); BlockState oldState = world.getBlockState(pos); BlockState newState = args.get(1); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java deleted file mode 100644 index eefee657..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableComponentMixin.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.component.type.JukeboxPlayableComponent; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import static net.minecraft.block.JukeboxBlock.HAS_RECORD; - - -@Mixin(JukeboxPlayableComponent.class) -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) { - BlockState blockState = world.getBlockState(pos); - - BlockChangeCallback.EVENT.invoker().changeBlock( - world, - pos, - blockState.with(HAS_RECORD, false), - blockState, - null, - world.getBlockEntity(pos), - Sources.INTERACT, - player); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableMixin.java new file mode 100644 index 00000000..9a66bd5d --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/JukeboxPlayableMixin.java @@ -0,0 +1,37 @@ +package com.github.quiltservertools.ledger.mixin; + +import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.JukeboxPlayable; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.InteractionResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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 static net.minecraft.world.level.block.JukeboxBlock.HAS_RECORD; + +@Mixin(JukeboxPlayable.class) +public abstract class JukeboxPlayableMixin { + + @Inject(method = "tryInsertIntoJukebox", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/block/entity/JukeboxBlockEntity;setTheItem(Lnet/minecraft/world/item/ItemStack;)V")) + private static void ledgerPlayerInsertMusicDisc(Level world, BlockPos pos, ItemStack itemStack, Player player, CallbackInfoReturnable cir) { + BlockState blockState = world.getBlockState(pos); + + BlockChangeCallback.EVENT.invoker().changeBlock( + world, + pos, + blockState.setValue(HAS_RECORD, false), + blockState, + null, + world.getBlockEntity(pos), + Sources.INTERACT, + player); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/LilyPadBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/LilyPadBlockMixin.java deleted file mode 100644 index 03c99de5..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/LilyPadBlockMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.LilyPadBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCollisionHandler; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(LilyPadBlock.class) -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, EntityCollisionHandler handler, boolean bl, CallbackInfo ci) { - if (entity.getFirstPassenger() instanceof PlayerEntity player) { - BlockBreakCallback.EVENT.invoker().breakBlock(world, new BlockPos(pos), state, null, Sources.VEHICLE, player); - } else { - BlockBreakCallback.EVENT.invoker().breakBlock(world, new BlockPos(pos), state, null, Sources.VEHICLE); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/LockableContainerBlockEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/LockableContainerBlockEntityMixin.java deleted file mode 100644 index 83e5ce2c..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/LockableContainerBlockEntityMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -import com.github.quiltservertools.ledger.actionutils.LocationalInventory; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.entity.LockableContainerBlockEntity; -import net.minecraft.util.math.BlockPos; -import org.jetbrains.annotations.NotNull; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(LockableContainerBlockEntity.class) -public abstract class LockableContainerBlockEntityMixin extends BlockEntity implements LocationalInventory { - public LockableContainerBlockEntityMixin(BlockEntityType type, BlockPos pos, BlockState state) { - super(type, pos, state); - } - - @NotNull - @Override - public BlockPos getLocation() { - return this.pos; - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/MoveItemsTaskMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/MoveItemsTaskMixin.java deleted file mode 100644 index a2f69ffd..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/MoveItemsTaskMixin.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -import com.github.quiltservertools.ledger.callbacks.ItemInsertCallback; -import com.github.quiltservertools.ledger.callbacks.ItemRemoveCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.ai.brain.task.MoveItemsTask; -import net.minecraft.entity.mob.PathAwareEntity; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -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.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -import java.util.WeakHashMap; - -@Mixin(MoveItemsTask.class) -public class MoveItemsTaskMixin { - - @Shadow - private MoveItemsTask.Storage targetStorage; - - @Unique - private static final WeakHashMap ledger$entityTargetMap = new WeakHashMap<>(); - - @Inject(method = "takeStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;markDirty()V")) - public void onTakeStack(PathAwareEntity entity, Inventory inventory, CallbackInfo ci) { - ItemStack stack = entity.getEquippedStack(EquipmentSlot.MAINHAND); - World world = entity.getEntityWorld(); - ItemRemoveCallback.EVENT.invoker().remove(stack, targetStorage.pos(), (ServerWorld) world, Sources.COPPER_GOLEM, entity); - } - - @Inject(method = "placeStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;markDirty()V")) - private void onPlaceStack(PathAwareEntity entity, Inventory inventory, CallbackInfo ci) { - ledger$entityTargetMap.put(entity, targetStorage.pos()); - } - - @Inject(method = "invalidateTargetStorage", at = @At("HEAD")) - private void onInvalidateTargetStorage(PathAwareEntity entity, CallbackInfo ci) { - ledger$entityTargetMap.remove(entity); - } - - @ModifyArgs(method = "insertStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;setStack(ILnet/minecraft/item/ItemStack;)V")) - private static void onInsertStack(Args args, PathAwareEntity entity, Inventory inventory) { - ItemStack itemStack = args.get(1); - World world = entity.getEntityWorld(); - BlockPos targetPos = ledger$entityTargetMap.getOrDefault(entity, null); - if (targetPos == null) return; - - ItemInsertCallback.EVENT.invoker().insert(itemStack, targetPos, (ServerWorld) world, Sources.COPPER_GOLEM, entity); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java deleted file mode 100644 index 6cf914f8..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/NetherPortalMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.github.quiltservertools.ledger.mixin; - -import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldAccess; -import net.minecraft.world.dimension.NetherPortal; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(NetherPortal.class) -public abstract class NetherPortalMixin { - - @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/PortalShapeMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/PortalShapeMixin.java new file mode 100644 index 00000000..6afd3967 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/PortalShapeMixin.java @@ -0,0 +1,26 @@ +package com.github.quiltservertools.ledger.mixin; + +import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.portal.PortalShape; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(PortalShape.class) +public abstract class PortalShapeMixin { + + @Inject(method = "method_64315", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelAccessor;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static void logPortalPlacement(LevelAccessor worldAccess, BlockState state, BlockPos pos, CallbackInfo ci) { + if (worldAccess instanceof ServerLevel world) { + BlockPlaceCallback.EVENT.invoker().place(world, pos.immutable(), state, null, Sources.PORTAL); + } + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionImplMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/ServerExplosionMixin.java similarity index 51% rename from src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionImplMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/ServerExplosionMixin.java index 52cf4d4b..412123fc 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ExplosionImplMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/ServerExplosionMixin.java @@ -5,15 +5,15 @@ import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; 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.explosion.ExplosionImpl; +import net.minecraft.world.level.block.BaseFireBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.ServerExplosion; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -22,51 +22,51 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(ExplosionImpl.class) -public abstract class ExplosionImplMixin { +@Mixin(ServerExplosion.class) +public abstract class ServerExplosionMixin { @Shadow @Final - private ServerWorld world; + private ServerLevel level; @Shadow - public abstract @Nullable LivingEntity getCausingEntity(); + public abstract @Nullable LivingEntity getIndirectSourceEntity(); @Shadow @Final @Nullable - private Entity entity; + private Entity source; @Inject( method = "createFire", at = @At( value = "INVOKE", - target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z" + target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z" ) ) private void ledgerExplosionFireCallback(List positions, CallbackInfo ci, @Local BlockPos blockPos) { - BlockState blockState = AbstractFireBlock.getState(world, blockPos); + BlockState blockState = BaseFireBlock.getState(level, blockPos); LivingEntity entity; - if (this.entity instanceof PlayerCausable playerCausable && playerCausable.getCausingPlayer() != null) { + if (this.source instanceof PlayerCausable playerCausable && playerCausable.getCausingPlayer() != null) { entity = playerCausable.getCausingPlayer(); } else { - entity = getCausingEntity(); + entity = getIndirectSourceEntity(); } String source; - if (this.entity != null && !(this.entity instanceof PlayerEntity)) { - source = Registries.ENTITY_TYPE.getId(this.entity.getType()).getPath(); + if (this.source != null && !(this.source instanceof Player)) { + source = BuiltInRegistries.ENTITY_TYPE.getKey(this.source.getType()).getPath(); } else { source = Sources.EXPLOSION; } BlockPlaceCallback.EVENT.invoker().place( - world, + level, blockPos, blockState, - world.getBlockEntity(blockPos) != null ? world.getBlockEntity(blockPos) : null, + level.getBlockEntity(blockPos) != null ? level.getBlockEntity(blockPos) : null, source, - entity instanceof PlayerEntity player ? player : null + entity instanceof Player player ? player : null ); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/ServerPlayerEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/ServerPlayerMixin.java similarity index 57% rename from src/main/java/com/github/quiltservertools/ledger/mixin/ServerPlayerEntityMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/ServerPlayerMixin.java index 8bce6132..82a62d8f 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ServerPlayerEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/ServerPlayerMixin.java @@ -3,36 +3,36 @@ import com.github.quiltservertools.ledger.callbacks.EntityMountCallback; import com.github.quiltservertools.ledger.utility.HandlerWithContext; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.Entity; -import net.minecraft.screen.NamedScreenHandlerFactory; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.server.level.ServerPlayer; 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 java.util.OptionalInt; -@Mixin(ServerPlayerEntity.class) -public abstract class ServerPlayerEntityMixin { +@Mixin(ServerPlayer.class) +public abstract class ServerPlayerMixin { @Inject( - method = "openHandledScreen", + method = "openMenu", at = @At( value = "INVOKE", - target = "Lnet/minecraft/server/network/ServerPlayerEntity;onScreenHandlerOpened(Lnet/minecraft/screen/ScreenHandler;)V" + target = "Lnet/minecraft/server/level/ServerPlayer;initMenu(Lnet/minecraft/world/inventory/AbstractContainerMenu;)V" ) ) - public void addPositionContext(NamedScreenHandlerFactory factory, CallbackInfoReturnable cir, @Local ScreenHandler screenHandler) { + public void addPositionContext(MenuProvider factory, CallbackInfoReturnable cir, @Local AbstractContainerMenu screenHandler) { if (factory instanceof BlockEntity blockEntity) { - ((HandlerWithContext) screenHandler).setPos(blockEntity.getPos()); + ((HandlerWithContext) screenHandler).setPos(blockEntity.getBlockPos()); } } @Inject(method = "startRiding", at = @At(value = "RETURN")) public void onPlayerStartedRiding(Entity entity, boolean force, boolean emitEvent, CallbackInfoReturnable cir) { - ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; + ServerPlayer player = (ServerPlayer) (Object) this; if (!cir.getReturnValue()) { return; diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/SetBlockCommandMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/SetBlockCommandMixin.java index a096c9a6..444e6c9c 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/SetBlockCommandMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/SetBlockCommandMixin.java @@ -3,16 +3,16 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.pattern.CachedBlockPosition; -import net.minecraft.command.argument.BlockStateArgument; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.command.SetBlockCommand; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.pattern.BlockInWorld; +import net.minecraft.commands.arguments.blocks.BlockInput; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.server.commands.SetBlockCommand; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -23,25 +23,25 @@ @Mixin(SetBlockCommand.class) public abstract class SetBlockCommandMixin { @ModifyArgs( - method = "execute", + method = "setBlock", at = @At( value = "INVOKE", - target = "Lnet/minecraft/command/argument/BlockStateArgument;setBlockState(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/util/math/BlockPos;I)Z" + target = "Lnet/minecraft/commands/arguments/blocks/BlockInput;place(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/core/BlockPos;I)Z" ) ) - private static void logSetBlockChange(Args args, ServerCommandSource source, BlockPos pos, BlockStateArgument block, SetBlockCommand.Mode mode, @Nullable Predicate condition, boolean strict) { - ServerWorld world = args.get(0); + private static void logSetBlockChange(Args args, CommandSourceStack source, BlockPos pos, BlockInput block, SetBlockCommand.Mode mode, @Nullable Predicate condition, boolean strict) { + ServerLevel world = args.get(0); BlockState oldState = world.getBlockState(pos); BlockEntity oldBlockEntity = world.getBlockEntity(pos); - BlockState newState = block.getBlockState(); + BlockState newState = block.getState(); Entity entity = source.getEntity(); - PlayerEntity player = entity instanceof PlayerEntity ? (PlayerEntity) entity : null; + Player player = entity instanceof Player ? (Player) entity : null; if (!oldState.isAir()) { - BlockBreakCallback.EVENT.invoker().breakBlock(world, pos.toImmutable(), oldState, oldBlockEntity, Sources.COMMAND, player); + BlockBreakCallback.EVENT.invoker().breakBlock(world, pos.immutable(), oldState, oldBlockEntity, Sources.COMMAND, player); } - BlockPlaceCallback.EVENT.invoker().place(world, pos.toImmutable(), newState, null, Sources.COMMAND, player); + BlockPlaceCallback.EVENT.invoker().place(world, pos.immutable(), newState, null, Sources.COMMAND, player); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/ShovelItemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/ShovelItemMixin.java index 4a6509f9..b11ec812 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/ShovelItemMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/ShovelItemMixin.java @@ -2,10 +2,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.item.ShovelItem; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.item.ShovelItem; +import net.minecraft.core.BlockPos; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -13,12 +13,12 @@ @Mixin(ShovelItem.class) public abstract class ShovelItemMixin { - @ModifyArgs(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logPathFlattening(Args args, ItemUsageContext context) { + @ModifyArgs(method = "useOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logPathFlattening(Args args, UseOnContext context) { var player = context.getPlayer(); BlockState state = args.get(1); BlockPos pos = args.get(0); - var world = context.getWorld(); + var world = context.getLevel(); if (player != null) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, world.getBlockState(pos), state, null, null, player); } else { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/SlotMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/SlotMixin.java index 66554518..fa64850a 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/SlotMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/SlotMixin.java @@ -4,11 +4,11 @@ import com.github.quiltservertools.ledger.actionutils.LocationalInventory; import com.github.quiltservertools.ledger.utility.HandledSlot; import com.github.quiltservertools.ledger.utility.HandlerWithContext; -import net.minecraft.inventory.Inventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.screen.slot.Slot; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.Slot; +import net.minecraft.core.BlockPos; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; @@ -22,50 +22,50 @@ @Mixin(Slot.class) public abstract class SlotMixin implements HandledSlot { @Unique - private ScreenHandler handler = null; + private AbstractContainerMenu handler = null; @Unique private ItemStack oldStack = null; @Shadow @Final - public Inventory inventory; + public Container container; @Shadow @Final - private int index; + private int slot; @Shadow - public abstract ItemStack getStack(); + public abstract ItemStack getItem(); @NotNull @Override - public ScreenHandler getHandler() { + public AbstractContainerMenu getHandler() { return handler; } @Override - public void setHandler(@NotNull ScreenHandler handler) { + public void setHandler(@NotNull AbstractContainerMenu handler) { this.handler = handler; - oldStack = this.getStack() == null ? ItemStack.EMPTY : this.getStack().copy(); + oldStack = this.getItem() == null ? ItemStack.EMPTY : this.getItem().copy(); } - @Inject(method = "markDirty", at = @At(value = "HEAD")) + @Inject(method = "setChanged", at = @At(value = "HEAD")) private void ledgerLogChanges(CallbackInfo ci) { BlockPos pos = getInventoryLocation(); HandlerWithContext handlerWithContext = (HandlerWithContext) handler; if (pos != null && handlerWithContext.getPlayer() != null) { - handlerWithContext.onStackChanged(oldStack, this.getStack().copy(), pos); + handlerWithContext.onStackChanged(oldStack, this.getItem().copy(), pos); } - oldStack = this.getStack().copy(); + oldStack = this.getItem().copy(); } @Unique @Nullable private BlockPos getInventoryLocation() { - Inventory slotInventory = this.inventory; + Container slotInventory = this.container; if (slotInventory instanceof DoubleInventoryHelper) { - slotInventory = ((DoubleInventoryHelper) slotInventory).getInventory(this.index); + slotInventory = ((DoubleInventoryHelper) slotInventory).getInventory(this.slot); } if (slotInventory instanceof LocationalInventory) { return ((LocationalInventory) slotInventory).getLocation(); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/TransportItemsBetweenContainersMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/TransportItemsBetweenContainersMixin.java new file mode 100644 index 00000000..c1c33b38 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/TransportItemsBetweenContainersMixin.java @@ -0,0 +1,59 @@ +package com.github.quiltservertools.ledger.mixin; + +import com.github.quiltservertools.ledger.callbacks.ItemInsertCallback; +import com.github.quiltservertools.ledger.callbacks.ItemRemoveCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.ai.behavior.TransportItemsBetweenContainers; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.Container; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import java.util.WeakHashMap; + +@Mixin(TransportItemsBetweenContainers.class) +public class TransportItemsBetweenContainersMixin { + + @Shadow + private TransportItemsBetweenContainers.TransportItemTarget target; + + @Unique + private static final WeakHashMap ledger$entityTargetMap = new WeakHashMap<>(); + + @Inject(method = "pickUpItems", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Container;setChanged()V")) + public void onTakeStack(PathfinderMob entity, Container inventory, CallbackInfo ci) { + ItemStack stack = entity.getItemBySlot(EquipmentSlot.MAINHAND); + Level world = entity.level(); + ItemRemoveCallback.EVENT.invoker().remove(stack, target.pos(), (ServerLevel) world, Sources.COPPER_GOLEM, entity); + } + + @Inject(method = "putDownItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Container;setChanged()V")) + private void onPlaceStack(PathfinderMob entity, Container inventory, CallbackInfo ci) { + ledger$entityTargetMap.put(entity, target.pos()); + } + + @Inject(method = "stopTargetingCurrentTarget", at = @At("HEAD")) + private void onInvalidateTargetStorage(PathfinderMob entity, CallbackInfo ci) { + ledger$entityTargetMap.remove(entity); + } + + @ModifyArgs(method = "addItemsToContainer", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Container;setItem(ILnet/minecraft/world/item/ItemStack;)V")) + private static void onInsertStack(Args args, PathfinderMob entity, Container inventory) { + ItemStack itemStack = args.get(1); + Level world = entity.level(); + BlockPos targetPos = ledger$entityTargetMap.getOrDefault(entity, null); + if (targetPos == null) return; + + ItemInsertCallback.EVENT.invoker().insert(itemStack, targetPos, (ServerLevel) world, Sources.COPPER_GOLEM, entity); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/WaterlilyBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/WaterlilyBlockMixin.java new file mode 100644 index 00000000..64e3e0cd --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/WaterlilyBlockMixin.java @@ -0,0 +1,27 @@ +package com.github.quiltservertools.ledger.mixin; + +import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.WaterlilyBlock; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.InsideBlockEffectApplier; +import net.minecraft.world.entity.player.Player; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(WaterlilyBlock.class) +public abstract class WaterlilyBlockMixin { + @Inject(method = "entityInside", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;)Z")) + private void ledgerLogLilyPadBreak(BlockState state, Level world, BlockPos pos, Entity entity, InsideBlockEffectApplier handler, boolean bl, CallbackInfo ci) { + if (entity.getFirstPassenger() instanceof Player player) { + BlockBreakCallback.EVENT.invoker().breakBlock(world, new BlockPos(pos), state, null, Sources.VEHICLE, player); + } else { + BlockBreakCallback.EVENT.invoker().breakBlock(world, new BlockPos(pos), state, null, Sources.VEHICLE); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantPartBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantPartBlockMixin.java deleted file mode 100644 index eb9d08c1..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantPartBlockMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.AbstractPlantPartBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -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(AbstractPlantPartBlock.class) -public abstract class AbstractPlantPartBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logPlantBreaks(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.BROKE); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantStemBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantStemBlockMixin.java deleted file mode 100644 index ea79bc73..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/AbstractPlantStemBlockMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.AbstractPlantStemBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(AbstractPlantStemBlock.class) -public abstract class AbstractPlantStemBlockMixin { - @ModifyArgs(method = "grow", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z")) - public void logPlantGrowth(Args args, ServerWorld world, Random random, BlockPos sourcePos, BlockState sourceState) { - BlockPos pos = args.get(0); - BlockState state = args.get(1); - BlockPlaceCallback.EVENT.invoker().place(world, pos, state, null, Sources.GROW); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooBlockMixin.java deleted file mode 100644 index a1202c8c..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooBlockMixin.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BambooBlock; -import net.minecraft.block.BlockState; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -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(BambooBlock.class) -public abstract class BambooBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logBambooBreak(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooStalkBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooStalkBlockMixin.java new file mode 100644 index 00000000..95486a86 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BambooStalkBlockMixin.java @@ -0,0 +1,21 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.BambooStalkBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; +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(BambooStalkBlock.class) +public abstract class BambooStalkBlockMixin { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logBambooBreak(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { + BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BedBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BedBlockMixin.java index 73b73ccc..037cefa1 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BedBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/BedBlockMixin.java @@ -3,14 +3,14 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BedBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.BedBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -22,23 +22,23 @@ public abstract class BedBlockMixin { @Unique private BlockEntity oldBlockEntity = null; - @Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void storeBlockEntity(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable cir, @Local(ordinal = 1) BlockPos blockPos) { + @Inject(method = "playerWillDestroy", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void storeBlockEntity(Level world, BlockPos pos, BlockState state, Player player, CallbackInfoReturnable cir, @Local(ordinal = 1) BlockPos blockPos) { oldBlockEntity = world.getBlockEntity(blockPos); } - @Inject(method = "onBreak", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER)) - public void logBedBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable cir, @Local(ordinal = 1) BlockPos blockPos, @Local(ordinal = 1) BlockState blockState) { + @Inject(method = "playerWillDestroy", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z", shift = At.Shift.AFTER)) + public void logBedBreak(Level world, BlockPos pos, BlockState state, Player player, CallbackInfoReturnable cir, @Local(ordinal = 1) BlockPos blockPos, @Local(ordinal = 1) BlockState blockState) { BlockBreakCallback.EVENT.invoker().breakBlock(world, blockPos, blockState, oldBlockEntity, player); } - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void storeBlockEntity(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void storeBlockEntity(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { oldBlockEntity = world.getBlockEntity(pos); } - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z", shift = At.Shift.AFTER)) - public void logBedExplosion(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z", shift = At.Shift.AFTER)) + public void logBedExplosion(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, oldBlockEntity, Sources.INTERACT, player); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ButtonBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ButtonBlockMixin.java index c319844e..9c1e02ab 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ButtonBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ButtonBlockMixin.java @@ -1,13 +1,13 @@ package com.github.quiltservertools.ledger.mixin.blocks; import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.ButtonBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ButtonBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -19,15 +19,15 @@ @Mixin(ButtonBlock.class) public abstract class ButtonBlockMixin { @Unique - private PlayerEntity activePlayer; + private Player activePlayer; - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/ButtonBlock;powerOn(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;)V")) - public void logButtonClick(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/ButtonBlock;press(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)V")) + public void logButtonClick(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { activePlayer = player; } - @ModifyArgs(method = "powerOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logLeverUse(Args args, BlockState state, World world, BlockPos pos, PlayerEntity playerEntity) { + @ModifyArgs(method = "press", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logLeverUse(Args args, BlockState state, Level world, BlockPos pos, Player playerEntity) { if (activePlayer == null) return; BlockState newState = args.get(1); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CactusBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CactusBlockMixin.java index bfad40cf..fb9b9905 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CactusBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CactusBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CactusBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CactusBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,8 @@ @Mixin(CactusBlock.class) public abstract class CactusBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logCactusBreak(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logCactusBreak(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); } } 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 2afe515a..c1aae815 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 @@ -2,17 +2,17 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CakeBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CakeBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,30 +24,30 @@ public abstract class CakeBlockMixin { @Shadow @Final - public static IntProperty BITES; + public static IntegerProperty BITES; - @Inject(method = "tryEat", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/WorldAccess;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) + @Inject(method = "eat", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/LevelAccessor;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) private static void ledgerLogCakeEat( - WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable cir) { + LevelAccessor world, BlockPos pos, BlockState state, Player player, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock( - player.getEntityWorld(), + player.level(), pos, world.getBlockState(pos), - state.with(BITES, state.get(BITES) + 1), + state.setValue(BITES, state.getValue(BITES) + 1), null, null, Sources.CONSUME, player); } - @Inject(method = "tryEat", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/WorldAccess;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z", + @Inject(method = "eat", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/LevelAccessor;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z", shift = At.Shift.AFTER)) private static void ledgerLogCakeEatAndRemove( - WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable cir) { + LevelAccessor world, BlockPos pos, BlockState state, Player player, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock( - player.getEntityWorld(), + player.level(), pos, state, world.getBlockState(pos), @@ -57,13 +57,13 @@ private static void ledgerLogCakeEatAndRemove( player); } - @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", + @Inject(method = "useItemOn", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/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, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHitResult, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock( - player.getEntityWorld(), + player.level(), pos, state, world.getBlockState(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 98b5daed..85495c45 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 @@ -3,20 +3,20 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.CampfireBlock; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -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.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CampfireBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -32,29 +32,29 @@ public abstract class CampfireBlockMixin { @Final public static BooleanProperty LIT; - @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", - target = "Lnet/minecraft/entity/player/PlayerEntity;incrementStat(Lnet/minecraft/util/Identifier;)V") + @Inject(method = "useItemOn", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/entity/player/Player;awardStat(Lnet/minecraft/resources/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, Level world, BlockPos pos, Player player, InteractionHand 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); } - @Inject(method = "extinguish", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/WorldAccess;emitGameEvent(Lnet/minecraft/entity/Entity;Lnet/minecraft/registry/entry/RegistryEntry;Lnet/minecraft/util/math/BlockPos;)V")) - private static void logCampfireExtinguish(Entity entity, WorldAccess worldAccess, BlockPos pos, BlockState blockState, CallbackInfo ci) { - if (worldAccess instanceof World world) { - if (entity instanceof PlayerEntity player) { - BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, blockState.with(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH, player); + @Inject(method = "dowse", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/LevelAccessor;gameEvent(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/Holder;Lnet/minecraft/core/BlockPos;)V")) + private static void logCampfireExtinguish(Entity entity, LevelAccessor worldAccess, BlockPos pos, BlockState blockState, CallbackInfo ci) { + if (worldAccess instanceof Level world) { + if (entity instanceof Player player) { + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, blockState.setValue(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH, player); } else { - BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, blockState.with(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH); + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, blockState.setValue(LIT, Boolean.FALSE), world.getBlockEntity(pos), null, Sources.EXTINGUISH); } } } @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private void logCampfireProjectileIgnite(World world, BlockState blockState, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { - BlockChangeCallback.EVENT.invoker().changeBlock(world, hit.getBlockPos(), blockState, blockState.with(LIT, Boolean.TRUE), world.getBlockEntity(hit.getBlockPos()), null, Sources.FIRE); + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private void logCampfireProjectileIgnite(Level world, BlockState blockState, BlockHitResult hit, Projectile projectile, CallbackInfo ci) { + BlockChangeCallback.EVENT.invoker().changeBlock(world, hit.getBlockPos(), blockState, blockState.setValue(LIT, Boolean.TRUE), world.getBlockEntity(hit.getBlockPos()), null, Sources.FIRE); } } \ No newline at end of file diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java index 46239304..57cae42b 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CandleBlockMixin.java @@ -2,15 +2,15 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.AbstractCandleBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; +import net.minecraft.world.level.block.AbstractCandleBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.LevelAccessor; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -26,13 +26,13 @@ public abstract class CandleBlockMixin { public static BooleanProperty LIT; @Inject(method = "extinguish", at = @At(value = "RETURN")) - private static void ledgerLogCandleExtinguish(PlayerEntity player, BlockState state, WorldAccess worldAccess, BlockPos pos, CallbackInfo ci) { - if (worldAccess instanceof World world) { + private static void ledgerLogCandleExtinguish(Player player, BlockState state, LevelAccessor worldAccess, BlockPos pos, CallbackInfo ci) { + if (worldAccess instanceof Level world) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, state, - state.with(LIT, !state.get(LIT)), + state.setValue(LIT, !state.getValue(LIT)), null, null, Sources.EXTINGUISH, player); @@ -40,12 +40,12 @@ private static void ledgerLogCandleExtinguish(PlayerEntity player, BlockState st } @Inject(method = "onProjectileHit", at = @At(value = "RETURN")) - private void ledgerLogCandleLit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { + private void ledgerLogCandleLit(Level world, BlockState state, BlockHitResult hit, Projectile projectile, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock( world, hit.getBlockPos(), state, - state.with(LIT, !state.get(LIT)), + state.setValue(LIT, !state.getValue(LIT)), null, null, Sources.FIRE); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CarvedPumpkinBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CarvedPumpkinBlockMixin.java index 8857ed05..6fc04fa7 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CarvedPumpkinBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CarvedPumpkinBlockMixin.java @@ -3,10 +3,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.CarvedPumpkinBlock; -import net.minecraft.block.pattern.BlockPattern; -import net.minecraft.block.pattern.CachedBlockPosition; -import net.minecraft.world.World; +import net.minecraft.world.level.block.CarvedPumpkinBlock; +import net.minecraft.world.level.block.state.pattern.BlockPattern; +import net.minecraft.world.level.block.state.pattern.BlockInWorld; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,11 +14,11 @@ @Mixin(CarvedPumpkinBlock.class) public abstract class CarvedPumpkinBlockMixin { - @Inject(method = "breakPatternBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z", shift = At.Shift.AFTER)) - private static void logStatueBreak(World world, BlockPattern.Result patternResult, CallbackInfo ci, @Local CachedBlockPosition cachedBlockPosition) { - if (cachedBlockPosition.getBlockState().isAir()) { + @Inject(method = "clearPatternBlocks", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z", shift = At.Shift.AFTER)) + private static void logStatueBreak(Level world, BlockPattern.BlockPatternMatch patternResult, CallbackInfo ci, @Local BlockInWorld cachedBlockPosition) { + if (cachedBlockPosition.getState().isAir()) { return; } - BlockBreakCallback.EVENT.invoker().breakBlock(world, cachedBlockPosition.getBlockPos(), cachedBlockPosition.getBlockState(), cachedBlockPosition.getBlockEntity(), Sources.STATUE); + BlockBreakCallback.EVENT.invoker().breakBlock(world, cachedBlockPosition.getPos(), cachedBlockPosition.getState(), cachedBlockPosition.getEntity(), Sources.STATUE); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusFlowerBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusFlowerBlockMixin.java index 6aada4ab..471516a3 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusFlowerBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusFlowerBlockMixin.java @@ -2,13 +2,13 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.ChorusFlowerBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ChorusFlowerBlock; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,10 +16,10 @@ @Mixin(ChorusFlowerBlock.class) public abstract class ChorusFlowerBlockMixin { - @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z")) - public void logChorusFlowerBreak(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { + @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;)Z")) + public void logChorusFlowerBreak(Level world, BlockState state, BlockHitResult hit, Projectile projectile, CallbackInfo ci) { Entity entity = projectile.getOwner(); - if (entity instanceof PlayerEntity player) { + if (entity instanceof Player player) { BlockBreakCallback.EVENT.invoker().breakBlock(world, hit.getBlockPos(), state, null, Sources.PROJECTILE, player); } else { BlockBreakCallback.EVENT.invoker().breakBlock(world, hit.getBlockPos(), state, null, Sources.PROJECTILE); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusPlantBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusPlantBlockMixin.java index 4bd1568f..1b4afc5b 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusPlantBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ChorusPlantBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.ChorusPlantBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ChorusPlantBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,8 @@ @Mixin(ChorusPlantBlock.class) public abstract class ChorusPlantBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logChorusPlantBreak(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logChorusPlantBreak(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ComparatorBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ComparatorBlockMixin.java index 698d8c07..56cea2e5 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ComparatorBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ComparatorBlockMixin.java @@ -2,15 +2,15 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.ComparatorBlock; -import net.minecraft.block.enums.ComparatorMode; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.EnumProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ComparatorBlock; +import net.minecraft.world.level.block.state.properties.ComparatorMode; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.properties.EnumProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,8 +24,8 @@ public abstract class ComparatorBlockMixin { @Final public static EnumProperty MODE; - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logComparatorInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logComparatorInteraction(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state.cycle(MODE), state, world.getBlockEntity(pos), world.getBlockEntity(pos), Sources.INTERACT, player); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CopperGolemStatueBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CopperGolemStatueBlockMixin.java index 19237e8e..69f92877 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CopperGolemStatueBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/CopperGolemStatueBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CopperGolemStatueBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CopperGolemStatueBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -14,8 +14,8 @@ @Mixin(CopperGolemStatueBlock.class) public class CopperGolemStatueBlockMixin { - @ModifyArgs(method = "changePose", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void onChangePose(Args args, World world, BlockState oldState, BlockPos pos, PlayerEntity player) { + @ModifyArgs(method = "updatePose", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void onChangePose(Args args, Level world, BlockState oldState, BlockPos pos, Player player) { BlockState newState = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, Sources.INTERACT, player); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DaylightDetectorBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DaylightDetectorBlockMixin.java index a7b401be..1308f347 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DaylightDetectorBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DaylightDetectorBlockMixin.java @@ -2,13 +2,13 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.DaylightDetectorBlock; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.DaylightDetectorBlock; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -16,8 +16,8 @@ @Mixin(DaylightDetectorBlock.class) public abstract class DaylightDetectorBlockMixin { - @ModifyArgs(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logDaylightDetectorToggling(Args args, BlockState oldState, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + @ModifyArgs(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logDaylightDetectorToggling(Args args, BlockState oldState, Level world, BlockPos pos, Player player, BlockHitResult hit) { BlockState newState = args.get(1); BlockEntity blockEntity = world.getBlockEntity(pos); if (player == null) { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DecoratedPotBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DecoratedPotBlockMixin.java index fcf222d5..dd8ec18e 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DecoratedPotBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/DecoratedPotBlockMixin.java @@ -4,19 +4,19 @@ import com.github.quiltservertools.ledger.callbacks.ItemInsertCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.DecoratedPotBlock; -import net.minecraft.block.entity.DecoratedPotBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.DecoratedPotBlock; +import net.minecraft.world.level.block.entity.DecoratedPotBlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -25,15 +25,15 @@ @Mixin(DecoratedPotBlock.class) public abstract class DecoratedPotBlockMixin { - @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;splitUnlessCreative(ILnet/minecraft/entity/LivingEntity;)Lnet/minecraft/item/ItemStack;")) - public void logItemInsert(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir, @Local DecoratedPotBlockEntity decoratedPotBlockEntity) { - ItemInsertCallback.EVENT.invoker().insert(stack.copyWithCount(1), pos, (ServerWorld) world, Sources.PLAYER, (ServerPlayerEntity) player); + @Inject(method = "useItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;consumeAndReturn(ILnet/minecraft/world/entity/LivingEntity;)Lnet/minecraft/world/item/ItemStack;")) + public void logItemInsert(ItemStack stack, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable cir, @Local DecoratedPotBlockEntity decoratedPotBlockEntity) { + ItemInsertCallback.EVENT.invoker().insert(stack.copyWithCount(1), pos, (ServerLevel) world, Sources.PLAYER, (ServerPlayer) player); } - @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { + @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logProjectileHit(Level world, BlockState state, BlockHitResult hit, Projectile projectile, CallbackInfo ci) { if (world.getBlockEntity(hit.getBlockPos()) instanceof DecoratedPotBlockEntity decoratedPotBlockEntity) { - if (projectile.getOwner() instanceof ServerPlayerEntity player) { + if (projectile.getOwner() instanceof ServerPlayer player) { BlockBreakCallback.EVENT.invoker().breakBlock(world, hit.getBlockPos(), state, decoratedPotBlockEntity, Sources.PLAYER, player); } else { BlockBreakCallback.EVENT.invoker().breakBlock(world, hit.getBlockPos(), state, decoratedPotBlockEntity, Sources.PROJECTILE); 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 2c627b56..68f0fefe 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 @@ -2,16 +2,16 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.DoorBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.block.WireOrientation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.DoorBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.redstone.Orientation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -26,13 +26,13 @@ public abstract class DoorBlockMixin { @Final public static BooleanProperty OPEN; - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logDoorInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logDoorInteraction(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state.cycle(OPEN), state, null, null, Sources.INTERACT, player); } - @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, WireOrientation wireOrientation, boolean notify, CallbackInfo ci) { + @Inject(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logRedstoneDoorInteraction(BlockState state, Level world, BlockPos pos, Block sourceBlock, Orientation 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/FarmBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FarmBlockMixin.java new file mode 100644 index 00000000..1cc2825d --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FarmBlockMixin.java @@ -0,0 +1,28 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FarmBlock; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(FarmBlock.class) +public abstract class FarmBlockMixin { + + @Inject(method = "turnToDirt", at = @At("HEAD")) + private static void logSetToDirt(Entity entity, BlockState blockState, Level world, BlockPos pos, CallbackInfo ci) { + if (entity instanceof Player player) { + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, Blocks.DIRT.defaultBlockState(), null, null, Sources.TRAMPLE, player); + } else { + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, Blocks.DIRT.defaultBlockState(), null, null, Sources.TRAMPLE); + } + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FarmlandBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FarmlandBlockMixin.java deleted file mode 100644 index 3e6d1316..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FarmlandBlockMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.FarmlandBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(FarmlandBlock.class) -public abstract class FarmlandBlockMixin { - - @Inject(method = "setToDirt", at = @At("HEAD")) - private static void logSetToDirt(Entity entity, BlockState blockState, World world, BlockPos pos, CallbackInfo ci) { - if (entity instanceof PlayerEntity player) { - BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, Blocks.DIRT.getDefaultState(), null, null, Sources.TRAMPLE, player); - } else { - BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, blockState, Blocks.DIRT.getDefaultState(), null, null, Sources.TRAMPLE); - } - } -} 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 206dc4a3..9b44492e 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 @@ -2,16 +2,16 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.FenceGateBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.block.WireOrientation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.FenceGateBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.redstone.Orientation; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -26,13 +26,13 @@ public abstract class FenceGateBlockMixin { @Final public static BooleanProperty OPEN; - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logFenceGateInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logFenceGateInteraction(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state.cycle(OPEN), state, null, null, Sources.INTERACT, player); } - @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, WireOrientation wireOrientation, boolean notify, CallbackInfo ci) { + @Inject(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logRedstoneFenceGateInteraction(BlockState state, Level world, BlockPos pos, Block sourceBlock, Orientation 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/FireBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FireBlockMixin.java index 97488026..1de766be 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FireBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FireBlockMixin.java @@ -3,12 +3,12 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.FireBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.FireBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,26 +17,26 @@ @Mixin(FireBlock.class) public abstract class FireBlockMixin { @Inject( - method = "trySpreadingFire", + method = "checkBurnOut", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z" + target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z" ) ) - private void ledgerBlockBurnBreakInvoker(World world, BlockPos pos, int spreadFactor, Random random, int currentAge, CallbackInfo ci, @Local BlockState blockState) { + private void ledgerBlockBurnBreakInvoker(Level world, BlockPos pos, int spreadFactor, RandomSource random, int currentAge, CallbackInfo ci, @Local BlockState blockState) { if (blockState.getBlock() != Blocks.FIRE) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, blockState, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null, Sources.FIRE); } } @Inject( - method = "trySpreadingFire", + method = "checkBurnOut", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z" + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z" ) ) - private void ledgerBlockBurnReplaceInvoker(World world, BlockPos pos, int spreadFactor, Random random, int currentAge, CallbackInfo ci, @Local BlockState blockState) { + private void ledgerBlockBurnReplaceInvoker(Level world, BlockPos pos, int spreadFactor, RandomSource random, int currentAge, CallbackInfo ci, @Local BlockState blockState) { if (blockState.getBlock() != Blocks.FIRE) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, blockState, world.getBlockEntity(pos) != null ? world.getBlockEntity(pos) : null, Sources.FIRE); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowableFluidMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowableFluidMixin.java deleted file mode 100644 index d260f079..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowableFluidMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; -import net.minecraft.block.BlockState; -import net.minecraft.fluid.FlowableFluid; -import net.minecraft.fluid.FluidState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(FlowableFluid.class) -public abstract class FlowableFluidMixin { - @ModifyExpressionValue(method = "getUpdatedState", at = @At(value = "INVOKE", target = "Lnet/minecraft/fluid/FlowableFluid;getStill(Z)Lnet/minecraft/fluid/FluidState;")) - private FluidState logFluidSourceCreation(FluidState original, World world, BlockPos pos, BlockState state) { - //BlockPlaceCallback.EVENT.invoker().place(world, pos, original.getBlockState(), null, Sources.FLUID); //TODO doesn't seem to fully work and is very spammy - return original; - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowerPotBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowerPotBlockMixin.java index d706b44b..6efa8d8c 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowerPotBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowerPotBlockMixin.java @@ -1,12 +1,12 @@ package com.github.quiltservertools.ledger.mixin.blocks; import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.FlowerPotBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.FlowerPotBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -14,8 +14,8 @@ @Mixin(FlowerPotBlock.class) public abstract class FlowerPotBlockMixin { - @ModifyArgs(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logFlowerPotInteractions(Args args, BlockState oldState, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + @ModifyArgs(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logFlowerPotInteractions(Args args, BlockState oldState, Level world, BlockPos pos, Player player, BlockHitResult hit) { BlockState state = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, state, null, null, player); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowingFluidMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowingFluidMixin.java new file mode 100644 index 00000000..4494cf2b --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FlowingFluidMixin.java @@ -0,0 +1,19 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.material.FlowingFluid; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(FlowingFluid.class) +public abstract class FlowingFluidMixin { + @ModifyExpressionValue(method = "getNewLiquid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/material/FlowingFluid;getSource(Z)Lnet/minecraft/world/level/material/FluidState;")) + private FluidState logFluidSourceCreation(FluidState original, Level world, BlockPos pos, BlockState state) { + //BlockPlaceCallback.EVENT.invoker().place(world, pos, original.getBlockState(), null, Sources.FLUID); //TODO doesn't seem to fully work and is very spammy + return original; + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/GrowingPlantBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/GrowingPlantBlockMixin.java new file mode 100644 index 00000000..ad91006d --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/GrowingPlantBlockMixin.java @@ -0,0 +1,21 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.GrowingPlantBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; +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(GrowingPlantBlock.class) +public abstract class GrowingPlantBlockMixin { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logPlantBreaks(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { + BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.BROKE); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/GrowingPlantHeadBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/GrowingPlantHeadBlockMixin.java new file mode 100644 index 00000000..bfd81fb7 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/GrowingPlantHeadBlockMixin.java @@ -0,0 +1,23 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.GrowingPlantHeadBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Mixin(GrowingPlantHeadBlock.class) +public abstract class GrowingPlantHeadBlockMixin { + @ModifyArgs(method = "performBonemeal", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z")) + public void logPlantGrowth(Args args, ServerLevel world, RandomSource random, BlockPos sourcePos, BlockState sourceState) { + BlockPos pos = args.get(0); + BlockState state = args.get(1); + BlockPlaceCallback.EVENT.invoker().place(world, pos, state, null, Sources.GROW); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/IceBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/IceBlockMixin.java index a7f2e9ac..a28006f5 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/IceBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/IceBlockMixin.java @@ -1,11 +1,11 @@ package com.github.quiltservertools.ledger.mixin.blocks; import com.github.quiltservertools.ledger.callbacks.BlockMeltCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.IceBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.IceBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,14 +16,14 @@ public abstract class IceBlockMixin { // Logs the decay of ice blocks. // Log decay into air - @Inject(method = "melt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logFrostedIceDecayAir(BlockState state, World world, BlockPos pos, CallbackInfo ci) { - BlockMeltCallback.EVENT.invoker().melt(world, pos, state, Blocks.AIR.getDefaultState(), world.getBlockEntity(pos)); + @Inject(method = "melt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logFrostedIceDecayAir(BlockState state, Level world, BlockPos pos, CallbackInfo ci) { + BlockMeltCallback.EVENT.invoker().melt(world, pos, state, Blocks.AIR.defaultBlockState(), world.getBlockEntity(pos)); } // Log decay into other blocks - @Inject(method = "melt", 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 logFrostedIceDecayWater(BlockState state, World world, BlockPos pos, CallbackInfo ci) { + @Inject(method = "melt", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) + public void logFrostedIceDecayWater(BlockState state, Level world, BlockPos pos, CallbackInfo ci) { BlockMeltCallback.EVENT.invoker().melt(world, pos, state, world.getBlockState(pos), world.getBlockEntity(pos)); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/JukeboxBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/JukeboxBlockMixin.java index ba5c5799..90427994 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/JukeboxBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/JukeboxBlockMixin.java @@ -2,14 +2,14 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.JukeboxBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.JukeboxBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,15 +24,15 @@ public abstract class JukeboxBlockMixin { @Final public static BooleanProperty HAS_RECORD; - @Inject(method = "onUse", at = @At(value = "INVOKE", - target = "Lnet/minecraft/block/entity/JukeboxBlockEntity;dropRecord()V")) - private void ledgerLogDiscRemoved(BlockState blockState, World world, BlockPos pos, PlayerEntity player, - BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/block/entity/JukeboxBlockEntity;popOutTheItem()V")) + private void ledgerLogDiscRemoved(BlockState blockState, Level world, BlockPos pos, Player player, + BlockHitResult hit, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, blockState, - blockState.with(HAS_RECORD, false), + blockState.setValue(HAS_RECORD, false), world.getBlockEntity(pos), null, Sources.INTERACT, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeavesBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeavesBlockMixin.java index 594db697..05daced6 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeavesBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeavesBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.LeavesBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.LeavesBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,8 @@ @Mixin(LeavesBlock.class) public abstract class LeavesBlockMixin { - @Inject(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logLeafDecay(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logLeafDecay(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, state.hasBlockEntity() ? world.getBlockEntity(pos) : null, Sources.DECAY); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeverBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeverBlockMixin.java index 5c2d298f..3c5897a7 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeverBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LeverBlockMixin.java @@ -1,13 +1,13 @@ package com.github.quiltservertools.ledger.mixin.blocks; import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.LeverBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.LeverBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -20,15 +20,15 @@ public abstract class LeverBlockMixin { @Unique - private PlayerEntity activePlayer; + private Player activePlayer; - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/LeverBlock;togglePower(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;)V")) - public void storePlayer(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/LeverBlock;pull(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)V")) + public void storePlayer(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { activePlayer = player; } - @ModifyArgs(method = "togglePower", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logLeverUse(Args args, BlockState state, World world, BlockPos pos, PlayerEntity playerEntity) { + @ModifyArgs(method = "pull", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logLeverUse(Args args, BlockState state, Level world, BlockPos pos, Player playerEntity) { if (activePlayer == null) return; BlockState newState = args.get(1); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FluidBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LiquidBlockMixin.java similarity index 62% rename from src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FluidBlockMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LiquidBlockMixin.java index 2e98ad00..22b06a78 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/FluidBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/LiquidBlockMixin.java @@ -2,22 +2,22 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.FluidBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.LiquidBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -@Mixin(FluidBlock.class) -public abstract class FluidBlockMixin { +@Mixin(LiquidBlock.class) +public abstract class LiquidBlockMixin { @ModifyArgs( - method = "receiveNeighborFluids", - at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z") + method = "shouldSpreadLiquid", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z") ) - private void ledgerLogFluidBlockForm(Args args, World world, BlockPos pos, BlockState state) { + private void ledgerLogFluidBlockForm(Args args, Level world, BlockPos pos, BlockState state) { BlockPos blockPos = args.get(0); BlockState blockState = args.get(1); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/NoteBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/NoteBlockMixin.java index a88a80e3..416b7ae3 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/NoteBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/NoteBlockMixin.java @@ -1,12 +1,12 @@ package com.github.quiltservertools.ledger.mixin.blocks; import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import net.minecraft.block.BlockState; -import net.minecraft.block.NoteBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.NoteBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -14,8 +14,8 @@ @Mixin(NoteBlock.class) public abstract class NoteBlockMixin { - @ModifyArgs(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logNoteBlockChanges(Args args, BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + @ModifyArgs(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logNoteBlockChanges(Args args, BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit) { BlockState newState = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, newState, null, null, player); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/OxidizableCopperGolemStatueBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/OxidizableCopperGolemStatueBlockMixin.java deleted file mode 100644 index 726236b3..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/OxidizableCopperGolemStatueBlockMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.BlockState; -import net.minecraft.block.OxidizableCopperGolemStatueBlock; -import net.minecraft.entity.passive.CopperGolemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(OxidizableCopperGolemStatueBlock.class) -public class OxidizableCopperGolemStatueBlockMixin { - - @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;damage(ILnet/minecraft/entity/LivingEntity;Lnet/minecraft/entity/EquipmentSlot;)V")) - public void onUseWithAxe(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir, @Local CopperGolemEntity copperGolemEntity) { - NbtCompound oldState = NbtUtils.INSTANCE.blockStateToProperties(state); - if (oldState == null) { - oldState = new NbtCompound(); - } - - EntityModifyCallback.EVENT.invoker().modify(world, pos, oldState, copperGolemEntity, stack, player, Sources.REANIMATE); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/PointedDripstoneBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/PointedDripstoneBlockMixin.java index a91912cc..89d317bb 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/PointedDripstoneBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/PointedDripstoneBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.PointedDripstoneBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.PointedDripstoneBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -15,9 +15,9 @@ @Mixin(PointedDripstoneBlock.class) public abstract class PointedDripstoneBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logDripstoneLostBottomBreak(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logDripstoneLostBottomBreak(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RepeaterBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RepeaterBlockMixin.java index 82fe04d4..0f3eddff 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RepeaterBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RepeaterBlockMixin.java @@ -2,14 +2,14 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.RepeaterBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.IntProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.RepeaterBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.properties.IntegerProperty; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -21,10 +21,10 @@ public abstract class RepeaterBlockMixin { @Shadow @Final - public static IntProperty DELAY; + public static IntegerProperty DELAY; - @Inject(method = "onUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logRepeaterInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit, CallbackInfoReturnable cir) { + @Inject(method = "useWithoutItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logRepeaterInteraction(BlockState state, Level world, BlockPos pos, Player player, BlockHitResult hit, CallbackInfoReturnable cir) { BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, state.cycle(DELAY), null, null, Sources.INTERACT, player); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RootedDirtBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RootedDirtBlockMixin.java index 68d99a2c..d6bd0424 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RootedDirtBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/RootedDirtBlockMixin.java @@ -2,12 +2,12 @@ import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.RootedDirtBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.RootedDirtBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -15,8 +15,8 @@ @Mixin(RootedDirtBlock.class) public abstract class RootedDirtBlockMixin { - @Inject(method = "grow", at = @At("HEAD")) - public void logHangingRootsGrowth(ServerWorld world, Random random, BlockPos pos, BlockState state, CallbackInfo ci) { - BlockPlaceCallback.EVENT.invoker().place(world, pos.down(), Blocks.HANGING_ROOTS.getDefaultState(), null, Sources.GROW); + @Inject(method = "performBonemeal", at = @At("HEAD")) + public void logHangingRootsGrowth(ServerLevel world, RandomSource random, BlockPos pos, BlockState state, CallbackInfo ci) { + BlockPlaceCallback.EVENT.invoker().place(world, pos.below(), Blocks.HANGING_ROOTS.defaultBlockState(), null, Sources.GROW); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ScaffoldingBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ScaffoldingBlockMixin.java index 973832e4..0b61cf5e 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ScaffoldingBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ScaffoldingBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.ScaffoldingBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ScaffoldingBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -15,9 +15,9 @@ @Mixin(ScaffoldingBlock.class) public abstract class ScaffoldingBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", - target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logScaffoldLostBottomBreak(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", at = @At(value = "INVOKE", + target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logScaffoldLostBottomBreak(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ShelfBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ShelfBlockMixin.java index 2ae5ba18..fc7149cd 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ShelfBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/ShelfBlockMixin.java @@ -5,14 +5,14 @@ import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.ShelfBlock; -import net.minecraft.block.entity.ShelfBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.ShelfBlock; +import net.minecraft.world.level.block.entity.ShelfBlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -20,30 +20,30 @@ public class ShelfBlockMixin { @ModifyExpressionValue( - method = "swapSingleStack", + method = "swapSingleItem", at = @At( value = "INVOKE", - target = "Lnet/minecraft/block/entity/ShelfBlockEntity;swapStackNoMarkDirty(ILnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;" + target = "Lnet/minecraft/world/level/block/entity/ShelfBlockEntity;swapItemNoUpdate(ILnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;" ) ) - private static ItemStack onSwapSingleStack(ItemStack shelfHeldStack, ItemStack playerStack, PlayerEntity player, ShelfBlockEntity shelfBlockEntity, int hitSlot, PlayerInventory playerInventory) { + private static ItemStack onSwapSingleStack(ItemStack shelfHeldStack, ItemStack playerStack, Player player, ShelfBlockEntity shelfBlockEntity, int hitSlot, Inventory playerInventory) { if (!shelfHeldStack.isEmpty()) { - ItemRemoveCallback.EVENT.invoker().remove(shelfHeldStack, shelfBlockEntity.getPos(), (ServerWorld) player.getEntityWorld(), Sources.PLAYER, player); + ItemRemoveCallback.EVENT.invoker().remove(shelfHeldStack, shelfBlockEntity.getBlockPos(), (ServerLevel) player.level(), Sources.PLAYER, player); } if (!playerStack.isEmpty()) { - ItemInsertCallback.EVENT.invoker().insert(playerStack, shelfBlockEntity.getPos(), (ServerWorld) player.getEntityWorld(), Sources.PLAYER, player); + ItemInsertCallback.EVENT.invoker().insert(playerStack, shelfBlockEntity.getBlockPos(), (ServerLevel) player.level(), Sources.PLAYER, player); } return shelfHeldStack; } - @ModifyExpressionValue(method = "swapAllStacks", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/entity/ShelfBlockEntity;swapStackNoMarkDirty(ILnet/minecraft/item/ItemStack;)Lnet/minecraft/item/ItemStack;")) - private static ItemStack onSwapAllStacks(ItemStack shelfHeldStack, World world, BlockPos pos, PlayerInventory playerInventory, @Local ShelfBlockEntity shelfBlockEntity, @Local(ordinal = 0) ItemStack playerHeldStack) { + @ModifyExpressionValue(method = "swapHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/ShelfBlockEntity;swapItemNoUpdate(ILnet/minecraft/world/item/ItemStack;)Lnet/minecraft/world/item/ItemStack;")) + private static ItemStack onSwapAllStacks(ItemStack shelfHeldStack, Level world, BlockPos pos, Inventory playerInventory, @Local ShelfBlockEntity shelfBlockEntity, @Local(ordinal = 0) ItemStack playerHeldStack) { if (!shelfHeldStack.isEmpty()) { - ItemRemoveCallback.EVENT.invoker().remove(shelfHeldStack, shelfBlockEntity.getPos(), (ServerWorld) world, Sources.PLAYER, playerInventory.player); + ItemRemoveCallback.EVENT.invoker().remove(shelfHeldStack, shelfBlockEntity.getBlockPos(), (ServerLevel) world, Sources.PLAYER, playerInventory.player); } if (!playerHeldStack.isEmpty()) { - ItemInsertCallback.EVENT.invoker().insert(playerHeldStack, shelfBlockEntity.getPos(), (ServerWorld) world, Sources.PLAYER, playerInventory.player); + ItemInsertCallback.EVENT.invoker().insert(playerHeldStack, shelfBlockEntity.getBlockPos(), (ServerLevel) world, Sources.PLAYER, playerInventory.player); } return shelfHeldStack; diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpongeBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpongeBlockMixin.java index 13767042..7beee6b4 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpongeBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpongeBlockMixin.java @@ -3,10 +3,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.SpongeBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.SpongeBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -21,29 +21,29 @@ public abstract class SpongeBlockMixin { private BlockState oldBlockState; @Inject(method = "method_49829", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static void logWaterDrainNonSource(BlockPos actorBlockPos, World world, BlockPos pos, CallbackInfoReturnable cir) { + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static void logWaterDrainNonSource(BlockPos actorBlockPos, Level world, BlockPos pos, CallbackInfoReturnable cir) { // pos is the blockpos for affected water BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, world.getBlockState(pos), null, Sources.SPONGE); } @Inject(method = "method_49829", at = @At(value = "INVOKE", - target = "Lnet/minecraft/block/FluidDrainable;tryDrainFluid(Lnet/minecraft/entity/LivingEntity;Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Lnet/minecraft/item/ItemStack;")) - private static void logWaterDrainSource(BlockPos actorBlockPos, World world, BlockPos pos, CallbackInfoReturnable cir) { + target = "Lnet/minecraft/world/level/block/BucketPickup;pickupBlock(Lnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/level/LevelAccessor;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/world/item/ItemStack;")) + private static void logWaterDrainSource(BlockPos actorBlockPos, Level world, BlockPos pos, CallbackInfoReturnable cir) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, world.getBlockState(pos), null, Sources.SPONGE); } - @Inject(method = "update", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void ledgerStoreState(World world, BlockPos pos, CallbackInfo ci) { + @Inject(method = "tryAbsorbWater", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void ledgerStoreState(Level world, BlockPos pos, CallbackInfo ci) { oldBlockState = world.getBlockState(pos); // first invocation will be sponge, all others after will be wet sponge // because sponges will execute this method & absorbWater for every face in contact with water. } - @Inject(method = "update", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void ledgerLogSpongeToWetSponge(World world, BlockPos pos, CallbackInfo ci) { + @Inject(method = "tryAbsorbWater", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void ledgerLogSpongeToWetSponge(Level world, BlockPos pos, CallbackInfo ci) { BlockState newBlockState = world.getBlockState(pos); if (oldBlockState == newBlockState) {return;} // if the sponge is already wet don't log BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldBlockState, newBlockState, null, null, Sources.WET); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpreadableBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpreadingSnowyDirtBlockMixin.java similarity index 58% rename from src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpreadableBlockMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpreadingSnowyDirtBlockMixin.java index 6aa9091e..50c752a0 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpreadableBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SpreadingSnowyDirtBlockMixin.java @@ -2,23 +2,23 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.SpreadableBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.SpreadingSnowyDirtBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; 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(SpreadableBlock.class) -public abstract class SpreadableBlockMixin { +@Mixin(SpreadingSnowyDirtBlock.class) +public abstract class SpreadingSnowyDirtBlockMixin { @Inject(method = "randomTick", at = @At(value = "INVOKE", - target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", + target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) - private void ledgerLogGrassToDirt(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + private void ledgerLogGrassToDirt(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { if (state == world.getBlockState(pos)) { return; // should be something with snow when snow is melting off } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SugarCaneBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SugarCaneBlockMixin.java index efd6994e..a8fbba9a 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SugarCaneBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/SugarCaneBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.SugarCaneBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.SugarCaneBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,8 +14,8 @@ @Mixin(SugarCaneBlock.class) public abstract class SugarCaneBlockMixin { - @Inject(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;breakBlock(Lnet/minecraft/util/math/BlockPos;Z)Z")) - public void logSugarCaneBreak(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { + @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;Z)Z")) + public void logSugarCaneBreak(BlockState state, ServerLevel world, BlockPos pos, RandomSource random, CallbackInfo ci) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, null, Sources.GRAVITY); } } 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 new file mode 100644 index 00000000..1e89fbfa --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapDoorBlockMixin.java @@ -0,0 +1,35 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.TrapDoorBlock; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.redstone.Orientation; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TrapDoorBlock.class) +public abstract class TrapDoorBlockMixin { + @Shadow + @Final + public static BooleanProperty OPEN; + + @Inject(method = "toggle", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logTrapdoorInteraction(BlockState state, Level world, BlockPos pos, Player player, CallbackInfo ci) { + BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state.cycle(OPEN), state, null, null, Sources.INTERACT, player); + } + + @Inject(method = "neighborChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logTrapdoorRedstoneInteraction(BlockState state, Level world, BlockPos pos, Block sourceBlock, Orientation 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/TrapdoorBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapdoorBlockMixin.java deleted file mode 100644 index d2047f48..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/TrapdoorBlockMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks; - -import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.TrapdoorBlock; -import net.minecraft.entity.player.PlayerEntity; -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; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -@Mixin(TrapdoorBlock.class) -public abstract class TrapdoorBlockMixin { - @Shadow - @Final - public static BooleanProperty OPEN; - - @Inject(method = "flip", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logTrapdoorInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, CallbackInfo ci) { - BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state.cycle(OPEN), state, null, null, Sources.INTERACT, player); - } - - @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, 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/WeatheringCopperGolemStatueBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/WeatheringCopperGolemStatueBlockMixin.java new file mode 100644 index 00000000..759aed4a --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/WeatheringCopperGolemStatueBlockMixin.java @@ -0,0 +1,35 @@ +package com.github.quiltservertools.ledger.mixin.blocks; + +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.WeatheringCopperGolemStatueBlock; +import net.minecraft.world.entity.animal.golem.CopperGolem; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +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(WeatheringCopperGolemStatueBlock.class) +public class WeatheringCopperGolemStatueBlockMixin { + + @Inject(method = "useItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;hurtAndBreak(ILnet/minecraft/world/entity/LivingEntity;Lnet/minecraft/world/entity/EquipmentSlot;)V")) + public void onUseWithAxe(ItemStack stack, BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable cir, @Local CopperGolem copperGolemEntity) { + CompoundTag oldState = NbtUtils.INSTANCE.blockStateToProperties(state); + if (oldState == null) { + oldState = new CompoundTag(); + } + + EntityModifyCallback.EVENT.invoker().modify(world, pos, oldState, copperGolemEntity, stack, player, Sources.REANIMATE); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/WetSpongeBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/WetSpongeBlockMixin.java index 52edf5da..4cb801c4 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/WetSpongeBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/WetSpongeBlockMixin.java @@ -2,10 +2,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.WetSpongeBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.WetSpongeBlock; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,9 +14,9 @@ @Mixin(WetSpongeBlock.class) public abstract class WetSpongeBlockMixin { - @Inject(method = "onBlockAdded", at = @At(value = "INVOKE_ASSIGN", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logSpongeToWetSponge(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) { + @Inject(method = "onPlace", at = @At(value = "INVOKE_ASSIGN", + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logSpongeToWetSponge(BlockState state, Level world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) { BlockState newBlockState = world.getBlockState(pos); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, state, newBlockState, null, null, Sources.DRY); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBehaviorMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBehaviorMixin.java deleted file mode 100644 index 9415ffb1..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBehaviorMixin.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks.cauldron; - -import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.cauldron.CauldronBehavior; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.sound.SoundEvent; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.util.function.Predicate; - -@Mixin(CauldronBehavior.class) -public interface CauldronBehaviorMixin { - - @Inject(method = "emptyCauldron", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;")) - private static void ledgerLogFullDrainCauldron(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack, ItemStack output, - Predicate predicate, SoundEvent soundEvent, CallbackInfoReturnable cir) { - ledgerLogDrainCauldron(world, pos, state, player); - } - - @Inject(method = "fillCauldron", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;getItem()Lnet/minecraft/item/Item;")) - private static void ledgerLogFillCauldron(World world, BlockPos pos, PlayerEntity player, Hand hand, ItemStack stack, BlockState state, - SoundEvent soundEvent, CallbackInfoReturnable cir) { - ledgerLogFillCauldron(world, pos, world.getBlockState(pos), state, player); - } - - @Inject(method = "method_32219", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", - shift = At.Shift.AFTER)) - private static void ledgerLogBottleFillWaterCauldron(BlockState state, World world, BlockPos pos, - PlayerEntity player, Hand hand, ItemStack stack, CallbackInfoReturnable cir) { - ledgerLogFillCauldron(world, pos, state, world.getBlockState(pos), player); - } - - @Inject(method = "method_32222", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", - shift = At.Shift.AFTER)) - private static void ledgerLogBottleFillEmptyCauldron(BlockState state, World world, BlockPos pos, - PlayerEntity player, Hand hand, ItemStack stack, CallbackInfoReturnable cir) { - ledgerLogFillCauldron(world, pos, state, world.getBlockState(pos), player); - } - - @Unique - private static void ledgerLogDrainCauldron(World world, BlockPos pos, BlockState oldState, PlayerEntity player) { - BlockChangeCallback.EVENT.invoker().changeBlock( - world, - pos, - oldState, - Blocks.CAULDRON.getDefaultState(), - null, - null, - Sources.DRAIN, - player); - } - - @Unique - private static void ledgerLogFillCauldron(World world, BlockPos pos, BlockState oldState, BlockState newState, PlayerEntity player) { - BlockChangeCallback.EVENT.invoker().changeBlock( - world, - pos, - oldState, - newState, - null, - null, - Sources.FILL, - player); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBlockMixin.java index 2a6f85ab..4fdf8646 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronBlockMixin.java @@ -2,12 +2,12 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CauldronBlock; -import net.minecraft.fluid.Fluid; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CauldronBlock; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -16,9 +16,9 @@ @Mixin(CauldronBlock.class) public abstract class CauldronBlockMixin { - @Inject(method = "fillFromDripstone", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER)) - private void ledgerLogIncrementLevelCauldron(BlockState state, World world, BlockPos pos, Fluid fluid, CallbackInfo ci) { + @Inject(method = "receiveStalactiteDrip", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) + private void ledgerLogIncrementLevelCauldron(BlockState state, Level world, BlockPos pos, Fluid fluid, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, @@ -29,9 +29,9 @@ private void ledgerLogIncrementLevelCauldron(BlockState state, World world, Bloc Sources.DRIP); } - @Inject(method = "precipitationTick", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER)) - private void ledgerLogIncrementLevelCauldron(BlockState state, World world, BlockPos pos, Biome.Precipitation precipitation, CallbackInfo ci) { + @Inject(method = "handlePrecipitation", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) + private void ledgerLogIncrementLevelCauldron(BlockState state, Level world, BlockPos pos, Biome.Precipitation precipitation, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronInteractionMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronInteractionMixin.java new file mode 100644 index 00000000..724c35e1 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/CauldronInteractionMixin.java @@ -0,0 +1,79 @@ +package com.github.quiltservertools.ledger.mixin.blocks.cauldron; + +import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.core.cauldron.CauldronInteraction; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.function.Predicate; + +@Mixin(CauldronInteraction.class) +public interface CauldronInteractionMixin { + + @Inject(method = "fillBucket", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;")) + private static void ledgerLogFullDrainCauldron(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, ItemStack stack, ItemStack output, + Predicate predicate, SoundEvent soundEvent, CallbackInfoReturnable cir) { + ledgerLogDrainCauldron(world, pos, state, player); + } + + @Inject(method = "emptyBucket", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;getItem()Lnet/minecraft/world/item/Item;")) + private static void ledgerLogFillCauldron(Level world, BlockPos pos, Player player, InteractionHand hand, ItemStack stack, BlockState state, + SoundEvent soundEvent, CallbackInfoReturnable cir) { + ledgerLogFillCauldron(world, pos, world.getBlockState(pos), state, player); + } + + @Inject(method = "method_32219", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", + shift = At.Shift.AFTER)) + private static void ledgerLogBottleFillWaterCauldron(BlockState state, Level world, BlockPos pos, + Player player, InteractionHand hand, ItemStack stack, CallbackInfoReturnable cir) { + ledgerLogFillCauldron(world, pos, state, world.getBlockState(pos), player); + } + + @Inject(method = "method_32222", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", + shift = At.Shift.AFTER)) + private static void ledgerLogBottleFillEmptyCauldron(BlockState state, Level world, BlockPos pos, + Player player, InteractionHand hand, ItemStack stack, CallbackInfoReturnable cir) { + ledgerLogFillCauldron(world, pos, state, world.getBlockState(pos), player); + } + + @Unique + private static void ledgerLogDrainCauldron(Level world, BlockPos pos, BlockState oldState, Player player) { + BlockChangeCallback.EVENT.invoker().changeBlock( + world, + pos, + oldState, + Blocks.CAULDRON.defaultBlockState(), + null, + null, + Sources.DRAIN, + player); + } + + @Unique + private static void ledgerLogFillCauldron(Level world, BlockPos pos, BlockState oldState, BlockState newState, Player player) { + BlockChangeCallback.EVENT.invoker().changeBlock( + world, + pos, + oldState, + newState, + null, + null, + Sources.FILL, + player); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/LeveledCauldronBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/LayeredCauldronBlockMixin.java similarity index 50% rename from src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/LeveledCauldronBlockMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/LayeredCauldronBlockMixin.java index e4f89f2a..c589ad17 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/LeveledCauldronBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/cauldron/LayeredCauldronBlockMixin.java @@ -2,32 +2,32 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.LeveledCauldronBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityCollisionHandler; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.fluid.Fluid; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.biome.Biome; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.LayeredCauldronBlock; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.InsideBlockEffectApplier; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.material.Fluid; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.biome.Biome; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -@Mixin(LeveledCauldronBlock.class) -public abstract class LeveledCauldronBlockMixin { +@Mixin(LayeredCauldronBlock.class) +public abstract class LayeredCauldronBlockMixin { @Unique - private static PlayerEntity playerEntity; + private static Player playerEntity; - @Inject(method = "decrementFluidLevel", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", + @Inject(method = "lowerFillLevel", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) - private static void ledgerLogDecrementLevelCauldron(BlockState state, World world, BlockPos pos, CallbackInfo ci) { + private static void ledgerLogDecrementLevelCauldron(BlockState state, Level world, BlockPos pos, CallbackInfo ci) { if (playerEntity != null) { BlockChangeCallback.EVENT.invoker().changeBlock( world, @@ -53,16 +53,16 @@ private static void ledgerLogDecrementLevelCauldron(BlockState state, World worl } @Inject(method = "method_71627", at = @At(value = "INVOKE", - target = "Lnet/minecraft/block/LeveledCauldronBlock;onFireCollision(Lnet/minecraft/block/BlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V")) - private void ledgerLogPlayerExtinguish(ServerWorld serverWorld, BlockPos blockPos, BlockState blockState, World world, Entity collidedEntity, CallbackInfo ci) { - if (collidedEntity instanceof PlayerEntity) { - playerEntity = (PlayerEntity) collidedEntity; + target = "Lnet/minecraft/world/level/block/LayeredCauldronBlock;handleEntityOnFireInside(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;)V")) + private void ledgerLogPlayerExtinguish(ServerLevel serverWorld, BlockPos blockPos, BlockState blockState, Level world, Entity collidedEntity, CallbackInfo ci) { + if (collidedEntity instanceof Player) { + playerEntity = (Player) collidedEntity; } } - @Inject(method = "fillFromDripstone", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER)) - private void ledgerLogIncrementLevelCauldron(BlockState state, World world, BlockPos pos, Fluid fluid, CallbackInfo ci) { + @Inject(method = "receiveStalactiteDrip", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) + private void ledgerLogIncrementLevelCauldron(BlockState state, Level world, BlockPos pos, Fluid fluid, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, @@ -73,9 +73,9 @@ private void ledgerLogIncrementLevelCauldron(BlockState state, World world, Bloc Sources.DRIP); } - @Inject(method = "precipitationTick", at = @At(value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", shift = At.Shift.AFTER)) - private void ledgerLogIncrementLevelCauldron(BlockState state, World world, BlockPos pos, Biome.Precipitation precipitation, CallbackInfo ci) { + @Inject(method = "handlePrecipitation", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) + private void ledgerLogIncrementLevelCauldron(BlockState state, Level world, BlockPos pos, Biome.Precipitation precipitation, CallbackInfo ci) { BlockChangeCallback.EVENT.invoker().changeBlock( world, pos, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralBlockMixin.java deleted file mode 100644 index b547dea8..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralBlockMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks.coral; - -import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(CoralBlock.class) -public abstract class CoralBlockMixin { - @ModifyArgs(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logCoralDeath(Args args, BlockState oldState, ServerWorld world, BlockPos pos, Random random) { - BlockState newState = args.get(1); - BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, Sources.DECAY); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralFanBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralFanBlockMixin.java index 0a6fb75f..87c97da9 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralFanBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralFanBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralFanBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CoralFanBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -14,8 +14,8 @@ @Mixin(CoralFanBlock.class) public abstract class CoralFanBlockMixin { - @ModifyArgs(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logCoralDeath(Args args, BlockState oldState, ServerWorld world, BlockPos pos, Random random) { + @ModifyArgs(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logCoralDeath(Args args, BlockState oldState, ServerLevel world, BlockPos pos, RandomSource random) { BlockState newState = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, Sources.DECAY); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralBlockBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralPlantBlockMixin.java similarity index 52% rename from src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralBlockBlockMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralPlantBlockMixin.java index bec8b7d9..50048b6b 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralBlockBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralPlantBlockMixin.java @@ -2,20 +2,20 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralBlockBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CoralPlantBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.invoke.arg.Args; -@Mixin(CoralBlockBlock.class) -public abstract class CoralBlockBlockMixin { - @ModifyArgs(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logCoralDeath(Args args, BlockState oldState, ServerWorld world, BlockPos pos, Random random) { +@Mixin(CoralPlantBlock.class) +public abstract class CoralPlantBlockMixin { + @ModifyArgs(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logCoralDeath(Args args, BlockState oldState, ServerLevel world, BlockPos pos, RandomSource random) { BlockState newState = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, Sources.DECAY); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralWallFanBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralWallFanBlockMixin.java index 165ecde3..6f93cc2e 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralWallFanBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/coral/CoralWallFanBlockMixin.java @@ -2,11 +2,11 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.CoralWallFanBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.CoralWallFanBlock; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.util.RandomSource; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.ModifyArgs; @@ -14,8 +14,8 @@ @Mixin(CoralWallFanBlock.class) public abstract class CoralWallFanBlockMixin { - @ModifyArgs(method = "scheduledTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - public void logCoralDeath(Args args, BlockState oldState, ServerWorld world, BlockPos pos, Random random) { + @ModifyArgs(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + public void logCoralDeath(Args args, BlockState oldState, ServerLevel world, BlockPos pos, RandomSource random) { BlockState newState = args.get(1); BlockChangeCallback.EVENT.invoker().changeBlock(world, pos, oldState, newState, null, null, Sources.DECAY); } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/ScreenHandlerMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/AbstractContainerMenuMixin.java similarity index 51% rename from src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/ScreenHandlerMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/AbstractContainerMenuMixin.java index 3ce4580b..794d6bd6 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/ScreenHandlerMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/AbstractContainerMenuMixin.java @@ -1,19 +1,19 @@ package com.github.quiltservertools.ledger.mixin.blocks.lectern; import com.github.quiltservertools.ledger.utility.PlayerLecternHook; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.screen.LecternScreenHandler; -import net.minecraft.screen.ScreenHandler; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.inventory.LecternMenu; +import net.minecraft.world.inventory.AbstractContainerMenu; 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(ScreenHandler.class) -public class ScreenHandlerMixin { - @Inject(method = "onClosed", at = @At(value = "HEAD")) - public void onClosed(PlayerEntity player, CallbackInfo ci) { - if (player.currentScreenHandler instanceof LecternScreenHandler) { +@Mixin(AbstractContainerMenu.class) +public class AbstractContainerMenuMixin { + @Inject(method = "removed", at = @At(value = "HEAD")) + public void onClosed(Player player, CallbackInfo ci) { + if (player.containerMenu instanceof LecternMenu) { PlayerLecternHook.getActiveHandlers().remove(player); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternBlockMixin.java index 6a0e6ff4..05ed9c43 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternBlockMixin.java @@ -3,16 +3,16 @@ import com.github.quiltservertools.ledger.callbacks.ItemInsertCallback; import com.github.quiltservertools.ledger.utility.PlayerLecternHook; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.block.LecternBlock; -import net.minecraft.block.entity.LecternBlockEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.LecternBlock; +import net.minecraft.world.level.block.entity.LecternBlockEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -20,15 +20,15 @@ @Mixin(LecternBlock.class) public class LecternBlockMixin { - @Inject(method = "putBook", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V")) - private static void logPutBook(LivingEntity user, World world, BlockPos pos, BlockState state, ItemStack stack, CallbackInfo ci) { + @Inject(method = "placeBook", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/BlockPos;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + private static void logPutBook(LivingEntity user, Level world, BlockPos pos, BlockState state, ItemStack stack, CallbackInfo ci) { LecternBlockEntity blockEntity = (LecternBlockEntity) world.getBlockEntity(pos); if (blockEntity == null) return; - ItemInsertCallback.EVENT.invoker().insert(blockEntity.getBook(), pos, (ServerWorld) world, Sources.PLAYER, (ServerPlayerEntity) user); + ItemInsertCallback.EVENT.invoker().insert(blockEntity.getBook(), pos, (ServerLevel) world, Sources.PLAYER, (ServerPlayer) user); } - @Inject(method = "openScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;openHandledScreen(Lnet/minecraft/screen/NamedScreenHandlerFactory;)Ljava/util/OptionalInt;")) - public void storeLectern(World world, BlockPos pos, PlayerEntity player, CallbackInfo ci) { + @Inject(method = "openScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;openMenu(Lnet/minecraft/world/MenuProvider;)Ljava/util/OptionalInt;")) + public void storeLectern(Level world, BlockPos pos, Player player, CallbackInfo ci) { PlayerLecternHook.getActiveHandlers().put(player, world.getBlockEntity(pos)); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternMenuMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternMenuMixin.java new file mode 100644 index 00000000..a48fd435 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternMenuMixin.java @@ -0,0 +1,25 @@ +package com.github.quiltservertools.ledger.mixin.blocks.lectern; + +import com.github.quiltservertools.ledger.callbacks.ItemRemoveCallback; +import com.github.quiltservertools.ledger.utility.PlayerLecternHook; +import com.github.quiltservertools.ledger.utility.Sources; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.LecternMenu; +import net.minecraft.server.level.ServerPlayer; +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(LecternMenu.class) +public class LecternMenuMixin { + @Inject(method = "clickMenuButton", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Container;setChanged()V")) + public void logPickBook(Player player, int id, CallbackInfoReturnable cir, @Local ItemStack itemStack) { + ServerPlayer serverPlayer = (ServerPlayer) player; + BlockEntity blockEntity = PlayerLecternHook.getActiveHandlers().get(player); + ItemRemoveCallback.EVENT.invoker().remove(itemStack, blockEntity.getBlockPos(), serverPlayer.level(), Sources.PLAYER, serverPlayer); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternScreenHandlerMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternScreenHandlerMixin.java deleted file mode 100644 index fdfbe29f..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/lectern/LecternScreenHandlerMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.blocks.lectern; - -import com.github.quiltservertools.ledger.callbacks.ItemRemoveCallback; -import com.github.quiltservertools.ledger.utility.PlayerLecternHook; -import com.github.quiltservertools.ledger.utility.Sources; -import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.LecternScreenHandler; -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; - -@Mixin(LecternScreenHandler.class) -public class LecternScreenHandlerMixin { - @Inject(method = "onButtonClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Inventory;markDirty()V")) - public void logPickBook(PlayerEntity player, int id, CallbackInfoReturnable cir, @Local ItemStack itemStack) { - ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player; - BlockEntity blockEntity = PlayerLecternHook.getActiveHandlers().get(player); - ItemRemoveCallback.EVENT.invoker().remove(itemStack, blockEntity.getPos(), serverPlayer.getEntityWorld(), Sources.PLAYER, serverPlayer); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockEntityMixin.java index 065f4b2a..8a1dd541 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockEntityMixin.java @@ -4,14 +4,14 @@ import com.github.quiltservertools.ledger.utility.NbtUtils; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.SignBlockEntity; -import net.minecraft.block.entity.SignText; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.level.block.entity.SignText; +import net.minecraft.world.entity.player.Player; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -31,15 +31,15 @@ public abstract class SignBlockEntityMixin { * @param instance The sign block entity being edited * @param textChanger A parameter for the original operation * @param front Whether the interaction is happening on the front of the sign - * @param original The original {@link SignBlockEntity#changeText(UnaryOperator, boolean)} operation that this + * @param original The original {@link SignBlockEntity#updateText(UnaryOperator, boolean)} operation that this * mixin wraps. * @return Returns the result of calling {@code original} with this method's parameters. */ @WrapOperation( - method = "tryChangeText", + method = "updateSignText", at = @At( value = "INVOKE", - target = "Lnet/minecraft/block/entity/SignBlockEntity;changeText(Ljava/util/function/UnaryOperator;Z)Z" + target = "Lnet/minecraft/world/level/block/entity/SignBlockEntity;updateText(Ljava/util/function/UnaryOperator;Z)Z" ) ) private boolean logSignTextChange( @@ -49,21 +49,21 @@ private boolean logSignTextChange( Operation original ) { - World world = instance.getWorld(); - DynamicRegistryManager registryManager = world.getRegistryManager(); - BlockPos pos = instance.getPos(); - BlockState state = instance.getCachedState(); + Level world = instance.getLevel(); + RegistryAccess registryManager = world.registryAccess(); + BlockPos pos = instance.getBlockPos(); + BlockState state = instance.getBlockState(); // a bad hack to copy the old sign block entity for rollbacks - @Nullable BlockEntity oldSignEntity = BlockEntity.createFromNbt(pos, state, NbtUtils.INSTANCE.createNbt(instance, registryManager), registryManager); + @Nullable BlockEntity oldSignEntity = BlockEntity.loadStatic(pos, state, NbtUtils.INSTANCE.createNbt(instance, registryManager), registryManager); boolean result = original.call(instance, textChanger, front); if (result && oldSignEntity != null) { assert world != null : "World cannot be null, this is already in the target method"; - UUID editorID = instance.getEditor(); - PlayerEntity player = world.getPlayerByUuid(editorID); + UUID editorID = instance.getPlayerWhoMayEdit(); + Player player = world.getPlayerByUUID(editorID); assert player != null : "The editor must exist, this is already checked in target method"; BlockChangeCallback.EVENT.invoker() diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/AbstractSignBlockMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockMixin.java similarity index 60% rename from src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/AbstractSignBlockMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockMixin.java index ca44c184..2bda5907 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/AbstractSignBlockMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/blocks/sign/SignBlockMixin.java @@ -4,22 +4,22 @@ import com.github.quiltservertools.ledger.utility.NbtUtils; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.minecraft.block.AbstractSignBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.SignBlockEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.SignChangingItem; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.SignBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.SignBlockEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.SignApplicator; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -@Mixin(AbstractSignBlock.class) -public class AbstractSignBlockMixin { +@Mixin(SignBlock.class) +public class SignBlockMixin { /** * Wraps the operation of item-based interactions with signs like waxing, dyeing, and using glow ink, with a @@ -33,32 +33,32 @@ public class AbstractSignBlockMixin { * @param signBlockEntity The sign block entity being interacted with * @param front Whether the interaction is happening on the front of the sign * @param player The player interacting with the sign - * @param original The original {@link SignChangingItem#useOnSign(World, SignBlockEntity, boolean, PlayerEntity)} + * @param original The original {@link SignApplicator#tryApplyToSign(Level, SignBlockEntity, boolean, Player)} * operation that this mixin wraps. * @return Returns the result of calling {@code original} with this method's parameters. */ @WrapOperation( - method = "onUseWithItem", + method = "useItemOn", at = @At( value = "INVOKE", - target = "Lnet/minecraft/item/SignChangingItem;useOnSign(Lnet/minecraft/world/World;Lnet/minecraft/block/entity/SignBlockEntity;ZLnet/minecraft/entity/player/PlayerEntity;)Z" + target = "Lnet/minecraft/world/item/SignApplicator;tryApplyToSign(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/block/entity/SignBlockEntity;ZLnet/minecraft/world/entity/player/Player;)Z" ) ) private boolean logSignItemInteraction( - SignChangingItem instance, - World world, - SignBlockEntity signBlockEntity, - boolean front, - PlayerEntity player, - Operation original + SignApplicator instance, + Level world, + SignBlockEntity signBlockEntity, + boolean front, + Player player, + Operation original ) { - BlockState state = signBlockEntity.getCachedState(); - BlockPos pos = signBlockEntity.getPos(); - DynamicRegistryManager registryManager = world.getRegistryManager(); + BlockState state = signBlockEntity.getBlockState(); + BlockPos pos = signBlockEntity.getBlockPos(); + RegistryAccess registryManager = world.registryAccess(); // a bad hack to copy the old sign block entity for rollbacks - @Nullable BlockEntity oldSignEntity = BlockEntity.createFromNbt(pos, state, NbtUtils.INSTANCE.createNbt(signBlockEntity, registryManager), registryManager); + @Nullable BlockEntity oldSignEntity = BlockEntity.loadStatic(pos, state, NbtUtils.INSTANCE.createNbt(signBlockEntity, registryManager), registryManager); boolean result = original.call(instance, world, signBlockEntity, front, player); if (result && oldSignEntity != null) { diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/AbstractHurtingProjectileMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/AbstractHurtingProjectileMixin.java new file mode 100644 index 00000000..4633c054 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/AbstractHurtingProjectileMixin.java @@ -0,0 +1,22 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.utility.PlayerCausable; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.hurtingprojectile.AbstractHurtingProjectile; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(AbstractHurtingProjectile.class) +public abstract class AbstractHurtingProjectileMixin implements PlayerCausable { + @Nullable + @Override + public Player getCausingPlayer() { + if (((AbstractHurtingProjectile) (Object) this).getOwner() instanceof Mob entity) { + if (entity.getTarget() instanceof Player player) { + return player; + } + } + return null; + } +} 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 deleted file mode 100644 index 2775fe6e..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandEntityMixin.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.EntityKillCallback; -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.decoration.ArmorStandEntity; -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.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ArmorStandEntity.class) -public abstract class ArmorStandEntityMixin { - @Unique - private NbtCompound oldEntityTags; - @Unique - private ItemStack oldEntityStack; - - @Inject(method = "equip", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;equipStack(Lnet/minecraft/entity/EquipmentSlot;Lnet/minecraft/item/ItemStack;)V")) - private void legerLogOldEntity(PlayerEntity player, EquipmentSlot slot, ItemStack playerStack, Hand hand, CallbackInfoReturnable cir) { - LivingEntity entity = (LivingEntity) (Object) this; - this.oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); - this.oldEntityStack = entity.getEquippedStack(slot); - } - - @Inject(method = "equip", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;equipStack(Lnet/minecraft/entity/EquipmentSlot;Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) - private void ledgerArmorStandInteract(PlayerEntity player, EquipmentSlot slot, ItemStack playerStack, Hand hand, CallbackInfoReturnable cir) { - LivingEntity entity = (LivingEntity) (Object) this; - if (!oldEntityStack.isEmpty()) { - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, oldEntityStack, player, Sources.REMOVE); - } - if (!playerStack.isEmpty()) { - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, playerStack, player, Sources.EQUIP); - } - } - - @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.getEntityWorld(), entity.getBlockPos(), entity, damageSource); - } - - @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(world, entity.getBlockPos(), entity, source); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandMixin.java new file mode 100644 index 00000000..24866d66 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ArmorStandMixin.java @@ -0,0 +1,59 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.EntityKillCallback; +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.decoration.ArmorStand; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionHand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ArmorStand.class) +public abstract class ArmorStandMixin { + @Unique + private CompoundTag oldEntityTags; + @Unique + private ItemStack oldEntityStack; + + @Inject(method = "swapItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;setItemSlot(Lnet/minecraft/world/entity/EquipmentSlot;Lnet/minecraft/world/item/ItemStack;)V")) + private void legerLogOldEntity(Player player, EquipmentSlot slot, ItemStack playerStack, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + this.oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + this.oldEntityStack = entity.getItemBySlot(slot); + } + + @Inject(method = "swapItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;setItemSlot(Lnet/minecraft/world/entity/EquipmentSlot;Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) + private void ledgerArmorStandInteract(Player player, EquipmentSlot slot, ItemStack playerStack, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + if (!oldEntityStack.isEmpty()) { + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, oldEntityStack, player, Sources.REMOVE); + } + if (!playerStack.isEmpty()) { + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, playerStack, player, Sources.EQUIP); + } + } + + @Inject(method = "causeDamage", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;kill(Lnet/minecraft/server/level/ServerLevel;)V")) + private void ledgerArmorStandKill(ServerLevel world, DamageSource damageSource, float amount, CallbackInfo ci) { + LivingEntity entity = (LivingEntity) (Object) this; + EntityKillCallback.EVENT.invoker().kill(entity.level(), entity.blockPosition(), entity, damageSource); + } + + @Inject(method = "hurtServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ArmorStand;kill(Lnet/minecraft/server/level/ServerLevel;)V")) + private void ledgerArmorStandKill(ServerLevel world, DamageSource source, float amount, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + EntityKillCallback.EVENT.invoker().kill(world, entity.blockPosition(), entity, source); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CatEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CatEntityMixin.java deleted file mode 100644 index e8ff265e..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CatEntityMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(CatEntity.class) -public abstract class CatEntityMixin { - @Unique - private NbtCompound oldEntityTags; - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CatEntity;setCollarColor(Lnet/minecraft/util/DyeColor;)V")) - private void ledgerLogOldEntity(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - LivingEntity entity = (LivingEntity) (Object) this; - this.oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CatEntity;setCollarColor(Lnet/minecraft/util/DyeColor;)V", shift = At.Shift.AFTER)) - private void ledgerCatCollarColour(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - LivingEntity entity = (LivingEntity) (Object) this; - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, player.getStackInHand(hand), player, Sources.DYE); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CatMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CatMixin.java new file mode 100644 index 00000000..6f48ebbf --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CatMixin.java @@ -0,0 +1,34 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.feline.Cat; +import net.minecraft.world.entity.player.Player; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Cat.class) +public abstract class CatMixin { + @Unique + private CompoundTag oldEntityTags; + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/feline/Cat;setCollarColor(Lnet/minecraft/world/item/DyeColor;)V")) + private void ledgerLogOldEntity(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + this.oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/feline/Cat;setCollarColor(Lnet/minecraft/world/item/DyeColor;)V", shift = At.Shift.AFTER)) + private void ledgerCatCollarColour(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, player.getItemInHand(hand), player, Sources.DYE); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CopperGolemEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CopperGolemEntityMixin.java deleted file mode 100644 index 40145fe0..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CopperGolemEntityMixin.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.listeners.EntityCallbackListenerKt; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import com.llamalad7.mixinextras.sugar.Share; -import com.llamalad7.mixinextras.sugar.ref.LocalRef; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.CopperGolemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(CopperGolemEntity.class) -public class CopperGolemEntityMixin { - @Inject(method = "interactMob", at = @At(value = "HEAD")) - public void setOldEntityTags(CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { - LivingEntity entity = (LivingEntity) (Object) this; - oldEntityTagsRef.set(NbtUtils.INSTANCE.createNbt(entity)); - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CopperGolemEntity;sheared(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/sound/SoundCategory;Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) - public void afterShear(PlayerEntity player, Hand hand, CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { - World world = player.getEntityWorld(); - CopperGolemEntity copperGolemEntity = (CopperGolemEntity) (Object) this; - BlockPos pos = copperGolemEntity.getBlockPos(); - EntityModifyCallback.EVENT.invoker().modify(world, pos, oldEntityTagsRef.get(), copperGolemEntity, null, player, Sources.SHEAR); - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;syncWorldEvent(Lnet/minecraft/entity/Entity;ILnet/minecraft/util/math/BlockPos;I)V", ordinal = 0)) - public void onWax(PlayerEntity player, Hand hand, CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { - World world = player.getEntityWorld(); - CopperGolemEntity copperGolemEntity = (CopperGolemEntity) (Object) this; - BlockPos pos = copperGolemEntity.getBlockPos(); - EntityModifyCallback.EVENT.invoker().modify(world, pos, oldEntityTagsRef.get(), copperGolemEntity, null, player, Sources.WAX); - } - - // This catches 2 cases - removing oxidation with an axe, and using an axe on an unaffected copper golem resetting their next oxidation age. - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSoundFromEntity(Lnet/minecraft/entity/Entity;Lnet/minecraft/entity/Entity;Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V")) - public void onAxe(PlayerEntity player, Hand hand, CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { - World world = player.getEntityWorld(); - CopperGolemEntity copperGolemEntity = (CopperGolemEntity) (Object) this; - BlockPos pos = copperGolemEntity.getBlockPos(); - EntityModifyCallback.EVENT.invoker().modify(world, pos, oldEntityTagsRef.get(), copperGolemEntity, null, player, Sources.INTERACT); - } - - @Inject(method = "turnIntoStatue", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/CopperGolemEntity;discard()V")) - public void onTurningIntoStatue(ServerWorld world, CallbackInfo ci) { - CopperGolemEntity copperGolemEntity = (CopperGolemEntity) (Object) this; - BlockPos pos = copperGolemEntity.getBlockPos(); - EntityCallbackListenerKt.onKill(world, pos, copperGolemEntity, Sources.STATUE); - - BlockState blockState = world.getBlockState(pos); - BlockEntity be = world.getBlockEntity(pos); - BlockPlaceCallback.EVENT.invoker().place(world, pos, blockState, be, Sources.STATUE); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CopperGolemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CopperGolemMixin.java new file mode 100644 index 00000000..f6906890 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CopperGolemMixin.java @@ -0,0 +1,70 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.listeners.EntityCallbackListenerKt; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.golem.CopperGolem; +import net.minecraft.world.entity.player.Player; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(CopperGolem.class) +public class CopperGolemMixin { + @Inject(method = "mobInteract", at = @At(value = "HEAD")) + public void setOldEntityTags(CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { + LivingEntity entity = (LivingEntity) (Object) this; + oldEntityTagsRef.set(NbtUtils.INSTANCE.createNbt(entity)); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/golem/CopperGolem;shear(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/sounds/SoundSource;Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) + public void afterShear(Player player, InteractionHand hand, CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { + Level world = player.level(); + CopperGolem copperGolemEntity = (CopperGolem) (Object) this; + BlockPos pos = copperGolemEntity.blockPosition(); + EntityModifyCallback.EVENT.invoker().modify(world, pos, oldEntityTagsRef.get(), copperGolemEntity, null, player, Sources.SHEAR); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;levelEvent(Lnet/minecraft/world/entity/Entity;ILnet/minecraft/core/BlockPos;I)V", ordinal = 0)) + public void onWax(Player player, InteractionHand hand, CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { + Level world = player.level(); + CopperGolem copperGolemEntity = (CopperGolem) (Object) this; + BlockPos pos = copperGolemEntity.blockPosition(); + EntityModifyCallback.EVENT.invoker().modify(world, pos, oldEntityTagsRef.get(), copperGolemEntity, null, player, Sources.WAX); + } + + // This catches 2 cases - removing oxidation with an axe, and using an axe on an unaffected copper golem resetting their next oxidation age. + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;playSound(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FF)V")) + public void onAxe(Player player, InteractionHand hand, CallbackInfoReturnable cir, @Share("oldEntityTags") LocalRef oldEntityTagsRef) { + Level world = player.level(); + CopperGolem copperGolemEntity = (CopperGolem) (Object) this; + BlockPos pos = copperGolemEntity.blockPosition(); + EntityModifyCallback.EVENT.invoker().modify(world, pos, oldEntityTagsRef.get(), copperGolemEntity, null, player, Sources.INTERACT); + } + + @Inject(method = "turnToStatue", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/golem/CopperGolem;discard()V")) + public void onTurningIntoStatue(ServerLevel world, CallbackInfo ci) { + CopperGolem copperGolemEntity = (CopperGolem) (Object) this; + BlockPos pos = copperGolemEntity.blockPosition(); + EntityCallbackListenerKt.onKill(world, pos, copperGolemEntity, Sources.STATUE); + + BlockState blockState = world.getBlockState(pos); + BlockEntity be = world.getBlockEntity(pos); + BlockPlaceCallback.EVENT.invoker().place(world, pos, blockState, be, Sources.STATUE); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CreeperEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CreeperEntityMixin.java deleted file mode 100644 index 3dad3a3f..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CreeperEntityMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.utility.PlayerCausable; -import net.minecraft.entity.mob.CreeperEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(CreeperEntity.class) -public abstract class CreeperEntityMixin implements PlayerCausable { - @Unique - private PlayerEntity ignitePlayer; - - @Unique - @Override - public PlayerEntity getCausingPlayer() { - if (ignitePlayer != null) return ignitePlayer; - if (((CreeperEntity) (Object) this).getTarget() instanceof PlayerEntity player) return player; - return null; - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/mob/CreeperEntity;ignite()V")) - private void trackIgnitingPlayer(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - ignitePlayer = player; - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CreeperMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CreeperMixin.java new file mode 100644 index 00000000..f5ed6e08 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/CreeperMixin.java @@ -0,0 +1,31 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.utility.PlayerCausable; +import net.minecraft.world.entity.monster.Creeper; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Creeper.class) +public abstract class CreeperMixin implements PlayerCausable { + @Unique + private Player ignitePlayer; + + @Unique + @Override + public Player getCausingPlayer() { + if (ignitePlayer != null) return ignitePlayer; + if (((Creeper) (Object) this).getTarget() instanceof Player player) return player; + return null; + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/monster/Creeper;ignite()V")) + private void trackIgnitingPlayer(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + ignitePlayer = player; + } +} 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 deleted file mode 100644 index 5d1cd72a..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalEntityMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.utility.PlayerCausable; -import net.minecraft.entity.damage.DamageSource; -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; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(EndCrystalEntity.class) -public abstract class EndCrystalEntityMixin implements PlayerCausable { - - @Unique - private PlayerEntity causingPlayer; - - @Unique - @Override - public PlayerEntity getCausingPlayer() { - return causingPlayer; - } - - @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) { - this.causingPlayer = player; - } - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalMixin.java new file mode 100644 index 00000000..168f8fc5 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EndCrystalMixin.java @@ -0,0 +1,35 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.utility.PlayerCausable; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.boss.enderdragon.EndCrystal; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.projectile.Projectile; +import net.minecraft.server.level.ServerLevel; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(EndCrystal.class) +public abstract class EndCrystalMixin implements PlayerCausable { + + @Unique + private Player causingPlayer; + + @Unique + @Override + public Player getCausingPlayer() { + return causingPlayer; + } + + @Inject(method = "hurtServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;explode(Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/damagesource/DamageSource;Lnet/minecraft/world/level/ExplosionDamageCalculator;DDDFZLnet/minecraft/world/level/Level$ExplosionInteraction;)V")) + public void correctEndCrystalEntitySource(ServerLevel world, DamageSource source, float amount, CallbackInfoReturnable cir) { + if (source.getDirectEntity() instanceof Player player) { + this.causingPlayer = player; + } else if (source.getDirectEntity() instanceof Projectile projectile && projectile.getOwner() instanceof Player player) { + this.causingPlayer = 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 deleted file mode 100644 index ec46b718..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonEntityMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -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; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; - -@Mixin(EnderDragonEntity.class) -public abstract class EnderDragonEntityMixin { - @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; - 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/EnderDragonMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonMixin.java new file mode 100644 index 00000000..a0259655 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EnderDragonMixin.java @@ -0,0 +1,30 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.level.Level; +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(EnderDragon.class) +public abstract class EnderDragonMixin { + @Inject( + method = "checkWalls", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/server/level/ServerLevel;removeBlock(Lnet/minecraft/core/BlockPos;Z)Z" + ) + ) + private void logEnderDragonBreakingBlocks(ServerLevel world, AABB box, CallbackInfoReturnable cir, @Local BlockPos blockPos) { + EnderDragon entity = (EnderDragon) (Object) this; + BlockBreakCallback.EVENT.invoker().breakBlock(world, blockPos, world.getBlockState(blockPos), world.getBlockEntity(blockPos), BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).getPath()); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EvokerEntityWololoGoalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EvokerEntityWololoGoalMixin.java index 638e5c6a..c79eef21 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EvokerEntityWololoGoalMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/EvokerEntityWololoGoalMixin.java @@ -4,11 +4,11 @@ import com.github.quiltservertools.ledger.utility.NbtUtils; import com.github.quiltservertools.ledger.utility.Sources; import com.llamalad7.mixinextras.sugar.Local; -import net.minecraft.entity.mob.EvokerEntity; -import net.minecraft.entity.passive.SheepEntity; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.DyeColor; +import net.minecraft.world.entity.animal.sheep.Sheep; +import net.minecraft.world.entity.monster.illager.Evoker; +import net.minecraft.world.item.Items; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.item.DyeColor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; @@ -16,22 +16,22 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -@Mixin(EvokerEntity.WololoGoal.class) +@Mixin(Evoker.EvokerWololoSpellGoal.class) public abstract class EvokerEntityWololoGoalMixin { @Unique - private NbtCompound oldEntityTags; + private CompoundTag oldEntityTags; - @Inject(method = "castSpell", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;setColor(Lnet/minecraft/util/DyeColor;)V")) - public void legerLogOldEntity(CallbackInfo ci, @Local SheepEntity sheepEntity) { + @Inject(method = "performSpellCasting", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/sheep/Sheep;setColor(Lnet/minecraft/world/item/DyeColor;)V")) + public void legerLogOldEntity(CallbackInfo ci, @Local Sheep sheepEntity) { if (sheepEntity.getColor() != DyeColor.RED) { this.oldEntityTags = NbtUtils.INSTANCE.createNbt(sheepEntity); } } - @Inject(method = "castSpell", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/SheepEntity;setColor(Lnet/minecraft/util/DyeColor;)V", shift = At.Shift.AFTER)) - public void ledgerEvokerDyeSheep(CallbackInfo ci, @Local SheepEntity sheepEntity) { + @Inject(method = "performSpellCasting", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/sheep/Sheep;setColor(Lnet/minecraft/world/item/DyeColor;)V", shift = At.Shift.AFTER)) + public void ledgerEvokerDyeSheep(CallbackInfo ci, @Local Sheep sheepEntity) { if (oldEntityTags != null) { - EntityModifyCallback.EVENT.invoker().modify(sheepEntity.getEntityWorld(), sheepEntity.getBlockPos(), oldEntityTags, sheepEntity, Items.RED_DYE.getDefaultStack(), null, Sources.DYE); + EntityModifyCallback.EVENT.invoker().modify(sheepEntity.level(), sheepEntity.blockPosition(), oldEntityTags, sheepEntity, Items.RED_DYE.getDefaultInstance(), null, Sources.DYE); } } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ExplosiveProjectileEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ExplosiveProjectileEntityMixin.java deleted file mode 100644 index b911ec29..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ExplosiveProjectileEntityMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.utility.PlayerCausable; -import net.minecraft.entity.mob.MobEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ExplosiveProjectileEntity; -import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Mixin; - -@Mixin(ExplosiveProjectileEntity.class) -public abstract class ExplosiveProjectileEntityMixin implements PlayerCausable { - @Nullable - @Override - public PlayerEntity getCausingPlayer() { - if (((ExplosiveProjectileEntity) (Object) this).getOwner() instanceof MobEntity entity) { - if (entity.getTarget() instanceof PlayerEntity player) { - return player; - } - } - return null; - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/FallingBlockEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/FallingBlockEntityMixin.java index 7a965e15..66ff4840 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/FallingBlockEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/FallingBlockEntityMixin.java @@ -3,10 +3,10 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.block.BlockState; -import net.minecraft.entity.FallingBlockEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.item.FallingBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -21,11 +21,11 @@ public abstract class FallingBlockEntityMixin { private BlockState blockState; @Inject( - method = "spawnFromBlock", + method = "fall", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) - private static void ledgerBlockFallInvoker(World world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) + private static void ledgerBlockFallInvoker(Level world, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, state, state.hasBlockEntity() ? world.getBlockEntity(pos) : null, Sources.GRAVITY); } @@ -33,10 +33,10 @@ private static void ledgerBlockFallInvoker(World world, BlockPos pos, BlockState method = "tick", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z")) + target = "Lnet/minecraft/world/level/Level;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z")) private void ledgerBlockLandInvoker(Args args) { FallingBlockEntity entity = (FallingBlockEntity) (Object) this; BlockPos pos = args.get(0); - BlockPlaceCallback.EVENT.invoker().place(entity.getEntityWorld(), pos, this.blockState, null, Sources.GRAVITY); + BlockPlaceCallback.EVENT.invoker().place(entity.level(), pos, this.blockState, null, Sources.GRAVITY); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemEntityMixin.java index 0b3e4cb6..d8a5f569 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemEntityMixin.java @@ -4,12 +4,12 @@ import com.llamalad7.mixinextras.sugar.Local; import com.llamalad7.mixinextras.sugar.Share; import com.llamalad7.mixinextras.sugar.ref.LocalRef; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -20,27 +20,27 @@ public abstract class ItemEntityMixin extends Entity { @Shadow - public abstract ItemStack getStack(); + public abstract ItemStack getItem(); - public ItemEntityMixin(EntityType type, World world) { + public ItemEntityMixin(EntityType type, Level world) { super(type, world); } - @Inject(method = "onPlayerCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;insertStack(Lnet/minecraft/item/ItemStack;)Z")) - public void storeItemStack(PlayerEntity player, CallbackInfo ci, @Local ItemStack itemStack, @Share("originalItemStack") LocalRef originalItemStackRef) { + @Inject(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;add(Lnet/minecraft/world/item/ItemStack;)Z")) + public void storeItemStack(Player player, CallbackInfo ci, @Local ItemStack itemStack, @Share("originalItemStack") LocalRef originalItemStackRef) { originalItemStackRef.set(itemStack.copy()); } // insertStack modifies the ItemStack instance of the ItemEntity // The player may not be able to pick up all items from the stack - @Inject(method = "onPlayerCollision", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;insertStack(Lnet/minecraft/item/ItemStack;)Z", shift = At.Shift.AFTER)) - private void logPlayerItemPickUp(PlayerEntity player, CallbackInfo ci, @Local ItemStack modifiedItemStack, @Share("originalItemStack") LocalRef originalItemStackRef) { + @Inject(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;add(Lnet/minecraft/world/item/ItemStack;)Z", shift = At.Shift.AFTER)) + private void logPlayerItemPickUp(Player player, CallbackInfo ci, @Local ItemStack modifiedItemStack, @Share("originalItemStack") LocalRef originalItemStackRef) { var originalItemStack = originalItemStackRef.get(); int modifiedCount = modifiedItemStack.getCount(); int originalCount = originalItemStack.getCount(); if (modifiedCount < originalCount) { - ItemEntity itemEntityCopy = new ItemEntity(this.getEntityWorld(), this.getX(), this.getY(), this.getZ(), originalItemStackRef.get().copyWithCount(originalCount - modifiedCount)); + ItemEntity itemEntityCopy = new ItemEntity(this.level(), this.getX(), this.getY(), this.getZ(), originalItemStackRef.get().copyWithCount(originalCount - modifiedCount)); ItemPickUpCallback.EVENT.invoker().pickUp(itemEntityCopy, player); } } 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 deleted file mode 100644 index 4c08f017..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameEntityMixin.java +++ /dev/null @@ -1,83 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.EntityKillCallback; -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.Entity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.decoration.ItemFrameEntity; -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.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(ItemFrameEntity.class) -public abstract class ItemFrameEntityMixin { - @Shadow - public abstract ItemStack getHeldItemStack(); - - @Unique - private NbtCompound oldEntityTags; - - @Inject(method = "interact", at = @At(value = "HEAD")) - private void ledgerLogOldEntity(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - Entity entity = (Entity) (Object) this; - oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); - } - - @Inject(method = "dropHeldStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setHeldItemStack(Lnet/minecraft/item/ItemStack;)V")) - private void ledgerLogOldEntity2(ServerWorld world, Entity entityActor, boolean dropSelf, CallbackInfo ci) { - if (entityActor == null) { - return; - } - Entity entity = (Entity) (Object) this; - oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); - } - - @Inject(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setHeldItemStack(Lnet/minecraft/item/ItemStack;)V", shift = At.Shift.AFTER)) - private void ledgerItemFrameEquip(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - ItemStack playerStack = player.getStackInHand(hand); - Entity entity = (Entity) (Object) this; - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, playerStack, player, Sources.EQUIP); - } - - @Inject(method = "dropHeldStack", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setHeldItemStack(Lnet/minecraft/item/ItemStack;)V")) - private void ledgerItemFrameRemove(ServerWorld world, Entity entityActor, boolean dropSelf, CallbackInfo ci) { - ItemStack entityStack = this.getHeldItemStack(); - if (entityStack.isEmpty() || entityActor == null) { - return; - } - Entity entity = (Entity) (Object) this; - EntityModifyCallback.EVENT.invoker().modify(entityActor.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, entityStack, entityActor, Sources.REMOVE); - } - - @Inject(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;setRotation(I)V", shift = At.Shift.AFTER)) - private void ledgerItemFrameRotate(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - Entity entity = (Entity) (Object) this; - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, null, player, Sources.ROTATE); - } - - @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.getEntityWorld(), entity.getBlockPos(), entity, source); - } - - @Inject(method = "canStayAttached", at = @At(value = "RETURN")) - private void ledgerItemFrameKill(CallbackInfoReturnable cir) { - if (cir.getReturnValue() == Boolean.FALSE) { - Entity entity = (Entity) (Object) this; - EntityKillCallback.EVENT.invoker().kill(entity.getEntityWorld(), entity.getBlockPos(), entity, entity.getDamageSources().magic()); - } - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameMixin.java new file mode 100644 index 00000000..becb340f --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ItemFrameMixin.java @@ -0,0 +1,83 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.EntityKillCallback; +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.decoration.ItemFrame; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(ItemFrame.class) +public abstract class ItemFrameMixin { + @Shadow + public abstract ItemStack getItem(); + + @Unique + private CompoundTag oldEntityTags; + + @Inject(method = "interact", at = @At(value = "HEAD")) + private void ledgerLogOldEntity(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + Entity entity = (Entity) (Object) this; + oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + } + + @Inject(method = "dropItem(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/Entity;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ItemFrame;setItem(Lnet/minecraft/world/item/ItemStack;)V")) + private void ledgerLogOldEntity2(ServerLevel world, Entity entityActor, boolean dropSelf, CallbackInfo ci) { + if (entityActor == null) { + return; + } + Entity entity = (Entity) (Object) this; + oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + } + + @Inject(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ItemFrame;setItem(Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) + private void ledgerItemFrameEquip(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + ItemStack playerStack = player.getItemInHand(hand); + Entity entity = (Entity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, playerStack, player, Sources.EQUIP); + } + + @Inject(method = "dropItem(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/Entity;Z)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ItemFrame;setItem(Lnet/minecraft/world/item/ItemStack;)V")) + private void ledgerItemFrameRemove(ServerLevel world, Entity entityActor, boolean dropSelf, CallbackInfo ci) { + ItemStack entityStack = this.getItem(); + if (entityStack.isEmpty() || entityActor == null) { + return; + } + Entity entity = (Entity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(entityActor.level(), entity.blockPosition(), oldEntityTags, entity, entityStack, entityActor, Sources.REMOVE); + } + + @Inject(method = "interact", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/ItemFrame;setRotation(I)V", shift = At.Shift.AFTER)) + private void ledgerItemFrameRotate(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + Entity entity = (Entity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, null, player, Sources.ROTATE); + } + + @Inject(method = "hurtServer", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/decoration/HangingEntity;hurtServer(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/damagesource/DamageSource;F)Z")) + private void ledgerItemFrameKill(ServerLevel world, DamageSource source, float amount, CallbackInfoReturnable cir) { + Entity entity = (Entity) (Object) this; + EntityKillCallback.EVENT.invoker().kill(entity.level(), entity.blockPosition(), entity, source); + } + + @Inject(method = "survives", at = @At(value = "RETURN")) + private void ledgerItemFrameKill(CallbackInfoReturnable cir) { + if (cir.getReturnValue() == Boolean.FALSE) { + Entity entity = (Entity) (Object) this; + EntityKillCallback.EVENT.invoker().kill(entity.level(), entity.blockPosition(), entity, entity.damageSources().magic()); + } + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningBoltMixin.java similarity index 51% rename from src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningBoltMixin.java index 2da2d966..d311a20c 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LightningBoltMixin.java @@ -2,42 +2,42 @@ 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; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LightningBolt; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.BlockPos; 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(LightningEntity.class) -public abstract class LightningEntityMixin { +@Mixin(LightningBolt.class) +public abstract class LightningBoltMixin { @Inject( method = "spawnFire", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z", + target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/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()); + LightningBolt entity = (LightningBolt) (Object) this; + BlockPlaceCallback.EVENT.invoker().place(entity.level(), blockPos, blockState, null, BuiltInRegistries.ENTITY_TYPE.getKey(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", + target = "Lnet/minecraft/server/level/ServerLevel;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/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(), blockPos, blockState, null, Registries.ENTITY_TYPE.getId(entity.getType()).getPath()); + LightningBolt entity = (LightningBolt) (Object) this; + BlockPlaceCallback.EVENT.invoker().place(entity.level(), blockPos, blockState, null, BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).getPath()); } } diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LivingEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LivingEntityMixin.java index 52f9f231..11449d62 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LivingEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/LivingEntityMixin.java @@ -2,10 +2,10 @@ import com.github.quiltservertools.ledger.callbacks.EntityDismountCallback; import com.github.quiltservertools.ledger.callbacks.EntityKillCallback; -import net.minecraft.entity.Entity; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.player.Player; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -14,22 +14,22 @@ @Mixin(LivingEntity.class) public abstract class LivingEntityMixin { @Inject( - method = "onDeath", - at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/damage/DamageSource;getAttacker()Lnet/minecraft/entity/Entity;") + method = "die", + at = @At(value = "INVOKE", target = "Lnet/minecraft/world/damagesource/DamageSource;getEntity()Lnet/minecraft/world/entity/Entity;") ) private void ledgerEntityKillInvoker(DamageSource source, CallbackInfo ci) { LivingEntity entity = (LivingEntity) (Object) this; EntityKillCallback.EVENT.invoker().kill( - entity.getEntityWorld(), entity.getBlockPos(), entity, source + entity.level(), entity.blockPosition(), entity, source ); } - @Inject(method = "onDismounted", at = @At("RETURN")) + @Inject(method = "dismountVehicle", at = @At("RETURN")) private void onEntityDismount(Entity vehicle, CallbackInfo ci) { LivingEntity entity = (LivingEntity) (Object) this; - if (!(entity instanceof PlayerEntity player)) { + if (!(entity instanceof Player player)) { return; } 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 deleted file mode 100644 index 7860068c..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobEntityMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -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.getEntityWorld(), entity.getBlockPos(), entity, Sources.CONVERSION); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobMixin.java new file mode 100644 index 00000000..b1d3718f --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/MobMixin.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.world.entity.EntityType; +import net.minecraft.world.entity.EntitySpawnReason; +import net.minecraft.world.entity.ConversionParams; +import net.minecraft.world.entity.Mob; +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(Mob.class) +public abstract class MobMixin { + @Inject( + method = "convertTo(Lnet/minecraft/world/entity/EntityType;Lnet/minecraft/world/entity/ConversionParams;Lnet/minecraft/world/entity/EntitySpawnReason;Lnet/minecraft/world/entity/ConversionParams$AfterConversion;)Lnet/minecraft/world/entity/Mob;", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/entity/Mob;discard()V" + ) + ) + private void ledgerEntityConversion(EntityType entityType, ConversionParams context, EntitySpawnReason reason, ConversionParams.AfterConversion finalizer, CallbackInfoReturnable cir) { + Mob entity = (Mob) (Object) this; + EntityCallbackListenerKt.onKill(entity.level(), entity.blockPosition(), 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 deleted file mode 100644 index 1b6ae518..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerEntityMixin.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; -import net.minecraft.entity.mob.RavagerEntity; -import net.minecraft.registry.Registries; -import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(RavagerEntity.class) -public abstract class RavagerEntityMixin { - @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).getEntityWorld(); - BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, world.getBlockState(pos), world.getBlockEntity(pos), Registries.ENTITY_TYPE.getId(((RavagerEntity) (Object) this).getType()).getPath()); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerMixin.java new file mode 100644 index 00000000..5d5c45dd --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/RavagerMixin.java @@ -0,0 +1,20 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; +import net.minecraft.world.entity.monster.Ravager; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.BlockPos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; + +@Mixin(Ravager.class) +public abstract class RavagerMixin { + @ModifyArgs(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerLevel;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;)Z")) + public void logRavagerBreakingLeaves(Args args) { + BlockPos pos = args.get(0); + var world = ((Ravager) (Object) this).level(); + BlockBreakCallback.EVENT.invoker().breakBlock(world, pos, world.getBlockState(pos), world.getBlockEntity(pos), BuiltInRegistries.ENTITY_TYPE.getKey(((Ravager) (Object) this).getType()).getPath()); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerMixin.java similarity index 63% rename from src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerEntityMixin.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerMixin.java index 3d00a334..c510cb96 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/ServerPlayerMixin.java @@ -1,20 +1,20 @@ package com.github.quiltservertools.ledger.mixin.entities; import com.github.quiltservertools.ledger.callbacks.ItemDropCallback; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.server.level.ServerPlayer; 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(ServerPlayerEntity.class) -public abstract class ServerPlayerEntityMixin { - @Inject(method = "dropItem", at = @At("RETURN")) +@Mixin(ServerPlayer.class) +public abstract class ServerPlayerMixin { + @Inject(method = "drop", at = @At("RETURN")) private void logPlayerItemDrop(ItemStack stack, boolean dropAtSelf, boolean retainOwnership, CallbackInfoReturnable cir) { - PlayerEntity player = (PlayerEntity) (Object) this; + Player player = (Player) (Object) this; var itemEntity = cir.getReturnValue(); if (itemEntity != null) { 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 deleted file mode 100644 index 957d1bd6..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepEntityMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.SheepEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(SheepEntity.class) -public abstract class SheepEntityMixin { - @Unique - private NbtCompound oldEntityTags; - - @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 = NbtUtils.INSTANCE.createNbt(entity); - } - - @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.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, null, player, Sources.SHEAR); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepMixin.java new file mode 100644 index 00000000..325806c4 --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SheepMixin.java @@ -0,0 +1,34 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.sheep.Sheep; +import net.minecraft.world.entity.player.Player; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Sheep.class) +public abstract class SheepMixin { + @Unique + private CompoundTag oldEntityTags; + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/sheep/Sheep;shear(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/sounds/SoundSource;Lnet/minecraft/world/item/ItemStack;)V")) + private void ledgerLogOldEntity(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/sheep/Sheep;shear(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/sounds/SoundSource;Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) + private void ledgerSheepWoolShear(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), 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 deleted file mode 100644 index 7d9dab17..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemEntityMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -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; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@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)) - public void logSnowGolemSnow(CallbackInfo ci, @Local BlockState blockState, @Local BlockPos blockPos) { - BlockPlaceCallback.EVENT.invoker().place(((LivingEntity) (Object) this).getEntityWorld(), blockPos, blockState, null, Sources.SNOW_GOLEM); - } - - @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 = NbtUtils.INSTANCE.createNbt(entity); - } - - @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.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, null, player, Sources.SHEAR); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemMixin.java new file mode 100644 index 00000000..a4f28c3c --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/SnowGolemMixin.java @@ -0,0 +1,44 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback; +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.golem.SnowGolem; +import net.minecraft.world.entity.player.Player; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.core.BlockPos; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SnowGolem.class) +public abstract class SnowGolemMixin { + @Unique + private CompoundTag oldEntityTags; + + @Inject(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;setBlockAndUpdate(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;)Z", shift = At.Shift.AFTER)) + public void logSnowGolemSnow(CallbackInfo ci, @Local BlockState blockState, @Local BlockPos blockPos) { + BlockPlaceCallback.EVENT.invoker().place(((LivingEntity) (Object) this).level(), blockPos, blockState, null, Sources.SNOW_GOLEM); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/golem/SnowGolem;shear(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/sounds/SoundSource;Lnet/minecraft/world/item/ItemStack;)V")) + private void ledgerOldEntity(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/golem/SnowGolem;shear(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/sounds/SoundSource;Lnet/minecraft/world/item/ItemStack;)V", shift = At.Shift.AFTER)) + private void ledgerSnowGolemPumpkinShear(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, null, player, Sources.SHEAR); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/WolfEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/WolfEntityMixin.java deleted file mode 100644 index f482e780..00000000 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/WolfEntityMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.github.quiltservertools.ledger.mixin.entities; - -import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; -import com.github.quiltservertools.ledger.utility.NbtUtils; -import com.github.quiltservertools.ledger.utility.Sources; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.WolfEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -@Mixin(WolfEntity.class) -public abstract class WolfEntityMixin { - @Unique - private NbtCompound oldEntityTags; - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setCollarColor(Lnet/minecraft/util/DyeColor;)V")) - private void ledgerOldEntity(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - LivingEntity entity = (LivingEntity) (Object) this; - oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); - } - - @Inject(method = "interactMob", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/passive/WolfEntity;setCollarColor(Lnet/minecraft/util/DyeColor;)V", shift = At.Shift.AFTER)) - private void ledgerDogCollarColour(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - LivingEntity entity = (LivingEntity) (Object) this; - EntityModifyCallback.EVENT.invoker().modify(player.getEntityWorld(), entity.getBlockPos(), oldEntityTags, entity, player.getStackInHand(hand), player, Sources.DYE); - } -} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/WolfMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/WolfMixin.java new file mode 100644 index 00000000..c18bfddf --- /dev/null +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/WolfMixin.java @@ -0,0 +1,34 @@ +package com.github.quiltservertools.ledger.mixin.entities; + +import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback; +import com.github.quiltservertools.ledger.utility.NbtUtils; +import com.github.quiltservertools.ledger.utility.Sources; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.wolf.Wolf; +import net.minecraft.world.entity.player.Player; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(Wolf.class) +public abstract class WolfMixin { + @Unique + private CompoundTag oldEntityTags; + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/wolf/Wolf;setCollarColor(Lnet/minecraft/world/item/DyeColor;)V")) + private void ledgerOldEntity(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + oldEntityTags = NbtUtils.INSTANCE.createNbt(entity); + } + + @Inject(method = "mobInteract", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/wolf/Wolf;setCollarColor(Lnet/minecraft/world/item/DyeColor;)V", shift = At.Shift.AFTER)) + private void ledgerDogCollarColour(Player player, InteractionHand hand, CallbackInfoReturnable cir) { + LivingEntity entity = (LivingEntity) (Object) this; + EntityModifyCallback.EVENT.invoker().modify(player.level(), entity.blockPosition(), oldEntityTags, entity, player.getItemInHand(hand), player, Sources.DYE); + } +} diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java index f1306831..8054f40f 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/CallForHelpGoalMixin.java @@ -3,15 +3,15 @@ import com.github.quiltservertools.ledger.callbacks.BlockBreakCallback; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.minecraft.entity.Entity; -import net.minecraft.registry.Registries; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.entity.Entity; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @Mixin( - targets = "net.minecraft.entity.mob.SilverfishEntity$CallForHelpGoal" + targets = "net.minecraft.world.entity.monster.Silverfish$SilverfishWakeUpFriendsGoal" ) public class CallForHelpGoalMixin { @@ -19,17 +19,17 @@ public class CallForHelpGoalMixin { method = "tick", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/World;breakBlock(Lnet/minecraft/util/math/BlockPos;ZLnet/minecraft/entity/Entity;)Z" + target = "Lnet/minecraft/world/level/Level;destroyBlock(Lnet/minecraft/core/BlockPos;ZLnet/minecraft/world/entity/Entity;)Z" ) ) private boolean logSilverFishBreakInfestedBlock( - World world, + Level world, BlockPos pos, boolean drop, Entity entity, Operation original ) { - String source = Registries.ENTITY_TYPE.getId(entity.getType()).getPath(); + String source = BuiltInRegistries.ENTITY_TYPE.getKey(entity.getType()).getPath(); BlockBreakCallback.EVENT.invoker() .breakBlock( world, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java index b2ba4553..18bfcf65 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/entities/silverfish/WanderAndInfestGoalMixin.java @@ -3,21 +3,21 @@ import com.github.quiltservertools.ledger.callbacks.BlockChangeCallback; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; -import net.minecraft.block.BlockState; -import net.minecraft.entity.ai.goal.WanderAroundGoal; -import net.minecraft.entity.mob.PathAwareEntity; -import net.minecraft.registry.Registries; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldAccess; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.ai.goal.RandomStrollGoal; +import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelAccessor; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @Mixin( - targets = "net.minecraft.entity.mob.SilverfishEntity$WanderAndInfestGoal" + targets = "net.minecraft.world.entity.monster.Silverfish$SilverfishMergeWithStoneGoal" ) -public abstract class WanderAndInfestGoalMixin extends WanderAroundGoal { +public abstract class WanderAndInfestGoalMixin extends RandomStrollGoal { - public WanderAndInfestGoalMixin(PathAwareEntity mob, double speed) { + public WanderAndInfestGoalMixin(PathfinderMob mob, double speed) { super(mob, speed); } @@ -25,22 +25,22 @@ public WanderAndInfestGoalMixin(PathAwareEntity mob, double speed) { method = "start", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/WorldAccess;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;I)Z" + target = "Lnet/minecraft/world/level/LevelAccessor;setBlock(Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;I)Z" ) ) private boolean logSilverFishInfestBlock( - WorldAccess worldAccess, + LevelAccessor worldAccess, BlockPos pos, BlockState state, int flags, Operation original ) { BlockState oldState = worldAccess.getBlockState(pos); - String source = Registries.ENTITY_TYPE.getId(this.mob.getType()).getPath(); + String source = BuiltInRegistries.ENTITY_TYPE.getKey(this.mob.getType()).getPath(); BlockChangeCallback.EVENT.invoker() .changeBlock( - this.mob.getEntityWorld(), + this.mob.level(), pos, oldState, state, diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/preview/EntityTrackerEntryAccessor.java b/src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerEntityAccessor.java similarity index 53% rename from src/main/java/com/github/quiltservertools/ledger/mixin/preview/EntityTrackerEntryAccessor.java rename to src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerEntityAccessor.java index b0a18be4..0c443208 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/preview/EntityTrackerEntryAccessor.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerEntityAccessor.java @@ -1,12 +1,12 @@ package com.github.quiltservertools.ledger.mixin.preview; -import net.minecraft.entity.Entity; -import net.minecraft.server.network.EntityTrackerEntry; +import net.minecraft.world.entity.Entity; +import net.minecraft.server.level.ServerEntity; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; -@Mixin(EntityTrackerEntry.class) -public interface EntityTrackerEntryAccessor { +@Mixin(ServerEntity.class) +public interface ServerEntityAccessor { @Accessor Entity getEntity(); diff --git a/src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerPlayerEntityMixin.java b/src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerPlayerEntityMixin.java index 5fa3e80c..376f2dc4 100644 --- a/src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerPlayerEntityMixin.java +++ b/src/main/java/com/github/quiltservertools/ledger/mixin/preview/ServerPlayerEntityMixin.java @@ -5,11 +5,11 @@ import com.github.quiltservertools.ledger.utility.HandlerWithContext; import com.llamalad7.mixinextras.sugar.Local; import kotlin.Pair; -import net.minecraft.inventory.SimpleInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.ScreenHandler; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.math.BlockPos; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.core.BlockPos; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -21,29 +21,29 @@ import static com.github.quiltservertools.ledger.utility.ItemChangeLogicKt.addItem; import static com.github.quiltservertools.ledger.utility.ItemChangeLogicKt.removeMatchingItem; -@Mixin(targets = "net.minecraft.server.network.ServerPlayerEntity$1") +@Mixin(targets = "net.minecraft.server.level.ServerPlayer$1") public abstract class ServerPlayerEntityMixin { // synthetic field ServerPlayerEntity from the outer class @Final @Shadow - ServerPlayerEntity field_58075; + ServerPlayer field_58075; @ModifyArg( - method = "updateState", + method = "sendInitialData", at = @At( value = "INVOKE", - target = "Lnet/minecraft/network/packet/s2c/play/InventoryS2CPacket;(IILjava/util/List;Lnet/minecraft/item/ItemStack;)V" + target = "Lnet/minecraft/network/protocol/game/ClientboundContainerSetContentPacket;(IILjava/util/List;Lnet/minecraft/world/item/ItemStack;)V" ), index = 2 ) - private List modifyStacks(List stacks, @Local(argsOnly = true) ScreenHandler handler) { + private List modifyStacks(List stacks, @Local(argsOnly = true) AbstractContainerMenu handler) { BlockPos pos = ((HandlerWithContext) handler).getPos(); if (pos == null) return stacks; - Preview preview = Ledger.previewCache.get(field_58075.getUuid()); + Preview preview = Ledger.previewCache.get(field_58075.getUUID()); if (preview == null) return stacks; List> modifiedItems = preview.getModifiedItems().get(pos); if (modifiedItems == null) return stacks; - SimpleInventory inventory = new SimpleInventory(stacks.toArray(new ItemStack[]{})); + SimpleContainer inventory = new SimpleContainer(stacks.toArray(new ItemStack[]{})); for (Pair modifiedItem : modifiedItems) { if (modifiedItem.component2()) { addItem(modifiedItem.component1(), inventory); @@ -51,6 +51,6 @@ private List modifyStacks(List stacks, @Local(argsOnly = t removeMatchingItem(modifiedItem.component1(), inventory); } } - return inventory.getHeldStacks(); + return inventory.getItems(); } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/Ledger.kt b/src/main/kotlin/com/github/quiltservertools/ledger/Ledger.kt index 14ad5ec9..e9b6781c 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/Ledger.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/Ledger.kt @@ -33,9 +33,9 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry import net.fabricmc.loader.api.FabricLoader -import net.minecraft.registry.Registries +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.resources.Identifier import net.minecraft.server.MinecraftServer -import net.minecraft.util.Identifier import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger import org.jetbrains.exposed.v1.core.vendors.SQLiteDialect @@ -98,9 +98,9 @@ object Ledger : DedicatedServerModInitializer, CoroutineScope { Ledger.launch { val idSet = setOf() - .plus(Registries.BLOCK.ids) - .plus(Registries.ITEM.ids) - .plus(Registries.ENTITY_TYPE.ids) + .plus(BuiltInRegistries.BLOCK.keySet()) + .plus(BuiltInRegistries.ITEM.keySet()) + .plus(BuiltInRegistries.ENTITY_TYPE.keySet()) logInfo("Inserting ${idSet.size} registry keys into the database...") DatabaseManager.insertIdentifiers(idSet) @@ -145,7 +145,7 @@ object Ledger : DedicatedServerModInitializer, CoroutineScope { registerEntityListeners() } - fun identifier(path: String) = Identifier.of(MOD_ID, path) + fun identifier(path: String) = Identifier.fromNamespaceAndPath(MOD_ID, path) } fun logDebug(message: String) = Ledger.logger.debug(message) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/AbstractActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/AbstractActionType.kt index 460db7bb..876cc638 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/AbstractActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/AbstractActionType.kt @@ -5,43 +5,43 @@ import com.github.quiltservertools.ledger.utility.MessageUtils import com.github.quiltservertools.ledger.utility.Sources import com.github.quiltservertools.ledger.utility.TextColorPallet import com.github.quiltservertools.ledger.utility.literal +import net.minecraft.ChatFormatting +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.BlockPos +import net.minecraft.network.chat.ClickEvent +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent +import net.minecraft.resources.Identifier import net.minecraft.server.MinecraftServer -import net.minecraft.server.PlayerConfigEntry -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.text.ClickEvent -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text -import net.minecraft.util.Formatting -import net.minecraft.util.Identifier +import net.minecraft.server.level.ServerPlayer +import net.minecraft.server.players.NameAndId import net.minecraft.util.Util -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.world.level.Level import java.time.Instant import kotlin.time.ExperimentalTime abstract class AbstractActionType : ActionType { override var id: Int = -1 override var timestamp: Instant = Instant.now() - override var pos: BlockPos = BlockPos.ORIGIN + override var pos: BlockPos = BlockPos.ZERO override var world: Identifier? = null - override var objectIdentifier: Identifier = Identifier.ofVanilla("air") - override var oldObjectIdentifier: Identifier = Identifier.ofVanilla("air") + override var objectIdentifier: Identifier = Identifier.withDefaultNamespace("air") + override var oldObjectIdentifier: Identifier = Identifier.withDefaultNamespace("air") override var objectState: String? = null override var oldObjectState: String? = null override var sourceName: String = Sources.UNKNOWN - override var sourceProfile: PlayerConfigEntry? = null + override var sourceProfile: NameAndId? = null override var extraData: String? = null override var rolledBack: Boolean = false override fun rollback(server: MinecraftServer): Boolean = false - override fun previewRollback(preview: Preview, player: ServerPlayerEntity) = Unit - override fun previewRestore(preview: Preview, player: ServerPlayerEntity) = Unit + override fun previewRollback(preview: Preview, player: ServerPlayer) = Unit + override fun previewRestore(preview: Preview, player: ServerPlayer) = Unit override fun restore(server: MinecraftServer): Boolean = false @ExperimentalTime - override fun getMessage(source: ServerCommandSource): Text { - val message = Text.translatable( + override fun getMessage(source: CommandSourceStack): Component { + val message = Component.translatable( "text.ledger.action_message", getTimeMessage(), getSourceMessage(), @@ -52,16 +52,16 @@ abstract class AbstractActionType : ActionType { message.style = TextColorPallet.light if (rolledBack) { - message.formatted(Formatting.STRIKETHROUGH) + message.withStyle(ChatFormatting.STRIKETHROUGH) } return message } @ExperimentalTime - open fun getTimeMessage(): Text = MessageUtils.instantToText(timestamp) + open fun getTimeMessage(): Component = MessageUtils.instantToText(timestamp) - open fun getSourceMessage(): Text { + open fun getSourceMessage(): Component { if (sourceProfile == null) { return "@$sourceName".literal().setStyle(TextColorPallet.secondary) } @@ -73,8 +73,8 @@ abstract class AbstractActionType : ActionType { return "@$sourceName (${sourceProfile!!.name})".literal().setStyle(TextColorPallet.secondary) } - open fun getActionMessage(): Text = Text.translatable("text.ledger.action.$identifier") - .styled { + open fun getActionMessage(): Component = Component.translatable("text.ledger.action.$identifier") + .withStyle { it.withHoverEvent( HoverEvent.ShowText( identifier.literal() @@ -82,12 +82,12 @@ abstract class AbstractActionType : ActionType { ) } - open fun getObjectMessage(source: ServerCommandSource): Text = Text.translatable( - Util.createTranslationKey( + open fun getObjectMessage(source: CommandSourceStack): Component = Component.translatable( + Util.makeDescriptionId( this.getTranslationType(), objectIdentifier ) - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowText( objectIdentifier.toString().literal() @@ -95,17 +95,17 @@ abstract class AbstractActionType : ActionType { ) } - open fun getLocationMessage(): Text = "${pos.x} ${pos.y} ${pos.z}".literal() + open fun getLocationMessage(): Component = "${pos.x} ${pos.y} ${pos.z}".literal() .setStyle(TextColorPallet.secondary) - .styled { + .withStyle { it.withHoverEvent( HoverEvent.ShowText( - Text.literal(world?.let { "$it\n" } ?: "") - .append(Text.translatable("text.ledger.action_message.location.hover")) + Component.literal(world?.let { "$it\n" } ?: "") + .append(Component.translatable("text.ledger.action_message.location.hover")) ) ).withClickEvent( ClickEvent.RunCommand( - "/lg tp ${world ?: World.OVERWORLD.value} ${pos.x} ${pos.y} ${pos.z}" + "/lg tp ${world ?: Level.OVERWORLD.identifier()} ${pos.x} ${pos.y} ${pos.z}" ) ) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ActionType.kt index f65cb2b7..7773200d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ActionType.kt @@ -3,13 +3,13 @@ package com.github.quiltservertools.ledger.actions import com.github.quiltservertools.ledger.actionutils.Preview import com.github.quiltservertools.ledger.config.ActionsSpec import com.github.quiltservertools.ledger.config.config +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.resources.Identifier import net.minecraft.server.MinecraftServer -import net.minecraft.server.PlayerConfigEntry -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.text.Text -import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockPos +import net.minecraft.server.level.ServerPlayer +import net.minecraft.server.players.NameAndId import java.time.Instant import kotlin.time.ExperimentalTime @@ -24,18 +24,18 @@ interface ActionType { var objectState: String? var oldObjectState: String? var sourceName: String - var sourceProfile: PlayerConfigEntry? + var sourceProfile: NameAndId? var extraData: String? var rolledBack: Boolean fun rollback(server: MinecraftServer): Boolean fun restore(server: MinecraftServer): Boolean - fun previewRollback(preview: Preview, player: ServerPlayerEntity) - fun previewRestore(preview: Preview, player: ServerPlayerEntity) + fun previewRollback(preview: Preview, player: ServerPlayer) + fun previewRestore(preview: Preview, player: ServerPlayer) fun getTranslationType(): String @ExperimentalTime - fun getMessage(source: ServerCommandSource): Text + fun getMessage(source: CommandSourceStack): Component fun isBlacklisted() = config[ActionsSpec.typeBlacklist].contains(identifier) || config[ActionsSpec.objectBlacklist].contains(objectIdentifier) || diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockBreakActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockBreakActionType.kt index 33e9d651..8913fd33 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockBreakActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockBreakActionType.kt @@ -2,20 +2,20 @@ package com.github.quiltservertools.ledger.actions import com.github.quiltservertools.ledger.utility.TextColorPallet import com.github.quiltservertools.ledger.utility.literal -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text +import net.minecraft.commands.CommandSourceStack +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent import net.minecraft.util.Util class BlockBreakActionType : BlockChangeActionType() { override val identifier = "block-break" - override fun getObjectMessage(source: ServerCommandSource): Text = Text.translatable( - Util.createTranslationKey( + override fun getObjectMessage(source: CommandSourceStack): Component = Component.translatable( + Util.makeDescriptionId( this.getTranslationType(), oldObjectIdentifier ) - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowText( oldObjectIdentifier.toString().literal() 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 05adb061..646e051b 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockChangeActionType.kt @@ -7,50 +7,50 @@ 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.commands.CommandSourceStack +import net.minecraft.core.HolderGetter +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.core.registries.Registries +import net.minecraft.nbt.TagParser +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket +import net.minecraft.resources.Identifier import net.minecraft.server.MinecraftServer -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.storage.NbtReadView -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text -import net.minecraft.util.ErrorReporter -import net.minecraft.util.Identifier +import net.minecraft.server.level.ServerPlayer +import net.minecraft.util.ProblemReporter import net.minecraft.util.Util +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.storage.TagValueInput open class BlockChangeActionType : AbstractActionType() { override val identifier = "block-change" override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - world?.setBlockState(pos, oldBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) - ErrorReporter.Logging({ "ledger:rollback:block-change@$pos" }, LOGGER).use { - world?.getBlockEntity(pos)?.read( - NbtReadView.create( + world?.setBlockAndUpdate(pos, oldBlockState(world.holderLookup(Registries.BLOCK))) + ProblemReporter.ScopedCollector({ "ledger:rollback:block-change@$pos" }, LOGGER).use { + world?.getBlockEntity(pos)?.loadWithComponents( + TagValueInput.create( it, - server.registryManager, - StringNbtReader.readCompound(extraData) + server.registryAccess(), + TagParser.parseCompoundFully(extraData!!) ) ) } - world?.chunkManager?.markForUpdate(pos) + world?.chunkSource?.blockChanged(pos) return true } - override fun previewRollback(preview: Preview, player: ServerPlayerEntity) { - if (player.entityWorld.registryKey.value == world) { - player.networkHandler.sendPacket( - BlockUpdateS2CPacket( + override fun previewRollback(preview: Preview, player: ServerPlayer) { + if (player.level().dimension().identifier() == world) { + player.connection.send( + ClientboundBlockUpdatePacket( pos, - oldBlockState(player.entityWorld.createCommandRegistryWrapper(RegistryKeys.BLOCK)) + oldBlockState(player.level().holderLookup(Registries.BLOCK)) ) ) preview.positions.add(pos) @@ -60,17 +60,17 @@ open class BlockChangeActionType : AbstractActionType() { override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world) - world?.setBlockState(pos, newBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) + world?.setBlockAndUpdate(pos, newBlockState(world.holderLookup(Registries.BLOCK))) return true } - override fun previewRestore(preview: Preview, player: ServerPlayerEntity) { - if (player.entityWorld.registryKey.value == world) { - player.networkHandler.sendPacket( - BlockUpdateS2CPacket( + override fun previewRestore(preview: Preview, player: ServerPlayer) { + if (player.level().dimension().identifier() == world) { + player.connection.send( + ClientboundBlockUpdatePacket( pos, - newBlockState(player.entityWorld.createCommandRegistryWrapper(RegistryKeys.BLOCK)) + newBlockState(player.level().holderLookup(Registries.BLOCK)) ) ) preview.positions.add(pos) @@ -79,15 +79,15 @@ open class BlockChangeActionType : AbstractActionType() { override fun getTranslationType() = "block" - override fun getObjectMessage(source: ServerCommandSource): Text { - val text = Text.literal("") + override fun getObjectMessage(source: CommandSourceStack): Component { + val text = Component.literal("") text.append( - Text.translatable( - Util.createTranslationKey( + Component.translatable( + Util.makeDescriptionId( this.getTranslationType(), oldObjectIdentifier ) - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowText( oldObjectIdentifier.toString().literal() @@ -98,12 +98,12 @@ open class BlockChangeActionType : AbstractActionType() { if (oldObjectIdentifier != objectIdentifier) { text.append(" → ".literal()) text.append( - Text.translatable( - Util.createTranslationKey( + Component.translatable( + Util.makeDescriptionId( this.getTranslationType(), objectIdentifier ) - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowText( objectIdentifier.toString().literal() @@ -115,22 +115,22 @@ open class BlockChangeActionType : AbstractActionType() { return text } - fun oldBlockState(blockLookup: RegistryEntryLookup) = checkForBlockState( + fun oldBlockState(blockLookup: HolderGetter) = checkForBlockState( oldObjectIdentifier, oldObjectState?.let { NbtUtils.blockStateFromProperties( - StringNbtReader.readCompound(it), + TagParser.parseCompoundFully(it), oldObjectIdentifier, blockLookup ) } ) - fun newBlockState(blockLookup: RegistryEntryLookup) = checkForBlockState( + fun newBlockState(blockLookup: HolderGetter) = checkForBlockState( objectIdentifier, objectState?.let { NbtUtils.blockStateFromProperties( - StringNbtReader.readCompound(it), + TagParser.parseCompoundFully(it), objectIdentifier, blockLookup ) @@ -138,13 +138,13 @@ open class BlockChangeActionType : AbstractActionType() { ) private fun checkForBlockState(identifier: Identifier, checkState: BlockState?): BlockState { - val block = Registries.BLOCK.getOptionalValue(identifier) + val block = BuiltInRegistries.BLOCK.getOptional(identifier) if (block.isEmpty) { logWarn("Unknown block $identifier") - return Blocks.AIR.defaultState + return Blocks.AIR.defaultBlockState() } - var state = block.get().defaultState + var state = block.get().defaultBlockState() if (checkState != null) state = checkState return state 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 70c83551..3268d119 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockPlaceActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/BlockPlaceActionType.kt @@ -4,22 +4,22 @@ import com.github.quiltservertools.ledger.utility.LOGGER 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.commands.CommandSourceStack +import net.minecraft.core.registries.Registries +import net.minecraft.nbt.TagParser +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent import net.minecraft.server.MinecraftServer -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.storage.NbtReadView -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text -import net.minecraft.util.ErrorReporter +import net.minecraft.util.ProblemReporter import net.minecraft.util.Util +import net.minecraft.world.level.storage.TagValueInput class BlockPlaceActionType : BlockChangeActionType() { override val identifier = "block-place" override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - world?.setBlockState(pos, oldBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK))) + world?.setBlockAndUpdate(pos, oldBlockState(world.holderLookup(Registries.BLOCK))) return world != null } @@ -28,15 +28,15 @@ class BlockPlaceActionType : BlockChangeActionType() { val world = server.getWorld(world) if (world != null) { - val state = newBlockState(world.createCommandRegistryWrapper(RegistryKeys.BLOCK)) - world.setBlockState(pos, state) + val state = newBlockState(world.holderLookup(Registries.BLOCK)) + world.setBlockAndUpdate(pos, state) if (state.hasBlockEntity()) { - ErrorReporter.Logging({ "ledger:restore:block-place@$pos" }, LOGGER).use { - world.getBlockEntity(pos)?.read( - NbtReadView.create( + ProblemReporter.ScopedCollector({ "ledger:restore:block-place@$pos" }, LOGGER).use { + world.getBlockEntity(pos)?.loadWithComponents( + TagValueInput.create( it, - server.registryManager, - StringNbtReader.readCompound(extraData) + server.registryAccess(), + TagParser.parseCompoundFully(extraData!!) ) ) } @@ -46,12 +46,12 @@ class BlockPlaceActionType : BlockChangeActionType() { return world != null } - override fun getObjectMessage(source: ServerCommandSource): Text = Text.translatable( - Util.createTranslationKey( + override fun getObjectMessage(source: CommandSourceStack): Component = Component.translatable( + Util.makeDescriptionId( this.getTranslationType(), objectIdentifier ) - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowText( objectIdentifier.toString().literal() 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 8178355d..64357c94 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityChangeActionType.kt @@ -6,29 +6,29 @@ import com.github.quiltservertools.ledger.utility.UUID import com.github.quiltservertools.ledger.utility.getWorld import com.github.quiltservertools.ledger.utility.literal 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.BlockItem -import net.minecraft.item.ItemStack -import net.minecraft.nbt.StringNbtReader -import net.minecraft.registry.DynamicRegistryManager -import net.minecraft.registry.Registries +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.RegistryAccess +import net.minecraft.core.UUIDUtil +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.nbt.TagParser +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent +import net.minecraft.resources.Identifier import net.minecraft.server.MinecraftServer -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.storage.NbtReadView -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text -import net.minecraft.util.ErrorReporter -import net.minecraft.util.Identifier +import net.minecraft.util.ProblemReporter import net.minecraft.util.Util -import net.minecraft.util.Uuids +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.decoration.HangingEntity +import net.minecraft.world.entity.decoration.ItemFrame +import net.minecraft.world.item.BlockItem +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.storage.TagValueInput class EntityChangeActionType : AbstractActionType() { override val identifier = "entity-change" override fun getTranslationType(): String { - val item = getStack(DynamicRegistryManager.EMPTY).item + val item = getStack(RegistryAccess.EMPTY).item return if (item is BlockItem) { "block" } else { @@ -36,31 +36,31 @@ class EntityChangeActionType : AbstractActionType() { } } - private fun getStack(registryManager: DynamicRegistryManager): ItemStack { + private fun getStack(registryManager: RegistryAccess): ItemStack { if (extraData == null) return ItemStack.EMPTY try { - val readView = NbtReadView.create( - ErrorReporter.EMPTY, + val readView = TagValueInput.create( + ProblemReporter.DISCARDING, registryManager, - StringNbtReader.readCompound(extraData) + TagParser.parseCompoundFully(extraData!!) ) return readView.read(ItemStack.MAP_CODEC).orElse(ItemStack.EMPTY) } catch (_: CommandSyntaxException) { // In an earlier version of ledger extraData only stored the item id - val item = Registries.ITEM.get(Identifier.of(extraData)) - return item.defaultStack + val item = BuiltInRegistries.ITEM.getValue(Identifier.parse(extraData!!)) + return item.defaultInstance } } - override fun getObjectMessage(source: ServerCommandSource): Text { - val text = Text.literal("") + override fun getObjectMessage(source: CommandSourceStack): Component { + val text = Component.literal("") text.append( - Text.translatable( - Util.createTranslationKey( + Component.translatable( + Util.makeDescriptionId( "entity", objectIdentifier ) - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowText( objectIdentifier.toString().literal() @@ -69,13 +69,15 @@ class EntityChangeActionType : AbstractActionType() { } ) - val stack = getStack(source.registryManager) + val stack = getStack(source.registryAccess()) if (!stack.isEmpty) { - text.append(Text.literal(" ").append(Text.translatable("text.ledger.action_message.with")).append(" ")) text.append( - Text.translatable( - stack.item.translationKey - ).setStyle(TextColorPallet.secondaryVariant).styled { + Component.literal(" ").append(Component.translatable("text.ledger.action_message.with")).append(" ") + ) + text.append( + Component.translatable( + stack.item.descriptionId + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowItem( stack @@ -90,20 +92,20 @@ class EntityChangeActionType : AbstractActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val oldEntity = StringNbtReader.readCompound(oldObjectState) - val optionalUUID = oldEntity.get(UUID, Uuids.INT_STREAM_CODEC) + val oldEntity = TagParser.parseCompoundFully(oldObjectState!!) + val optionalUUID = oldEntity.read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world?.getEntity(optionalUUID.get()) if (entity != null) { - ErrorReporter.Logging({ "ledger:rollback:entity-change@$pos" }, LOGGER).use { - val readView = NbtReadView.create(it, server.registryManager, oldEntity) - if (entity is ItemFrameEntity) { - entity.heldItemStack = ItemStack.EMPTY + ProblemReporter.ScopedCollector({ "ledger:rollback:entity-change@$pos" }, LOGGER).use { + val readView = TagValueInput.create(it, server.registryAccess(), oldEntity) + if (entity is ItemFrame) { + entity.item = ItemStack.EMPTY } when (entity) { - is LivingEntity -> entity.readData(readView) - is AbstractDecorationEntity -> entity.readData(readView) + is LivingEntity -> entity.load(readView) + is HangingEntity -> entity.load(readView) } } return true @@ -113,20 +115,20 @@ class EntityChangeActionType : AbstractActionType() { override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val newEntity = StringNbtReader.readCompound(objectState) - val optionalUUID = newEntity.get(UUID, Uuids.INT_STREAM_CODEC) + val newEntity = TagParser.parseCompoundFully(objectState!!) + val optionalUUID = newEntity.read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world?.getEntity(optionalUUID.get()) if (entity != null) { - ErrorReporter.Logging({ "ledger:restore:entity-change@$pos" }, LOGGER).use { - val readView = NbtReadView.create(it, server.registryManager, newEntity) - if (entity is ItemFrameEntity) { - entity.heldItemStack = ItemStack.EMPTY + ProblemReporter.ScopedCollector({ "ledger:restore:entity-change@$pos" }, LOGGER).use { + val readView = TagValueInput.create(it, server.registryAccess(), newEntity) + if (entity is ItemFrame) { + entity.item = ItemStack.EMPTY } when (entity) { - is LivingEntity -> entity.readData(readView) - is AbstractDecorationEntity -> entity.readData(readView) + is LivingEntity -> entity.load(readView) + is HangingEntity -> entity.load(readView) } } return true 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 2a07c653..811e8d8e 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/EntityKillActionType.kt @@ -4,71 +4,71 @@ import com.github.quiltservertools.ledger.actionutils.Preview import com.github.quiltservertools.ledger.utility.LOGGER 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.network.listener.ClientPlayPacketListener -import net.minecraft.network.packet.Packet -import net.minecraft.registry.Registries +import net.minecraft.core.UUIDUtil +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.nbt.TagParser +import net.minecraft.network.protocol.Packet +import net.minecraft.network.protocol.game.ClientGamePacketListener import net.minecraft.server.MinecraftServer -import net.minecraft.server.network.EntityTrackerEntry -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.server.world.ServerWorld -import net.minecraft.storage.NbtReadView -import net.minecraft.util.ErrorReporter -import net.minecraft.util.Uuids -import net.minecraft.util.math.Vec3d +import net.minecraft.server.level.ServerEntity +import net.minecraft.server.level.ServerLevel +import net.minecraft.server.level.ServerPlayer +import net.minecraft.util.ProblemReporter +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.EntitySpawnReason +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.level.storage.TagValueInput +import net.minecraft.world.phys.Vec3 import java.util.function.Predicate class EntityKillActionType : AbstractActionType() { override val identifier = "entity-kill" - val noopPacketSender = object : EntityTrackerEntry.TrackerPacketSender { - override fun sendToListeners(packet: Packet?) = Unit - override fun sendToSelfAndListeners(packet: Packet?) = Unit - override fun sendToListenersIf( - packet: Packet?, - predicate: Predicate? + val noopPacketSender = object : ServerEntity.Synchronizer { + override fun sendToTrackingPlayers(packet: Packet) = Unit + override fun sendToTrackingPlayersAndSelf(packet: Packet) = Unit + override fun sendToTrackingPlayersFiltered( + packet: Packet, + predicate: Predicate ) = Unit } override fun getTranslationType() = "entity" - private fun getEntity(world: ServerWorld, reporter: ErrorReporter): Entity? { - val entityType = Registries.ENTITY_TYPE.getOptionalValue(objectIdentifier) + private fun getEntity(world: ServerLevel, reporter: ProblemReporter): Entity? { + val entityType = BuiltInRegistries.ENTITY_TYPE.getOptional(objectIdentifier) if (entityType.isEmpty) return null - val entity = entityType.get().create(world, SpawnReason.COMMAND)!! - val readView = NbtReadView.create(reporter, world.registryManager, StringNbtReader.readCompound(extraData)) - entity.readData(readView) - entity.velocity = Vec3d.ZERO - entity.fireTicks = 0 - if (entity is LivingEntity) entity.health = entity.defaultMaxHealth.toFloat() + val entity = entityType.get().create(world, EntitySpawnReason.COMMAND)!! + val readView = TagValueInput.create(reporter, world.registryAccess(), TagParser.parseCompoundFully(extraData!!)) + entity.load(readView) + entity.setDeltaMovement(Vec3.ZERO) + entity.setRemainingFireTicks(0) + if (entity is LivingEntity) entity.health = entity.maxHealth return entity } - override fun previewRollback(preview: Preview, player: ServerPlayerEntity) { - val world = player.entityWorld.server.getWorld(world)!! - val entity = getEntity(world, ErrorReporter.EMPTY) + override fun previewRollback(preview: Preview, player: ServerPlayer) { + val world = player.level().server.getWorld(world)!! + val entity = getEntity(world, ProblemReporter.DISCARDING) ?: return - val entityTrackerEntry = EntityTrackerEntry(world, entity, 1, false, noopPacketSender) - entityTrackerEntry.startTracking(player) + val entityTrackerEntry = ServerEntity(world, entity, 1, false, noopPacketSender) + entityTrackerEntry.addPairing(player) preview.spawnedEntityTrackers.add(entityTrackerEntry) } - override fun previewRestore(preview: Preview, player: ServerPlayerEntity) { - val world = player.entityWorld.server.getWorld(world) + override fun previewRestore(preview: Preview, player: ServerPlayer) { + val world = player.level().server.getWorld(world) - val tag = StringNbtReader.readCompound(extraData) - val optionalUuid = tag.get("UUID", Uuids.INT_STREAM_CODEC) + val tag = TagParser.parseCompoundFully(extraData!!) + val optionalUuid = tag.read("UUID", UUIDUtil.CODEC) if (optionalUuid.isPresent) { val uuid = optionalUuid.get() val entity = world?.getEntity(uuid) entity?.let { - val entityTrackerEntry = EntityTrackerEntry(world, entity, 1, false, noopPacketSender) - entityTrackerEntry.stopTracking(player) + val entityTrackerEntry = ServerEntity(world, entity, 1, false, noopPacketSender) + entityTrackerEntry.removePairing(player) preview.removedEntityTrackers.add(entityTrackerEntry) } } @@ -76,9 +76,9 @@ class EntityKillActionType : AbstractActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world)!! - ErrorReporter.Logging({ "ledger:rollback:entity-kill@$pos" }, LOGGER).use { + ProblemReporter.ScopedCollector({ "ledger:rollback:entity-kill@$pos" }, LOGGER).use { val entity = getEntity(world, it) ?: return false - world.spawnEntity(entity) + world.addFreshEntity(entity) } return true } @@ -86,7 +86,7 @@ class EntityKillActionType : AbstractActionType() { override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val optionalUUID = StringNbtReader.readCompound(extraData)!!.get(UUID, Uuids.INT_STREAM_CODEC) + val optionalUUID = TagParser.parseCompoundFully(extraData!!).read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world?.getEntity(optionalUUID.get()) 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 49721213..d099ee12 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemChangeActionType.kt @@ -8,22 +8,22 @@ import com.github.quiltservertools.ledger.utility.getOtherChestSide import com.github.quiltservertools.ledger.utility.getWorld import com.github.quiltservertools.ledger.utility.literal import com.github.quiltservertools.ledger.utility.removeMatchingItem -import net.minecraft.block.Blocks -import net.minecraft.block.ChestBlock -import net.minecraft.block.InventoryProvider -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.ItemStack -import net.minecraft.item.Items +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent 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.math.BlockPos +import net.minecraft.server.level.ServerLevel +import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.Container +import net.minecraft.world.WorldlyContainerHolder +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.Items +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.ChestBlock +import net.minecraft.world.level.block.LecternBlock +import net.minecraft.world.level.block.entity.ChestBlockEntity +import net.minecraft.world.level.block.entity.LecternBlockEntity abstract class ItemChangeActionType : AbstractActionType() { // Not used @@ -32,15 +32,15 @@ abstract class ItemChangeActionType : AbstractActionType() { private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties( extraData, objectIdentifier, - server.registryManager + server.registryAccess() ) - override fun getObjectMessage(source: ServerCommandSource): Text { + override fun getObjectMessage(source: CommandSourceStack): Component { val stack = getStack(source.server) return "${stack.count} ".literal().append( stack.itemName - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowItem( stack @@ -49,10 +49,10 @@ abstract class ItemChangeActionType : AbstractActionType() { } } - protected fun previewItemChange(preview: Preview, player: ServerPlayerEntity, insert: Boolean) { - val world = player.entityWorld.server.getWorld(world) + protected fun previewItemChange(preview: Preview, player: ServerPlayer, insert: Boolean) { + val world = player.level().server.getWorld(world) val state = world?.getBlockState(pos) - state?.isOf(Blocks.CHEST)?.let { + state?.`is`(Blocks.CHEST)?.let { if (it) { val otherPos = getOtherChestSide(state, pos) if (otherPos != null) { @@ -63,24 +63,24 @@ abstract class ItemChangeActionType : AbstractActionType() { addPreview(preview, player, pos, insert) } - private fun addPreview(preview: Preview, player: ServerPlayerEntity, pos: BlockPos, insert: Boolean) { + private fun addPreview(preview: Preview, player: ServerPlayer, pos: BlockPos, insert: Boolean) { preview.modifiedItems.compute(pos) { _, list -> list ?: mutableListOf() - }?.add(Pair(getStack(player.entityWorld.server), insert)) + }?.add(Pair(getStack(player.level().server), insert)) } - private fun getInventory(world: ServerWorld): Inventory? { - var inventory: Inventory? = null + private fun getInventory(world: ServerLevel): Container? { + var inventory: Container? = null val blockState = world.getBlockState(pos) val block = blockState.block - if (block is InventoryProvider) { - inventory = (block as InventoryProvider).getInventory(blockState, world, pos) + if (block is WorldlyContainerHolder) { + inventory = (block as WorldlyContainerHolder).getContainer(blockState, world, pos) } else if (world.getBlockEntity(pos) != null) { val blockEntity = world.getBlockEntity(pos)!! - if (blockEntity is Inventory) { + if (blockEntity is Container) { inventory = blockEntity if (inventory is ChestBlockEntity && block is ChestBlock) { - inventory = ChestBlock.getInventory(block, blockState, world, pos, true) + inventory = ChestBlock.getContainer(block, blockState, world, pos, true) } } } @@ -96,11 +96,11 @@ abstract class ItemChangeActionType : AbstractActionType() { val rollbackStack = getStack(server) if (inventory != null) { return removeMatchingItem(rollbackStack, inventory) - } else if (rollbackStack.isOf(Items.WRITABLE_BOOK) || rollbackStack.isOf(Items.WRITTEN_BOOK)) { + } else if (rollbackStack.`is`(Items.WRITABLE_BOOK) || rollbackStack.`is`(Items.WRITTEN_BOOK)) { val blockEntity = world.getBlockEntity(pos) if (blockEntity is LecternBlockEntity) { blockEntity.book = ItemStack.EMPTY - LecternBlock.setHasBook(null, world, pos, blockEntity.cachedState, false) + LecternBlock.resetBookState(null, world, pos, blockEntity.blockState, false) return true } } @@ -117,11 +117,11 @@ abstract class ItemChangeActionType : AbstractActionType() { val rollbackStack = getStack(server) if (inventory != null) { return addItem(rollbackStack, inventory) - } else if (rollbackStack.isOf(Items.WRITABLE_BOOK) || rollbackStack.isOf(Items.WRITTEN_BOOK)) { + } else if (rollbackStack.`is`(Items.WRITABLE_BOOK) || rollbackStack.`is`(Items.WRITTEN_BOOK)) { val blockEntity = world.getBlockEntity(pos) if (blockEntity is LecternBlockEntity && !blockEntity.hasBook()) { blockEntity.book = rollbackStack - LecternBlock.setHasBook(null, world, pos, blockEntity.cachedState, true) + LecternBlock.resetBookState(null, world, pos, blockEntity.blockState, true) return true } } 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 be1fad17..89a58be6 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemDropActionType.kt @@ -6,17 +6,17 @@ import com.github.quiltservertools.ledger.utility.TextColorPallet import com.github.quiltservertools.ledger.utility.UUID import com.github.quiltservertools.ledger.utility.getWorld 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.nbt.StringNbtReader +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.UUIDUtil +import net.minecraft.nbt.TagParser +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent import net.minecraft.server.MinecraftServer -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.storage.NbtReadView -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text -import net.minecraft.util.ErrorReporter -import net.minecraft.util.Uuids +import net.minecraft.util.ProblemReporter +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.EntityType +import net.minecraft.world.entity.item.ItemEntity +import net.minecraft.world.level.storage.TagValueInput // TODO remove duplication from ItemPickUpActionType and ItemDropActionType open class ItemDropActionType : AbstractActionType() { @@ -28,15 +28,15 @@ open class ItemDropActionType : AbstractActionType() { private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties( extraData, objectIdentifier, - server.registryManager + server.registryAccess() ) - override fun getObjectMessage(source: ServerCommandSource): Text { + override fun getObjectMessage(source: CommandSourceStack): Component { val stack = getStack(source.server) return "${stack.count} ".literal().append( stack.itemName - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowItem( stack @@ -48,8 +48,8 @@ open class ItemDropActionType : AbstractActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val newEntity = StringNbtReader.readCompound(objectState) - val optionalUUID = newEntity!!.get(UUID, Uuids.INT_STREAM_CODEC) + val newEntity = TagParser.parseCompoundFully(objectState!!) + val optionalUUID = newEntity.read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world?.getEntity(optionalUUID.get()) @@ -63,17 +63,17 @@ open class ItemDropActionType : AbstractActionType() { override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world)!! - val newEntity = StringNbtReader.readCompound(objectState) - val optionalUUID = newEntity!!.get(UUID, Uuids.INT_STREAM_CODEC) + val newEntity = TagParser.parseCompoundFully(objectState!!) + val optionalUUID = newEntity.read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world.getEntity(optionalUUID.get()) if (entity == null) { val entity = ItemEntity(EntityType.ITEM, world) - ErrorReporter.Logging({ "ledger:restore:item-drop@$pos" }, LOGGER).use { - val readView = NbtReadView.create(it, world.registryManager, newEntity) - entity.readData(readView) - world.spawnEntity(entity) + ProblemReporter.ScopedCollector({ "ledger:restore:item-drop@$pos" }, LOGGER).use { + val readView = TagValueInput.create(it, world.registryAccess(), newEntity) + entity.load(readView) + world.addFreshEntity(entity) } } return true diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemInsertActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemInsertActionType.kt index fe7504d2..07d425e1 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemInsertActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemInsertActionType.kt @@ -2,16 +2,16 @@ package com.github.quiltservertools.ledger.actions import com.github.quiltservertools.ledger.actionutils.Preview import net.minecraft.server.MinecraftServer -import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.level.ServerPlayer class ItemInsertActionType : ItemChangeActionType() { override val identifier: String = "item-insert" - override fun previewRollback(preview: Preview, player: ServerPlayerEntity) { + override fun previewRollback(preview: Preview, player: ServerPlayer) { previewItemChange(preview, player, false) } - override fun previewRestore(preview: Preview, player: ServerPlayerEntity) { + override fun previewRestore(preview: Preview, player: ServerPlayer) { previewItemChange(preview, player, true) } 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 bacfd465..551486e1 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemPickUpActionType.kt @@ -6,17 +6,17 @@ import com.github.quiltservertools.ledger.utility.TextColorPallet import com.github.quiltservertools.ledger.utility.UUID import com.github.quiltservertools.ledger.utility.getWorld 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.nbt.StringNbtReader +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.UUIDUtil +import net.minecraft.nbt.TagParser +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent import net.minecraft.server.MinecraftServer -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.storage.NbtReadView -import net.minecraft.text.HoverEvent -import net.minecraft.text.Text -import net.minecraft.util.ErrorReporter -import net.minecraft.util.Uuids +import net.minecraft.util.ProblemReporter +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.EntityType +import net.minecraft.world.entity.item.ItemEntity +import net.minecraft.world.level.storage.TagValueInput open class ItemPickUpActionType : AbstractActionType() { override val identifier = "item-pick-up" @@ -27,15 +27,15 @@ open class ItemPickUpActionType : AbstractActionType() { private fun getStack(server: MinecraftServer) = NbtUtils.itemFromProperties( extraData, objectIdentifier, - server.registryManager + server.registryAccess() ) - override fun getObjectMessage(source: ServerCommandSource): Text { + override fun getObjectMessage(source: CommandSourceStack): Component { val stack = getStack(source.server) return "${stack.count} ".literal().append( stack.itemName - ).setStyle(TextColorPallet.secondaryVariant).styled { + ).setStyle(TextColorPallet.secondaryVariant).withStyle { it.withHoverEvent( HoverEvent.ShowItem( stack @@ -47,17 +47,17 @@ open class ItemPickUpActionType : AbstractActionType() { override fun rollback(server: MinecraftServer): Boolean { val world = server.getWorld(world)!! - val oldEntity = StringNbtReader.readCompound(oldObjectState) - val optionalUUID = oldEntity.get(UUID, Uuids.INT_STREAM_CODEC) + val oldEntity = TagParser.parseCompoundFully(oldObjectState!!) + val optionalUUID = oldEntity.read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world.getEntity(optionalUUID.get()) if (entity == null) { val entity = ItemEntity(EntityType.ITEM, world) - ErrorReporter.Logging({ "ledger:rollback:item-pick-up@$pos" }, LOGGER).use { - val readView = NbtReadView.create(it, world.registryManager, oldEntity) - entity.readData(readView) - world.spawnEntity(entity) + ProblemReporter.ScopedCollector({ "ledger:rollback:item-pick-up@$pos" }, LOGGER).use { + val readView = TagValueInput.create(it, world.registryAccess(), oldEntity) + entity.load(readView) + world.addFreshEntity(entity) } } return true @@ -66,8 +66,8 @@ open class ItemPickUpActionType : AbstractActionType() { override fun restore(server: MinecraftServer): Boolean { val world = server.getWorld(world) - val oldEntity = StringNbtReader.readCompound(oldObjectState) - val optionalUUID = oldEntity.get(UUID, Uuids.INT_STREAM_CODEC) + val oldEntity = TagParser.parseCompoundFully(oldObjectState!!) + val optionalUUID = oldEntity.read(UUID, UUIDUtil.CODEC) if (optionalUUID.isEmpty) return false val entity = world?.getEntity(optionalUUID.get()) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemRemoveActionType.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemRemoveActionType.kt index 69e4fdaa..e8f41664 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemRemoveActionType.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actions/ItemRemoveActionType.kt @@ -2,16 +2,16 @@ package com.github.quiltservertools.ledger.actions import com.github.quiltservertools.ledger.actionutils.Preview import net.minecraft.server.MinecraftServer -import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.level.ServerPlayer class ItemRemoveActionType : ItemChangeActionType() { override val identifier: String = "item-remove" - override fun previewRollback(preview: Preview, player: ServerPlayerEntity) { + override fun previewRollback(preview: Preview, player: ServerPlayer) { previewItemChange(preview, player, true) } - override fun previewRestore(preview: Preview, player: ServerPlayerEntity) { + override fun previewRestore(preview: Preview, player: ServerPlayer) { previewItemChange(preview, player, false) } 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 81f034da..42fad3af 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionFactory.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionFactory.kt @@ -15,72 +15,72 @@ import com.github.quiltservertools.ledger.actions.ItemRemoveActionType import com.github.quiltservertools.ledger.utility.NbtUtils import com.github.quiltservertools.ledger.utility.NbtUtils.createNbt import com.github.quiltservertools.ledger.utility.Sources -import net.minecraft.block.BlockState -import net.minecraft.block.Blocks -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.Entity -import net.minecraft.entity.ItemEntity -import net.minecraft.entity.LivingEntity -import net.minecraft.entity.damage.DamageSource -import net.minecraft.entity.passive.CopperGolemEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtCompound -import net.minecraft.registry.Registries -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.nbt.CompoundTag +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.animal.golem.CopperGolem +import net.minecraft.world.entity.item.ItemEntity +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState object ActionFactory { fun blockBreakAction( - world: World, + world: Level, pos: BlockPos, state: BlockState, source: String, entity: BlockEntity? = null ): BlockBreakActionType { val action = BlockBreakActionType() - setBlockData(action, pos, world, Blocks.AIR.defaultState, state, source, entity) + setBlockData(action, pos, world, Blocks.AIR.defaultBlockState(), state, source, entity) return action } fun blockBreakAction( - world: World, + world: Level, pos: BlockPos, state: BlockState, - player: PlayerEntity, + player: Player, entity: BlockEntity? = null, source: String = Sources.PLAYER ): BlockChangeActionType { val action = blockBreakAction(world, pos, state, source, entity) - action.sourceProfile = player.playerConfigEntry + action.sourceProfile = player.nameAndId() return action } fun blockPlaceAction( - world: World, + world: Level, pos: BlockPos, state: BlockState, source: String, entity: BlockEntity? = null ): BlockChangeActionType { val action = BlockPlaceActionType() - setBlockData(action, pos, world, state, Blocks.AIR.defaultState, source, entity) + setBlockData(action, pos, world, state, Blocks.AIR.defaultBlockState(), source, entity) return action } fun blockPlaceAction( - world: World, + world: Level, pos: BlockPos, state: BlockState, - player: PlayerEntity, + player: Player, entity: BlockEntity? = null, source: String = Sources.PLAYER ): BlockChangeActionType { val action = blockPlaceAction(world, pos, state, source, entity) - action.sourceProfile = player.playerConfigEntry + action.sourceProfile = player.nameAndId() return action } @@ -88,23 +88,23 @@ object ActionFactory { private fun setBlockData( action: ActionType, pos: BlockPos, - world: World, + world: Level, state: BlockState, oldState: BlockState, source: String, entity: BlockEntity? = null ) { action.pos = pos - action.world = world.registryKey.value - action.objectIdentifier = Registries.BLOCK.getId(state.block) - action.oldObjectIdentifier = Registries.BLOCK.getId(oldState.block) + action.world = world.dimension().identifier() + action.objectIdentifier = BuiltInRegistries.BLOCK.getKey(state.block) + action.oldObjectIdentifier = BuiltInRegistries.BLOCK.getKey(oldState.block) action.objectState = NbtUtils.blockStateToProperties(state)?.toString() action.oldObjectState = NbtUtils.blockStateToProperties(oldState)?.toString() action.sourceName = source - action.extraData = entity?.createNbt(world.registryManager)?.toString() + action.extraData = entity?.saveWithoutMetadata(world.registryAccess())?.toString() } - fun itemInsertAction(world: World, stack: ItemStack, pos: BlockPos, source: String): ItemInsertActionType { + fun itemInsertAction(world: Level, stack: ItemStack, pos: BlockPos, source: String): ItemInsertActionType { val action = ItemInsertActionType() setItemData(action, pos, world, stack, source) @@ -112,17 +112,17 @@ object ActionFactory { } fun itemInsertAction( - world: World, + world: Level, stack: ItemStack, pos: BlockPos, source: LivingEntity ): ItemInsertActionType { val action = ItemInsertActionType() var sourceType = Sources.UNKNOWN - if (source is PlayerEntity) { + if (source is Player) { sourceType = Sources.PLAYER - action.sourceProfile = source.playerConfigEntry - } else if (source is CopperGolemEntity) { + action.sourceProfile = source.nameAndId() + } else if (source is CopperGolem) { sourceType = Sources.COPPER_GOLEM action.sourceName = sourceType } @@ -131,7 +131,7 @@ object ActionFactory { return action } - fun itemRemoveAction(world: World, stack: ItemStack, pos: BlockPos, source: String): ItemRemoveActionType { + fun itemRemoveAction(world: Level, stack: ItemStack, pos: BlockPos, source: String): ItemRemoveActionType { val action = ItemRemoveActionType() setItemData(action, pos, world, stack, source) @@ -139,17 +139,17 @@ object ActionFactory { } fun itemRemoveAction( - world: World, + world: Level, stack: ItemStack, pos: BlockPos, source: LivingEntity ): ItemRemoveActionType { val action = ItemRemoveActionType() var sourceType = Sources.UNKNOWN - if (source is PlayerEntity) { + if (source is Player) { sourceType = Sources.PLAYER - action.sourceProfile = source.playerConfigEntry - } else if (source is CopperGolemEntity) { + action.sourceProfile = source.nameAndId() + } else if (source is CopperGolem) { sourceType = Sources.COPPER_GOLEM action.sourceName = sourceType } @@ -160,14 +160,14 @@ object ActionFactory { fun itemPickUpAction( entity: ItemEntity, - source: PlayerEntity + source: Player ): ItemPickUpActionType { val action = ItemPickUpActionType() - setItemData(action, entity.blockPos, entity.entityWorld, entity.stack, Sources.PLAYER) + setItemData(action, entity.blockPosition(), entity.level(), entity.item, Sources.PLAYER) action.oldObjectState = entity.createNbt().toString() - action.sourceProfile = source.playerConfigEntry + action.sourceProfile = source.nameAndId() return action } @@ -178,12 +178,12 @@ object ActionFactory { ): ItemDropActionType { val action = ItemDropActionType() - setItemData(action, entity.blockPos, entity.entityWorld, entity.stack, Sources.PLAYER) + setItemData(action, entity.blockPosition(), entity.level(), entity.item, Sources.PLAYER) action.objectState = entity.createNbt().toString() - if (source is PlayerEntity) { - action.sourceProfile = source.playerConfigEntry - } else if (source is CopperGolemEntity) { + if (source is Player) { + action.sourceProfile = source.nameAndId() + } else if (source is CopperGolem) { action.sourceName = Sources.COPPER_GOLEM } @@ -191,60 +191,60 @@ object ActionFactory { } fun blockChangeAction( - world: World, + world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, oldBlockEntity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ): ActionType { val action = BlockChangeActionType() setBlockData(action, pos, world, newState, oldState, source, oldBlockEntity) - action.sourceProfile = player?.playerConfigEntry + action.sourceProfile = player?.nameAndId() return action } private fun setItemData( action: ActionType, pos: BlockPos, - world: World, + world: Level, stack: ItemStack, source: String ) { action.pos = pos - action.world = world.registryKey.value - action.objectIdentifier = Registries.ITEM.getId(stack.item) + action.world = world.dimension().identifier() + action.objectIdentifier = BuiltInRegistries.ITEM.getKey(stack.item) action.sourceName = source if (!stack.isEmpty) { - action.extraData = stack.createNbt(world.registryManager).toString() + action.extraData = stack.createNbt(world.registryAccess()).toString() } } - fun entityKillAction(world: World, pos: BlockPos, entity: Entity, cause: DamageSource): EntityKillActionType { - val killer = cause.attacker + fun entityKillAction(world: Level, pos: BlockPos, entity: Entity, cause: DamageSource): EntityKillActionType { + val killer = cause.entity val action = EntityKillActionType() when { - killer is PlayerEntity -> { + killer is Player -> { setEntityData(action, pos, world, entity, Sources.PLAYER) - action.sourceProfile = killer.playerConfigEntry + action.sourceProfile = killer.nameAndId() } killer != null -> { - val source = Registries.ENTITY_TYPE.getId(killer.type).path + val source = BuiltInRegistries.ENTITY_TYPE.getKey(killer.type).path setEntityData(action, pos, world, entity, source) } else -> { - setEntityData(action, pos, world, entity, cause.name) + setEntityData(action, pos, world, entity, cause.msgId) } } return action } - fun entityKillAction(world: World, pos: BlockPos, entity: Entity, source: String): EntityKillActionType { + fun entityKillAction(world: Level, pos: BlockPos, entity: Entity, source: String): EntityKillActionType { val action = EntityKillActionType() setEntityData(action, pos, world, entity, source) return action @@ -253,21 +253,21 @@ object ActionFactory { private fun setEntityData( action: ActionType, pos: BlockPos, - world: World, + world: Level, entity: Entity, source: String ) { action.pos = pos - action.world = world.registryKey.value - action.objectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) + action.world = world.dimension().identifier() + action.objectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) action.sourceName = source action.extraData = entity.createNbt().toString() } fun entityChangeAction( - world: World, + world: Level, pos: BlockPos, - oldEntityTags: NbtCompound, + oldEntityTags: CompoundTag, entity: Entity, itemStack: ItemStack?, entityActor: Entity?, @@ -276,19 +276,19 @@ object ActionFactory { val action = EntityChangeActionType() action.pos = pos - action.world = world.registryKey.value - action.objectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) - action.oldObjectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) + action.world = world.dimension().identifier() + action.objectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) + action.oldObjectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) if (itemStack != null && !itemStack.isEmpty) { - action.extraData = itemStack.createNbt(world.registryManager).toString() + action.extraData = itemStack.createNbt(world.registryAccess()).toString() } action.oldObjectState = oldEntityTags.toString() action.objectState = entity.createNbt().toString() action.sourceName = sourceType - if (entityActor is PlayerEntity) { - action.sourceProfile = entityActor.playerConfigEntry + if (entityActor is Player) { + action.sourceProfile = entityActor.nameAndId() } return action @@ -296,42 +296,42 @@ object ActionFactory { fun entityMountAction( entity: Entity, - player: PlayerEntity, + player: Player, ): EntityMountActionType { - val world = entity.entityWorld + val world = entity.level() val action = EntityMountActionType() - action.pos = entity.blockPos - action.world = world.registryKey.value - action.objectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) - action.oldObjectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) + action.pos = entity.blockPosition() + action.world = world.dimension().identifier() + action.objectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) + action.oldObjectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) action.objectState = entity.createNbt().toString() action.sourceName = Sources.PLAYER - action.sourceProfile = player.playerConfigEntry + action.sourceProfile = player.nameAndId() return action } fun entityDismountAction( entity: Entity, - player: PlayerEntity, + player: Player, ): EntityDismountActionType { - val world = entity.entityWorld + val world = entity.level() val action = EntityDismountActionType() - action.pos = entity.blockPos - action.world = world.registryKey.value - action.objectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) - action.oldObjectIdentifier = Registries.ENTITY_TYPE.getId(entity.type) + action.pos = entity.blockPosition() + action.world = world.dimension().identifier() + action.objectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) + action.oldObjectIdentifier = BuiltInRegistries.ENTITY_TYPE.getKey(entity.type) action.objectState = entity.createNbt().toString() action.sourceName = Sources.PLAYER - action.sourceProfile = player.playerConfigEntry + action.sourceProfile = player.nameAndId() return action } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionSearchParams.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionSearchParams.kt index 017ba5f3..7ef4b8ef 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionSearchParams.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/ActionSearchParams.kt @@ -4,15 +4,15 @@ import com.github.quiltservertools.ledger.Ledger import com.github.quiltservertools.ledger.config.SearchSpec import com.github.quiltservertools.ledger.utility.Negatable import com.mojang.brigadier.exceptions.SimpleCommandExceptionType -import net.minecraft.text.Text -import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockBox +import net.minecraft.network.chat.Component +import net.minecraft.resources.Identifier +import net.minecraft.world.level.levelgen.structure.BoundingBox import java.time.Instant import java.util.* import kotlin.math.max data class ActionSearchParams( - val bounds: BlockBox?, + val bounds: BoundingBox?, val before: Instant?, val after: Instant?, val rolledBack: Boolean?, @@ -36,27 +36,27 @@ data class ActionSearchParams( fun ensureSpecific() { if (bounds == null) { - throw SimpleCommandExceptionType(Text.translatable("error.ledger.unspecific.range")).create() + throw SimpleCommandExceptionType(Component.translatable("error.ledger.unspecific.range")).create() } - val range = (max(bounds.blockCountX, max(bounds.blockCountY, bounds.blockCountZ)) + 1) / 2 + val range = (max(bounds.xSpan, max(bounds.ySpan, bounds.zSpan)) + 1) / 2 if (range > Ledger.config[SearchSpec.maxRange] && bounds != GLOBAL) { throw SimpleCommandExceptionType( - Text.translatable("error.ledger.unspecific.range_to_big", Ledger.config[SearchSpec.maxRange]) + Component.translatable("error.ledger.unspecific.range_to_big", Ledger.config[SearchSpec.maxRange]) ).create() } if (sourceNames == null && sourcePlayerIds == null && after == null && before == null) { - throw SimpleCommandExceptionType(Text.translatable("error.ledger.unspecific.source_or_time")).create() + throw SimpleCommandExceptionType(Component.translatable("error.ledger.unspecific.source_or_time")).create() } } companion object { - val GLOBAL: BlockBox = - BlockBox(-Int.MAX_VALUE, -Int.MAX_VALUE, -Int.MAX_VALUE, Int.MAX_VALUE, Int.MAX_VALUE, Int.MAX_VALUE) + val GLOBAL: BoundingBox = + BoundingBox(-Int.MAX_VALUE, -Int.MAX_VALUE, -Int.MAX_VALUE, Int.MAX_VALUE, Int.MAX_VALUE, Int.MAX_VALUE) inline fun build(block: Builder.() -> Unit) = Builder().apply(block).build() } class Builder { - var bounds: BlockBox? = null + var bounds: BoundingBox? = null var before: Instant? = null var after: Instant? = null var rolledBack: Boolean? = null diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/DoubleInventoryHelper.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/DoubleInventoryHelper.kt index f5115777..f29f2f82 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/DoubleInventoryHelper.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/DoubleInventoryHelper.kt @@ -1,7 +1,7 @@ package com.github.quiltservertools.ledger.actionutils -import net.minecraft.inventory.Inventory +import net.minecraft.world.Container interface DoubleInventoryHelper { - fun getInventory(slot: Int): Inventory + fun getInventory(slot: Int): Container } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/LocationalInventory.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/LocationalInventory.kt index 6ea65dc1..0ead4ae7 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/LocationalInventory.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/LocationalInventory.kt @@ -1,6 +1,6 @@ package com.github.quiltservertools.ledger.actionutils -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos interface LocationalInventory { fun getLocation(): BlockPos diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/Preview.kt b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/Preview.kt index 33957f9f..d75cb00c 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/Preview.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/actionutils/Preview.kt @@ -3,36 +3,36 @@ package com.github.quiltservertools.ledger.actionutils import com.github.quiltservertools.ledger.actions.ActionType import com.github.quiltservertools.ledger.commands.subcommands.RestoreCommand import com.github.quiltservertools.ledger.commands.subcommands.RollbackCommand -import com.github.quiltservertools.ledger.mixin.preview.EntityTrackerEntryAccessor +import com.github.quiltservertools.ledger.mixin.preview.ServerEntityAccessor import com.github.quiltservertools.ledger.utility.Context import com.github.quiltservertools.ledger.utility.TextColorPallet -import net.minecraft.item.ItemStack -import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket -import net.minecraft.server.network.EntityTrackerEntry -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.text.Text -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.network.chat.Component +import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket +import net.minecraft.server.level.ServerEntity +import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.item.ItemStack class Preview( private val params: ActionSearchParams, actions: List, - player: ServerPlayerEntity, + player: ServerPlayer, private val type: Type ) { val positions = mutableSetOf() // Preview entities that got spawned. Need to removed - val spawnedEntityTrackers = mutableSetOf() + val spawnedEntityTrackers = mutableSetOf() // Preview entities that got removed. Need to be spawned - val removedEntityTrackers = mutableSetOf() + val removedEntityTrackers = mutableSetOf() // Preview items that should be modified in screen handlers (true = added, false = removed) val modifiedItems = mutableMapOf>>() init { - player.sendMessage( - Text.translatable( + player.displayClientMessage( + Component.translatable( "text.ledger.preview.start", actions.size ).setStyle(TextColorPallet.primary), @@ -47,34 +47,34 @@ class Preview( } } - fun cancel(player: ServerPlayerEntity) { + fun cancel(player: ServerPlayer) { for (pos in positions) { - player.networkHandler.sendPacket(BlockUpdateS2CPacket(player.entityWorld, pos)) + player.connection.send(ClientboundBlockUpdatePacket(player.level(), pos)) } cleanup(player) } - private fun cleanup(player: ServerPlayerEntity) { + private fun cleanup(player: ServerPlayer) { // Cleanup preview entities, to keep client and server in sync spawnedEntityTrackers.forEach { if (!isEntityPresent(it)) { - it.stopTracking(player) + it.removePairing(player) } } removedEntityTrackers.forEach { if (isEntityPresent(it)) { - it.startTracking(player) + it.addPairing(player) } } } - private fun isEntityPresent(entityTrackerEntry: EntityTrackerEntry): Boolean { - val entity = (entityTrackerEntry as EntityTrackerEntryAccessor).entity - return entity.entityWorld.getEntityById(entity.id) != null + private fun isEntityPresent(entityTrackerEntry: ServerEntity): Boolean { + val entity = (entityTrackerEntry as ServerEntityAccessor).entity + return entity.level().getEntity(entity.id) != null } fun apply(context: Context) { - cleanup(context.source.playerOrThrow) + cleanup(context.source.playerOrException) when (type) { Type.ROLLBACK -> RollbackCommand.rollback(context, params) Type.RESTORE -> RestoreCommand.restore(context, params) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/api/LedgerExtension.kt b/src/main/kotlin/com/github/quiltservertools/ledger/api/LedgerExtension.kt index 7a053e85..39d0d8a4 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/api/LedgerExtension.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/api/LedgerExtension.kt @@ -1,7 +1,7 @@ package com.github.quiltservertools.ledger.api import com.uchuhimo.konf.ConfigSpec -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier interface LedgerExtension { fun getIdentifier(): Identifier diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockBreakCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockBreakCallback.kt index ffe2b07e..0f37563b 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockBreakCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockBreakCallback.kt @@ -3,26 +3,26 @@ package com.github.quiltservertools.ledger.callbacks import com.github.quiltservertools.ledger.utility.Sources import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState fun interface BlockBreakCallback { fun breakBlock( - world: World, + world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ) - fun breakBlock(world: World, pos: BlockPos, state: BlockState, entity: BlockEntity?, player: PlayerEntity) = + fun breakBlock(world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, player: Player) = breakBlock(world, pos, state, entity, Sources.PLAYER, player) - fun breakBlock(world: World, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String) = + fun breakBlock(world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String) = breakBlock(world, pos, state, entity, source, null) companion object { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockChangeCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockChangeCallback.kt index ec6f815c..eeb49861 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockChangeCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockChangeCallback.kt @@ -3,37 +3,37 @@ package com.github.quiltservertools.ledger.callbacks import com.github.quiltservertools.ledger.utility.Sources import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState fun interface BlockChangeCallback { fun changeBlock( - world: World, + world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, oldBlockEntity: BlockEntity?, newBlockEntity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ) fun changeBlock( - world: World, + world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, oldBlockEntity: BlockEntity?, newBlockEntity: BlockEntity?, - player: PlayerEntity + player: Player ) = changeBlock(world, pos, oldState, newState, oldBlockEntity, newBlockEntity, Sources.PLAYER, player) fun changeBlock( - world: World, + world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockMeltCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockMeltCallback.kt index fc1b8386..8d2e9724 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockMeltCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockMeltCallback.kt @@ -2,13 +2,13 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState fun interface BlockMeltCallback { - fun melt(world: World, pos: BlockPos, oldState: BlockState, newState: BlockState, entity: BlockEntity?) + fun melt(world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, entity: BlockEntity?) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockPlaceCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockPlaceCallback.kt index 3b3f0e1c..5898a60d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockPlaceCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/BlockPlaceCallback.kt @@ -3,26 +3,26 @@ package com.github.quiltservertools.ledger.callbacks import com.github.quiltservertools.ledger.utility.Sources import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState fun interface BlockPlaceCallback { fun place( - world: World, + world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ) - fun place(world: World, pos: BlockPos, state: BlockState, entity: BlockEntity?, player: PlayerEntity) = + fun place(world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, player: Player) = place(world, pos, state, entity, Sources.PLAYER, player) - fun place(world: World, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String) = + fun place(world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String) = place(world, pos, state, entity, source, null) companion object { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityDismountCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityDismountCallback.kt index 2932b9be..5e988cf7 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityDismountCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityDismountCallback.kt @@ -2,11 +2,11 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.Entity -import net.minecraft.entity.player.PlayerEntity +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.player.Player fun interface EntityDismountCallback { - fun dismount(entity: Entity, playerEntity: PlayerEntity) + fun dismount(entity: Entity, playerEntity: Player) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityKillCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityKillCallback.kt index 0b8aa4b0..35070a3b 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityKillCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityKillCallback.kt @@ -2,13 +2,13 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.Entity -import net.minecraft.entity.damage.DamageSource -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.entity.Entity +import net.minecraft.world.level.Level fun interface EntityKillCallback { - fun kill(world: World, pos: BlockPos, entity: Entity, source: DamageSource) + fun kill(world: Level, pos: BlockPos, entity: Entity, source: DamageSource) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityModifyCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityModifyCallback.kt index c305a365..aae69a44 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityModifyCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityModifyCallback.kt @@ -2,17 +2,17 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.Entity -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtCompound -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.nbt.CompoundTag +import net.minecraft.world.entity.Entity +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.Level fun interface EntityModifyCallback { fun modify( - world: World, + world: Level, pos: BlockPos, - oldEntityTags: NbtCompound, + oldEntityTags: CompoundTag, newEntity: Entity, itemStack: ItemStack?, entityActor: Entity?, diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityMountCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityMountCallback.kt index 0728fd82..7a07d81d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityMountCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/EntityMountCallback.kt @@ -2,11 +2,11 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.Entity -import net.minecraft.entity.player.PlayerEntity +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.player.Player fun interface EntityMountCallback { - fun mount(entity: Entity, playerEntity: PlayerEntity) + fun mount(entity: Entity, playerEntity: Player) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemDropCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemDropCallback.kt index 7617b21a..3bc04798 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemDropCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemDropCallback.kt @@ -2,8 +2,8 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.ItemEntity -import net.minecraft.entity.LivingEntity +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.item.ItemEntity fun interface ItemDropCallback { fun drop(entity: ItemEntity, playerOrGolem: LivingEntity) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemInsertCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemInsertCallback.kt index 475762a3..5b2ee686 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemInsertCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemInsertCallback.kt @@ -2,13 +2,13 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.LivingEntity -import net.minecraft.item.ItemStack -import net.minecraft.server.world.ServerWorld -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.server.level.ServerLevel +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.item.ItemStack fun interface ItemInsertCallback { - fun insert(stack: ItemStack, pos: BlockPos, world: ServerWorld, source: String, entity: LivingEntity?) + fun insert(stack: ItemStack, pos: BlockPos, world: ServerLevel, source: String, entity: LivingEntity?) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemPickUpCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemPickUpCallback.kt index 9b63967c..ecbe77d1 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemPickUpCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemPickUpCallback.kt @@ -2,11 +2,11 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.ItemEntity -import net.minecraft.entity.player.PlayerEntity +import net.minecraft.world.entity.item.ItemEntity +import net.minecraft.world.entity.player.Player fun interface ItemPickUpCallback { - fun pickUp(entity: ItemEntity, player: PlayerEntity) + fun pickUp(entity: ItemEntity, player: Player) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemRemoveCallback.kt b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemRemoveCallback.kt index 05a380e3..3de96a78 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemRemoveCallback.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/callbacks/ItemRemoveCallback.kt @@ -2,13 +2,13 @@ package com.github.quiltservertools.ledger.callbacks import net.fabricmc.fabric.api.event.Event import net.fabricmc.fabric.api.event.EventFactory -import net.minecraft.entity.LivingEntity -import net.minecraft.item.ItemStack -import net.minecraft.server.world.ServerWorld -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.server.level.ServerLevel +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.item.ItemStack fun interface ItemRemoveCallback { - fun remove(stack: ItemStack, pos: BlockPos, world: ServerWorld, source: String, entity: LivingEntity?) + fun remove(stack: ItemStack, pos: BlockPos, world: ServerLevel, source: String, entity: LivingEntity?) companion object { @JvmField diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/LedgerCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/LedgerCommand.kt index d7c81bd5..cb5f84c1 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/LedgerCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/LedgerCommand.kt @@ -14,7 +14,7 @@ import com.github.quiltservertools.ledger.commands.subcommands.TeleportCommand import com.github.quiltservertools.ledger.utility.BrigadierUtils import com.github.quiltservertools.ledger.utility.Dispatcher import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.server.command.CommandManager.literal +import net.minecraft.commands.Commands.literal fun registerCommands(dispatcher: Dispatcher) { val rootNode = diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/arguments/SearchParamArgument.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/arguments/SearchParamArgument.kt index 01a21517..97a1c363 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/arguments/SearchParamArgument.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/arguments/SearchParamArgument.kt @@ -20,13 +20,13 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException import com.mojang.brigadier.exceptions.SimpleCommandExceptionType import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.server.command.CommandManager -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.text.Text -import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockBox -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3i +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.Commands +import net.minecraft.core.BlockPos +import net.minecraft.core.Vec3i +import net.minecraft.network.chat.Component +import net.minecraft.resources.Identifier +import net.minecraft.world.level.levelgen.structure.BoundingBox import java.time.Instant import java.util.* import java.util.concurrent.CompletableFuture @@ -45,8 +45,8 @@ object SearchParamArgument { paramSuggesters["rolledback"] = Parameter(RollbackStatusParameter()) } - fun argument(name: String): RequiredArgumentBuilder { - return CommandManager.argument(name, StringArgumentType.greedyString()) + fun argument(name: String): RequiredArgumentBuilder { + return Commands.argument(name, StringArgumentType.greedyString()) .suggests { context, builder -> val input = builder.input val lastSpaceIndex = input.lastIndexOf(' ') @@ -86,7 +86,7 @@ object SearchParamArgument { } @Suppress("UNCHECKED_CAST") - fun get(input: String, source: ServerCommandSource): ActionSearchParams { + fun get(input: String, source: CommandSourceStack): ActionSearchParams { val reader = StringReader(input) val result = HashMultimap.create() while (reader.canRead()) { @@ -96,7 +96,7 @@ object SearchParamArgument { .create() val value = if (parameter is NegatableParameter) parameter.parseNegatable(reader) else parameter.parse(reader) - result.put(propertyName, value) + result.put(propertyName, value!!) } val builder = ActionSearchParams.Builder() @@ -110,11 +110,11 @@ object SearchParamArgument { val range = value as Int? if (range != null) { val range = range - 1 - builder.bounds = BlockBox.create( - BlockPos.ofFloored(source.position).subtract(Vec3i(range, range, range)), - BlockPos.ofFloored(source.position).add(Vec3i(range, range, range)) + builder.bounds = BoundingBox.fromCorners( + BlockPos.containing(source.position).subtract(Vec3i(range, range, range)), + BlockPos.containing(source.position).offset(Vec3i(range, range, range)) ) - val world = Negatable.allow(source.world.registryKey.value) + val world = Negatable.allow(source.level.dimension().identifier()) if (builder.worlds == null) { builder.worlds = mutableSetOf(world) } else { @@ -152,7 +152,7 @@ object SearchParamArgument { builder.sourceNames!!.add(nonPlayer) } } else { - val profile = source.server.apiServices.nameToIdCache?.findByName(sourceInput.property) + val profile = source.server.services().nameToIdCache?.get(sourceInput.property) // If the player doesn't exist use a random UUID to make the query not match val id = profile?.orElse(null)?.id ?: UUID.randomUUID() @@ -193,7 +193,7 @@ object SearchParamArgument { return builder.build() } - fun get(context: CommandContext, name: String): ActionSearchParams { + fun get(context: CommandContext, name: String): ActionSearchParams { val input = StringArgumentType.getString(context, name) return get(input, context.source) } @@ -202,7 +202,7 @@ object SearchParamArgument { val input = builder.remaining.lowercase() for (param in paramSuggesters.keys) { if (param.startsWith(input)) { - builder.suggest("$param:", Text.translatable("text.ledger.parameter.$param.description")) + builder.suggest("$param:", Component.translatable("text.ledger.parameter.$param.description")) } } return builder @@ -211,7 +211,7 @@ object SearchParamArgument { private open class Parameter(private val parameter: SimpleParameter) { open fun listSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { return try { @@ -237,7 +237,7 @@ object SearchParamArgument { private class NegatableParameter(parameter: SimpleParameter) : Parameter(parameter) { override fun listSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { val builder = if (builder.remaining.startsWith("!")) builder.createOffset(builder.start + 1) else builder diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ActionParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ActionParameter.kt index f2a90f09..49f392b3 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ActionParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/ActionParameter.kt @@ -6,18 +6,18 @@ import com.mojang.brigadier.arguments.StringArgumentType import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.command.CommandSource -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.SharedSuggestionProvider import java.util.concurrent.CompletableFuture class ActionParameter : SimpleParameter() { override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { val types = ActionRegistry.getTypes() // Need to check equality to catch null - return CommandSource.suggestMatching( + return SharedSuggestionProvider.suggest( types, builder ) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/DimensionParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/DimensionParameter.kt index 2625e0b9..7150b56a 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/DimensionParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/DimensionParameter.kt @@ -4,16 +4,16 @@ import com.mojang.brigadier.StringReader import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.command.argument.DimensionArgumentType -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.util.Identifier +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.arguments.DimensionArgument +import net.minecraft.resources.Identifier import java.util.concurrent.CompletableFuture class DimensionParameter : SimpleParameter() { - override fun parse(stringReader: StringReader): Identifier = DimensionArgumentType.dimension().parse(stringReader) + override fun parse(stringReader: StringReader): Identifier = DimensionArgument.dimension().parse(stringReader) override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder - ): CompletableFuture = DimensionArgumentType.dimension().listSuggestions(context, builder) + ): CompletableFuture = DimensionArgument.dimension().listSuggestions(context, builder) } 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 1952660a..45a0e621 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 @@ -4,64 +4,68 @@ import com.mojang.brigadier.StringReader import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.command.CommandSource -import net.minecraft.command.argument.IdentifierArgumentType -import net.minecraft.registry.Registries -import net.minecraft.registry.RegistryKeys -import net.minecraft.registry.tag.TagKey -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.util.Identifier +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.SharedSuggestionProvider +import net.minecraft.commands.arguments.IdentifierArgument +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.core.registries.Registries +import net.minecraft.resources.Identifier +import net.minecraft.tags.TagKey import java.util.concurrent.CompletableFuture class ObjectParameter : SimpleParameter>() { private val identifiers = mutableListOf().apply { - addAll(Registries.ITEM.ids) - addAll(Registries.BLOCK.ids) - addAll(Registries.ENTITY_TYPE.ids) + addAll(BuiltInRegistries.ITEM.keySet()) + addAll(BuiltInRegistries.BLOCK.keySet()) + addAll(BuiltInRegistries.ENTITY_TYPE.keySet()) } override fun parse(stringReader: StringReader): List { if (stringReader.string.isEmpty()) return listOf() if (stringReader.string[stringReader.cursor] == '#') { stringReader.skip() - val tagId = IdentifierArgumentType.identifier().parse(stringReader) + val tagId = IdentifierArgument.id().parse(stringReader) - val blockTag = TagKey.of(RegistryKeys.BLOCK, tagId) + val blockTag = TagKey.create(Registries.BLOCK, tagId) if (blockTag != null) { - return Registries.BLOCK.iterateEntries( + return BuiltInRegistries.BLOCK.getTagOrEmpty( blockTag - ).map { Registries.BLOCK.getId(it.value()) } + ).map { BuiltInRegistries.BLOCK.getKey(it.value()) } } - val itemTag = TagKey.of(RegistryKeys.ITEM, tagId) - if (itemTag != null) Registries.ITEM.iterateEntries(itemTag).map { Registries.ITEM.getId(it.value()) } + val itemTag = TagKey.create(Registries.ITEM, tagId) + if (itemTag != null) { + BuiltInRegistries.ITEM.getTagOrEmpty( + itemTag + ).map { BuiltInRegistries.ITEM.getKey(it.value()) } + } - val entityTag = TagKey.of(RegistryKeys.ENTITY_TYPE, tagId) + val entityTag = TagKey.create(Registries.ENTITY_TYPE, tagId) if (entityTag != null) { - return Registries.ENTITY_TYPE.iterateEntries(entityTag).map { - Registries.ENTITY_TYPE.getId(it.value()) + return BuiltInRegistries.ENTITY_TYPE.getTagOrEmpty(entityTag).map { + BuiltInRegistries.ENTITY_TYPE.getKey(it.value()) } } } - return listOf(IdentifierArgumentType.identifier().parse(stringReader)) + return listOf(IdentifierArgument.id().parse(stringReader)) } override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { return if (builder.remaining.startsWith("#")) { - CommandSource.suggestIdentifiers( + SharedSuggestionProvider.suggestResource( mutableListOf().apply { - 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()) + addAll(BuiltInRegistries.BLOCK.tags.map { it.key().location }.toList()) + addAll(BuiltInRegistries.ITEM.tags.map { it.key().location }.toList()) + addAll(BuiltInRegistries.ENTITY_TYPE.tags.map { it.key().location }.toList()) }, builder.createOffset(builder.start + 1) ) } else { - CommandSource.suggestIdentifiers( + SharedSuggestionProvider.suggestResource( identifiers, builder ) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RangeParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RangeParameter.kt index e261a1f8..775371ab 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RangeParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RangeParameter.kt @@ -6,8 +6,8 @@ import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.exceptions.CommandSyntaxException import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.command.CommandSource -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.SharedSuggestionProvider import java.util.concurrent.CompletableFuture private const val MAX_SIZE = 9 @@ -31,13 +31,13 @@ class RangeParameter : SimpleParameter() { } override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { val remaining = builder.remaining.lowercase() val reader = StringReader(remaining) - CommandSource.suggestMatching(listOf(GLOBAL), builder) + SharedSuggestionProvider.suggest(listOf(GLOBAL), builder) var suggestNumber = false try { reader.readInt() diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RollbackStatusParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RollbackStatusParameter.kt index a3b22975..9dbb2b03 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RollbackStatusParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/RollbackStatusParameter.kt @@ -5,14 +5,14 @@ import com.mojang.brigadier.arguments.BoolArgumentType import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack import java.util.concurrent.CompletableFuture class RollbackStatusParameter : SimpleParameter() { override fun parse(stringReader: StringReader): Boolean = BoolArgumentType.bool().parse(stringReader) override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture = BoolArgumentType.bool().listSuggestions(context, builder) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SimpleParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SimpleParameter.kt index eefcb59c..cc17ee70 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SimpleParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SimpleParameter.kt @@ -2,8 +2,8 @@ package com.github.quiltservertools.ledger.commands.parameters import com.mojang.brigadier.StringReader import com.mojang.brigadier.suggestion.SuggestionProvider -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack -abstract class SimpleParameter : SuggestionProvider { +abstract class SimpleParameter : SuggestionProvider { abstract fun parse(stringReader: StringReader): T } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SourceParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SourceParameter.kt index 3c7d510c..8fbb4abf 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SourceParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/SourceParameter.kt @@ -5,8 +5,8 @@ import com.mojang.brigadier.StringReader import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.command.CommandSource -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.SharedSuggestionProvider import java.util.concurrent.CompletableFuture class SourceParameter : SimpleParameter() { @@ -21,17 +21,17 @@ class SourceParameter : SimpleParameter() { } override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { val stringReader = StringReader(builder.input) stringReader.cursor = builder.start - val sources = context.source.playerNames + val sources = context.source.onlinePlayerNames DatabaseManager.getKnownSources().forEach { sources.add("@$it") } - return CommandSource.suggestMatching( + return SharedSuggestionProvider.suggest( sources, builder ) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/TimeParameter.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/TimeParameter.kt index d3fa9327..d14efef7 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/TimeParameter.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/parameters/TimeParameter.kt @@ -4,7 +4,7 @@ import com.mojang.brigadier.StringReader import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.suggestion.Suggestions import com.mojang.brigadier.suggestion.SuggestionsBuilder -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack import java.time.Duration import java.time.Instant import java.util.concurrent.CompletableFuture @@ -49,7 +49,7 @@ class TimeParameter : SimpleParameter() { private fun isCharValid(c: Char) = c in '0'..'9' || c in 'a'..'z' override fun getSuggestions( - context: CommandContext, + context: CommandContext, builder: SuggestionsBuilder ): CompletableFuture { val remaining = builder.remaining.lowercase() diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/InspectCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/InspectCommand.kt index d790fe32..c4745f0d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/InspectCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/InspectCommand.kt @@ -9,10 +9,10 @@ import com.github.quiltservertools.ledger.utility.inspectOff import com.github.quiltservertools.ledger.utility.inspectOn import com.github.quiltservertools.ledger.utility.isInspecting import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.command.argument.BlockPosArgumentType -import net.minecraft.server.command.CommandManager.argument -import net.minecraft.server.command.CommandManager.literal -import net.minecraft.util.math.BlockPos +import net.minecraft.commands.Commands.argument +import net.minecraft.commands.Commands.literal +import net.minecraft.commands.arguments.coordinates.BlockPosArgument +import net.minecraft.core.BlockPos object InspectCommand : BuildableCommand { override fun build(): LiteralNode = @@ -21,21 +21,21 @@ object InspectCommand : BuildableCommand { .executes { toggleInspect(it) } .then( literal("on") - .executes { it.source.playerOrThrow.inspectOn() } + .executes { it.source.playerOrException.inspectOn() } ) .then( literal("off") - .executes { it.source.playerOrThrow.inspectOff() } + .executes { it.source.playerOrException.inspectOff() } ) .then( - argument("pos", BlockPosArgumentType.blockPos()) - .executes { inspectBlock(it, BlockPosArgumentType.getBlockPos(it, "pos")) } + argument("pos", BlockPosArgument.blockPos()) + .executes { inspectBlock(it, BlockPosArgument.getBlockPos(it, "pos")) } ) .build() private fun toggleInspect(context: Context): Int { val source = context.source - val player = source.playerOrThrow + val player = source.playerOrException return if (player.isInspecting()) { player.inspectOff() diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PageCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PageCommand.kt index 9fafe4c2..67bc9c4b 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PageCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PageCommand.kt @@ -9,9 +9,9 @@ import com.github.quiltservertools.ledger.utility.MessageUtils import com.github.quiltservertools.ledger.utility.TextColorPallet import com.mojang.brigadier.arguments.IntegerArgumentType import kotlinx.coroutines.launch -import net.minecraft.server.command.CommandManager.argument -import net.minecraft.server.command.CommandManager.literal -import net.minecraft.text.Text +import net.minecraft.commands.Commands.argument +import net.minecraft.commands.Commands.literal +import net.minecraft.network.chat.Component object PageCommand : BuildableCommand { override fun build(): LiteralNode = @@ -25,21 +25,21 @@ object PageCommand : BuildableCommand { private fun page(context: Context, page: Int): Int { val source = context.source - val params = Ledger.searchCache[source.name] + val params = Ledger.searchCache[source.textName] if (params != null) { Ledger.launch { MessageUtils.warnBusy(source) val results = DatabaseManager.searchActions(params, page) if (results.page > results.pages) { - source.sendError(Text.translatable("error.ledger.no_more_pages")) + source.sendFailure(Component.translatable("error.ledger.no_more_pages")) return@launch } MessageUtils.sendSearchResults( source, results, - Text.translatable( + Component.translatable( "text.ledger.header.search" ).setStyle(TextColorPallet.primary) ) @@ -47,7 +47,7 @@ object PageCommand : BuildableCommand { return 1 } else { - source.sendError(Text.translatable("error.ledger.no_cached_params")) + source.sendFailure(Component.translatable("error.ledger.no_cached_params")) return -1 } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PlayerCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PlayerCommand.kt index 49ac7717..aa65ff5d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PlayerCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PlayerCommand.kt @@ -8,26 +8,26 @@ import com.github.quiltservertools.ledger.utility.LiteralNode import com.github.quiltservertools.ledger.utility.MessageUtils import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.command.argument.GameProfileArgumentType -import net.minecraft.server.PlayerConfigEntry -import net.minecraft.server.command.CommandManager.argument -import net.minecraft.server.command.CommandManager.literal -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack +import net.minecraft.commands.Commands.argument +import net.minecraft.commands.Commands.literal +import net.minecraft.commands.arguments.GameProfileArgument +import net.minecraft.server.players.NameAndId object PlayerCommand : BuildableCommand { override fun build(): LiteralNode { return literal("player") .requires(Permissions.require("ledger.commands.player", CommandConsts.PERMISSION_LEVEL)) .then( - argument("player", GameProfileArgumentType.gameProfile()) + argument("player", GameProfileArgument.gameProfile()) .executes { - return@executes lookupPlayer(GameProfileArgumentType.getProfileArgument(it, "player"), it.source) + return@executes lookupPlayer(GameProfileArgument.getGameProfiles(it, "player"), it.source) } ) .build() } - private fun lookupPlayer(profiles: MutableCollection, source: ServerCommandSource): Int { + private fun lookupPlayer(profiles: MutableCollection, source: CommandSourceStack): Int { Ledger.launch { val players = DatabaseManager.searchPlayers(profiles.toSet()) MessageUtils.sendPlayerMessage(source, players) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PreviewCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PreviewCommand.kt index 773f7335..56f86239 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PreviewCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PreviewCommand.kt @@ -12,15 +12,15 @@ import com.github.quiltservertools.ledger.utility.LiteralNode import com.github.quiltservertools.ledger.utility.MessageUtils import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.server.command.CommandManager -import net.minecraft.text.Text +import net.minecraft.commands.Commands +import net.minecraft.network.chat.Component object PreviewCommand : BuildableCommand { override fun build(): LiteralNode { - return CommandManager.literal("preview") + return Commands.literal("preview") .requires(Permissions.require("ledger.commands.preview", CommandConsts.PERMISSION_LEVEL)) .then( - CommandManager.literal("rollback") + Commands.literal("rollback") .then( SearchParamArgument.argument(CommandConsts.PARAMS) .executes { @@ -33,7 +33,7 @@ object PreviewCommand : BuildableCommand { ) ) .then( - CommandManager.literal("restore") + Commands.literal("restore") .then( SearchParamArgument.argument(CommandConsts.PARAMS) .executes { @@ -45,21 +45,21 @@ object PreviewCommand : BuildableCommand { } ) ) - .then(CommandManager.literal("apply").executes { apply(it) }) - .then(CommandManager.literal("cancel").executes { cancel(it) }) + .then(Commands.literal("apply").executes { apply(it) }) + .then(Commands.literal("cancel").executes { cancel(it) }) .build() } private fun preview(context: Context, params: ActionSearchParams, type: Preview.Type): Int { val source = context.source - val player = source.playerOrThrow + val player = source.playerOrException params.ensureSpecific() Ledger.launch { MessageUtils.warnBusy(source) val actions = DatabaseManager.previewActions(params, type) if (actions.isEmpty()) { - source.sendError(Text.translatable("error.ledger.command.no_results")) + source.sendFailure(Component.translatable("error.ledger.command.no_results")) return@launch } @@ -70,13 +70,13 @@ object PreviewCommand : BuildableCommand { } private fun apply(context: Context): Int { - val uuid = context.source.playerOrThrow.uuid + val uuid = context.source.playerOrException.uuid if (Ledger.previewCache.containsKey(uuid)) { Ledger.previewCache[uuid]?.apply(context) Ledger.previewCache.remove(uuid) } else { - context.source.sendError(Text.translatable("error.ledger.no_preview")) + context.source.sendFailure(Component.translatable("error.ledger.no_preview")) return -1 } @@ -84,13 +84,13 @@ object PreviewCommand : BuildableCommand { } private fun cancel(context: Context): Int { - val uuid = context.source.playerOrThrow.uuid + val uuid = context.source.playerOrException.uuid if (Ledger.previewCache.containsKey(uuid)) { - Ledger.previewCache[uuid]?.cancel(context.source.playerOrThrow) + Ledger.previewCache[uuid]?.cancel(context.source.playerOrException) Ledger.previewCache.remove(uuid) } else { - context.source.sendError(Text.translatable("error.ledger.no_preview")) + context.source.sendFailure(Component.translatable("error.ledger.no_preview")) return -1 } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PurgeCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PurgeCommand.kt index 5e205f1d..80dd33f3 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PurgeCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/PurgeCommand.kt @@ -13,8 +13,8 @@ import com.github.quiltservertools.ledger.utility.LiteralNode import com.github.quiltservertools.ledger.utility.TextColorPallet import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.server.command.CommandManager.literal -import net.minecraft.text.Text +import net.minecraft.commands.Commands.literal +import net.minecraft.network.chat.Component object PurgeCommand : BuildableCommand { override fun build(): LiteralNode { @@ -30,14 +30,14 @@ object PurgeCommand : BuildableCommand { private fun runPurge(ctx: Context, params: ActionSearchParams): Int { val source = ctx.source - source.sendFeedback( - { Text.translatable("text.ledger.purge.starting").setStyle(TextColorPallet.secondary) }, + source.sendSuccess( + { Component.translatable("text.ledger.purge.starting").setStyle(TextColorPallet.secondary) }, true ) Ledger.launch { DatabaseManager.purgeActions(params) - source.sendFeedback( - { Text.translatable("text.ledger.purge.complete").setStyle(TextColorPallet.secondary) }, + source.sendSuccess( + { Component.translatable("text.ledger.purge.complete").setStyle(TextColorPallet.secondary) }, true ) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RestoreCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RestoreCommand.kt index ae39a247..f2c55023 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RestoreCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RestoreCommand.kt @@ -14,12 +14,12 @@ import com.github.quiltservertools.ledger.utility.launchMain import com.github.quiltservertools.ledger.utility.literal import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.server.command.CommandManager -import net.minecraft.text.Text +import net.minecraft.commands.Commands +import net.minecraft.network.chat.Component object RestoreCommand : BuildableCommand { override fun build(): LiteralNode { - return CommandManager.literal("restore") + return Commands.literal("restore") .requires(Permissions.require("ledger.commands.rollback", CommandConsts.PERMISSION_LEVEL)) .then( SearchParamArgument.argument("params") @@ -36,13 +36,13 @@ object RestoreCommand : BuildableCommand { val actions = DatabaseManager.selectRestore(params) if (actions.isEmpty()) { - source.sendError(Text.translatable("error.ledger.command.no_results")) + source.sendFailure(Component.translatable("error.ledger.command.no_results")) return@launch } - source.sendFeedback( + source.sendSuccess( { - Text.translatable( + Component.translatable( "text.ledger.restore.start", actions.size.toString().literal().setStyle(TextColorPallet.secondary) ).setStyle(TextColorPallet.primary) @@ -50,7 +50,7 @@ object RestoreCommand : BuildableCommand { true ) - context.source.world.launchMain { + context.source.level.launchMain { val fails = HashMap() val actionIds = HashSet() for (action in actions) { @@ -65,9 +65,9 @@ object RestoreCommand : BuildableCommand { } for (entry in fails.entries) { - source.sendFeedback( + source.sendSuccess( { - Text.translatable("text.ledger.restore.fail", entry.key, entry.value).setStyle( + Component.translatable("text.ledger.restore.fail", entry.key, entry.value).setStyle( TextColorPallet.secondary ) }, @@ -75,9 +75,9 @@ object RestoreCommand : BuildableCommand { ) } - source.sendFeedback( + source.sendSuccess( { - Text.translatable( + Component.translatable( "text.ledger.restore.finish", actions.size ).setStyle(TextColorPallet.primary) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RollbackCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RollbackCommand.kt index 5bb91ba7..6a55bac7 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RollbackCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/RollbackCommand.kt @@ -14,12 +14,12 @@ import com.github.quiltservertools.ledger.utility.launchMain import com.github.quiltservertools.ledger.utility.literal import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.server.command.CommandManager -import net.minecraft.text.Text +import net.minecraft.commands.Commands +import net.minecraft.network.chat.Component object RollbackCommand : BuildableCommand { override fun build(): LiteralNode { - return CommandManager.literal("rollback") + return Commands.literal("rollback") .requires(Permissions.require("ledger.commands.rollback", CommandConsts.PERMISSION_LEVEL)) .then( SearchParamArgument.argument("params") @@ -36,13 +36,13 @@ object RollbackCommand : BuildableCommand { val actions = DatabaseManager.selectRollback(params) if (actions.isEmpty()) { - source.sendError(Text.translatable("error.ledger.command.no_results")) + source.sendFailure(Component.translatable("error.ledger.command.no_results")) return@launch } - source.sendFeedback( + source.sendSuccess( { - Text.translatable( + Component.translatable( "text.ledger.rollback.start", actions.size.toString().literal().setStyle(TextColorPallet.secondary) ).setStyle(TextColorPallet.primary) @@ -50,7 +50,7 @@ object RollbackCommand : BuildableCommand { true ) - context.source.world.launchMain { + context.source.level.launchMain { val fails = HashMap() val actionIds = HashSet() for (action in actions) { @@ -65,9 +65,9 @@ object RollbackCommand : BuildableCommand { } for (entry in fails.entries) { - source.sendFeedback( + source.sendSuccess( { - Text.translatable("text.ledger.rollback.fail", entry.key, entry.value).setStyle( + Component.translatable("text.ledger.rollback.fail", entry.key, entry.value).setStyle( TextColorPallet.secondary ) }, @@ -75,9 +75,9 @@ object RollbackCommand : BuildableCommand { ) } - source.sendFeedback( + source.sendSuccess( { - Text.translatable( + Component.translatable( "text.ledger.rollback.finish", actions.size ).setStyle(TextColorPallet.primary) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/SearchCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/SearchCommand.kt index 1564732e..b8983793 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/SearchCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/SearchCommand.kt @@ -12,8 +12,8 @@ import com.github.quiltservertools.ledger.utility.MessageUtils import com.github.quiltservertools.ledger.utility.TextColorPallet import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.server.command.CommandManager.literal -import net.minecraft.text.Text +import net.minecraft.commands.Commands.literal +import net.minecraft.network.chat.Component object SearchCommand : BuildableCommand { override fun build(): LiteralNode { @@ -30,20 +30,20 @@ object SearchCommand : BuildableCommand { val source = context.source Ledger.launch { - Ledger.searchCache[source.name] = params + Ledger.searchCache[source.textName] = params MessageUtils.warnBusy(source) val results = DatabaseManager.searchActions(params, 1) if (results.actions.isEmpty()) { - source.sendError(Text.translatable("error.ledger.command.no_results")) + source.sendFailure(Component.translatable("error.ledger.command.no_results")) return@launch } MessageUtils.sendSearchResults( source, results, - Text.translatable( + Component.translatable( "text.ledger.header.search" ).setStyle(TextColorPallet.primary) ) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/StatusCommand.kt b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/StatusCommand.kt index 50a9942c..52745ca4 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/StatusCommand.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/commands/subcommands/StatusCommand.kt @@ -14,14 +14,14 @@ import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.loader.api.FabricLoader import net.fabricmc.loader.api.SemanticVersion -import net.minecraft.server.command.CommandManager -import net.minecraft.text.ClickEvent -import net.minecraft.text.Text +import net.minecraft.commands.Commands +import net.minecraft.network.chat.ClickEvent +import net.minecraft.network.chat.Component import java.net.URI object StatusCommand : BuildableCommand { override fun build(): LiteralNode = - CommandManager.literal("status") + Commands.literal("status") .requires(Permissions.require("ledger.commands.status", CommandConsts.PERMISSION_LEVEL)) .executes { status(it) } .build() @@ -29,37 +29,37 @@ object StatusCommand : BuildableCommand { private fun status(context: Context): Int { Ledger.launch { val source = context.source - source.sendMessage( - Text.translatable("text.ledger.header.status") + source.sendSystemMessage( + Component.translatable("text.ledger.header.status") .setStyle(TextColorPallet.primary) ) - source.sendMessage( - Text.translatable( + source.sendSystemMessage( + Component.translatable( "text.ledger.status.queue", ActionQueueService.size.toString().literal() .setStyle(TextColorPallet.secondaryVariant) ).setStyle(TextColorPallet.secondary) ) - source.sendMessage( - Text.translatable( + source.sendSystemMessage( + Component.translatable( "text.ledger.status.version", getVersion().friendlyString.literal() .setStyle(TextColorPallet.secondaryVariant) ).setStyle(TextColorPallet.secondary) ) - source.sendMessage( - Text.translatable( + source.sendSystemMessage( + Component.translatable( "text.ledger.status.db_type", DatabaseManager.databaseType.literal() .setStyle(TextColorPallet.secondaryVariant) ).setStyle(TextColorPallet.secondary) ) - source.sendMessage( - Text.translatable( + source.sendSystemMessage( + Component.translatable( "text.ledger.status.discord", "text.ledger.status.discord.join".translate() .setStyle(TextColorPallet.secondaryVariant) - .styled { + .withStyle { it.withClickEvent( ClickEvent.OpenUrl( URI("https://discord.gg/FpRNYrQaGP") @@ -68,12 +68,12 @@ object StatusCommand : BuildableCommand { } ).setStyle(TextColorPallet.secondary) ) - source.sendMessage( - Text.translatable( + source.sendSystemMessage( + Component.translatable( "text.ledger.status.wiki", "text.ledger.status.wiki.view".translate() .setStyle(TextColorPallet.secondaryVariant) - .styled { + .withStyle { it.withClickEvent( ClickEvent.OpenUrl( URI("https://www.quiltservertools.net/Ledger/${getVersion().friendlyString}/") 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 65d1d867..23a933a6 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 @@ -5,47 +5,47 @@ import com.github.quiltservertools.ledger.commands.CommandConsts import com.github.quiltservertools.ledger.utility.Context import com.github.quiltservertools.ledger.utility.LiteralNode import me.lucko.fabric.api.permissions.v0.Permissions -import net.minecraft.command.argument.DimensionArgumentType -import net.minecraft.command.argument.PosArgument -import net.minecraft.command.argument.Vec3ArgumentType -import net.minecraft.server.command.CommandManager -import net.minecraft.server.world.ServerWorld +import net.minecraft.commands.Commands +import net.minecraft.commands.arguments.DimensionArgument +import net.minecraft.commands.arguments.coordinates.Coordinates +import net.minecraft.commands.arguments.coordinates.Vec3Argument +import net.minecraft.server.level.ServerLevel object TeleportCommand : BuildableCommand { private const val BLOCK_CENTER_OFFSET = 0.5 override fun build(): LiteralNode = - CommandManager.literal("tp") + Commands.literal("tp") .requires(Permissions.require("ledger.commands.tp", CommandConsts.PERMISSION_LEVEL)) .then( - CommandManager.argument("world", DimensionArgumentType.dimension()) + Commands.argument("world", DimensionArgument.dimension()) .then( - CommandManager.argument("location", Vec3ArgumentType.vec3()) + Commands.argument("location", Vec3Argument.vec3()) .executes { teleport( it, - DimensionArgumentType.getDimensionArgument(it, "world"), - Vec3ArgumentType.getPosArgument(it, "location") + DimensionArgument.getDimension(it, "world"), + Vec3Argument.getCoordinates(it, "location") ) } ) ) .build() - private fun teleport(context: Context, world: ServerWorld, posArg: PosArgument): Int { - val player = context.source.playerOrThrow - val pos = posArg.toAbsoluteBlockPos(context.source) + private fun teleport(context: Context, world: ServerLevel, posArg: Coordinates): Int { + val player = context.source.playerOrException + val pos = posArg.getBlockPos(context.source) val x = pos.x.toDouble() + BLOCK_CENTER_OFFSET val z = pos.z.toDouble() + BLOCK_CENTER_OFFSET - player.teleport( + player.teleportTo( world, x, pos.y.toDouble(), z, emptySet(), - player.yaw, - player.pitch, + player.yRot, + player.xRot, true ) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/config/ActionsSpec.kt b/src/main/kotlin/com/github/quiltservertools/ledger/config/ActionsSpec.kt index 4ec55e1c..368a5449 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/config/ActionsSpec.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/config/ActionsSpec.kt @@ -1,7 +1,7 @@ package com.github.quiltservertools.ledger.config import com.uchuhimo.konf.ConfigSpec -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier object ActionsSpec : ConfigSpec() { val typeBlacklist by required>() diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt b/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt index 62e953f2..d5b7656b 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/config/DatabaseSpec.kt @@ -3,7 +3,7 @@ package com.github.quiltservertools.ledger.config import com.github.quiltservertools.ledger.Ledger import com.uchuhimo.konf.Config import com.uchuhimo.konf.ConfigSpec -import net.minecraft.util.WorldSavePath +import net.minecraft.world.level.storage.LevelResource import java.nio.file.Path @Suppress("MagicNumber") @@ -22,6 +22,6 @@ fun Config.getDatabasePath(): Path { return if (location != null) { Path.of(location) } else { - Ledger.server.getSavePath(WorldSavePath.ROOT) + Ledger.server.getWorldPath(LevelResource.ROOT) } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/config/LedgerConfig.kt b/src/main/kotlin/com/github/quiltservertools/ledger/config/LedgerConfig.kt index edc95e12..30759494 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/config/LedgerConfig.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/config/LedgerConfig.kt @@ -4,7 +4,7 @@ import com.github.quiltservertools.ledger.config.util.IdentifierMixin import com.uchuhimo.konf.Config import com.uchuhimo.konf.source.toml import net.fabricmc.loader.api.FabricLoader -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier const val CONFIG_PATH = "ledger.toml" diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/config/util/IdentifierSerialization.kt b/src/main/kotlin/com/github/quiltservertools/ledger/config/util/IdentifierSerialization.kt index 3c8e0c63..f691772a 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/config/util/IdentifierSerialization.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/config/util/IdentifierSerialization.kt @@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.JsonSerializer import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.annotation.JsonDeserialize import com.fasterxml.jackson.databind.annotation.JsonSerialize -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier object IdentifierSerializer : JsonSerializer() { override fun serialize(value: Identifier, gen: JsonGenerator, serializers: SerializerProvider) { @@ -17,7 +17,10 @@ object IdentifierSerializer : JsonSerializer() { } object IdentifierDeserializer : JsonDeserializer() { - override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Identifier = Identifier.of(p.valueAsString) + override fun deserialize( + p: JsonParser, + ctxt: DeserializationContext + ): Identifier = Identifier.parse(p.valueAsString) } @JsonSerialize(using = IdentifierSerializer::class) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseCacheService.kt b/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseCacheService.kt index 44a6029f..43e66467 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseCacheService.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseCacheService.kt @@ -2,7 +2,7 @@ package com.github.quiltservertools.ledger.database import com.google.common.collect.BiMap import com.google.common.collect.HashBiMap -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier import java.util.UUID object DatabaseCacheService { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt b/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt index 24c38aea..73fae65d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/database/DatabaseManager.kt @@ -21,9 +21,9 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.delay import kotlinx.coroutines.newSingleThreadContext -import net.minecraft.server.PlayerConfigEntry -import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.resources.Identifier +import net.minecraft.server.players.NameAndId import org.jetbrains.exposed.v1.core.Column import org.jetbrains.exposed.v1.core.Op import org.jetbrains.exposed.v1.core.SortOrder @@ -241,7 +241,7 @@ object DatabaseManager { type.oldObjectState = action[Tables.Actions.oldBlockState] type.sourceName = sourceCache[action[Tables.Actions.sourceName].value]!! type.sourceProfile = action.getOrNull(Tables.Actions.sourcePlayer)?.let { - Ledger.server.apiServices.nameToIdCache?.getByUuid(playerCache[it.value]!!)?.orElse(null) + Ledger.server.services().nameToIdCache?.get(playerCache[it.value]!!)?.orElse(null) } type.extraData = action[Tables.Actions.extraData] type.rolledBack = action[Tables.Actions.rolledBack] @@ -256,9 +256,9 @@ object DatabaseManager { var op: Op = Op.TRUE if (params.bounds != null && params.bounds != ActionSearchParams.GLOBAL) { - op = op.and { Tables.Actions.x.between(params.bounds.minX, params.bounds.maxX) } - op = op.and { Tables.Actions.y.between(params.bounds.minY, params.bounds.maxY) } - op = op.and { Tables.Actions.z.between(params.bounds.minZ, params.bounds.maxZ) } + op = op.and { Tables.Actions.x.between(params.bounds.minX(), params.bounds.maxX()) } + op = op.and { Tables.Actions.y.between(params.bounds.minY(), params.bounds.maxY()) } + op = op.and { Tables.Actions.z.between(params.bounds.minZ(), params.bounds.maxZ()) } } if (params.before != null && params.after != null) { @@ -422,7 +422,7 @@ object DatabaseManager { } private suspend fun execute(body: suspend Transaction.() -> T): T { - while (Ledger.server.overworld?.savingDisabled != false) { + while (Ledger.server.overworld()?.noSave != false) { delay(timeMillis = 1000) } @@ -444,7 +444,7 @@ object DatabaseManager { } } - suspend fun searchPlayers(players: Set): List = + suspend fun searchPlayers(players: Set): List = execute { return@execute selectPlayers(players) } @@ -476,7 +476,10 @@ object DatabaseManager { this[Tables.Actions.z] = action.pos.z this[Tables.Actions.objectId] = getOrCreateRegistryKeyId(action.objectIdentifier) this[Tables.Actions.oldObjectId] = getOrCreateRegistryKeyId(action.oldObjectIdentifier) - this[Tables.Actions.world] = getOrCreateWorldId(action.world ?: Ledger.server.overworld.registryKey.value) + this[Tables.Actions.world] = getOrCreateWorldId( + action.world ?: Ledger.server.overworld().dimension() + .identifier() + ) this[Tables.Actions.blockState] = action.objectState this[Tables.Actions.oldBlockState] = action.oldObjectState this[Tables.Actions.sourceName] = getOrCreateSourceId(action.sourceName) @@ -664,7 +667,7 @@ object DatabaseManager { id inSubQuery Tables.Actions.select(id).where(buildQueryParams(params)) } - private fun Transaction.selectPlayers(players: Set): List { + private fun Transaction.selectPlayers(players: Set): List { val query = Tables.Players.selectAll() for (player in players) { query.orWhere { Tables.Players.playerId eq player.id() } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/database/Tables.kt b/src/main/kotlin/com/github/quiltservertools/ledger/database/Tables.kt index 6d2a8c72..63d3ddac 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/database/Tables.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/database/Tables.kt @@ -1,6 +1,6 @@ package com.github.quiltservertools.ledger.database -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier import org.jetbrains.exposed.v1.core.alias import org.jetbrains.exposed.v1.core.dao.id.EntityID import org.jetbrains.exposed.v1.core.dao.id.IntIdTable diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/BlockEventListener.kt b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/BlockEventListener.kt index 2f52c8d6..d8eba1e6 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/BlockEventListener.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/BlockEventListener.kt @@ -8,12 +8,12 @@ import com.github.quiltservertools.ledger.callbacks.BlockMeltCallback import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback import com.github.quiltservertools.ledger.database.ActionQueueService import com.github.quiltservertools.ledger.utility.Sources -import net.minecraft.block.AirBlock -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.AirBlock +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState fun registerBlockListeners() { BlockMeltCallback.EVENT.register(::onMelt) @@ -23,12 +23,12 @@ fun registerBlockListeners() { } fun onBlockPlace( - world: World, + world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ) { val action: ActionType = if (player != null) { ActionFactory.blockPlaceAction(world, pos, state, player, entity, source) @@ -39,12 +39,12 @@ fun onBlockPlace( } fun onBlockBreak( - world: World, + world: Level, pos: BlockPos, state: BlockState, entity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ) { val action: ActionType = if (player != null) { ActionFactory.blockBreakAction(world, pos, state, player, entity, source) @@ -56,21 +56,21 @@ fun onBlockBreak( } fun onBlockChange( - world: World, + world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, oldBlockEntity: BlockEntity?, newBlockEntity: BlockEntity?, source: String, - player: PlayerEntity? + player: Player? ) { ActionQueueService.addToQueue( ActionFactory.blockChangeAction(world, pos, oldState, newState, oldBlockEntity, source, player) ) } -fun onMelt(world: World, pos: BlockPos, oldState: BlockState, newState: BlockState, entity: BlockEntity?) { +fun onMelt(world: Level, pos: BlockPos, oldState: BlockState, newState: BlockState, entity: BlockEntity?) { ActionQueueService.addToQueue( ActionFactory.blockBreakAction(world, pos, oldState, Sources.MELT, entity) ) 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 bb11ac21..db686342 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/EntityCallbackListener.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/EntityCallbackListener.kt @@ -4,12 +4,12 @@ import com.github.quiltservertools.ledger.actionutils.ActionFactory import com.github.quiltservertools.ledger.callbacks.EntityKillCallback import com.github.quiltservertools.ledger.callbacks.EntityModifyCallback import com.github.quiltservertools.ledger.database.ActionQueueService -import net.minecraft.entity.Entity -import net.minecraft.entity.damage.DamageSource -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtCompound -import net.minecraft.util.math.BlockPos -import net.minecraft.world.World +import net.minecraft.core.BlockPos +import net.minecraft.nbt.CompoundTag +import net.minecraft.world.damagesource.DamageSource +import net.minecraft.world.entity.Entity +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.Level fun registerEntityListeners() { EntityKillCallback.EVENT.register(::onKill) @@ -17,7 +17,7 @@ fun registerEntityListeners() { } private fun onKill( - world: World, + world: Level, pos: BlockPos, entity: Entity, source: DamageSource @@ -28,7 +28,7 @@ private fun onKill( } fun onKill( - world: World, + world: Level, pos: BlockPos, entity: Entity, source: String @@ -39,9 +39,9 @@ fun onKill( } private fun onModify( - world: World, + world: Level, pos: BlockPos, - oldEntityTags: NbtCompound, + oldEntityTags: CompoundTag, entity: Entity, itemStack: ItemStack?, entityActor: Entity?, 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 e2c1dc27..a1a8c72c 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/PlayerEventListener.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/PlayerEventListener.kt @@ -17,22 +17,22 @@ import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents import net.fabricmc.fabric.api.event.player.UseBlockCallback import net.fabricmc.fabric.api.networking.v1.PacketSender import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.Entity -import net.minecraft.entity.ItemEntity -import net.minecraft.entity.LivingEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.item.ItemPlacementContext +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction 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 -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Direction -import net.minecraft.world.World +import net.minecraft.server.level.ServerPlayer +import net.minecraft.server.network.ServerGamePacketListenerImpl +import net.minecraft.world.InteractionHand +import net.minecraft.world.InteractionResult +import net.minecraft.world.entity.Entity +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.item.ItemEntity +import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.context.BlockPlaceContext +import net.minecraft.world.level.Level +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.phys.BlockHitResult fun registerPlayerListeners() { PlayerBlockBreakEvents.AFTER.register(::onBlockBreak) @@ -46,49 +46,49 @@ fun registerPlayerListeners() { EntityDismountCallback.EVENT.register(::onEntityDismount) } -fun onLeave(handler: ServerPlayNetworkHandler, server: MinecraftServer) { +fun onLeave(handler: ServerGamePacketListenerImpl, server: MinecraftServer) { handler.player.disableNetworking() } private fun onUseBlock( - player: PlayerEntity, - world: World, - hand: Hand, + player: Player, + world: Level, + hand: InteractionHand, blockHitResult: BlockHitResult -): ActionResult { - if (player is ServerPlayerEntity && player.isInspecting() && hand == Hand.MAIN_HAND) { - player.commandSource.inspectBlock(blockHitResult.blockPos.offset(blockHitResult.side)) - return ActionResult.SUCCESS +): InteractionResult { + if (player is ServerPlayer && player.isInspecting() && hand == InteractionHand.MAIN_HAND) { + player.createCommandSourceStack().inspectBlock(blockHitResult.blockPos.relative(blockHitResult.direction)) + return InteractionResult.SUCCESS } - return ActionResult.PASS + return InteractionResult.PASS } private fun onBlockAttack( - player: PlayerEntity, - world: World, - hand: Hand, + player: Player, + world: Level, + hand: InteractionHand, pos: BlockPos, direction: Direction -): ActionResult { - if (player is ServerPlayerEntity && player.isInspecting()) { - player.commandSource.inspectBlock(pos) - return ActionResult.SUCCESS +): InteractionResult { + if (player is ServerPlayer && player.isInspecting()) { + player.createCommandSourceStack().inspectBlock(pos) + return InteractionResult.SUCCESS } - return ActionResult.PASS + return InteractionResult.PASS } -private fun onJoin(networkHandler: ServerPlayNetworkHandler, packetSender: PacketSender, server: MinecraftServer) { +private fun onJoin(networkHandler: ServerGamePacketListenerImpl, packetSender: PacketSender, server: MinecraftServer) { Ledger.launch { - DatabaseManager.logPlayer(networkHandler.player.uuid, networkHandler.player.nameForScoreboard) + DatabaseManager.logPlayer(networkHandler.player.uuid, networkHandler.player.scoreboardName) } } private fun onBlockPlace( - world: World, - player: PlayerEntity, + world: Level, + player: Player, pos: BlockPos, state: BlockState, - context: ItemPlacementContext?, + context: BlockPlaceContext?, blockEntity: BlockEntity? ) { ActionQueueService.addToQueue( @@ -103,8 +103,8 @@ private fun onBlockPlace( } private fun onBlockBreak( - world: World, - player: PlayerEntity, + world: Level, + player: Player, pos: BlockPos, state: BlockState, blockEntity: BlockEntity? @@ -122,7 +122,7 @@ private fun onBlockBreak( private fun onItemPickUp( entity: ItemEntity, - player: PlayerEntity + player: Player ) { ActionQueueService.addToQueue(ActionFactory.itemPickUpAction(entity, player)) } @@ -136,14 +136,14 @@ private fun onItemDrop( private fun onEntityMount( entity: Entity, - playerEntity: PlayerEntity, + playerEntity: Player, ) { ActionQueueService.addToQueue(ActionFactory.entityMountAction(entity, playerEntity)) } private fun onEntityDismount( entity: Entity, - playerEntity: PlayerEntity, + playerEntity: Player, ) { ActionQueueService.addToQueue(ActionFactory.entityDismountAction(entity, playerEntity)) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/WorldEventListener.kt b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/WorldEventListener.kt index 72c124e9..5f4aaa02 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/listeners/WorldEventListener.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/listeners/WorldEventListener.kt @@ -8,11 +8,11 @@ import com.github.quiltservertools.ledger.database.ActionQueueService import com.github.quiltservertools.ledger.database.DatabaseManager import kotlinx.coroutines.launch import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents -import net.minecraft.entity.LivingEntity -import net.minecraft.item.ItemStack +import net.minecraft.core.BlockPos import net.minecraft.server.MinecraftServer -import net.minecraft.server.world.ServerWorld -import net.minecraft.util.math.BlockPos +import net.minecraft.server.level.ServerLevel +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.item.ItemStack fun registerWorldEventListeners() { ItemInsertCallback.EVENT.register(::onItemInsert) @@ -20,16 +20,16 @@ fun registerWorldEventListeners() { ServerWorldEvents.LOAD.register(::onWorldLoad) } -fun onWorldLoad(server: MinecraftServer, world: ServerWorld) { +fun onWorldLoad(server: MinecraftServer, world: ServerLevel) { Ledger.launch { - DatabaseManager.registerWorld(world.registryKey.value) + DatabaseManager.registerWorld(world.dimension().identifier()) } } private fun onItemRemove( stack: ItemStack, pos: BlockPos, - world: ServerWorld, + world: ServerLevel, source: String, entity: LivingEntity? ) { @@ -47,7 +47,7 @@ private fun onItemRemove( private fun onItemInsert( stack: ItemStack, pos: BlockPos, - world: ServerWorld, + world: ServerLevel, source: String, entity: LivingEntity? ) { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/Networking.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/Networking.kt index b512b47e..1606582a 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/Networking.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/Networking.kt @@ -9,11 +9,11 @@ import com.github.quiltservertools.ledger.network.packet.receiver.RollbackC2SPac import com.github.quiltservertools.ledger.network.packet.receiver.SearchC2SPacket import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking -import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.level.ServerPlayer object Networking { // List of players who have a compatible client mod - private var networkedPlayers = mutableSetOf() + private var networkedPlayers = mutableSetOf() const val PROTOCOL_VERSION = 3 init { @@ -35,9 +35,9 @@ object Networking { } } - fun ServerPlayerEntity.hasNetworking() = networkedPlayers.contains(this) + fun ServerPlayer.hasNetworking() = networkedPlayers.contains(this) - fun ServerPlayerEntity.enableNetworking() = networkedPlayers.add(this) + fun ServerPlayer.enableNetworking() = networkedPlayers.add(this) - fun ServerPlayerEntity.disableNetworking() = networkedPlayers.remove(this) + fun ServerPlayer.disableNetworking() = networkedPlayers.remove(this) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/LedgerPacketTypes.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/LedgerPacketTypes.kt index 1684183f..6a1b3c86 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/LedgerPacketTypes.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/LedgerPacketTypes.kt @@ -1,7 +1,7 @@ package com.github.quiltservertools.ledger.network.packet import com.github.quiltservertools.ledger.Ledger -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier enum class LedgerPacketTypes(val id: Identifier) { ACTION(Ledger.identifier("action")), diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/Receiver.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/Receiver.kt index 51b3a454..276b636d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/Receiver.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/Receiver.kt @@ -1,17 +1,17 @@ package com.github.quiltservertools.ledger.network.packet import net.fabricmc.fabric.api.networking.v1.PacketSender -import net.minecraft.network.PacketByteBuf +import net.minecraft.network.FriendlyByteBuf import net.minecraft.server.MinecraftServer -import net.minecraft.server.network.ServerPlayNetworkHandler -import net.minecraft.server.network.ServerPlayerEntity +import net.minecraft.server.level.ServerPlayer +import net.minecraft.server.network.ServerGamePacketListenerImpl interface Receiver { fun receive( server: MinecraftServer, - player: ServerPlayerEntity, - handler: ServerPlayNetworkHandler, - buf: PacketByteBuf, + player: ServerPlayer, + handler: ServerGamePacketListenerImpl, + buf: FriendlyByteBuf, sender: PacketSender ) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/action/ActionS2CPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/action/ActionS2CPacket.kt index 05e16ccd..75e306ae 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/action/ActionS2CPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/action/ActionS2CPacket.kt @@ -2,38 +2,38 @@ package com.github.quiltservertools.ledger.network.packet.action import com.github.quiltservertools.ledger.actions.ActionType import com.github.quiltservertools.ledger.network.packet.LedgerPacketTypes -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.network.packet.CustomPayload.Id +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload +import net.minecraft.network.protocol.common.custom.CustomPacketPayload.Type -data class ActionS2CPacket(val content: ActionType) : CustomPayload { - private fun write(buf: PacketByteBuf?) { +data class ActionS2CPacket(val content: ActionType) : CustomPacketPayload { + private fun write(buf: FriendlyByteBuf?) { // Position buf?.writeBlockPos(content.pos) // Type - buf?.writeString(content.identifier) + buf?.writeUtf(content.identifier) // Dimension - buf?.writeIdentifier(content.world) + buf?.writeIdentifier(content.world!!) // Objects buf?.writeIdentifier(content.oldObjectIdentifier) buf?.writeIdentifier(content.objectIdentifier) // Source - buf?.writeString(content.sourceProfile?.name ?: "@" + content.sourceName) + buf?.writeUtf(content.sourceProfile?.name ?: "@" + content.sourceName) // Epoch second of event, sent as a long buf?.writeLong(content.timestamp.epochSecond) // Has been rolled back? buf?.writeBoolean(content.rolledBack) // NBT - buf?.writeString(content.extraData ?: "") + buf?.writeUtf(content.extraData ?: "") } - override fun getId() = ID + override fun type() = ID companion object { - val ID: Id = Id(LedgerPacketTypes.ACTION.id) - val CODEC: PacketCodec = CustomPayload.codecOf( + val ID: Type = Type(LedgerPacketTypes.ACTION.id) + val CODEC: StreamCodec = CustomPacketPayload.codec( ActionS2CPacket::write - ) { _: PacketByteBuf? -> TODO() } + ) { _: FriendlyByteBuf? -> TODO() } } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/handshake/HandshakeS2CPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/handshake/HandshakeS2CPacket.kt index 433023f2..15de4505 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/handshake/HandshakeS2CPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/handshake/HandshakeS2CPacket.kt @@ -1,33 +1,33 @@ package com.github.quiltservertools.ledger.network.packet.handshake import com.github.quiltservertools.ledger.network.packet.LedgerPacketTypes -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class HandshakeS2CPacket(val content: HandshakeContent) : CustomPayload { - fun write(buf: PacketByteBuf?) { +data class HandshakeS2CPacket(val content: HandshakeContent) : CustomPacketPayload { + fun write(buf: FriendlyByteBuf?) { // Ledger information // Protocol Version buf?.writeInt(content.protocolVersion) // Ledger Version - buf?.writeString(content.ledgerVersion) + buf?.writeUtf(content.ledgerVersion) // We tell the client mod how many actions we are writing buf?.writeInt(content.actions.size) for (action in content.actions) { - buf?.writeString(action) + buf?.writeUtf(action) } } - override fun getId() = ID + override fun type() = ID companion object { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.HANDSHAKE.id) - val CODEC: PacketCodec = CustomPayload.codecOf( + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.HANDSHAKE.id) + val CODEC: StreamCodec = CustomPacketPayload.codec( HandshakeS2CPacket::write - ) { _: PacketByteBuf? -> TODO() } + ) { _: FriendlyByteBuf? -> TODO() } } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/HandshakeC2SPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/HandshakeC2SPacket.kt index 95d32899..93d6f19f 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/HandshakeC2SPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/HandshakeC2SPacket.kt @@ -12,20 +12,20 @@ import com.github.quiltservertools.ledger.registry.ActionRegistry import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking import net.fabricmc.loader.api.FabricLoader -import net.minecraft.nbt.NbtCompound -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.text.Text +import net.minecraft.nbt.CompoundTag +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.chat.Component +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload import java.util.* -data class HandshakeC2SPacket(val nbt: NbtCompound?) : CustomPayload { +data class HandshakeC2SPacket(val nbt: CompoundTag?) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ServerPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.HANDSHAKE.id) - val CODEC: PacketCodec = CustomPayload.codecOf({ _, _ -> TODO() }, { + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.HANDSHAKE.id) + val CODEC: StreamCodec = CustomPacketPayload.codec({ _, _ -> TODO() }, { HandshakeC2SPacket(it.readNbt()) }) @@ -56,8 +56,8 @@ data class HandshakeC2SPacket(val nbt: NbtCompound?) : CustomPayload { ServerPlayNetworking.send(player, packet) player.enableNetworking() } else { - player.sendMessage( - Text.translatable( + player.displayClientMessage( + Component.translatable( "text.ledger.network.protocols_mismatched", Networking.PROTOCOL_VERSION, info.get().protocolVersion @@ -71,10 +71,10 @@ data class HandshakeC2SPacket(val nbt: NbtCompound?) : CustomPayload { ) } } else { - player.sendMessage(Text.translatable("text.ledger.network.no_mod_info"), false) + player.displayClientMessage(Component.translatable("text.ledger.network.no_mod_info"), false) } } - private fun readInfo(nbt: NbtCompound?): Optional { + private fun readInfo(nbt: CompoundTag?): Optional { if (nbt == null) { return Optional.empty() } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/InspectC2SPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/InspectC2SPacket.kt index 0c1c0c21..059ea03e 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/InspectC2SPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/InspectC2SPacket.kt @@ -12,18 +12,18 @@ import com.github.quiltservertools.ledger.utility.getInspectResults import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class InspectC2SPacket(val pos: BlockPos, val pages: Int) : CustomPayload { +data class InspectC2SPacket(val pos: BlockPos, val pages: Int) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ServerPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.INSPECT_POS.id) - val CODEC: PacketCodec = CustomPayload.codecOf({ _, _ -> TODO() }, { + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.INSPECT_POS.id) + val CODEC: StreamCodec = CustomPacketPayload.codec({ _, _ -> TODO() }, { InspectC2SPacket(it.readBlockPos(), it.readInt()) }) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/PurgeC2SPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/PurgeC2SPacket.kt index 10e2e2c4..d855bf58 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/PurgeC2SPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/PurgeC2SPacket.kt @@ -12,18 +12,18 @@ import com.github.quiltservertools.ledger.utility.getInspectResults import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class PurgeC2SPacket(val pos: BlockPos, val pages: Int) : CustomPayload { +data class PurgeC2SPacket(val pos: BlockPos, val pages: Int) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ServerPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.PURGE.id) - val CODEC: PacketCodec = CustomPayload.codecOf({ _, _ -> TODO() }, { + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.PURGE.id) + val CODEC: StreamCodec = CustomPacketPayload.codec({ _, _ -> TODO() }, { PurgeC2SPacket(it.readBlockPos(), it.readInt()) }) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/RollbackC2SPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/RollbackC2SPacket.kt index 19e93a9a..51f1825c 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/RollbackC2SPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/receiver/RollbackC2SPacket.kt @@ -11,18 +11,18 @@ import com.github.quiltservertools.ledger.network.packet.response.ResponseS2CPac import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class RollbackC2SPacket(val input: String) : CustomPayload { +data class RollbackC2SPacket(val input: String) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ServerPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.ROLLBACK.id) - val CODEC: PacketCodec = CustomPayload.codecOf({ _, _ -> TODO() }, { - RollbackC2SPacket(it.readString()) + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.ROLLBACK.id) + val CODEC: StreamCodec = CustomPacketPayload.codec({ _, _ -> TODO() }, { + RollbackC2SPacket(it.readUtf()) }) override fun receive(payload: RollbackC2SPacket, context: ServerPlayNetworking.Context) { @@ -38,7 +38,7 @@ data class RollbackC2SPacket(val input: String) : CustomPayload { return } - val params = SearchParamArgument.get(payload.input, player.commandSource) + val params = SearchParamArgument.get(payload.input, player.createCommandSourceStack()) ResponseS2CPacket.sendResponse( ResponseContent(LedgerPacketTypes.PURGE.id, ResponseCodes.EXECUTING.code), 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 5723a08b..c85877ff 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 @@ -13,19 +13,19 @@ import com.github.quiltservertools.ledger.utility.TextColorPallet import kotlinx.coroutines.launch import me.lucko.fabric.api.permissions.v0.Permissions import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.text.Text +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.chat.Component +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class SearchC2SPacket(val args: String, val pages: Int) : CustomPayload { +data class SearchC2SPacket(val args: String, val pages: Int) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ServerPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.SEARCH.id) - val CODEC: PacketCodec = CustomPayload.codecOf({ _, _ -> TODO() }, { - SearchC2SPacket(it.readString(), it.readInt()) + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.SEARCH.id) + val CODEC: StreamCodec = CustomPacketPayload.codec({ _, _ -> TODO() }, { + SearchC2SPacket(it.readUtf(), it.readInt()) }) override fun receive(payload: SearchC2SPacket, context: ServerPlayNetworking.Context) { @@ -44,7 +44,7 @@ data class SearchC2SPacket(val args: String, val pages: Int) : CustomPayload { return } - val source = player.commandSource + val source = player.createCommandSourceStack() val params = SearchParamArgument.get(payload.args, source) @@ -54,7 +54,7 @@ data class SearchC2SPacket(val args: String, val pages: Int) : CustomPayload { ) Ledger.launch { - Ledger.searchCache[source.name] = params + Ledger.searchCache[source.textName] = params MessageUtils.warnBusy(source) val results = DatabaseManager.searchActions(params, 1) @@ -64,7 +64,7 @@ data class SearchC2SPacket(val args: String, val pages: Int) : CustomPayload { MessageUtils.sendSearchResults( source, page, - Text.translatable( + Component.translatable( "text.ledger.header.search" ).setStyle(TextColorPallet.primary) ) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseContent.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseContent.kt index eb524be7..34daa65e 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseContent.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseContent.kt @@ -1,5 +1,5 @@ package com.github.quiltservertools.ledger.network.packet.response -import net.minecraft.util.Identifier +import net.minecraft.resources.Identifier data class ResponseContent(val type: Identifier, val response: Int) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseS2CPacket.kt b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseS2CPacket.kt index a890cc06..b619144d 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseS2CPacket.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/network/packet/response/ResponseS2CPacket.kt @@ -2,25 +2,25 @@ package com.github.quiltservertools.ledger.network.packet.response import com.github.quiltservertools.ledger.network.packet.LedgerPacketTypes import net.fabricmc.fabric.api.networking.v1.PacketSender -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class ResponseS2CPacket(val content: ResponseContent) : CustomPayload { - fun write(buf: PacketByteBuf?) { +data class ResponseS2CPacket(val content: ResponseContent) : CustomPacketPayload { + fun write(buf: FriendlyByteBuf?) { // Packet type, rollback response would be `ledger.rollback` buf?.writeIdentifier(content.type) // Response code buf?.writeInt(content.response) } - override fun getId() = ID + override fun type() = ID companion object { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerPacketTypes.RESPONSE.id) - val CODEC: PacketCodec = CustomPayload.codecOf( + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerPacketTypes.RESPONSE.id) + val CODEC: StreamCodec = CustomPacketPayload.codec( ResponseS2CPacket::write - ) { _: PacketByteBuf? -> TODO() } + ) { _: FriendlyByteBuf? -> TODO() } fun sendResponse(content: ResponseContent, sender: PacketSender) { sender.sendPacket(ResponseS2CPacket(content)) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/Aliases.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/Aliases.kt index db3a928c..48b14211 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/Aliases.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/Aliases.kt @@ -3,8 +3,8 @@ package com.github.quiltservertools.ledger.utility import com.mojang.brigadier.CommandDispatcher import com.mojang.brigadier.context.CommandContext import com.mojang.brigadier.tree.LiteralCommandNode -import net.minecraft.server.command.ServerCommandSource +import net.minecraft.commands.CommandSourceStack -typealias Dispatcher = CommandDispatcher -typealias LiteralNode = LiteralCommandNode -typealias Context = CommandContext +typealias Dispatcher = CommandDispatcher +typealias LiteralNode = LiteralCommandNode +typealias Context = CommandContext diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/Extensions.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/Extensions.kt index 3fcbea6c..db5fdaf9 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/Extensions.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/Extensions.kt @@ -1,29 +1,33 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.registry.RegistryKey -import net.minecraft.registry.RegistryKeys +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.registries.Registries +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.MutableComponent +import net.minecraft.resources.Identifier +import net.minecraft.resources.ResourceKey import net.minecraft.server.MinecraftServer -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.text.MutableText -import net.minecraft.text.Text -import net.minecraft.util.Identifier +import net.minecraft.server.level.ServerPlayer import kotlin.time.Duration.Companion.milliseconds import kotlin.time.times -fun MutableText.appendWithSpace(text: Text) { +fun MutableComponent.appendWithSpace(text: Component) { this.append(text) this.append(" ".literal()) } -fun String.literal() = Text.literal(this) -fun String.translate() = Text.translatable(this) +fun String.literal() = Component.literal(this) +fun String.translate() = Component.translatable(this) -fun ServerCommandSource.hasPlayer() = this.entity is ServerPlayerEntity +fun CommandSourceStack.hasPlayer() = this.entity is ServerPlayer // fun String.translate(vararg args: Any) = TranslatableText(this, args) -fun MinecraftServer.getWorld(identifier: Identifier?) = getWorld(RegistryKey.of(RegistryKeys.WORLD, identifier)) +fun MinecraftServer.getWorld(identifier: Identifier?) = identifier?.let { + getLevel( + ResourceKey.create(Registries.DIMENSION, identifier) + ) +} val TICK_LENGTH = 50.milliseconds inline val Int.ticks get() = this * TICK_LENGTH diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandledSlot.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandledSlot.kt index dec7d929..769a7ff4 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandledSlot.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandledSlot.kt @@ -1,8 +1,8 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.screen.ScreenHandler +import net.minecraft.world.inventory.AbstractContainerMenu interface HandledSlot { - fun getHandler(): ScreenHandler - fun setHandler(handler: ScreenHandler) + fun getHandler(): AbstractContainerMenu + fun setHandler(handler: AbstractContainerMenu) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandlerWithContext.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandlerWithContext.kt index 2d3cf8f3..65a03bd9 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandlerWithContext.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/HandlerWithContext.kt @@ -1,11 +1,11 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.item.ItemStack -import net.minecraft.server.network.ServerPlayerEntity -import net.minecraft.util.math.BlockPos +import net.minecraft.core.BlockPos +import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.item.ItemStack interface HandlerWithContext { var pos: BlockPos? - fun getPlayer(): ServerPlayerEntity? + fun getPlayer(): ServerPlayer? fun onStackChanged(old: ItemStack, new: ItemStack, pos: BlockPos) } 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 843ba5f1..fcce5fb2 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/InspectionManager.kt @@ -5,33 +5,33 @@ import com.github.quiltservertools.ledger.actionutils.ActionSearchParams import com.github.quiltservertools.ledger.actionutils.SearchResults import com.github.quiltservertools.ledger.database.DatabaseManager import kotlinx.coroutines.launch -import net.minecraft.block.BedBlock -import net.minecraft.block.BlockState -import net.minecraft.block.ChestBlock -import net.minecraft.block.DoorBlock -import net.minecraft.block.enums.BedPart -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 -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Direction +import net.minecraft.ChatFormatting +import net.minecraft.commands.CommandSourceStack +import net.minecraft.core.BlockPos +import net.minecraft.core.Direction +import net.minecraft.network.chat.Component +import net.minecraft.server.level.ServerPlayer +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.block.BedBlock +import net.minecraft.world.level.block.ChestBlock +import net.minecraft.world.level.block.DoorBlock +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.properties.BedPart +import net.minecraft.world.level.block.state.properties.ChestType +import net.minecraft.world.level.block.state.properties.DoubleBlockHalf +import net.minecraft.world.level.levelgen.structure.BoundingBox import java.util.* private val inspectingUsers = HashSet() -fun PlayerEntity.isInspecting() = inspectingUsers.contains(this.uuid) +fun Player.isInspecting() = inspectingUsers.contains(this.uuid) -fun PlayerEntity.inspectOn(): Int { +fun Player.inspectOn(): Int { inspectingUsers.add(this.uuid) - this.sendMessage( - Text.translatable( + this.displayClientMessage( + Component.translatable( "text.ledger.inspect.toggle", - "text.ledger.inspect.on".translate().formatted(Formatting.GREEN) + "text.ledger.inspect.on".translate().withStyle(ChatFormatting.GREEN) ).setStyle(TextColorPallet.secondary), false ) @@ -39,12 +39,12 @@ fun PlayerEntity.inspectOn(): Int { return 1 } -fun PlayerEntity.inspectOff(): Int { +fun Player.inspectOff(): Int { inspectingUsers.remove(this.uuid) - this.sendMessage( - Text.translatable( + this.displayClientMessage( + Component.translatable( "text.ledger.inspect.toggle", - "text.ledger.inspect.off".translate().formatted(Formatting.RED) + "text.ledger.inspect.off".translate().withStyle(ChatFormatting.RED) ).setStyle(TextColorPallet.secondary), false ) @@ -52,46 +52,46 @@ fun PlayerEntity.inspectOff(): Int { return 1 } -fun ServerCommandSource.inspectBlock(pos: BlockPos) { +fun CommandSourceStack.inspectBlock(pos: BlockPos) { val source = this Ledger.launch { - var area = BlockBox(pos) + var area = BoundingBox(pos) - val state = source.world.getBlockState(pos) + val state = source.level.getBlockState(pos) if (state.block is ChestBlock) { getOtherChestSide(state, pos)?.let { - area = BlockBox.create(pos, it) + area = BoundingBox.fromCorners(pos, it) } } else if (state.block is DoorBlock) { getOtherDoorHalf(state, pos).let { - area = BlockBox.create(pos, it) + area = BoundingBox.fromCorners(pos, it) } } else if (state.block is BedBlock) { getOtherBedPart(state, pos).let { - area = BlockBox.create(pos, it) + area = BoundingBox.fromCorners(pos, it) } } val params = ActionSearchParams.build { bounds = area - worlds = mutableSetOf(Negatable.allow(source.world.registryKey.value)) + worlds = mutableSetOf(Negatable.allow(source.level.dimension().identifier())) } - Ledger.searchCache[source.name] = params + Ledger.searchCache[source.textName] = params MessageUtils.warnBusy(source) val results = DatabaseManager.searchActions(params, 1) if (results.actions.isEmpty()) { - source.sendError(Text.translatable("error.ledger.command.no_results")) + source.sendFailure(Component.translatable("error.ledger.command.no_results")) return@launch } MessageUtils.sendSearchResults( source, results, - Text.translatable( + Component.translatable( "text.ledger.header.search.pos", "${pos.x} ${pos.y} ${pos.z}".literal() ).setStyle(TextColorPallet.primary) @@ -100,15 +100,15 @@ fun ServerCommandSource.inspectBlock(pos: BlockPos) { } fun getOtherChestSide(state: BlockState, pos: BlockPos): BlockPos? { - val type = state.get(ChestBlock.CHEST_TYPE) + val type = state.getValue(ChestBlock.TYPE) return if (type != ChestType.SINGLE) { // We now need to query other container results in the same chest - val facing = state.get(ChestBlock.FACING) + val facing = state.getValue(ChestBlock.FACING) if (type == ChestType.RIGHT) { // Chest is right, so left as you look at it - pos.offset(facing.rotateCounterclockwise(Direction.Axis.Y)) + pos.relative(facing.getCounterClockWise(Direction.Axis.Y)) } else { - pos.offset(facing.rotateClockwise(Direction.Axis.Y)) + pos.relative(facing.getClockWise(Direction.Axis.Y)) } } else { null @@ -116,31 +116,31 @@ fun getOtherChestSide(state: BlockState, pos: BlockPos): BlockPos? { } private fun getOtherDoorHalf(state: BlockState, pos: BlockPos): BlockPos { - val half = state.get(DoorBlock.HALF) + val half = state.getValue(DoorBlock.HALF) return if (half == DoubleBlockHalf.LOWER) { - pos.offset(Direction.UP) + pos.relative(Direction.UP) } else { - pos.offset(Direction.DOWN) + pos.relative(Direction.DOWN) } } private fun getOtherBedPart(state: BlockState, pos: BlockPos): BlockPos { - val part = state.get(BedBlock.PART) - val direction = state.get(BedBlock.FACING) + val part = state.getValue(BedBlock.PART) + val direction = state.getValue(BedBlock.FACING) return if (part == BedPart.FOOT) { - pos.offset(direction) + pos.relative(direction) } else { - pos.offset(direction.opposite) + pos.relative(direction.opposite) } } -suspend fun ServerPlayerEntity.getInspectResults(pos: BlockPos): SearchResults { - val source = this.commandSource +suspend fun ServerPlayer.getInspectResults(pos: BlockPos): SearchResults { + val source = this.createCommandSourceStack() val params = ActionSearchParams.build { - bounds = BlockBox(pos) + bounds = BoundingBox(pos) } - Ledger.searchCache[source.name] = params + Ledger.searchCache[source.textName] = params MessageUtils.warnBusy(source) return DatabaseManager.searchActions(params, 1) } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemChangeLogic.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemChangeLogic.kt index e2394000..6fc20cd2 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemChangeLogic.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemChangeLogic.kt @@ -1,40 +1,40 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.inventory.Inventory -import net.minecraft.item.ItemStack +import net.minecraft.world.Container +import net.minecraft.world.item.ItemStack -fun addItem(rollbackStack: ItemStack, inventory: Inventory): Boolean { +fun addItem(rollbackStack: ItemStack, inventory: Container): Boolean { // Check if the inventory has enough space var matchingCountLeft = 0 - for (i in 0 until inventory.size()) { - val stack = inventory.getStack(i) + for (i in 0 until inventory.containerSize) { + val stack = inventory.getItem(i) if (stack.isEmpty) { - matchingCountLeft += rollbackStack.maxCount - } else if (ItemStack.areItemsAndComponentsEqual(stack, rollbackStack)) { - matchingCountLeft += stack.maxCount - stack.count + matchingCountLeft += rollbackStack.maxStackSize + } else if (ItemStack.isSameItemSameComponents(stack, rollbackStack)) { + matchingCountLeft += stack.maxStackSize - stack.count } } if (matchingCountLeft < rollbackStack.count) { return false } var requiredCount = rollbackStack.count - for (i in 0 until inventory.size()) { - val stack = inventory.getStack(i) + for (i in 0 until inventory.containerSize) { + val stack = inventory.getItem(i) if (stack.isEmpty) { - if (requiredCount > rollbackStack.maxCount) { - inventory.setStack(i, rollbackStack.copyWithCount(rollbackStack.maxCount)) - requiredCount -= rollbackStack.maxCount + if (requiredCount > rollbackStack.maxStackSize) { + inventory.setItem(i, rollbackStack.copyWithCount(rollbackStack.maxStackSize)) + requiredCount -= rollbackStack.maxStackSize } else { - inventory.setStack(i, rollbackStack.copyWithCount(requiredCount)) + inventory.setItem(i, rollbackStack.copyWithCount(requiredCount)) requiredCount = 0 } - } else if (ItemStack.areItemsAndComponentsEqual(stack, rollbackStack)) { - val countUntilMax = rollbackStack.maxCount - stack.count + } else if (ItemStack.isSameItemSameComponents(stack, rollbackStack)) { + val countUntilMax = rollbackStack.maxStackSize - stack.count if (requiredCount > countUntilMax) { - inventory.setStack(i, rollbackStack.copyWithCount(rollbackStack.maxCount)) + inventory.setItem(i, rollbackStack.copyWithCount(rollbackStack.maxStackSize)) requiredCount -= countUntilMax } else { - inventory.setStack(i, rollbackStack.copyWithCount(stack.count + requiredCount)) + inventory.setItem(i, rollbackStack.copyWithCount(stack.count + requiredCount)) requiredCount = 0 } } @@ -45,12 +45,12 @@ fun addItem(rollbackStack: ItemStack, inventory: Inventory): Boolean { return false } -fun removeMatchingItem(rollbackStack: ItemStack, inventory: Inventory): Boolean { +fun removeMatchingItem(rollbackStack: ItemStack, inventory: Container): Boolean { // Check if the inventory has enough matching items var matchingCount = 0 - for (i in 0 until inventory.size()) { - val stack = inventory.getStack(i) - if (ItemStack.areItemsAndComponentsEqual(stack, rollbackStack)) { + for (i in 0 until inventory.containerSize) { + val stack = inventory.getItem(i) + if (ItemStack.isSameItemSameComponents(stack, rollbackStack)) { matchingCount += stack.count } } @@ -58,15 +58,15 @@ fun removeMatchingItem(rollbackStack: ItemStack, inventory: Inventory): Boolean return false } var requiredCount = rollbackStack.count - for (i in 0 until inventory.size()) { - val stack = inventory.getStack(i) - if (ItemStack.areItemsAndComponentsEqual(stack, rollbackStack)) { + for (i in 0 until inventory.containerSize) { + val stack = inventory.getItem(i) + if (ItemStack.isSameItemSameComponents(stack, rollbackStack)) { if (requiredCount < stack.count) { // Only some parts of this stack are needed - inventory.setStack(i, stack.copyWithCount(stack.count - requiredCount)) + inventory.setItem(i, stack.copyWithCount(stack.count - requiredCount)) requiredCount = 0 } else { - inventory.setStack(i, ItemStack.EMPTY) + inventory.setItem(i, ItemStack.EMPTY) requiredCount -= stack.count } if (requiredCount <= 0) { diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemData.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemData.kt index 2c52534f..76754993 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemData.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/ItemData.kt @@ -1,6 +1,6 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.component.ComponentChanges -import net.minecraft.item.Item +import net.minecraft.core.component.DataComponentPatch +import net.minecraft.world.item.Item -data class ItemData(val item: Item, val changes: ComponentChanges) +data class ItemData(val item: Item, val changes: DataComponentPatch) diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/McDispatcher.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/McDispatcher.kt index 1b5c4351..5cba6821 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/McDispatcher.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/McDispatcher.kt @@ -6,8 +6,8 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job import kotlinx.coroutines.Runnable import kotlinx.coroutines.launch -import net.minecraft.server.world.ServerWorld -import net.minecraft.world.World +import net.minecraft.server.level.ServerLevel +import net.minecraft.world.level.Level import kotlin.coroutines.AbstractCoroutineContextElement import kotlin.coroutines.CoroutineContext @@ -25,8 +25,8 @@ class McExecutor(val executor: (Runnable) -> Unit) : AbstractCoroutineContextEle fun launchMain(executor: (Runnable) -> Unit, block: suspend CoroutineScope.() -> Unit): Job = Ledger.launch(McDispatcher + McExecutor(executor), block = block) -fun World.launchMain(block: suspend CoroutineScope.() -> Unit) { +fun Level.launchMain(block: suspend CoroutineScope.() -> Unit) { when (this) { - is ServerWorld -> launchMain(server::execute, block) + is ServerLevel -> launchMain(server::execute, block) } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/MessageUtils.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/MessageUtils.kt index 9d5c5f89..875b2617 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/MessageUtils.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/MessageUtils.kt @@ -7,12 +7,12 @@ import com.github.quiltservertools.ledger.database.DatabaseManager import com.github.quiltservertools.ledger.network.Networking.hasNetworking import com.github.quiltservertools.ledger.network.packet.action.ActionS2CPacket import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking -import net.minecraft.server.command.ServerCommandSource -import net.minecraft.text.ClickEvent -import net.minecraft.text.HoverEvent -import net.minecraft.text.MutableText -import net.minecraft.text.Style -import net.minecraft.text.Text +import net.minecraft.commands.CommandSourceStack +import net.minecraft.network.chat.ClickEvent +import net.minecraft.network.chat.Component +import net.minecraft.network.chat.HoverEvent +import net.minecraft.network.chat.MutableComponent +import net.minecraft.network.chat.Style import java.time.Duration import java.time.Instant import java.time.format.DateTimeFormatter @@ -22,32 +22,34 @@ import kotlin.time.toKotlinDuration object MessageUtils { @OptIn(ExperimentalTime::class) - suspend fun sendSearchResults(source: ServerCommandSource, results: SearchResults, header: Text) { + suspend fun sendSearchResults(source: CommandSourceStack, results: SearchResults, header: Component) { // If the player has a Ledger compatible client, we send results as action packets rather than as chat messages - if (source.hasPlayer() && source.playerOrThrow.hasNetworking()) { + if (source.hasPlayer() && source.playerOrException.hasNetworking()) { for (n in results.page..results.pages) { val networkResults = DatabaseManager.searchActions(results.searchParams, n) networkResults.actions.forEach { - ServerPlayNetworking.send(source.player, ActionS2CPacket(it)) + ServerPlayNetworking.send(source.playerOrException, ActionS2CPacket(it)) } } return } - source.sendMessage(header) + source.sendSystemMessage(header) results.actions.forEach { actionType -> - source.sendMessage(actionType.getMessage(source)) + source.sendSystemMessage(actionType.getMessage(source)) } - source.sendMessage( - Text.translatable( + source.sendSystemMessage( + Component.translatable( "text.ledger.footer.search", - Text.translatable("text.ledger.footer.page_backward").setStyle(TextColorPallet.primaryVariant).styled { + Component.translatable( + "text.ledger.footer.page_backward" + ).setStyle(TextColorPallet.primaryVariant).withStyle { if (results.page > 1) { it.withHoverEvent( HoverEvent.ShowText( - Text.translatable("text.ledger.footer.page_backward.hover") + Component.translatable("text.ledger.footer.page_backward.hover") ) ).withClickEvent( ClickEvent.RunCommand("/lg pg ${results.page - 1}") @@ -58,11 +60,13 @@ object MessageUtils { }, results.page.toString().literal().setStyle(TextColorPallet.primaryVariant), results.pages.toString().literal().setStyle(TextColorPallet.primaryVariant), - Text.translatable("text.ledger.footer.page_forward").setStyle(TextColorPallet.primaryVariant).styled { + Component.translatable( + "text.ledger.footer.page_forward" + ).setStyle(TextColorPallet.primaryVariant).withStyle { if (results.page < results.pages) { it.withHoverEvent( HoverEvent.ShowText( - Text.translatable("text.ledger.footer.page_forward.hover") + Component.translatable("text.ledger.footer.page_forward.hover") ) ).withClickEvent( ClickEvent.RunCommand("/lg pg ${results.page + 1}") @@ -75,18 +79,18 @@ object MessageUtils { ) } - fun sendPlayerMessage(source: ServerCommandSource, results: List) { + fun sendPlayerMessage(source: CommandSourceStack, results: List) { if (results.isEmpty()) { - source.sendMessage("error.ledger.command.no_results".translate().setStyle(TextColorPallet.primary)) + source.sendSystemMessage("error.ledger.command.no_results".translate().setStyle(TextColorPallet.primary)) return } - source.sendMessage("text.ledger.header.search".translate().setStyle(TextColorPallet.secondary)) + source.sendSystemMessage("text.ledger.header.search".translate().setStyle(TextColorPallet.secondary)) results.forEach { - source.sendMessage(it.toText()) + source.sendSystemMessage(it.toText()) } } - fun warnBusy(source: ServerCommandSource) { + fun warnBusy(source: CommandSourceStack) { // if (DatabaseManager.dbMutex.isLocked) { //TODO // source.sendFeedback( // { @@ -99,9 +103,9 @@ object MessageUtils { // } } - fun instantToText(time: Instant): MutableText { + fun instantToText(time: Instant): MutableComponent { val duration = Duration.between(time, Instant.now()).toKotlinDuration() - val text: MutableText = "".literal() + val text: MutableComponent = "".literal() duration.toComponents { days, hours, minutes, seconds, _ -> @@ -113,12 +117,12 @@ object MessageUtils { } } - val message = Text.translatable("text.ledger.action_message.time_diff", text) + val message = Component.translatable("text.ledger.action_message.time_diff", text) val formatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM) val timeMessage = formatter.format(time.atZone(Ledger.config[SearchSpec.timeZone])).literal() - message.styled { + message.withStyle { it.withHoverEvent( HoverEvent.ShowText( timeMessage 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 5846111e..b3c91393 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/NbtUtils.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/NbtUtils.kt @@ -2,23 +2,23 @@ package com.github.quiltservertools.ledger.utility import com.mojang.logging.LogUtils import com.mojang.serialization.Dynamic -import net.minecraft.block.Block -import net.minecraft.block.BlockState -import net.minecraft.block.entity.BlockEntity -import net.minecraft.datafixer.Schemas -import net.minecraft.datafixer.TypeReferences -import net.minecraft.entity.Entity -import net.minecraft.item.ItemStack -import net.minecraft.nbt.NbtCompound -import net.minecraft.nbt.NbtHelper +import net.minecraft.core.HolderGetter +import net.minecraft.core.HolderLookup +import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.NbtOps -import net.minecraft.nbt.StringNbtReader -import net.minecraft.registry.RegistryEntryLookup -import net.minecraft.registry.RegistryWrapper -import net.minecraft.storage.NbtReadView -import net.minecraft.storage.NbtWriteView -import net.minecraft.util.ErrorReporter -import net.minecraft.util.Identifier +import net.minecraft.nbt.NbtUtils +import net.minecraft.nbt.TagParser +import net.minecraft.resources.Identifier +import net.minecraft.util.ProblemReporter +import net.minecraft.util.datafix.DataFixers +import net.minecraft.util.datafix.fixes.References +import net.minecraft.world.entity.Entity +import net.minecraft.world.item.ItemStack +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.entity.BlockEntity +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.storage.TagValueInput +import net.minecraft.world.level.storage.TagValueOutput const val ITEM_NBT_DATA_VERSION = 3817 const val ITEM_COMPONENTS_DATA_VERSION = 3825 @@ -31,25 +31,25 @@ const val UUID = "UUID" // Entity val LOGGER = LogUtils.getLogger() object NbtUtils { - fun blockStateToProperties(state: BlockState): NbtCompound? { - val stateTag = NbtHelper.fromBlockState(state) - if (state.block.defaultState == state) return null // Don't store default block state + fun blockStateToProperties(state: BlockState): CompoundTag? { + val stateTag = NbtUtils.writeBlockState(state) + if (state.block.defaultBlockState() == state) return null // Don't store default block state return stateTag.getCompound(PROPERTIES).orElse(null) } fun blockStateFromProperties( - tag: NbtCompound, + tag: CompoundTag, name: Identifier, - blockLookup: RegistryEntryLookup + blockLookup: HolderGetter ): BlockState { - val stateTag = NbtCompound() + val stateTag = CompoundTag() stateTag.putString("Name", name.toString()) stateTag.put(PROPERTIES, tag) - return NbtHelper.toBlockState(blockLookup, stateTag) + return NbtUtils.readBlockState(blockLookup, stateTag) } - fun itemFromProperties(tag: String?, name: Identifier, registries: RegistryWrapper.WrapperLookup): ItemStack { - val extraDataTag = StringNbtReader.readCompound(tag ?: "{}") + fun itemFromProperties(tag: String?, name: Identifier, registries: HolderLookup.Provider): ItemStack { + val extraDataTag = TagParser.parseCompoundFully(tag ?: "{}") var itemTag = extraDataTag if (!extraDataTag.contains(COUNT)) { // 1.20.4 and lower (need data fixing) @@ -58,41 +58,41 @@ object NbtUtils { // Ledger ItemStack in 1.20.4 and earlier had "Count" omitted if it was 1 itemTag.putByte(COUNT_PRE_1_20_5, 1) } - itemTag = Schemas.getFixer().update( - TypeReferences.ITEM_STACK, + itemTag = DataFixers.getDataFixer().update( + References.ITEM_STACK, Dynamic(NbtOps.INSTANCE, itemTag), ITEM_NBT_DATA_VERSION, ITEM_COMPONENTS_DATA_VERSION - ).cast(NbtOps.INSTANCE) as NbtCompound? + ).cast(NbtOps.INSTANCE) as CompoundTag } - ErrorReporter.Logging({ "ledger:itemstack@$name" }, LOGGER).use { - val readView = NbtReadView.create(it, registries, itemTag) + ProblemReporter.ScopedCollector({ "ledger:itemstack@$name" }, LOGGER).use { + val readView = TagValueInput.create(it, registries, itemTag) return readView.read(ItemStack.MAP_CODEC).orElse(ItemStack.EMPTY) } } - fun BlockEntity.createNbt(registries: RegistryWrapper.WrapperLookup): NbtCompound { - ErrorReporter.Logging(this.reporterContext, LOGGER) + fun BlockEntity.createNbt(registries: HolderLookup.Provider): CompoundTag { + ProblemReporter.ScopedCollector(this.problemPath(), LOGGER) .use { - val writeView = NbtWriteView.create(it, registries) - this.writeDataWithId(writeView) - return writeView.nbt + val writeView = TagValueOutput.createWithContext(it, registries) + this.saveWithId(writeView) + return writeView.buildResult() } } - fun Entity.createNbt(): NbtCompound { - ErrorReporter.Logging(this.errorReporterContext, LOGGER) + fun Entity.createNbt(): CompoundTag { + ProblemReporter.ScopedCollector(this.problemPath(), LOGGER) .use { - val writeView = NbtWriteView.create(it, this.registryManager) - this.writeData(writeView) - return writeView.nbt + val writeView = TagValueOutput.createWithContext(it, this.registryAccess()) + this.saveWithoutId(writeView) + return writeView.buildResult() } } - fun ItemStack.createNbt(registries: RegistryWrapper.WrapperLookup): NbtCompound { - ErrorReporter.Logging({ "ledger:itemstack@${this.item}" }, LOGGER) + fun ItemStack.createNbt(registries: HolderLookup.Provider): CompoundTag { + ProblemReporter.ScopedCollector({ "ledger:itemstack@${this.item}" }, LOGGER) .use { - val writeView = NbtWriteView.create(it, registries) - writeView.put(ItemStack.MAP_CODEC, this) - return writeView.nbt + val writeView = TagValueOutput.createWithContext(it, registries) + writeView.store(ItemStack.MAP_CODEC, this) + return writeView.buildResult() } } } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerCausable.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerCausable.kt index 5c689f7a..056f43e9 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerCausable.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerCausable.kt @@ -1,7 +1,7 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.entity.player.PlayerEntity +import net.minecraft.world.entity.player.Player interface PlayerCausable { - val causingPlayer: PlayerEntity? + val causingPlayer: Player? } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerLecternHook.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerLecternHook.kt index 888eccf7..cc9b9c1c 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerLecternHook.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerLecternHook.kt @@ -1,9 +1,9 @@ package com.github.quiltservertools.ledger.utility -import net.minecraft.block.entity.BlockEntity -import net.minecraft.entity.player.PlayerEntity +import net.minecraft.world.entity.player.Player +import net.minecraft.world.level.block.entity.BlockEntity object PlayerLecternHook { @JvmStatic - val activeHandlers = HashMap() + val activeHandlers = HashMap() } diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerResult.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerResult.kt index 3b2dc235..cf435862 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerResult.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/PlayerResult.kt @@ -1,14 +1,14 @@ package com.github.quiltservertools.ledger.utility import com.github.quiltservertools.ledger.database.Tables -import net.minecraft.text.Text +import net.minecraft.network.chat.Component import java.time.Instant import java.util.* data class PlayerResult(val uuid: UUID, val name: String, val firstJoin: Instant, val lastJoin: Instant) { - fun toText(): Text { - return Text.translatable( + fun toText(): Component { + return Component.translatable( "text.ledger.player.result", name.literal().setStyle(TextColorPallet.light), MessageUtils.instantToText(firstJoin).setStyle(TextColorPallet.primaryVariant), diff --git a/src/main/kotlin/com/github/quiltservertools/ledger/utility/TextColorPallet.kt b/src/main/kotlin/com/github/quiltservertools/ledger/utility/TextColorPallet.kt index 3c4c0c8d..1735d694 100644 --- a/src/main/kotlin/com/github/quiltservertools/ledger/utility/TextColorPallet.kt +++ b/src/main/kotlin/com/github/quiltservertools/ledger/utility/TextColorPallet.kt @@ -3,22 +3,24 @@ package com.github.quiltservertools.ledger.utility import com.github.quiltservertools.ledger.config.ColorSpec import com.github.quiltservertools.ledger.config.config import com.mojang.serialization.DataResult -import net.minecraft.text.Style -import net.minecraft.text.TextColor +import net.minecraft.network.chat.Style +import net.minecraft.network.chat.TextColor @Suppress("MagicNumber") object TextColorPallet { val primary: Style - get() = Style.EMPTY.withColor(TextColor.parse(config[ColorSpec.primary]).getOrNull()) + get() = Style.EMPTY.withColor(TextColor.parseColor(config[ColorSpec.primary]).getOrNull()) - val primaryVariant: Style get() = Style.EMPTY.withColor( - TextColor.parse(config[ColorSpec.primaryVariant]).getOrNull() + val primaryVariant: Style + get() = Style.EMPTY.withColor( + TextColor.parseColor(config[ColorSpec.primaryVariant]).getOrNull() ) - val secondary: Style get() = Style.EMPTY.withColor(TextColor.parse(config[ColorSpec.secondary]).getOrNull()) - val secondaryVariant: Style get() = Style.EMPTY.withColor( - TextColor.parse(config[ColorSpec.secondaryVariant]).getOrNull() + val secondary: Style get() = Style.EMPTY.withColor(TextColor.parseColor(config[ColorSpec.secondary]).getOrNull()) + val secondaryVariant: Style + get() = Style.EMPTY.withColor( + TextColor.parseColor(config[ColorSpec.secondaryVariant]).getOrNull() ) - val light: Style get() = Style.EMPTY.withColor(TextColor.parse(config[ColorSpec.light]).getOrNull()) + val light: Style get() = Style.EMPTY.withColor(TextColor.parseColor(config[ColorSpec.light]).getOrNull()) } fun DataResult.getOrNull(): TextColor? = this.result().orElse(null) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 49274890..83ddc584 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "fabricloader": ">=0.16.2", "fabric": ">=0.133.13+1.21.9", "fabric-language-kotlin": ">=${fabricKotlin}", - "minecraft": ">=1.21.9" + "minecraft": ">=1.21.10" }, "breaks": { "cardboard": "*" diff --git a/src/main/resources/ledger.mixins.json b/src/main/resources/ledger.mixins.json index f0584897..e2e1d398 100644 --- a/src/main/resources/ledger.mixins.json +++ b/src/main/resources/ledger.mixins.json @@ -1,111 +1,111 @@ { - "required": true, - "package": "com.github.quiltservertools.ledger.mixin", - "mixins": [ - "AbstractBlockMixin", - "AnvilScreenHandlerMixin", - "AxeItemMixin", - "BlockItemMixin", - "BlockMixin", - "BucketDispenserBehaviorMixin", - "BucketItemMixin", - "CampfireBlockEntityMixin", - "ChestBlockMixin", - "CopperGolemGiveMixin", - "DoubleInventoryMixin", - "DyeItemMixin", - "ExplosionImplMixin", - "FillCommandMixin", - "FlintAndSteelItemMixin", - "FrostWalkerEnchantmentMixin", - "HoeItemMixin", - "HoneycombItemMixin", - "ItemScattererMixin", - "JukeboxPlayableComponentMixin", - "LilyPadBlockMixin", - "LockableContainerBlockEntityMixin", - "MoveItemsTaskMixin", - "NetherPortalMixin", - "ScreenHandlerMixin", - "ServerPlayerEntityMixin", - "SetBlockCommandMixin", - "ShovelItemMixin", - "SlotMixin", - "blocks.AbstractPlantPartBlockMixin", - "blocks.AbstractPlantStemBlockMixin", - "blocks.BambooBlockMixin", - "blocks.BedBlockMixin", - "blocks.ButtonBlockMixin", - "blocks.CactusBlockMixin", - "blocks.CakeBlockMixin", - "blocks.CampfireBlockMixin", - "blocks.CandleBlockMixin", - "blocks.CarvedPumpkinBlockMixin", - "blocks.ChorusFlowerBlockMixin", - "blocks.ChorusPlantBlockMixin", - "blocks.ComparatorBlockMixin", - "blocks.CopperGolemStatueBlockMixin", - "blocks.DaylightDetectorBlockMixin", - "blocks.DecoratedPotBlockMixin", - "blocks.DoorBlockMixin", - "blocks.FarmlandBlockMixin", - "blocks.FenceGateBlockMixin", - "blocks.FireBlockMixin", - "blocks.FlowerPotBlockMixin", - "blocks.FluidBlockMixin", - "blocks.IceBlockMixin", - "blocks.JukeboxBlockMixin", - "blocks.LeavesBlockMixin", - "blocks.LeverBlockMixin", - "blocks.NoteBlockMixin", - "blocks.OxidizableCopperGolemStatueBlockMixin", - "blocks.PointedDripstoneBlockMixin", - "blocks.RepeaterBlockMixin", - "blocks.RootedDirtBlockMixin", - "blocks.ScaffoldingBlockMixin", - "blocks.ShelfBlockMixin", - "blocks.SpongeBlockMixin", - "blocks.SpreadableBlockMixin", - "blocks.SugarCaneBlockMixin", - "blocks.TrapdoorBlockMixin", - "blocks.WetSpongeBlockMixin", - "blocks.cauldron.CauldronBehaviorMixin", - "blocks.cauldron.CauldronBlockMixin", - "blocks.cauldron.LeveledCauldronBlockMixin", - "blocks.coral.CoralBlockBlockMixin", - "blocks.coral.CoralBlockMixin", - "blocks.coral.CoralFanBlockMixin", - "blocks.coral.CoralWallFanBlockMixin", - "blocks.lectern.LecternBlockMixin", - "blocks.lectern.LecternScreenHandlerMixin", - "blocks.lectern.ScreenHandlerMixin", - "blocks.sign.AbstractSignBlockMixin", - "blocks.sign.SignBlockEntityMixin", - "entities.ArmorStandEntityMixin", - "entities.CatEntityMixin", - "entities.CopperGolemEntityMixin", - "entities.CreeperEntityMixin", - "entities.EndCrystalEntityMixin", - "entities.EnderDragonEntityMixin", - "entities.EvokerEntityWololoGoalMixin", - "entities.ExplosiveProjectileEntityMixin", - "entities.FallingBlockEntityMixin", - "entities.ItemEntityMixin", - "entities.ItemFrameEntityMixin", - "entities.LightningEntityMixin", - "entities.LivingEntityMixin", - "entities.MobEntityMixin", - "entities.RavagerEntityMixin", - "entities.ServerPlayerEntityMixin", - "entities.SheepEntityMixin", - "entities.SnowGolemEntityMixin", - "entities.WolfEntityMixin", - "entities.silverfish.CallForHelpGoalMixin", - "entities.silverfish.WanderAndInfestGoalMixin", - "preview.EntityTrackerEntryAccessor", - "preview.ServerPlayerEntityMixin" - ], - "injectors": { - "defaultRequire": 1 - } + "required": true, + "package": "com.github.quiltservertools.ledger.mixin", + "mixins": [ + "BlockBehaviourMixin", + "AnvilMenuMixin", + "AxeItemMixin", + "BlockItemMixin", + "BlockMixin", + "BucketDispenserBehaviorMixin", + "BucketItemMixin", + "CampfireBlockEntityMixin", + "ChestBlockMixin", + "CopperGolemGiveMixin", + "CompoundContainerMixin", + "DyeItemMixin", + "ServerExplosionMixin", + "FillCommandMixin", + "FlintAndSteelItemMixin", + "FrostWalkerEnchantmentMixin", + "HoeItemMixin", + "HoneycombItemMixin", + "ContainersMixin", + "JukeboxPlayableMixin", + "WaterlilyBlockMixin", + "BaseContainerBlockEntityMixin", + "TransportItemsBetweenContainersMixin", + "PortalShapeMixin", + "AbstractContainerMenuMixin", + "ServerPlayerMixin", + "SetBlockCommandMixin", + "ShovelItemMixin", + "SlotMixin", + "blocks.GrowingPlantBlockMixin", + "blocks.GrowingPlantHeadBlockMixin", + "blocks.BambooStalkBlockMixin", + "blocks.BedBlockMixin", + "blocks.ButtonBlockMixin", + "blocks.CactusBlockMixin", + "blocks.CakeBlockMixin", + "blocks.CampfireBlockMixin", + "blocks.CandleBlockMixin", + "blocks.CarvedPumpkinBlockMixin", + "blocks.ChorusFlowerBlockMixin", + "blocks.ChorusPlantBlockMixin", + "blocks.ComparatorBlockMixin", + "blocks.CopperGolemStatueBlockMixin", + "blocks.DaylightDetectorBlockMixin", + "blocks.DecoratedPotBlockMixin", + "blocks.DoorBlockMixin", + "blocks.FarmBlockMixin", + "blocks.FenceGateBlockMixin", + "blocks.FireBlockMixin", + "blocks.FlowerPotBlockMixin", + "blocks.LiquidBlockMixin", + "blocks.IceBlockMixin", + "blocks.JukeboxBlockMixin", + "blocks.LeavesBlockMixin", + "blocks.LeverBlockMixin", + "blocks.NoteBlockMixin", + "blocks.WeatheringCopperGolemStatueBlockMixin", + "blocks.PointedDripstoneBlockMixin", + "blocks.RepeaterBlockMixin", + "blocks.RootedDirtBlockMixin", + "blocks.ScaffoldingBlockMixin", + "blocks.ShelfBlockMixin", + "blocks.SpongeBlockMixin", + "blocks.SpreadingSnowyDirtBlockMixin", + "blocks.SugarCaneBlockMixin", + "blocks.TrapDoorBlockMixin", + "blocks.WetSpongeBlockMixin", + "blocks.cauldron.CauldronInteractionMixin", + "blocks.cauldron.CauldronBlockMixin", + "blocks.cauldron.LayeredCauldronBlockMixin", + "blocks.coral.CoralPlantBlockMixin", + "blocks.coral.CoralPlantBlockMixin", + "blocks.coral.CoralFanBlockMixin", + "blocks.coral.CoralWallFanBlockMixin", + "blocks.lectern.LecternBlockMixin", + "blocks.lectern.LecternMenuMixin", + "blocks.lectern.AbstractContainerMenuMixin", + "blocks.sign.SignBlockMixin", + "blocks.sign.SignBlockEntityMixin", + "entities.ArmorStandMixin", + "entities.CatMixin", + "entities.CopperGolemMixin", + "entities.CreeperMixin", + "entities.EndCrystalMixin", + "entities.EnderDragonMixin", + "entities.EvokerEntityWololoGoalMixin", + "entities.AbstractHurtingProjectileMixin", + "entities.FallingBlockEntityMixin", + "entities.ItemEntityMixin", + "entities.ItemFrameMixin", + "entities.LightningBoltMixin", + "entities.LivingEntityMixin", + "entities.MobMixin", + "entities.RavagerMixin", + "entities.ServerPlayerMixin", + "entities.SheepMixin", + "entities.SnowGolemMixin", + "entities.WolfMixin", + "entities.silverfish.CallForHelpGoalMixin", + "entities.silverfish.WanderAndInfestGoalMixin", + "preview.ServerEntityAccessor", + "preview.ServerPlayerEntityMixin" + ], + "injectors": { + "defaultRequire": 1 + } } diff --git a/src/testmod/java/com/github/quiltservertools/ledger/testmod/mixin/ClientPlayerInteractionManagerMixin.java b/src/testmod/java/com/github/quiltservertools/ledger/testmod/mixin/ClientPlayerInteractionManagerMixin.java deleted file mode 100644 index 477b7c1c..00000000 --- a/src/testmod/java/com/github/quiltservertools/ledger/testmod/mixin/ClientPlayerInteractionManagerMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.quiltservertools.ledger.testmod.mixin; - -import com.github.quiltservertools.ledger.testmod.LedgerTest; -import net.minecraft.client.network.ClientPlayerEntity; -import net.minecraft.client.network.ClientPlayerInteractionManager; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -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 com.github.quiltservertools.ledger.testmod.commands.InspectCommand; - -@Mixin(ClientPlayerInteractionManager.class) -public class ClientPlayerInteractionManagerMixin { - @Inject( - method = "interactBlock", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;sendSequencedPacket(Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/network/SequencedPacketCreator;)V" - ), - cancellable = true - ) - private void onInteractBlock(ClientPlayerEntity player, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { - if (!InspectCommand.INSTANCE.getInspectOn()) - return; - - cir.setReturnValue(ActionResult.SUCCESS); - LedgerTest.INSTANCE.inspectBlock(hitResult.getBlockPos()); - } -} diff --git a/src/testmod/java/com/github/quiltservertools/ledger/testmod/mixin/MultiPlayerGameModeMixin.java b/src/testmod/java/com/github/quiltservertools/ledger/testmod/mixin/MultiPlayerGameModeMixin.java new file mode 100644 index 00000000..0037afe5 --- /dev/null +++ b/src/testmod/java/com/github/quiltservertools/ledger/testmod/mixin/MultiPlayerGameModeMixin.java @@ -0,0 +1,33 @@ +package com.github.quiltservertools.ledger.testmod.mixin; + +import com.github.quiltservertools.ledger.testmod.LedgerTest; +import net.minecraft.client.player.LocalPlayer; +import net.minecraft.client.multiplayer.MultiPlayerGameMode; +import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.phys.BlockHitResult; +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 com.github.quiltservertools.ledger.testmod.commands.InspectCommand; + +@Mixin(MultiPlayerGameMode.class) +public class MultiPlayerGameModeMixin { + @Inject( + method = "useItemOn", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/client/multiplayer/MultiPlayerGameMode;startPrediction(Lnet/minecraft/client/multiplayer/ClientLevel;Lnet/minecraft/client/multiplayer/prediction/PredictiveAction;)V" + ), + cancellable = true + ) + private void onInteractBlock(LocalPlayer player, InteractionHand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { + if (!InspectCommand.INSTANCE.getInspectOn()) + return; + + cir.setReturnValue(InteractionResult.SUCCESS); + LedgerTest.INSTANCE.inspectBlock(hitResult.getBlockPos()); + } +} diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/LedgerTest.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/LedgerTest.kt index 284ea3bf..8181560a 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/LedgerTest.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/LedgerTest.kt @@ -11,16 +11,16 @@ import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallba import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking import net.fabricmc.fabric.api.event.player.PlayerBlockBreakEvents import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry -import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockPos +import net.minecraft.resources.Identifier +import net.minecraft.core.BlockPos import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.Logger object LedgerTest : ClientModInitializer { - val HANDSHAKE = Identifier.of("ledger", "handshake") - val INSPECT = Identifier.of("ledger", "inspect") - val SEARCH = Identifier.of("ledger", "search") - val ACTION = Identifier.of("ledger", "action") + val HANDSHAKE = Identifier.fromNamespaceAndPath("ledger", "handshake") + val INSPECT = Identifier.fromNamespaceAndPath("ledger", "inspect") + val SEARCH = Identifier.fromNamespaceAndPath("ledger", "search") + val ACTION = Identifier.fromNamespaceAndPath("ledger", "action") val LOGGER: Logger = LogManager.getLogger("LedgerTestmod") override fun onInitializeClient() { diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/InspectCommand.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/InspectCommand.kt index 07db69dc..e51b9477 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/InspectCommand.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/InspectCommand.kt @@ -3,7 +3,7 @@ package com.github.quiltservertools.ledger.testmod.commands import com.mojang.brigadier.tree.LiteralCommandNode import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource -import net.minecraft.text.Text +import net.minecraft.network.chat.Component object InspectCommand { var inspectOn = false @@ -13,9 +13,9 @@ object InspectCommand { .executes { inspectOn = !inspectOn if (inspectOn) { - it.source.sendFeedback(Text.literal("Enabled client-side inspect.")) + it.source.sendFeedback(Component.literal("Enabled client-side inspect.")) } else { - it.source.sendFeedback(Text.literal("Disabled client-side inspect.")) + it.source.sendFeedback(Component.literal("Disabled client-side inspect.")) } 1 } @@ -23,7 +23,7 @@ object InspectCommand { literal("on") .executes { inspectOn = true - it.source.sendFeedback(Text.literal("Enabled client-side inspect.")) + it.source.sendFeedback(Component.literal("Enabled client-side inspect.")) 1 } ) @@ -31,7 +31,7 @@ object InspectCommand { literal("off") .executes { inspectOn = false - it.source.sendFeedback(Text.literal("Disabled client-side inspect.")) + it.source.sendFeedback(Component.literal("Disabled client-side inspect.")) 1 } ) diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/ActionS2CPacket.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/ActionS2CPacket.kt index d7c8f502..4454d7cf 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/ActionS2CPacket.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/ActionS2CPacket.kt @@ -4,11 +4,11 @@ package com.github.quiltservertools.ledger.testmod.commands.packet import com.github.quiltservertools.ledger.testmod.LedgerTest import java.time.Instant import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.util.Identifier -import net.minecraft.util.math.BlockPos +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload +import net.minecraft.resources.Identifier +import net.minecraft.core.BlockPos data class ActionS2CPacket( val pos: BlockPos, @@ -20,23 +20,23 @@ data class ActionS2CPacket( val timestamp: Instant, val extraData: String ) : - CustomPayload { + CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ClientPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerTest.ACTION) - val CODEC: PacketCodec = - CustomPayload.codecOf({ _, _ -> TODO() }, { + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerTest.ACTION) + val CODEC: StreamCodec = + CustomPacketPayload.codec({ _, _ -> TODO() }, { ActionS2CPacket( it.readBlockPos(), - it.readString(), + it.readUtf(), it.readIdentifier(), it.readIdentifier(), it.readIdentifier(), - it.readString(), + it.readUtf(), Instant.ofEpochSecond(it.readLong()), - it.readString() + it.readUtf() ) }) diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeC2SPacket.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeC2SPacket.kt index ded3aa2f..74d24e45 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeC2SPacket.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeC2SPacket.kt @@ -2,23 +2,23 @@ package com.github.quiltservertools.ledger.testmod.commands.packet import com.github.quiltservertools.ledger.testmod.LedgerTest -import net.minecraft.nbt.NbtCompound -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload +import net.minecraft.nbt.CompoundTag +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class HandshakeC2SPacket(val nbt: NbtCompound?) : CustomPayload { +data class HandshakeC2SPacket(val nbt: CompoundTag?) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID - private fun write(buf: PacketByteBuf?) { + private fun write(buf: FriendlyByteBuf?) { buf?.writeNbt(nbt) } companion object { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerTest.HANDSHAKE) - val CODEC: PacketCodec = - CustomPayload.codecOf(HandshakeC2SPacket::write) { TODO() } + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerTest.HANDSHAKE) + val CODEC: StreamCodec = + CustomPacketPayload.codec(HandshakeC2SPacket::write) { TODO() } } } diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeS2CPacket.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeS2CPacket.kt index ca86fbd6..f9a5c05d 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeS2CPacket.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/HandshakeS2CPacket.kt @@ -3,25 +3,25 @@ package com.github.quiltservertools.ledger.testmod.commands.packet import com.github.quiltservertools.ledger.testmod.LedgerTest import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload data class HandshakeS2CPacket(val protocolVersion: Int, val ledgerVersion: String, val actionTypes: Collection) : - CustomPayload { + CustomPacketPayload { - override fun getId() = ID + override fun type() = ID companion object : ClientPlayNetworking.PlayPayloadHandler { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerTest.HANDSHAKE) - val CODEC: PacketCodec = - CustomPayload.codecOf({ _, _ -> TODO() }, { + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerTest.HANDSHAKE) + val CODEC: StreamCodec = + CustomPacketPayload.codec({ _, _ -> TODO() }, { val protocolVersion = it.readInt() - val ledgerVersion = it.readString() + val ledgerVersion = it.readUtf() val actionsLength = it.readInt() val actionTypes: MutableList = mutableListOf() for (i in 0..actionsLength) { - actionTypes.add(it.readString()) + actionTypes.add(it.readUtf()) } HandshakeS2CPacket(protocolVersion, ledgerVersion, actionTypes) }) diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/InspectC2SPacket.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/InspectC2SPacket.kt index b4af1461..f6f1f37f 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/InspectC2SPacket.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/InspectC2SPacket.kt @@ -2,23 +2,23 @@ package com.github.quiltservertools.ledger.testmod.commands.packet import com.github.quiltservertools.ledger.testmod.LedgerTest -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload -import net.minecraft.util.math.BlockPos +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload +import net.minecraft.core.BlockPos -data class InspectC2SPacket(val pos: BlockPos) : CustomPayload { +data class InspectC2SPacket(val pos: BlockPos) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID - private fun write(buf: PacketByteBuf?) { + private fun write(buf: FriendlyByteBuf?) { buf?.writeBlockPos(pos) } companion object { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerTest.INSPECT) - val CODEC: PacketCodec = - CustomPayload.codecOf(InspectC2SPacket::write) { TODO() } + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerTest.INSPECT) + val CODEC: StreamCodec = + CustomPacketPayload.codec(InspectC2SPacket::write) { TODO() } } } diff --git a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/SearchC2SPacket.kt b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/SearchC2SPacket.kt index db658aff..3b14d019 100644 --- a/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/SearchC2SPacket.kt +++ b/src/testmod/kotlin/com/github/quiltservertools/ledger/testmod/commands/packet/SearchC2SPacket.kt @@ -2,22 +2,22 @@ package com.github.quiltservertools.ledger.testmod.commands.packet import com.github.quiltservertools.ledger.testmod.LedgerTest -import net.minecraft.network.PacketByteBuf -import net.minecraft.network.codec.PacketCodec -import net.minecraft.network.packet.CustomPayload +import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.codec.StreamCodec +import net.minecraft.network.protocol.common.custom.CustomPacketPayload -data class SearchC2SPacket(val query: String) : CustomPayload { +data class SearchC2SPacket(val query: String) : CustomPacketPayload { - override fun getId() = ID + override fun type() = ID - private fun write(buf: PacketByteBuf?) { - buf?.writeString(query) + private fun write(buf: FriendlyByteBuf?) { + buf?.writeUtf(query) } companion object { - val ID: CustomPayload.Id = CustomPayload.Id(LedgerTest.SEARCH) - val CODEC: PacketCodec = - CustomPayload.codecOf(SearchC2SPacket::write) { TODO() } + val ID: CustomPacketPayload.Type = CustomPacketPayload.Type(LedgerTest.SEARCH) + val CODEC: StreamCodec = + CustomPacketPayload.codec(SearchC2SPacket::write) { TODO() } } }