This commit is contained in:
gnembon committed 2025-04-30 14:11:25 +02:00
1 parent d45f5ba05a
commit ef6ebac7fb
11 files changed
+88 -43

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check https://fabricmc.net/develop/ # check https://fabricmc.net/develop/
minecraft_version=25w16a minecraft_version=25w18a
loader_version=0.16.10 loader_version=0.16.10
jsr305_version=3.0.2 jsr305_version=3.0.2
fabric_version=0.119.5+1.21.5 fabric_version=0.119.5+1.21.5
@@ -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.entity.BlockEntityType;
import net.minecraft.world.level.block.piston.PistonMovingBlockEntity; import net.minecraft.world.level.block.piston.PistonMovingBlockEntity;
import net.minecraft.world.level.block.state.BlockState; 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.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; 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")) @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 (CarpetSettings.movableBlockEntities)
{ valueInput.child("carriedTileEntityCM").ifPresent(tag -> {
if (this.movedState.getBlock() instanceof EntityBlock) if (this.movedState.getBlock() instanceof EntityBlock)
this.carriedBlockEntity = ((EntityBlock) (this.movedState.getBlock())).newBlockEntity(worldPosition, movedState);// this.world); this.carriedBlockEntity = ((EntityBlock) (this.movedState.getBlock())).newBlockEntity(worldPosition, movedState);// this.world);
if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null if (carriedBlockEntity != null) //Can actually be null, as BlockPistonMoving.createNewTileEntity(...) returns null
this.carriedBlockEntity.loadWithComponents(NbtCompound_1.getCompound("carriedTileEntityCM").orElseThrow(), registries); this.carriedBlockEntity.loadWithComponents(tag);
setCarriedBlockEntity(carriedBlockEntity); setCarriedBlockEntity(carriedBlockEntity);
} });
} }
@Inject(method = "saveAdditional", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) @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 //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"));
} }
} }
} }
@@ -10,6 +10,8 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.CommonListenerCookie; import net.minecraft.server.network.CommonListenerCookie;
import net.minecraft.server.network.ServerGamePacketListenerImpl; import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.players.PlayerList; 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.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; 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.NetHandlerPlayServerFake;
import carpet.patches.EntityPlayerMPFake; import carpet.patches.EntityPlayerMPFake;
import java.util.Optional;
@Mixin(PlayerList.class) @Mixin(PlayerList.class)
public abstract class PlayerList_fakePlayersMixin public abstract class PlayerList_fakePlayersMixin
{ {
@@ -28,11 +32,11 @@ public abstract class PlayerList_fakePlayersMixin
private MinecraftServer server; private MinecraftServer server;
@Inject(method = "load", at = @At(value = "RETURN", shift = At.Shift.BEFORE)) @Inject(method = "load", at = @At(value = "RETURN", shift = At.Shift.BEFORE))
private void fixStartingPos(ServerPlayer serverPlayerEntity_1, CallbackInfoReturnable<CompoundTag> cir) private void fixStartingPos(ServerPlayer serverPlayer, ProblemReporter problemReporter, CallbackInfoReturnable<Optional<ValueInput>> cir)
{ {
if (serverPlayerEntity_1 instanceof EntityPlayerMPFake) if (serverPlayer instanceof EntityPlayerMPFake)
{ {
((EntityPlayerMPFake) serverPlayerEntity_1).fixStartingPosition.run(); ((EntityPlayerMPFake) serverPlayer).fixStartingPosition.run();
} }
} }
@@ -106,7 +106,7 @@ public class CarpetClient
ListTag outputTag = (ListTag) tag.get("output"); ListTag outputTag = (ListTag) tag.get("output");
for (int i = 0; i < outputTag.size(); i++) 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());
} }
} }
} }
@@ -104,7 +104,7 @@ public class ServerNetworkHandler
ListTag outputResult = new ListTag(); ListTag outputResult = new ListTag();
for (Component line : output) for (Component line : output)
{ {
outputResult.add(StringTag.valueOf(Component.Serializer.toJson(line, player.registryAccess()))); outputResult.add(StringTag.valueOf(line.getString()));
} }
if (!output.isEmpty()) if (!output.isEmpty())
{ {
@@ -53,6 +53,7 @@ import net.minecraft.server.level.TicketType;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.ItemTags; import net.minecraft.tags.ItemTags;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.level.ServerExplosion; import net.minecraft.world.level.ServerExplosion;
import net.minecraft.world.level.chunk.ChunkGenerator; import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.chunk.PalettedContainer; 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.RandomState;
import net.minecraft.world.level.levelgen.structure.Structure; import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureType; 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.mutable.MutableBoolean;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
@@ -829,7 +831,9 @@ public class WorldAccess
destTag.putInt("x", targetPos.getX()); destTag.putInt("x", targetPos.getX());
destTag.putInt("y", targetPos.getY()); destTag.putInt("y", targetPos.getY());
destTag.putInt("z", targetPos.getZ()); 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(); be.setChanged();
success = true; success = true;
} }
@@ -1718,13 +1718,13 @@ public class ShapeDispatcher
{ {
value = new FormattedTextValue(Component.literal(value.getString())); value = new FormattedTextValue(Component.literal(value.getString()));
} }
return StringTag.valueOf(((FormattedTextValue) value).serialize(regs)); return ((FormattedTextValue) value).serialize(regs);
} }
@Override @Override
public Value decode(Tag tag, Level level) public Value decode(Tag tag, Level level)
{ {
return FormattedTextValue.deserialize(tag.asString().get(), level.registryAccess()); return FormattedTextValue.deserialize(tag, level.registryAccess());
} }
} }
@@ -38,6 +38,7 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer; 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.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.TagValueInput;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Matrix4fStack; import org.joml.Matrix4fStack;
@@ -423,7 +425,9 @@ public class ShapesRenderer
BlockEntity.setLevel(client.level); BlockEntity.setLevel(client.level);
if (shape.blockEntity != null) 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));
}
} }
} }
} }
@@ -40,6 +40,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.tags.EntityTypeTags; import net.minecraft.tags.EntityTypeTags;
import net.minecraft.tags.TagKey; import net.minecraft.tags.TagKey;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.util.ProblemReporter;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance; 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.Level;
import net.minecraft.world.level.entity.EntityTypeTest; import net.minecraft.world.level.entity.EntityTypeTest;
import net.minecraft.world.level.pathfinder.Path; 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.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.HitResult;
@@ -526,7 +529,7 @@ public class EntityValue extends Value
} }
return Value.NULL; 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) -> { put("spawn_point", (e, a) -> {
if (e instanceof ServerPlayer spe) if (e instanceof ServerPlayer spe)
{ {
@@ -856,12 +859,16 @@ public class EntityValue extends Value
}); });
put("nbt", (e, a) -> { put("nbt", (e, a) -> {
CompoundTag nbttagcompound = e.saveWithoutId((new CompoundTag())); try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(e.problemPath(), CarpetScriptServer.LOG)) {
if (a == null) final TagValueOutput output = TagValueOutput.createWithContext(reporter, e.registryAccess());
{ e.saveWithoutId(output);
return new NBTSerializableValue(nbttagcompound); 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) -> { put("category", (e, a) -> {
@@ -1312,7 +1319,7 @@ public class EntityValue extends Value
} }
if (v.isNull()) if (v.isNull())
{ {
ec.restrictTo(BlockPos.ZERO, -1); ec.setHomeTo(BlockPos.ZERO, -1);
Map<String, Goal> tasks = Vanilla.Mob_getTemporaryTasks(ec); Map<String, Goal> tasks = Vanilla.Mob_getTemporaryTasks(ec);
Vanilla.Mob_getAI(ec, false).removeGoal(tasks.get("home")); Vanilla.Mob_getAI(ec, false).removeGoal(tasks.get("home"));
tasks.remove("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"); throw new InternalExpressionException("'home' requires at least one position argument, and optional distance");
} }
ec.restrictTo(pos, distance); ec.setHomeTo(pos, distance);
Map<String, Goal> tasks = Vanilla.Mob_getTemporaryTasks(ec); Map<String, Goal> tasks = Vanilla.Mob_getTemporaryTasks(ec);
if (!tasks.containsKey("home")) if (!tasks.containsKey("home"))
{ {
@@ -1675,7 +1682,9 @@ public class EntityValue extends Value
Value tagValue = NBTSerializableValue.fromValue(v); Value tagValue = NBTSerializableValue.fromValue(v);
if (tagValue instanceof NBTSerializableValue nbtsv) 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); e.setUUID(uUID);
} }
} }
@@ -1687,9 +1696,16 @@ public class EntityValue extends Value
Value tagValue = NBTSerializableValue.fromValue(v); Value tagValue = NBTSerializableValue.fromValue(v);
if (tagValue instanceof NBTSerializableValue nbtsv) 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()); 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); e.setUUID(uUID);
} }
} }
@@ -1742,10 +1758,18 @@ public class EntityValue extends Value
{ {
throw new NBTSerializableValue.IncompatibleTypeException(this); throw new NBTSerializableValue.IncompatibleTypeException(this);
} }
CompoundTag tag = new CompoundTag(); CompoundTag tag;
tag.put("Data", getEntity().saveWithoutId(new CompoundTag())); Entity entity = getEntity();
Registry<EntityType<?>> reg = getEntity().level().registryAccess().lookupOrThrow(Registries.ENTITY_TYPE); try (final ProblemReporter.ScopedCollector reporter = new ProblemReporter.ScopedCollector(entity.problemPath(), CarpetScriptServer.LOG)) {
tag.put("Name", StringTag.valueOf(reg.getKey(getEntity().getType()).toString())); final TagValueOutput output = TagValueOutput.createWithContext(reporter, entity.registryAccess());
entity.save(output);
tag = output.buildResult();
}
tag.put("Data", tag);
Registry<EntityType<?>> reg = entity.level().registryAccess().lookupOrThrow(Registries.ENTITY_TYPE);
tag.put("Name", StringTag.valueOf(reg.getKey(entity.getType()).toString()));
return tag; return tag;
} }
} }
@@ -1,9 +1,13 @@
package carpet.script.value; package carpet.script.value;
import carpet.script.exception.InternalExpressionException;
import com.mojang.serialization.DynamicOps;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.StringTag; import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
public class FormattedTextValue extends StringValue public class FormattedTextValue extends StringValue
@@ -86,7 +90,7 @@ public class FormattedTextValue extends StringValue
{ {
throw new NBTSerializableValue.IncompatibleTypeException(this); throw new NBTSerializableValue.IncompatibleTypeException(this);
} }
return StringTag.valueOf(Component.Serializer.toJson(text, regs)); return serialize(regs);
} }
@Override @Override
@@ -95,14 +99,14 @@ public class FormattedTextValue extends StringValue
return combine(this, o); 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) public static Component getTextByValue(Value value)
@@ -20,6 +20,7 @@ import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.RegistryAccess; import net.minecraft.core.RegistryAccess;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
@@ -391,7 +392,7 @@ public class ScreenValue extends Value
} }
else else
{ {
nbtList.add(itemStack.save(regs)); nbtList.add(ItemStack.CODEC.encodeStart(regs.createSerializationContext(NbtOps.INSTANCE), itemStack).getOrThrow(InternalExpressionException::new));
} }
} }
return nbtList; return nbtList;