Port new changes

This commit is contained in:
simibubi 2025-02-11 15:08:22 +01:00
parent ee4414f149
commit 6748c71ef1

View file

@ -5,8 +5,8 @@ import com.simibubi.create.foundation.mixin.accessor.NbtAccounterAccessor;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtAccounter; import net.minecraft.nbt.NbtAccounter;
import net.minecraft.nbt.Tag;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
public class ContraptionPickupLimiting { public class ContraptionPickupLimiting {
@ -36,17 +36,17 @@ public class ContraptionPickupLimiting {
/** /**
* @return true if the given NBT is too large for a contraption to be picked up with a wrench. * @return true if the given NBT is too large for a contraption to be picked up with a wrench.
*/ */
public static boolean isTooLargeForPickup(CompoundTag data) { public static boolean isTooLargeForPickup(Tag data) {
return nbtSize(data) > LIMIT; return nbtSize(data) > LIMIT;
} }
/** /**
* @return the size of the given NBT when read by the client according to {@link NbtAccounter} * @return the size of the given NBT when read by the client according to {@link NbtAccounter}
*/ */
private static long nbtSize(CompoundTag data) { private static long nbtSize(Tag data) {
FriendlyByteBuf test = new FriendlyByteBuf(Unpooled.buffer()); FriendlyByteBuf test = new FriendlyByteBuf(Unpooled.buffer());
test.writeNbt(data); test.writeNbt(data);
NbtAccounter sizeTracker = new NbtAccounter(Long.MAX_VALUE); NbtAccounter sizeTracker = NbtAccounter.unlimitedHeap();
test.readNbt(sizeTracker); test.readNbt(sizeTracker);
long size = ((NbtAccounterAccessor) sizeTracker).create$getUsage(); long size = ((NbtAccounterAccessor) sizeTracker).create$getUsage();
test.release(); test.release();