Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 1.21 #271

Merged
merged 26 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[versions]
minecraft = "1.20.6"
yarn-mappings = "1.20.6+build.3"
minecraft = "1.21"
yarn-mappings = "1.21+build.1"
fabric-loader = "0.15.11"

fabric-api = "0.99.0+1.20.6"
fabric-api = "0.100.1+1.21"

# Kotlin
kotlin = "1.9.23"
kotlin = "2.0.0"
# Also modrinth version in gradle.properties
fabric-kotlin = "1.10.19+kotlin.1.9.23"
fabric-kotlin = "1.11.0+kotlin.2.0.0"

fabric-permissions = "0.3.1"
translations = "2.3.0+1.20.5-rc2"
translations = "2.3.1+1.21-pre2"

exposed = "0.46.0"
sqlite-jdbc = "3.44.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@

import com.github.quiltservertools.ledger.callbacks.BlockPlaceCallback;
import com.github.quiltservertools.ledger.utility.Sources;
import net.minecraft.block.Blocks;
import net.minecraft.enchantment.FrostWalkerEnchantment;
import net.minecraft.entity.LivingEntity;
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.world.World;
import net.minecraft.util.math.Vec3d;
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(FrostWalkerEnchantment.class)
@Mixin(ReplaceDiskEnchantmentEffect.class)
public abstract class FrostWalkerEnchantmentMixin {
@ModifyArgs(method = "freezeWater", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)Z"))
private static void logFrostWalkerPlacement(Args args, LivingEntity entity, World world, BlockPos entityPos, int level) {
@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) {
// Frosted ice block is hardcoded in target class
BlockPos pos = args.get(0);
BlockState state = args.get(1);
pos = pos.toImmutable();
if (!(world.getBlockState(pos).getBlock() == Blocks.FROSTED_ICE)) {
BlockPlaceCallback.EVENT.invoker().place(world, pos, Blocks.FROSTED_ICE.getDefaultState(), null, Sources.FROST_WALKER,
entity instanceof PlayerEntity ? (PlayerEntity) entity : null);
}
// 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,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.MusicDiscItem;
import net.minecraft.util.ActionResult;
import net.minecraft.component.type.JukeboxPlayableComponent;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -16,14 +17,12 @@
import static net.minecraft.block.JukeboxBlock.HAS_RECORD;


@Mixin(MusicDiscItem.class)
public abstract class MusicDiscItemMixin {
@Mixin(JukeboxPlayableComponent.class)
public abstract class JukeboxPlayableComponentMixin {

@Inject(method = "useOnBlock", at = @At(value = "INVOKE",
@Inject(method = "tryPlayStack", at = @At(value = "INVOKE",
target = "Lnet/minecraft/block/entity/JukeboxBlockEntity;setStack(Lnet/minecraft/item/ItemStack;)V"))
public void ledgerPlayerInsertMusicDisc(ItemUsageContext context, CallbackInfoReturnable<ActionResult> cir) {
World world = context.getWorld();
BlockPos pos = context.getBlockPos();
private static void ledgerPlayerInsertMusicDisc(World world, BlockPos pos, ItemStack itemStack, PlayerEntity player, CallbackInfoReturnable<ItemActionResult> cir) {
BlockState blockState = world.getBlockState(pos);

BlockChangeCallback.EVENT.invoker().changeBlock(
Expand All @@ -34,6 +33,6 @@ public void ledgerPlayerInsertMusicDisc(ItemUsageContext context, CallbackInfoRe
null,
world.getBlockEntity(pos),
Sources.INTERACT,
context.getPlayer());
player);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public abstract class LeverBlockMixin {
@Unique
private PlayerEntity 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/block/BlockState;"))
@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<ActionResult> 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) {
public void logLeverUse(Args args, BlockState state, World world, BlockPos pos, PlayerEntity playerEntity) {
if (activePlayer == null) return;

BlockState newState = args.get(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minecraft.block.BlockState;
import net.minecraft.block.LecternBlock;
import net.minecraft.block.entity.LecternBlockEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -21,7 +21,7 @@
@Mixin(LecternBlock.class)
public class LecternBlockMixin {
@Inject(method = "putBook", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V"))
private static void logPutBook(Entity user, World world, BlockPos pos, BlockState state, ItemStack stack, CallbackInfo ci) {
private static void logPutBook(LivingEntity user, World 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
Expand Down Expand Up @@ -44,7 +45,7 @@ private void ledgerArmorStandInteract(PlayerEntity player, EquipmentSlot slot, I
}

@Inject(method = "updateHealth", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/decoration/ArmorStandEntity;kill()V"))
private void ledgerArmorStandKill(DamageSource damageSource, float amount, CallbackInfo ci) {
private void ledgerArmorStandKill(ServerWorld world, DamageSource damageSource, float amount, CallbackInfo ci) {
LivingEntity entity = (LivingEntity) (Object) this;
EntityKillCallback.EVENT.invoker().kill(entity.getWorld(), entity.getBlockPos(), entity, damageSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
import org.jetbrains.exposed.sql.vendors.SQLiteDialect
import java.nio.file.Files
import java.util.UUID
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration.Companion.minutes
Expand Down Expand Up @@ -144,7 +144,7 @@ object Ledger : DedicatedServerModInitializer, CoroutineScope {
registerEntityListeners()
}

fun identifier(path: String) = Identifier(MOD_ID, path)
fun identifier(path: String) = Identifier.of(MOD_ID, path)
}

fun logDebug(message: String) = Ledger.logger.debug(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ abstract class AbstractActionType : ActionType {
override var timestamp: Instant = Instant.now()
override var pos: BlockPos = BlockPos.ORIGIN
override var world: Identifier? = null
override var objectIdentifier: Identifier = Identifier("air")
override var oldObjectIdentifier: Identifier = Identifier("air")
override var objectIdentifier: Identifier = Identifier.ofVanilla("air")
override var oldObjectIdentifier: Identifier = Identifier.ofVanilla("air")
override var objectState: String? = null
override var oldObjectState: String? = null
override var sourceName: String = Sources.UNKNOWN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EntityChangeActionType : AbstractActionType() {
override val identifier = "entity-change"

override fun getTranslationType(): String {
val item = Registries.ITEM.get(Identifier(extraData))
val item = Registries.ITEM.get(Identifier.of(extraData))
return if (item is BlockItem && item !is AliasedBlockItem) {
"block"
} else {
Expand All @@ -49,14 +49,14 @@ class EntityChangeActionType : AbstractActionType() {
}
)

if (extraData != null && Identifier(extraData) != Identifier.tryParse("minecraft:air")) {
val stack = ItemStack(Registries.ITEM.get(Identifier(extraData)))
if (extraData != null && Identifier.of(extraData) != Identifier.tryParse("minecraft:air")) {
val stack = ItemStack(Registries.ITEM.get(Identifier.of(extraData)))
text.append(Text.literal(" ").append(Text.translatable("text.ledger.action_message.with")).append(" "))
text.append(
Text.translatable(
Util.createTranslationKey(
this.getTranslationType(),
Identifier(extraData)
Identifier.of(extraData)
)
).setStyle(TextColorPallet.secondaryVariant).styled {
it.withHoverEvent(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.quiltservertools.ledger.config

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

const val CONFIG_PATH = "ledger.toml"

Expand All @@ -13,6 +15,7 @@ val config: Config = Config {
addSpec(ColorSpec)
addSpec(NetworkingSpec)
}
.apply { this.mapper.addMixIn(Identifier::class.java, IdentifierMixin::class.java) }
.from.toml.resource(CONFIG_PATH)
.from.toml.watchFile(FabricLoader.getInstance().configDir.resolve("ledger.toml").toFile())
.from.env()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.quiltservertools.ledger.config.util

import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
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

object IdentifierSerializer : JsonSerializer<Identifier>() {
override fun serialize(value: Identifier, gen: JsonGenerator, serializers: SerializerProvider) {
gen.writeString(value.toString())
}
}

object IdentifierDeserializer : JsonDeserializer<Identifier>() {
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): Identifier = Identifier.of(p.valueAsString)
}

@JsonSerialize(using = IdentifierSerializer::class)
@JsonDeserialize(using = IdentifierDeserializer::class)
abstract class IdentifierMixin
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ object DatabaseManager {
type.timestamp = action[Tables.Actions.timestamp]
type.pos = BlockPos(action[Tables.Actions.x], action[Tables.Actions.y], action[Tables.Actions.z])
type.world = Identifier.tryParse(action[Tables.Worlds.identifier])
type.objectIdentifier = Identifier(action[Tables.ObjectIdentifiers.identifier])
type.oldObjectIdentifier = Identifier(
type.objectIdentifier = Identifier.of(action[Tables.ObjectIdentifiers.identifier])
type.oldObjectIdentifier = Identifier.of(
action[Tables.ObjectIdentifiers.alias("oldObjects")[Tables.ObjectIdentifiers.identifier]]
)
type.objectState = action[Tables.Actions.blockState]
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/ledger.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"HoneycombItemMixin",
"ItemScattererMixin",
"LockableContainerBlockEntityMixin",
"MusicDiscItemMixin",
"JukeboxPlayableComponentMixin",
"NetherPortalMixin",
"ScreenHandlerMixin",
"SetBlockCommandMixin",
Expand Down