Search in sources :

Example 1 with CompoundTag

use of net.minecraft.util.io.CompoundTag in project StationAPI by ModificationStation.

the class LevelRegistryRemapper method saveProperties.

@EventListener(priority = ListenerPriority.HIGH)
private static void saveProperties(LevelPropertiesEvent.Save event) {
    CompoundTag registriesTag = new CompoundTag();
    LevelSerialRegistry.saveAll(registriesTag);
    event.tag.put(of(MODID, "level_serial_registries").toString(), registriesTag);
}
Also used : CompoundTag(net.minecraft.util.io.CompoundTag) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 2 with CompoundTag

use of net.minecraft.util.io.CompoundTag in project StationAPI by ModificationStation.

the class MixinLevelManager method saveBlockStates.

@Inject(method = "method_1480(Lnet/minecraft/level/chunk/Chunk;Lnet/minecraft/level/Level;Lnet/minecraft/util/io/CompoundTag;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/io/CompoundTag;put(Ljava/lang/String;[B)V", ordinal = 0, shift = At.Shift.AFTER))
private static void saveBlockStates(Chunk chunk, Level level, CompoundTag tag, CallbackInfo ci) {
    ChunkSection[] sections = ((ChunkSectionsAccessor) chunk).getSections();
    ListTag listTag = new ListTag();
    for (int i = 0; i < sections.length; ++i) {
        ChunkSection section = sections[i];
        if (section != ChunkSection.EMPTY_SECTION) {
            CompoundTag compoundTag7 = new CompoundTag();
            compoundTag7.put("Y", (byte) (i & 255));
            section.getContainer().write(compoundTag7, "Palette", "BlockStates");
            listTag.add(compoundTag7);
        }
    }
    tag.put(SECTIONS_TAG, listTag);
}
Also used : ChunkSectionsAccessor(net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor) ChunkSection(net.modificationstation.stationapi.impl.level.chunk.ChunkSection) ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with CompoundTag

use of net.minecraft.util.io.CompoundTag in project StationAPI by ModificationStation.

the class MixinLevelManager method loadBlockState.

@Inject(method = "method_1479(Lnet/minecraft/level/Level;Lnet/minecraft/util/io/CompoundTag;)Lnet/minecraft/level/chunk/Chunk;", at = @At(value = "FIELD", target = "Lnet/minecraft/level/chunk/Chunk;tiles:[B", opcode = Opcodes.PUTFIELD, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private static void loadBlockState(Level arg, CompoundTag arg1, CallbackInfoReturnable<Chunk> cir, int var2, int var3, Chunk var4) {
    ChunkSection[] sections = ((ChunkSectionsAccessor) var4).getSections();
    if (arg1.containsKey(SECTIONS_TAG)) {
        ListTag listTag = arg1.getListTag(SECTIONS_TAG);
        for (int i = 0; i < listTag.size(); i++) {
            CompoundTag section = (CompoundTag) listTag.get(i);
            int k = section.getByte("Y");
            if (section.containsKey("Palette") && section.containsKey("BlockStates")) {
                ChunkSection chunkSection = new ChunkSection(k << 4);
                chunkSection.getContainer().read(section.getListTag("Palette"), ((LongArrayCompound) section).getLongArray("BlockStates"));
                chunkSection.calculateCounts();
                if (!chunkSection.isEmpty()) {
                    sections[k] = chunkSection;
                }
            // poiStorage.initForPalette(pos, chunkSection);
            }
        }
    }
}
Also used : ChunkSectionsAccessor(net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor) ChunkSection(net.modificationstation.stationapi.impl.level.chunk.ChunkSection) ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with CompoundTag

use of net.minecraft.util.io.CompoundTag in project StationAPI by ModificationStation.

the class BlockStateHelper method toBlockState.

public static BlockState toBlockState(CompoundTag tag) {
    if (tag.containsKey("Name")) {
        @NotNull Optional<BlockBase> block = BlockRegistry.INSTANCE.get(Identifier.of(tag.getString("Name")));
        if (block.isPresent()) {
            BlockStateHolder stateHolder = (BlockStateHolder) block.get();
            BlockState blockState = stateHolder.getDefaultState();
            if (tag.containsKey("Properties")) {
                CompoundTag compoundTag = tag.getCompoundTag("Properties");
                StateManager<BlockBase, BlockState> stateManager = stateHolder.getStateManager();
                for (String string : ((CompoundTagAccessor) compoundTag).stationapi$getData().keySet()) {
                    Property<?> property = stateManager.getProperty(string);
                    if (property != null) {
                        blockState = withProperty(blockState, property, string, compoundTag, tag);
                    }
                }
            }
            return blockState;
        }
    }
    return States.AIR.get();
}
Also used : BlockState(net.modificationstation.stationapi.api.block.BlockState) BlockBase(net.minecraft.block.BlockBase) BlockStateHolder(net.modificationstation.stationapi.api.block.BlockStateHolder) NotNull(org.jetbrains.annotations.NotNull) CompoundTag(net.minecraft.util.io.CompoundTag)

Example 5 with CompoundTag

use of net.minecraft.util.io.CompoundTag in project StationAPI by ModificationStation.

the class BlockStateHelper method fromBlockState.

public static CompoundTag fromBlockState(BlockState state) {
    CompoundTag compoundTag = new CompoundTag();
    compoundTag.put("Name", BlockRegistry.INSTANCE.getIdentifier(state.getBlock()).toString());
    ImmutableMap<Property<?>, Comparable<?>> immutableMap = state.getEntries();
    if (!immutableMap.isEmpty()) {
        CompoundTag compoundTag2 = new CompoundTag();
        for (Map.Entry<Property<?>, Comparable<?>> propertyComparableEntry : immutableMap.entrySet()) {
            Property<?> property = propertyComparableEntry.getKey();
            compoundTag2.put(property.getName(), nameValue(property, propertyComparableEntry.getValue()));
        }
        compoundTag.put("Properties", compoundTag2);
    }
    return compoundTag;
}
Also used : Property(net.modificationstation.stationapi.api.state.property.Property) ImmutableMap(com.google.common.collect.ImmutableMap) CompoundTag(net.minecraft.util.io.CompoundTag)

Aggregations

CompoundTag (net.minecraft.util.io.CompoundTag)9 ListTag (net.minecraft.util.io.ListTag)4 EventListener (net.mine_diver.unsafeevents.listener.EventListener)2 ChunkSection (net.modificationstation.stationapi.impl.level.chunk.ChunkSection)2 ChunkSectionsAccessor (net.modificationstation.stationapi.impl.level.chunk.ChunkSectionsAccessor)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 BlockBase (net.minecraft.block.BlockBase)1 ItemInstance (net.minecraft.item.ItemInstance)1 BlockState (net.modificationstation.stationapi.api.block.BlockState)1 BlockStateHolder (net.modificationstation.stationapi.api.block.BlockStateHolder)1 ModdedPacketHandler (net.modificationstation.stationapi.api.network.ModdedPacketHandler)1 Message (net.modificationstation.stationapi.api.packet.Message)1 Property (net.modificationstation.stationapi.api.state.property.Property)1 NotNull (org.jetbrains.annotations.NotNull)1