Search in sources :

Example 1 with RegistryKey

use of net.minecraft.util.registry.RegistryKey in project EtherealInventories by EnnuiL.

the class EtherinvStorageComponent method readFromNbt.

@Override
public void readFromNbt(NbtCompound nbt) {
    map.clear();
    if (nbt.contains("EtherinvStorage", NbtCompound.LIST_TYPE)) {
        NbtList nbtList = nbt.getList("EtherinvStorage", NbtCompound.COMPOUND_TYPE);
        for (int i = 0; i < nbtList.size(); i++) {
            NbtCompound compound = nbtList.getCompound(i);
            if (compound.containsUuid("UUID") && compound.contains("BlockPos", NbtCompound.INT_ARRAY_TYPE) && compound.contains("Dimension", NbtCompound.STRING_TYPE) && compound.contains("IsLoaded", NbtCompound.BYTE_TYPE)) {
                int[] blockPosList = compound.getIntArray("BlockPos");
                BlockPos blockPos = new BlockPos(blockPosList[0], MathHelper.clamp(blockPosList[1], -2.0E7, 2.0E7), blockPosList[2]);
                Optional<RegistryKey<World>> optionalDimension = World.CODEC.parse(NbtOps.INSTANCE, compound.get("Dimension")).result();
                RegistryKey<World> dimension = null;
                if (optionalDimension.isPresent()) {
                    dimension = optionalDimension.get();
                }
                Optional<UUID> owner = Optional.empty();
                if (compound.containsUuid("Owner")) {
                    owner = Optional.of(compound.getUuid("Owner"));
                }
                boolean loaded = compound.getBoolean("IsLoaded");
                map.put(compound.getUuid("UUID"), new EtherinvStorage(blockPos, dimension, owner, loaded));
            }
        }
    }
// World.CODEC.parse(NbtOps.INSTANCE, nbt.get("LodestoneDimension")).result();
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) World(net.minecraft.world.World) NbtList(net.minecraft.nbt.NbtList) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) RegistryKey(net.minecraft.util.registry.RegistryKey)

Aggregations

UUID (java.util.UUID)1 NbtCompound (net.minecraft.nbt.NbtCompound)1 NbtList (net.minecraft.nbt.NbtList)1 BlockPos (net.minecraft.util.math.BlockPos)1 RegistryKey (net.minecraft.util.registry.RegistryKey)1 World (net.minecraft.world.World)1