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.core.BlockPos;
|
||||||
import net.minecraft.nbt.NbtOps;
|
import net.minecraft.nbt.NbtOps;
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.resources.RegistryOps;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
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;
|
||||||
|
@ -22,9 +23,9 @@ public abstract class MountedFluidStorage implements IFluidHandler {
|
||||||
);
|
);
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static final StreamCodec<FriendlyByteBuf, MountedFluidStorage> STREAM_CODEC = StreamCodec.of(
|
public static final StreamCodec<RegistryFriendlyByteBuf, MountedFluidStorage> STREAM_CODEC = StreamCodec.of(
|
||||||
(b, t) -> b.writeWithCodec(NbtOps.INSTANCE, CODEC, t),
|
(b, t) -> b.writeWithCodec(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC, t),
|
||||||
b -> b.readWithCodecTrusted(NbtOps.INSTANCE, CODEC)
|
b -> b.readWithCodecTrusted(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC)
|
||||||
);
|
);
|
||||||
|
|
||||||
public final MountedFluidStorageType<? extends MountedFluidStorage> type;
|
public final MountedFluidStorageType<? extends MountedFluidStorage> type;
|
||||||
|
|
|
@ -5,10 +5,6 @@ import java.util.OptionalInt;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
import net.minecraft.nbt.NbtOps;
|
|
||||||
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.mojang.serialization.Codec;
|
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.content.contraptions.behaviour.MovementContext;
|
||||||
import com.simibubi.create.foundation.utility.CreateLang;
|
import com.simibubi.create.foundation.utility.CreateLang;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import net.minecraft.core.BlockPos;
|
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.Component;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.network.codec.StreamCodec;
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.resources.RegistryOps;
|
||||||
import net.minecraft.server.level.ServerLevel;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.sounds.SoundEvents;
|
import net.minecraft.sounds.SoundEvents;
|
||||||
|
@ -44,9 +42,9 @@ public abstract class MountedItemStorage implements IItemHandlerModifiable {
|
||||||
);
|
);
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static final StreamCodec<FriendlyByteBuf, MountedItemStorage> STREAM_CODEC = StreamCodec.of(
|
public static final StreamCodec<RegistryFriendlyByteBuf, MountedItemStorage> STREAM_CODEC = StreamCodec.of(
|
||||||
(b, t) -> b.writeWithCodec(NbtOps.INSTANCE, CODEC, t),
|
(b, t) -> b.writeWithCodec(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC, t),
|
||||||
b -> b.readWithCodecTrusted(NbtOps.INSTANCE, CODEC)
|
b -> b.readWithCodecTrusted(RegistryOps.create(NbtOps.INSTANCE, b.registryAccess()), CODEC)
|
||||||
);
|
);
|
||||||
|
|
||||||
public final MountedItemStorageType<? extends MountedItemStorage> type;
|
public final MountedItemStorageType<? extends MountedItemStorage> type;
|
||||||
|
|
|
@ -9,12 +9,13 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
|
import net.createmod.catnip.codecs.CatnipCodecUtils;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.collect.Sets.SetView;
|
import com.google.common.collect.Sets.SetView;
|
||||||
import com.mojang.datafixers.util.Pair;
|
|
||||||
import com.simibubi.create.Create;
|
import com.simibubi.create.Create;
|
||||||
import com.simibubi.create.api.contraption.storage.MountedStorageTypeRegistry;
|
import com.simibubi.create.api.contraption.storage.MountedStorageTypeRegistry;
|
||||||
import com.simibubi.create.api.contraption.storage.SyncedMountedStorage;
|
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.core.HolderLookup;
|
||||||
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.NbtUtils;
|
import net.minecraft.nbt.NbtUtils;
|
||||||
import net.minecraft.nbt.Tag;
|
import net.minecraft.nbt.Tag;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
@ -252,18 +252,14 @@ public class MountedStorageManager {
|
||||||
NBTHelper.iterateCompoundList(nbt.getList("items", Tag.TAG_COMPOUND), tag -> {
|
NBTHelper.iterateCompoundList(nbt.getList("items", Tag.TAG_COMPOUND), tag -> {
|
||||||
BlockPos pos = NBTHelper.readBlockPos(tag, "pos");
|
BlockPos pos = NBTHelper.readBlockPos(tag, "pos");
|
||||||
CompoundTag data = tag.getCompound("storage");
|
CompoundTag data = tag.getCompound("storage");
|
||||||
MountedItemStorage.CODEC.decode(NbtOps.INSTANCE, data)
|
CatnipCodecUtils.decode(MountedItemStorage.CODEC, registries, data)
|
||||||
.result()
|
|
||||||
.map(Pair::getFirst)
|
|
||||||
.ifPresent(storage -> this.addStorage(storage, pos));
|
.ifPresent(storage -> this.addStorage(storage, pos));
|
||||||
});
|
});
|
||||||
|
|
||||||
NBTHelper.iterateCompoundList(nbt.getList("fluids", Tag.TAG_COMPOUND), tag -> {
|
NBTHelper.iterateCompoundList(nbt.getList("fluids", Tag.TAG_COMPOUND), tag -> {
|
||||||
BlockPos pos = NBTHelper.readBlockPos(tag, "pos");
|
BlockPos pos = NBTHelper.readBlockPos(tag, "pos");
|
||||||
CompoundTag data = tag.getCompound("storage");
|
CompoundTag data = tag.getCompound("storage");
|
||||||
MountedFluidStorage.CODEC.decode(NbtOps.INSTANCE, data)
|
CatnipCodecUtils.decode(MountedFluidStorage.CODEC, registries, data)
|
||||||
.result()
|
|
||||||
.map(Pair::getFirst)
|
|
||||||
.ifPresent(storage -> this.addStorage(storage, pos));
|
.ifPresent(storage -> this.addStorage(storage, pos));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -303,7 +299,7 @@ public class MountedStorageManager {
|
||||||
ListTag items = new ListTag();
|
ListTag items = new ListTag();
|
||||||
this.getAllItemStorages().forEach((pos, storage) -> {
|
this.getAllItemStorages().forEach((pos, storage) -> {
|
||||||
if (!clientPacket || storage instanceof SyncedMountedStorage) {
|
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();
|
CompoundTag tag = new CompoundTag();
|
||||||
tag.put("pos", NbtUtils.writeBlockPos(pos));
|
tag.put("pos", NbtUtils.writeBlockPos(pos));
|
||||||
tag.put("storage", encoded);
|
tag.put("storage", encoded);
|
||||||
|
@ -319,7 +315,7 @@ public class MountedStorageManager {
|
||||||
ListTag fluids = new ListTag();
|
ListTag fluids = new ListTag();
|
||||||
this.getFluids().storages.forEach((pos, storage) -> {
|
this.getFluids().storages.forEach((pos, storage) -> {
|
||||||
if (!clientPacket || storage instanceof SyncedMountedStorage) {
|
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();
|
CompoundTag tag = new CompoundTag();
|
||||||
tag.put("pos", NbtUtils.writeBlockPos(pos));
|
tag.put("pos", NbtUtils.writeBlockPos(pos));
|
||||||
tag.put("storage", encoded);
|
tag.put("storage", encoded);
|
||||||
|
|
|
@ -131,7 +131,7 @@ public class InventorySummary {
|
||||||
public List<BigItemStack> getStacks() {
|
public List<BigItemStack> getStacks() {
|
||||||
if (stacksByCount == null) {
|
if (stacksByCount == null) {
|
||||||
List<BigItemStack> stacks = new ArrayList<>();
|
List<BigItemStack> stacks = new ArrayList<>();
|
||||||
items.forEach((i, list) -> list.forEach(stacks::add));
|
items.forEach((i, list) -> stacks.addAll(list));
|
||||||
return stacks;
|
return stacks;
|
||||||
}
|
}
|
||||||
return stacksByCount;
|
return stacksByCount;
|
||||||
|
@ -140,8 +140,8 @@ public class InventorySummary {
|
||||||
public List<BigItemStack> getStacksByCount() {
|
public List<BigItemStack> getStacksByCount() {
|
||||||
if (stacksByCount == null) {
|
if (stacksByCount == null) {
|
||||||
stacksByCount = new ArrayList<>();
|
stacksByCount = new ArrayList<>();
|
||||||
items.forEach((i, list) -> list.forEach(stacksByCount::add));
|
items.forEach((i, list) -> stacksByCount.addAll(list));
|
||||||
Collections.sort(stacksByCount, BigItemStack.comparator());
|
stacksByCount.sort(BigItemStack.comparator());
|
||||||
}
|
}
|
||||||
return stacksByCount;
|
return stacksByCount;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue