Search in sources :

Example 6 with CompoundTag

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

the class TileEntityFreezer method readIdentifyingData.

@Override
public void readIdentifyingData(CompoundTag nbttagcompound) {
    super.readIdentifyingData(nbttagcompound);
    ListTag nbttaglist = nbttagcompound.getListTag("Items");
    frozenItemStacks = new ItemInstance[getInventorySize()];
    for (int i = 0; i < nbttaglist.size(); i++) {
        CompoundTag nbttagcompound1 = (CompoundTag) nbttaglist.get(i);
        byte byte0 = nbttagcompound1.getByte("Slot");
        if (byte0 >= 0 && byte0 < frozenItemStacks.length) {
            frozenItemStacks[byte0] = new ItemInstance(nbttagcompound1);
        }
    }
    frozenProgress = nbttagcompound.getShort("BurnTime");
    frozenTimeForItem = nbttagcompound.getShort("CookTime");
}
Also used : ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag) ItemInstance(net.minecraft.item.ItemInstance)

Example 7 with CompoundTag

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

the class TileEntityFreezer method writeIdentifyingData.

@Override
public void writeIdentifyingData(CompoundTag nbttagcompound) {
    super.writeIdentifyingData(nbttagcompound);
    nbttagcompound.put("BurnTime", (short) frozenProgress);
    nbttagcompound.put("CookTime", (short) frozenTimeForItem);
    ListTag nbttaglist = new ListTag();
    for (int i = 0; i < frozenItemStacks.length; i++) {
        if (frozenItemStacks[i] != null) {
            CompoundTag nbttagcompound1 = new CompoundTag();
            nbttagcompound1.put("Slot", (byte) i);
            frozenItemStacks[i].toTag(nbttagcompound1);
            nbttaglist.add(nbttagcompound1);
        }
    }
    nbttagcompound.put("Items", nbttaglist);
}
Also used : ListTag(net.minecraft.util.io.ListTag) CompoundTag(net.minecraft.util.io.CompoundTag)

Example 8 with CompoundTag

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

the class NBTItem method useOnTile.

@Override
public boolean useOnTile(ItemInstance item, PlayerBase player, Level level, int x, int y, int z, int facing) {
    CompoundTag nbt = StationNBT.cast(item).getStationNBT();
    if (!nbt.containsKey(of(MODID, "rand_num").toString()))
        nbt.put(of(MODID, "rand_num").toString(), new Random().nextInt(3));
    player.sendMessage("Woah: " + nbt.getInt(of(MODID, "rand_num").toString()));
    return true;
}
Also used : CompoundTag(net.minecraft.util.io.CompoundTag)

Example 9 with CompoundTag

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

the class ServerRegistrySender method sendLevelRegistry.

@EventListener(priority = ListenerPriority.HIGH)
private static void sendLevelRegistry(PlayerPacketHandlerSetEvent event) {
    if (((ModdedPacketHandler) event.player.packetHandler).isModded()) {
        LOGGER.info("Sending level registries to \"" + event.player.name + "\"...");
        CompoundTag registries = new CompoundTag();
        LevelSerialRegistry.saveAll(registries);
        ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
        NBTIO.writeGzipped(registries, byteOutputStream);
        Message message = new Message(of(MODID, "server_registry_sync"));
        message.bytes = byteOutputStream.toByteArray();
        PacketHelper.sendTo(event.player, message);
    }
}
Also used : Message(net.modificationstation.stationapi.api.packet.Message) ModdedPacketHandler(net.modificationstation.stationapi.api.network.ModdedPacketHandler) CompoundTag(net.minecraft.util.io.CompoundTag) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

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