diff --git a/gradle.properties b/gradle.properties index 40629afb..90cdbbe6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check https://fabricmc.net/develop/ - minecraft_version=25w16a + minecraft_version=25w18a loader_version=0.16.10 jsr305_version=3.0.2 fabric_version=0.119.5+1.21.5 diff --git a/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java b/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java index c9d07991..5323f670 100644 --- a/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java +++ b/src/main/java/carpet/mixins/PistonMovingBlockEntity_movableBEMixin.java @@ -15,6 +15,10 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.piston.PistonMovingBlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.TagValueOutput; +import net.minecraft.world.level.storage.ValueInput; +import net.minecraft.world.level.storage.ValueOutput; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; @@ -134,25 +138,25 @@ public abstract class PistonMovingBlockEntity_movableBEMixin extends BlockEntity } @Inject(method = "loadAdditional", at = @At(value = "TAIL")) - private void onFromTag(CompoundTag NbtCompound_1, HolderLookup.Provider registries, CallbackInfo ci) + private void onFromTag(ValueInput valueInput, CallbackInfo ci) { - if (CarpetSettings.movableBlockEntities && NbtCompound_1.contains("carriedTileEntityCM")) - { - if (this.movedState.getBlock() instanceof EntityBlock) - this.carriedBlockEntity = ((EntityBlock) (this.movedState.getBlock())).newBlockEntity(worldPosition, movedState);// this.world); - if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null - this.carriedBlockEntity.loadWithComponents(NbtCompound_1.getCompound("carriedTileEntityCM").orElseThrow(), registries); - setCarriedBlockEntity(carriedBlockEntity); - } + if (CarpetSettings.movableBlockEntities) + valueInput.child("carriedTileEntityCM").ifPresent(tag -> { + if (this.movedState.getBlock() instanceof EntityBlock) + this.carriedBlockEntity = ((EntityBlock) (this.movedState.getBlock())).newBlockEntity(worldPosition, movedState);// this.world); + if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null + this.carriedBlockEntity.loadWithComponents(tag); + setCarriedBlockEntity(carriedBlockEntity); + }); } @Inject(method = "saveAdditional", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) - private void onToTag(CompoundTag NbtCompound_1, HolderLookup.Provider registries, CallbackInfo ci) + private void onToTag(ValueOutput valueOutput, CallbackInfo ci) { - if (CarpetSettings.movableBlockEntities && this.carriedBlockEntity != null) + if (CarpetSettings.movableBlockEntities && this.carriedBlockEntity != null && valueOutput instanceof TagValueOutput output) { //Leave name "carriedTileEntityCM" instead of "carriedBlockEntityCM" for upgrade compatibility with 1.13.2 movable TE - NbtCompound_1.put("carriedTileEntityCM", this.carriedBlockEntity.saveWithoutMetadata(registries)); + this.carriedBlockEntity.saveWithoutMetadata(output.child("carriedTileEntityCM")); } } } diff --git a/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java b/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java index 3cd54ed3..2d8dc9b5 100644 --- a/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java +++ b/src/main/java/carpet/mixins/PlayerList_fakePlayersMixin.java @@ -10,6 +10,8 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.players.PlayerList; +import net.minecraft.util.ProblemReporter; +import net.minecraft.world.level.storage.ValueInput; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -20,6 +22,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import carpet.patches.NetHandlerPlayServerFake; import carpet.patches.EntityPlayerMPFake; +import java.util.Optional; + @Mixin(PlayerList.class) public abstract class PlayerList_fakePlayersMixin { @@ -28,11 +32,11 @@ public abstract class PlayerList_fakePlayersMixin private MinecraftServer server; @Inject(method = "load", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) - private void fixStartingPos(ServerPlayer serverPlayerEntity_1, CallbackInfoReturnable cir) + private void fixStartingPos(ServerPlayer serverPlayer, ProblemReporter problemReporter, CallbackInfoReturnable> cir) { - if (serverPlayerEntity_1 instanceof EntityPlayerMPFake) + if (serverPlayer instanceof EntityPlayerMPFake) { - ((EntityPlayerMPFake) serverPlayerEntity_1).fixStartingPosition.run(); + ((EntityPlayerMPFake) serverPlayer).fixStartingPosition.run(); } } diff --git a/src/main/java/carpet/network/CarpetClient.java b/src/main/java/carpet/network/CarpetClient.java index d8893ea2..a2e83ee2 100644 --- a/src/main/java/carpet/network/CarpetClient.java +++ b/src/main/java/carpet/network/CarpetClient.java @@ -106,7 +106,7 @@ public class CarpetClient ListTag outputTag = (ListTag) tag.get("output"); for (int i = 0; i < outputTag.size(); i++) { - CarpetSettings.LOG.info(" - response: " + Component.Serializer.fromJson(outputTag.getString(i).orElseThrow(), clientPlayer.registryAccess()).getString()); + CarpetSettings.LOG.info(" - response: " + outputTag.getString(i).orElseThrow()); } } } diff --git a/src/main/java/carpet/network/ServerNetworkHandler.java b/src/main/java/carpet/network/ServerNetworkHandler.java index 79d8577e..86e4b0d9 100644 --- a/src/main/java/carpet/network/ServerNetworkHandler.java +++ b/src/main/java/carpet/network/ServerNetworkHandler.java @@ -104,7 +104,7 @@ public class ServerNetworkHandler ListTag outputResult = new ListTag(); for (Component line : output) { - outputResult.add(StringTag.valueOf(Component.Serializer.toJson(line, player.registryAccess()))); + outputResult.add(StringTag.valueOf(line.getString())); } if (!output.isEmpty()) { diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java index 8dac488b..2794a875 100644 --- a/src/main/java/carpet/script/api/WorldAccess.java +++ b/src/main/java/carpet/script/api/WorldAccess.java @@ -53,6 +53,7 @@ import net.minecraft.server.level.TicketType; import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.level.ServerExplosion; import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.PalettedContainer; @@ -64,6 +65,7 @@ import net.minecraft.world.level.levelgen.NoiseRouter; import net.minecraft.world.level.levelgen.RandomState; import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.StructureType; +import net.minecraft.world.level.storage.TagValueInput; import org.apache.commons.lang3.mutable.MutableBoolean; import org.apache.commons.lang3.tuple.Pair; @@ -829,7 +831,9 @@ public class WorldAccess destTag.putInt("x", targetPos.getX()); destTag.putInt("y", targetPos.getY()); destTag.putInt("z", targetPos.getZ()); - be.loadWithComponents(destTag, world.registryAccess()); + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(be.problemPath(), CarpetScriptServer.LOG)) { + be.loadWithComponents(TagValueInput.create(reporter, world.registryAccess(), destTag)); + } be.setChanged(); success = true; } diff --git a/src/main/java/carpet/script/utils/ShapeDispatcher.java b/src/main/java/carpet/script/utils/ShapeDispatcher.java index 12e1ed2e..041600f0 100644 --- a/src/main/java/carpet/script/utils/ShapeDispatcher.java +++ b/src/main/java/carpet/script/utils/ShapeDispatcher.java @@ -1718,13 +1718,13 @@ public class ShapeDispatcher { value = new FormattedTextValue(Component.literal(value.getString())); } - return StringTag.valueOf(((FormattedTextValue) value).serialize(regs)); + return ((FormattedTextValue) value).serialize(regs); } @Override public Value decode(Tag tag, Level level) { - return FormattedTextValue.deserialize(tag.asString().get(), level.registryAccess()); + return FormattedTextValue.deserialize(tag, level.registryAccess()); } } diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java index 51e7b86a..53892aab 100644 --- a/src/main/java/carpet/script/utils/ShapesRenderer.java +++ b/src/main/java/carpet/script/utils/ShapesRenderer.java @@ -38,6 +38,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.resources.ResourceKey; import net.minecraft.util.Mth; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.LightLayer; @@ -46,6 +47,7 @@ import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.RenderShape; 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.phys.Vec3; import org.joml.Matrix4f; import org.joml.Matrix4fStack; @@ -423,7 +425,9 @@ public class ShapesRenderer BlockEntity.setLevel(client.level); if (shape.blockEntity != null) { - BlockEntity.loadWithComponents(shape.blockEntity, client.level.registryAccess()); + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(BlockEntity.problemPath(), CarpetScriptServer.LOG)) { + BlockEntity.loadWithComponents(TagValueInput.create(reporter, client.level.registryAccess(), shape.blockEntity)); + } } } } diff --git a/src/main/java/carpet/script/value/EntityValue.java b/src/main/java/carpet/script/value/EntityValue.java index 800cf9e6..ea8a983c 100644 --- a/src/main/java/carpet/script/value/EntityValue.java +++ b/src/main/java/carpet/script/value/EntityValue.java @@ -40,6 +40,7 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.EntityTypeTags; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.InteractionHand; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffectInstance; @@ -73,6 +74,8 @@ import net.minecraft.world.level.GameType; import net.minecraft.world.level.Level; import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.level.pathfinder.Path; +import net.minecraft.world.level.storage.TagValueInput; +import net.minecraft.world.level.storage.TagValueOutput; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.HitResult; @@ -526,7 +529,7 @@ public class EntityValue extends Value } return Value.NULL; }); - put("home", (e, a) -> e instanceof Mob mob ? (mob.getRestrictRadius() > 0) ? new BlockValue(null, (ServerLevel) e.level(), mob.getRestrictCenter()) : Value.FALSE : Value.NULL); + put("home", (e, a) -> e instanceof Mob mob ? (mob.getHomeRadius() > 0) ? new BlockValue(null, (ServerLevel) e.level(), mob.getHomePosition()) : Value.FALSE : Value.NULL); put("spawn_point", (e, a) -> { if (e instanceof ServerPlayer spe) { @@ -856,12 +859,16 @@ public class EntityValue extends Value }); put("nbt", (e, a) -> { - CompoundTag nbttagcompound = e.saveWithoutId((new CompoundTag())); - if (a == null) - { - return new NBTSerializableValue(nbttagcompound); + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(e.problemPath(), CarpetScriptServer.LOG)) { + final TagValueOutput output = TagValueOutput.createWithContext(reporter, e.registryAccess()); + e.saveWithoutId(output); + CompoundTag nbttagcompound = output.buildResult(); + if (a == null) + { + return new NBTSerializableValue(nbttagcompound); + } + return new NBTSerializableValue(nbttagcompound).get(a); } - return new NBTSerializableValue(nbttagcompound).get(a); }); put("category", (e, a) -> { @@ -1312,7 +1319,7 @@ public class EntityValue extends Value } if (v.isNull()) { - ec.restrictTo(BlockPos.ZERO, -1); + ec.setHomeTo(BlockPos.ZERO, -1); Map tasks = Vanilla.Mob_getTemporaryTasks(ec); Vanilla.Mob_getAI(ec, false).removeGoal(tasks.get("home")); tasks.remove("home"); @@ -1345,7 +1352,7 @@ public class EntityValue extends Value throw new InternalExpressionException("'home' requires at least one position argument, and optional distance"); } - ec.restrictTo(pos, distance); + ec.setHomeTo(pos, distance); Map tasks = Vanilla.Mob_getTemporaryTasks(ec); if (!tasks.containsKey("home")) { @@ -1675,7 +1682,9 @@ public class EntityValue extends Value Value tagValue = NBTSerializableValue.fromValue(v); if (tagValue instanceof NBTSerializableValue nbtsv) { - e.load(nbtsv.getCompoundTag()); + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(e.problemPath(), CarpetScriptServer.LOG)) { + e.load(TagValueInput.create(reporter, e.registryAccess(), nbtsv.getCompoundTag())); + } e.setUUID(uUID); } } @@ -1687,9 +1696,16 @@ public class EntityValue extends Value Value tagValue = NBTSerializableValue.fromValue(v); if (tagValue instanceof NBTSerializableValue nbtsv) { - CompoundTag nbttagcompound = e.saveWithoutId((new CompoundTag())); + CompoundTag nbttagcompound; + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(e.problemPath(), CarpetScriptServer.LOG)) { + final TagValueOutput output = TagValueOutput.createWithContext(reporter, e.registryAccess()); + e.saveWithoutId(output); + nbttagcompound = output.buildResult(); + } nbttagcompound.merge(nbtsv.getCompoundTag()); - e.load(nbttagcompound); + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(e.problemPath(), CarpetScriptServer.LOG)) { + e.load(TagValueInput.create(reporter, e.registryAccess(), nbttagcompound)); + } e.setUUID(uUID); } } @@ -1742,10 +1758,18 @@ public class EntityValue extends Value { throw new NBTSerializableValue.IncompatibleTypeException(this); } - CompoundTag tag = new CompoundTag(); - tag.put("Data", getEntity().saveWithoutId(new CompoundTag())); - Registry> reg = getEntity().level().registryAccess().lookupOrThrow(Registries.ENTITY_TYPE); - tag.put("Name", StringTag.valueOf(reg.getKey(getEntity().getType()).toString())); + CompoundTag tag; + Entity entity = getEntity(); + try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(entity.problemPath(), CarpetScriptServer.LOG)) { + final TagValueOutput output = TagValueOutput.createWithContext(reporter, entity.registryAccess()); + entity.save(output); + tag = output.buildResult(); + } + + tag.put("Data", tag); + + Registry> reg = entity.level().registryAccess().lookupOrThrow(Registries.ENTITY_TYPE); + tag.put("Name", StringTag.valueOf(reg.getKey(entity.getType()).toString())); return tag; } } diff --git a/src/main/java/carpet/script/value/FormattedTextValue.java b/src/main/java/carpet/script/value/FormattedTextValue.java index b08e0942..3a8c5ee0 100644 --- a/src/main/java/carpet/script/value/FormattedTextValue.java +++ b/src/main/java/carpet/script/value/FormattedTextValue.java @@ -1,9 +1,13 @@ package carpet.script.value; +import carpet.script.exception.InternalExpressionException; +import com.mojang.serialization.DynamicOps; import net.minecraft.core.RegistryAccess; +import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; import net.minecraft.network.chat.MutableComponent; public class FormattedTextValue extends StringValue @@ -86,7 +90,7 @@ public class FormattedTextValue extends StringValue { throw new NBTSerializableValue.IncompatibleTypeException(this); } - return StringTag.valueOf(Component.Serializer.toJson(text, regs)); + return serialize(regs); } @Override @@ -95,14 +99,14 @@ public class FormattedTextValue extends StringValue return combine(this, o); } - public String serialize(RegistryAccess regs) + public Tag serialize(RegistryAccess regs) { - return Component.Serializer.toJson(text, regs); + return ComponentSerialization.CODEC.encodeStart(regs.createSerializationContext(NbtOps.INSTANCE), text).getOrThrow(InternalExpressionException::new);// text.getContents() Component.Serializer.toJson(text, regs); } - public static FormattedTextValue deserialize(String serialized, RegistryAccess regs) + public static FormattedTextValue deserialize(Tag tag, RegistryAccess regs) { - return new FormattedTextValue(Component.Serializer.fromJson(serialized, regs)); + return new FormattedTextValue(ComponentSerialization.CODEC.decode(regs.createSerializationContext(NbtOps.INSTANCE), tag).getOrThrow(InternalExpressionException::new).getFirst()); } public static Component getTextByValue(Value value) diff --git a/src/main/java/carpet/script/value/ScreenValue.java b/src/main/java/carpet/script/value/ScreenValue.java index a3c154ff..84b7ef02 100644 --- a/src/main/java/carpet/script/value/ScreenValue.java +++ b/src/main/java/carpet/script/value/ScreenValue.java @@ -20,6 +20,7 @@ import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; @@ -391,7 +392,7 @@ public class ScreenValue extends Value } else { - nbtList.add(itemStack.save(regs)); + nbtList.add(ItemStack.CODEC.encodeStart(regs.createSerializationContext(NbtOps.INSTANCE), itemStack).getOrThrow(InternalExpressionException::new)); } } return nbtList;