Java Code Examples for net.minecraft.nbt.NBTTagCompound#setByteArray()

The following examples show how to use net.minecraft.nbt.NBTTagCompound#setByteArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Processor.java    From Minecoprocessors with GNU General Public License v3.0 6 votes vote down vote up
@Override
public NBTTagCompound writeToNBT() {
  NBTTagCompound c = new NBTTagCompound();
  c.setByteArray(NBT_STACK, stack);
  c.setByteArray(NBT_REGISTERS, registers);
  c.setByte(NBT_FAULTCODE, faultCode);
  c.setLong(NBT_FLAGS, packFlags());
  if (error != null) {
    c.setString(NBT_ERROR, error);
  }
  NBTTagList programTag = new NBTTagList();
  for (byte[] b : program) {
    programTag.appendTag(new NBTTagByteArray(b));
  }
  c.setTag(NBT_PROGRAM, programTag);

  NBTTagList labelTag = new NBTTagList();
  for (Label label : labels) {
    labelTag.appendTag(label.toNbt());
  }
  c.setTag(NBT_LABELS, labelTag);

  return c;
}
 
Example 2
Source File: LostLuggage.java    From qcraft-mod with Apache License 2.0 6 votes vote down vote up
private void writeToNBT( NBTTagCompound nbt )
{
    NBTTagList luggageList = new NBTTagList();
    for( Luggage luggage : m_luggage )
    {
        NBTTagCompound luggageTag = new NBTTagCompound();
        luggageTag.setLong( "timeStamp", luggage.m_timeStamp );
        if( luggage.m_origin != null )
        {
            luggageTag.setString( "originAddress", luggage.m_origin.getAddress() );
        }
        if( luggage.m_destination != null )
        {
            luggageTag.setString( "destinationAddress", luggage.m_destination.getAddress() );
        }
        luggageTag.setByteArray( "luggage", luggage.m_luggage );
        luggageList.appendTag( luggageTag );
    }
    nbt.setTag( "luggage", luggageList );
}
 
Example 3
Source File: TileGravityController.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@Override
public void readDataFromNetwork(ByteBuf in, byte packetId,
		NBTTagCompound nbt) {
	super.readDataFromNetwork(in, packetId, nbt);
	if(packetId == 3) {
		nbt.setShort("progress",  in.readShort());
		nbt.setShort("radius", in.readShort());
	}
	else if(packetId == 4) {
		byte bytes[] = new byte[6];
		for(int i = 0; i < 6; i++)
			bytes[i] = in.readByte();
		nbt.setByteArray("bytes", bytes);
	}
	else if(packetId == 5) {
		nbt.setByte("redstoneState", in.readByte());
	}
}
 
Example 4
Source File: TileRocketLoader.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void readDataFromNetwork(ByteBuf in, byte packetId,
		NBTTagCompound nbt) {
	nbt.setByte("state", in.readByte());
	nbt.setByte("inputstate", in.readByte());

	byte bytes[] = new byte[6];
	for(int i = 0; i < 6; i++)
		bytes[i] = in.readByte();
	nbt.setByteArray("bytes", bytes);
}
 
Example 5
Source File: SyncedTileEntity.java    From OpenModsLib with MIT License 5 votes vote down vote up
private NBTTagCompound serializeInitializationData(NBTTagCompound tag) {
	final PacketBuffer tmp = new PacketBuffer(Unpooled.buffer());
	try {
		getSyncMap().writeInitializationData(tmp);
	} catch (IOException e) {
		throw new RuntimeException(e);
	}
	byte[] data = new byte[tmp.readableBytes()];
	tmp.readBytes(data);
	tag.setByteArray(TAG_SYNC_INIT, data);

	return tag;
}
 
Example 6
Source File: EntityShip.java    From archimedes-ships with MIT License 5 votes vote down vote up
@Override
protected void writeEntityToNBT(NBTTagCompound compound)
{
	super.writeEntityToNBT(compound);
	ByteArrayOutputStream baos = new ByteArrayOutputStream(shipChunk.getMemoryUsage());
	DataOutputStream out = new DataOutputStream(baos);
	try
	{
		ChunkIO.writeAll(out, shipChunk);
		out.flush();
		out.close();
	} catch (IOException e)
	{
		e.printStackTrace();
	}
	compound.setByteArray("chunk", baos.toByteArray());
	compound.setByte("seatX", (byte) seatX);
	compound.setByte("seatY", (byte) seatY);
	compound.setByte("seatZ", (byte) seatZ);
	compound.setByte("front", (byte) frontDirection);
	
	if (!shipChunk.chunkTileEntityMap.isEmpty())
	{
		NBTTagList tileentities = new NBTTagList();
		for (TileEntity tileentity : shipChunk.chunkTileEntityMap.values())
		{
			NBTTagCompound comp = new NBTTagCompound();
			tileentity.writeToNBT(comp);
			tileentities.appendTag(comp);
		}
		compound.setTag("tileent", tileentities);
	}
	
	compound.setString("name", info.shipName);
	if (info.owner != null)
	{
		compound.setString("owner", info.owner);
	}
}
 
Example 7
Source File: ItemStackHandlerLockable.java    From enderutilities with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public NBTTagCompound serializeNBT()
{
    NBTTagCompound nbt = super.serializeNBT();
    nbt = NBTUtils.writeItemsToTag(nbt, this.templateStacks, "TemplateItems", false);
    nbt.setByteArray("LockedSlots", this.locked.toByteArray());
    return nbt;
}
 
Example 8
Source File: HexUpdateHandler.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void handle(HexUpdateEvent event)
{
	NBTTagCompound nbt = event.centerToUpdate.getCustomNBT();
	if(nbt.hasKey("TFC2_Data"))
	{
		NBTTagCompound data = nbt.getCompoundTag("TFC2_Data");
		if(data.hasKey("CropData"))
		{
			NBTTagCompound cropData = data.getCompoundTag("CropData");
			long lastRegenTick = cropData.getLong("lastRegenTick");
			if(lastRegenTick + Timekeeper.ticksInPeriod < Timekeeper.getInstance().getTotalTicks())
			{
				cropData.setLong("lastRegenTick", lastRegenTick + Timekeeper.ticksInPeriod);
				float nutrients = cropData.getFloat("nutrients");
				float maxNutrients = TileCrop.GetMaxNutrients(event.map);
				cropData.setFloat("nutrients", Math.min(maxNutrients, nutrients + maxNutrients/4));
			}
		}
		if(data.hasKey("hydration"))
		{
			byte[] hydrationArray = data.getByteArray("hydration");
			int waterLevel = 0;
			for(int i = 0; i < 64; i++)
			{
				hydrationArray[i] = (byte)Math.max(0, hydrationArray[i]-5);
				waterLevel += hydrationArray[i];
			}
			if(waterLevel > 0)
				data.setByteArray("hydration", hydrationArray);
			else
				data.removeTag("hydration");
		}
	}
}
 
Example 9
Source File: SyncedTileEntityBase.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public SPacketUpdateTileEntity getUpdatePacket() {
    NBTTagCompound updateTag = new NBTTagCompound();
    NBTTagList tagList = new NBTTagList();
    for (UpdateEntry updateEntry : updateEntries) {
        NBTTagCompound entryTag = new NBTTagCompound();
        entryTag.setInteger("i", updateEntry.discriminator);
        entryTag.setByteArray("d", updateEntry.updateData);
        tagList.appendTag(entryTag);
    }
    this.updateEntries.clear();
    updateTag.setTag("d", tagList);
    return new SPacketUpdateTileEntity(getPos(), 0, updateTag);
}
 
Example 10
Source File: TileRocketFluidLoader.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void readDataFromNetwork(ByteBuf in, byte packetId,
		NBTTagCompound nbt) {
	nbt.setByte("state", in.readByte());
	nbt.setByte("inputstate", in.readByte());

	byte bytes[] = new byte[6];
	for(int i = 0; i < 6; i++)
		bytes[i] = in.readByte();
	nbt.setByteArray("bytes", bytes);
}
 
Example 11
Source File: QueryableShipData.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    long start = System.currentTimeMillis();

    Kryo kryo = ValkyrienSkiesMod.INSTANCE.getKryo();
    Output output = new Output(1024, -1);
    kryo.writeObject(output, allShips);
    compound.setByteArray(NBT_STORAGE_KEY, output.getBuffer());

    System.out.println("Price of write: " + (System.currentTimeMillis() - start) + "ms");

    return compound;
}
 
Example 12
Source File: SpongeSchematic.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void writeBlocksToTag(NBTTagCompound tag)
{
    NBTTagCompound paletteTag = this.writePaletteToTag(this.blockContainer.getPalette().getMapping());
    byte[] blockData = ((LitematicaBlockStateContainerFull) this.blockContainer).getBackingArrayAsByteArray();

    tag.setTag("Palette", paletteTag);
    tag.setByteArray("BlockData", blockData);
}
 
Example 13
Source File: SyncedTileEntityBase.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public NBTTagCompound getUpdateTag() {
    NBTTagCompound updateTag = super.getUpdateTag();
    updateTag.setInteger("x", getPos().getX());
    updateTag.setInteger("y", getPos().getY());
    updateTag.setInteger("z", getPos().getZ());
    ByteBuf backedBuffer = Unpooled.buffer();
    writeInitialSyncData(new PacketBuffer(backedBuffer));
    byte[] updateData = Arrays.copyOfRange(backedBuffer.array(), 0, backedBuffer.writerIndex());
    updateTag.setByteArray("d", updateData);
    return updateTag;
}
 
Example 14
Source File: TileEntityQuantumComputer.java    From qcraft-mod with Apache License 2.0 4 votes vote down vote up
public static void teleportPlayerRemote( EntityPlayer player, String remoteServerAddress, String remotePortalID, boolean takeItems )
{
    // Log the trip
    QCraft.log( "Sending player " + player.getDisplayName() + " to server \"" + remoteServerAddress + "\"" );

    NBTTagCompound luggage = new NBTTagCompound();
    if( takeItems )
    {
        // Remove and encode the items from the players inventory we want them to take with them
        NBTTagList items = new NBTTagList();
        InventoryPlayer playerInventory = player.inventory;
        for( int i = 0; i < playerInventory.getSizeInventory(); ++i )
        {
            ItemStack stack = playerInventory.getStackInSlot( i );
            if( stack != null && stack.stackSize > 0 )
            {
                // Ignore entangled items
                if( stack.getItem() == Item.getItemFromBlock( QCraft.Blocks.quantumComputer ) && ItemQuantumComputer.getEntanglementFrequency( stack ) >= 0 )
                {
                    continue;
                }
                if( stack.getItem() == Item.getItemFromBlock( QCraft.Blocks.qBlock ) && ItemQBlock.getEntanglementFrequency( stack ) >= 0 )
                {
                    continue;
                }

                // Store items
                NBTTagCompound itemTag = new NBTTagCompound();
                if (stack.getItem() == QCraft.Items.missingItem) {
                    itemTag = stack.stackTagCompound;
                } else {
                    GameRegistry.UniqueIdentifier uniqueId = GameRegistry.findUniqueIdentifierFor(stack.getItem());
                    String itemName = uniqueId.modId + ":" + uniqueId.name;
                    itemTag.setString("Name", itemName);
                    stack.writeToNBT( itemTag );
                }
                items.appendTag( itemTag );

                // Remove items
                playerInventory.setInventorySlotContents( i, null );
            }
        }

        if( items.tagCount() > 0 )
        {
            QCraft.log( "Removed " + items.tagCount() + " items from " + player.getDisplayName() + "'s inventory." );
            playerInventory.markDirty();
            luggage.setTag( "items", items );
        }
    }

    // Set the destination portal ID
    if( remotePortalID != null )
    {
        luggage.setString( "destinationPortal", remotePortalID );
    }

    try
    {
        // Cryptographically sign the luggage
        luggage.setString( "uuid", UUID.randomUUID().toString() );
        byte[] luggageData = CompressedStreamTools.compress( luggage );
        byte[] luggageSignature = EncryptionRegistry.Instance.signData( luggageData );
        NBTTagCompound signedLuggage = new NBTTagCompound();
        signedLuggage.setByteArray( "key", EncryptionRegistry.Instance.encodePublicKey( EncryptionRegistry.Instance.getLocalKeyPair().getPublic() ) );
        signedLuggage.setByteArray( "luggage", luggageData );
        signedLuggage.setByteArray( "signature", luggageSignature );

        // Send the player to the remote server with the luggage
        byte[] signedLuggageData = CompressedStreamTools.compress( signedLuggage );
        QCraft.requestGoToServer( player, remoteServerAddress, signedLuggageData );
    }
    catch( IOException e )
    {
        throw new RuntimeException( "Error encoding inventory" );
    }
    finally
    {
        // Prevent the player from being warped twice
        player.timeUntilPortal = 200;
    }
}
 
Example 15
Source File: ShipTransform.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
public void writeToNBT(NBTTagCompound compound, String name) {
    compound.setByteArray(name, ValkyrienNBTUtils.toByteArray(subspaceToGlobal));
}
 
Example 16
Source File: BitSet.java    From OpenModsLib with MIT License 4 votes vote down vote up
public void writeToNBT(NBTTagCompound tag) {
	tag.setByteArray("Bits", bits);
}
 
Example 17
Source File: TypeRW.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToNBT(byte[] o, NBTTagCompound tag, String name) {
	tag.setByteArray(name, o);
}
 
Example 18
Source File: SyncableByteArray.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToNBT(NBTTagCompound nbt, String name) {
	nbt.setByteArray(name, value);
}