mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-04 06:44:40 +01:00
Registry Ops 6
- Fix mounted storages not being (de)serialized with RegistryOps
This commit is contained in:
parent
e465f2ad81
commit
2c503525a6
4 changed files with 20 additions and 25 deletions
|
@ -8,8 +8,9 @@ import com.mojang.serialization.Codec;
|
|||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
@ -22,9 +23,9 @@ public abstract class MountedFluidStorage implements IFluidHandler {
|
|||
);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static final StreamCodec<FriendlyByteBuf, MountedFluidStorage> STREAM_CODEC = StreamCodec.of(
|
||||
(b, t) -> b.writeWithCodec(NbtOps.INSTANCE, CODEC, t),
|
||||
b -> b.readWithCodecTrusted(NbtOps.INSTANCE, CODEC)
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, MountedFluidStorage> STREAM_CODEC = StreamCodec.of(
|
||||
(b, t) -> b.writeWithCodec(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC, t),
|
||||
b -> b.readWithCodecTrusted(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC)
|
||||
);
|
||||
|
||||
public final MountedFluidStorageType<? extends MountedFluidStorage> type;
|
||||
|
|
|
@ -5,10 +5,6 @@ import java.util.OptionalInt;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
|
@ -19,11 +15,13 @@ import com.simibubi.create.content.contraptions.behaviour.MovementBehaviour;
|
|||
import com.simibubi.create.content.contraptions.behaviour.MovementContext;
|
||||
import com.simibubi.create.foundation.utility.CreateLang;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.codec.StreamCodec;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
|
@ -44,9 +42,9 @@ public abstract class MountedItemStorage implements IItemHandlerModifiable {
|
|||
);
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static final StreamCodec<FriendlyByteBuf, MountedItemStorage> STREAM_CODEC = StreamCodec.of(
|
||||
(b, t) -> b.writeWithCodec(NbtOps.INSTANCE, CODEC, t),
|
||||
b -> b.readWithCodecTrusted(NbtOps.INSTANCE, CODEC)
|
||||
public static final StreamCodec<RegistryFriendlyByteBuf, MountedItemStorage> STREAM_CODEC = StreamCodec.of(
|
||||
(b, t) -> b.writeWithCodec(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC, t),
|
||||
b -> b.readWithCodecTrusted(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC)
|
||||
);
|
||||
|
||||
public final MountedItemStorageType<? extends MountedItemStorage> type;
|
||||
|
|
|
@ -9,12 +9,13 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import net.createmod.catnip.codecs.CatnipCodecUtils;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.collect.Sets.SetView;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.simibubi.create.Create;
|
||||
import com.simibubi.create.api.contraption.storage.MountedStorageTypeRegistry;
|
||||
import com.simibubi.create.api.contraption.storage.SyncedMountedStorage;
|
||||
|
@ -38,7 +39,6 @@ import net.minecraft.core.BlockPos;
|
|||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
@ -252,18 +252,14 @@ public class MountedStorageManager {
|
|||
NBTHelper.iterateCompoundList(nbt.getList("items", Tag.TAG_COMPOUND), tag -> {
|
||||
BlockPos pos = NBTHelper.readBlockPos(tag, "pos");
|
||||
CompoundTag data = tag.getCompound("storage");
|
||||
MountedItemStorage.CODEC.decode(NbtOps.INSTANCE, data)
|
||||
.result()
|
||||
.map(Pair::getFirst)
|
||||
CatnipCodecUtils.decode(MountedItemStorage.CODEC, registries, data)
|
||||
.ifPresent(storage -> this.addStorage(storage, pos));
|
||||
});
|
||||
|
||||
NBTHelper.iterateCompoundList(nbt.getList("fluids", Tag.TAG_COMPOUND), tag -> {
|
||||
BlockPos pos = NBTHelper.readBlockPos(tag, "pos");
|
||||
CompoundTag data = tag.getCompound("storage");
|
||||
MountedFluidStorage.CODEC.decode(NbtOps.INSTANCE, data)
|
||||
.result()
|
||||
.map(Pair::getFirst)
|
||||
CatnipCodecUtils.decode(MountedFluidStorage.CODEC, registries, data)
|
||||
.ifPresent(storage -> this.addStorage(storage, pos));
|
||||
});
|
||||
|
||||
|
@ -303,7 +299,7 @@ public class MountedStorageManager {
|
|||
ListTag items = new ListTag();
|
||||
this.getAllItemStorages().forEach((pos, storage) -> {
|
||||
if (!clientPacket || storage instanceof SyncedMountedStorage) {
|
||||
MountedItemStorage.CODEC.encodeStart(NbtOps.INSTANCE, storage).result().ifPresent(encoded -> {
|
||||
CatnipCodecUtils.encode(MountedItemStorage.CODEC, registries, storage).ifPresent(encoded -> {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("pos", NbtUtils.writeBlockPos(pos));
|
||||
tag.put("storage", encoded);
|
||||
|
@ -319,7 +315,7 @@ public class MountedStorageManager {
|
|||
ListTag fluids = new ListTag();
|
||||
this.getFluids().storages.forEach((pos, storage) -> {
|
||||
if (!clientPacket || storage instanceof SyncedMountedStorage) {
|
||||
MountedFluidStorage.CODEC.encodeStart(NbtOps.INSTANCE, storage).result().ifPresent(encoded -> {
|
||||
CatnipCodecUtils.encode(MountedFluidStorage.CODEC, registries, storage).ifPresent(encoded -> {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put("pos", NbtUtils.writeBlockPos(pos));
|
||||
tag.put("storage", encoded);
|
||||
|
|
|
@ -131,7 +131,7 @@ public class InventorySummary {
|
|||
public List<BigItemStack> getStacks() {
|
||||
if (stacksByCount == null) {
|
||||
List<BigItemStack> stacks = new ArrayList<>();
|
||||
items.forEach((i, list) -> list.forEach(stacks::add));
|
||||
items.forEach((i, list) -> stacks.addAll(list));
|
||||
return stacks;
|
||||
}
|
||||
return stacksByCount;
|
||||
|
@ -140,8 +140,8 @@ public class InventorySummary {
|
|||
public List<BigItemStack> getStacksByCount() {
|
||||
if (stacksByCount == null) {
|
||||
stacksByCount = new ArrayList<>();
|
||||
items.forEach((i, list) -> list.forEach(stacksByCount::add));
|
||||
Collections.sort(stacksByCount, BigItemStack.comparator());
|
||||
items.forEach((i, list) -> stacksByCount.addAll(list));
|
||||
stacksByCount.sort(BigItemStack.comparator());
|
||||
}
|
||||
return stacksByCount;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue