Java Code Examples for net.minecraft.network.PacketBuffer#writeCompoundTag()

The following examples show how to use net.minecraft.network.PacketBuffer#writeCompoundTag() . 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: LongItemStack.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void writeItemStack(PacketBuffer packetBuffer) {
    if (itemStack.isEmpty()) {
        packetBuffer.writeShort(-1);
    } else {
        packetBuffer.writeShort(Item.getIdFromItem(itemStack.getItem()));
        packetBuffer.writeVarInt(itemStack.getCount());
        packetBuffer.writeShort(itemStack.getMetadata());
        NBTTagCompound nbttagcompound = null;

        if (itemStack.getItem().isDamageable() ||
            itemStack.getItem().getShareTag()) {
            nbttagcompound = itemStack.getItem().getNBTShareTag(itemStack);
        }
        packetBuffer.writeCompoundTag(nbttagcompound);
    }
}
 
Example 2
Source File: PacketDurabilitySync.java    From MiningGadgets with MIT License 5 votes vote down vote up
public static void encode(PacketDurabilitySync msg, PacketBuffer buffer) {
    List<Tuple<BlockPos, Integer>> thisList = msg.updateList;
    CompoundNBT tag = new CompoundNBT();
    ListNBT nbtList = new ListNBT();
    for (int i = 0; i < thisList.size(); i++) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.put("pos", NBTUtil.writeBlockPos(thisList.get(i).getA()));
        nbt.putInt("dur", thisList.get(i).getB());
        nbtList.add(i, nbt);
    }
    tag.put("list", nbtList);
    buffer.writeCompoundTag(tag);
}
 
Example 3
Source File: ByteBufUtils.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void writeFluidStack(PacketBuffer buf, @Nullable FluidStack fluidStack) {
    buf.writeBoolean(fluidStack != null);
    if (fluidStack != null) {
        NBTTagCompound tagCompound = new NBTTagCompound();
        fluidStack.writeToNBT(tagCompound);
        buf.writeCompoundTag(tagCompound);
    }
}
 
Example 4
Source File: PacketAtmSync.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = new NBTTagCompound();
	
	nbt.setString("type", type);
	nbt.setShort("pressure", (short)pressure);
	PacketBuffer packetBuffer = new PacketBuffer(out);
	
	packetBuffer.writeCompoundTag(nbt);
}
 
Example 5
Source File: PacketSatellite.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf outline) {
	PacketBuffer packetBuffer = new PacketBuffer(outline);
	NBTTagCompound nbt = new NBTTagCompound();
	machine.writeToNBT(nbt);
	
	packetBuffer.writeCompoundTag(nbt);
}
 
Example 6
Source File: PacketStorageTileUpdate.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = (NBTTagCompound)ReflectionHelper.getPrivateValue(SPacketUpdateTileEntity.class, (SPacketUpdateTileEntity)tile.getUpdatePacket(), "field_148860_e");


	out.writeInt(((Entity)entity).world.provider.getDimension());
	out.writeInt(((Entity)entity).getEntityId());
	out.writeInt(x);
	out.writeInt(y);
	out.writeInt(z);

	PacketBuffer packetBuffer = new PacketBuffer(out);
	packetBuffer.writeCompoundTag(nbt);
}
 
Example 7
Source File: PacketStellarInfo.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = new NBTTagCompound();
	out.writeInt(starId);
	out.writeBoolean(star == null);


	if((star != null)) {
		star.writeToNBT(nbt);
		PacketBuffer packetBuffer = new PacketBuffer(out);
		packetBuffer.writeCompoundTag(nbt);
	}

}
 
Example 8
Source File: PacketSpaceStationInfo.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = new NBTTagCompound();
	out.writeInt(stationNumber);
	boolean flag = false; //TODO //dimProperties == null;
	
	if(!flag) {
		
		//Try to send the nbt data of the dimension to the client, if it fails(probably due to non existent Biome ids) then remove the dimension
		try {
			spaceObject.writeToNbt(nbt);
			//spaceObject.getProperties().writeToNBT(nbt);
			PacketBuffer packetBuffer = new PacketBuffer(out);
			out.writeBoolean(false);
			packetBuffer.writeString(SpaceObjectManager.getSpaceManager().getItentifierFromClass(spaceObject.getClass()));
			packetBuffer.writeCompoundTag(nbt);
			
			packetBuffer.writeInt(spaceObject.getFuelAmount());
			packetBuffer.writeBoolean(spaceObject.hasWarpCores);
			
			out.writeInt(spaceObject.getForwardDirection().ordinal());
			
		} catch(NullPointerException e) {
			out.writeBoolean(true);
			Logger.getLogger("advancedRocketry").warning("Dimension " + stationNumber + " has thrown an exception trying to write NBT, deleting!");
			DimensionManager.getInstance().deleteDimension(stationNumber);
		}

	}
	else
		out.writeBoolean(flag);

}
 
Example 9
Source File: SyncableTank.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	if (fluid != null) {
		stream.writeBoolean(true);
		final String id = FluidRegistry.getFluidName(fluid.getFluid());
		stream.writeString(id);
		stream.writeInt(fluid.amount);
		stream.writeCompoundTag(fluid.tag);
	} else {
		stream.writeBoolean(false);
	}
}
 
Example 10
Source File: MessageBookCodeData.java    From Minecoprocessors with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void toBytes(final ByteBuf buf) {
  final PacketBuffer buffer = new PacketBuffer(buf);
  buffer.writeCompoundTag(nbt);
}
 
Example 11
Source File: PacketStationUpdate.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf out) {
	out.writeInt(stationNumber);
	out.writeInt(type.ordinal());

	switch(type) {
	case DEST_ORBIT_UPDATE:
		out.writeInt(spaceObject.getDestOrbitingBody());
		break;
	case ORBIT_UPDATE:
		out.writeInt(spaceObject.getOrbitingPlanetId());
		break;
	case FUEL_UPDATE:
		if(spaceObject instanceof SpaceObject)
			out.writeInt(((SpaceObject)spaceObject).getFuelAmount());
		break;
	case ROTANGLE_UPDATE:
		out.writeDouble(spaceObject.getRotation(EnumFacing.EAST));
		out.writeDouble(spaceObject.getRotation(EnumFacing.UP));
		out.writeDouble(spaceObject.getRotation(EnumFacing.NORTH));
		out.writeDouble(spaceObject.getDeltaRotation(EnumFacing.EAST));
		out.writeDouble(spaceObject.getDeltaRotation(EnumFacing.UP));
		out.writeDouble(spaceObject.getDeltaRotation(EnumFacing.NORTH));
		break;
	case ALTITUDE_UPDATE:
		out.writeFloat(spaceObject.getOrbitalDistance());
		break;
	case DIM_PROPERTY_UPDATE:
		NBTTagCompound nbt = new NBTTagCompound();
		try {
			spaceObject.getProperties().writeToNBT(nbt);
			PacketBuffer packetBuffer = new PacketBuffer(out);
			packetBuffer.writeCompoundTag(nbt);
		} catch(NullPointerException e) {
			out.writeBoolean(true);
			Logger.getLogger("advancedRocketry").warning("Dimension " + stationNumber + " has thrown an exception trying to write NBT, deleting!");
			DimensionManager.getInstance().deleteDimension(stationNumber);
		}
	default:
	}
}
 
Example 12
Source File: PacketDimInfo.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
@Override
public void write(ByteBuf out) {
	NBTTagCompound nbt = new NBTTagCompound();
	out.writeInt(dimNumber);
	boolean flag = dimProperties == null;
	
	if(!flag) {
		
		//Try to send the nbt data of the dimension to the client, if it fails(probably due to non existent Biome ids) then remove the dimension
		PacketBuffer packetBuffer = new PacketBuffer(out);
		try {
			dimProperties.writeToNBT(nbt);
			out.writeBoolean(false);
			packetBuffer.writeCompoundTag(nbt);
			
			out.writeShort(dimProperties.getRequiredArtifacts().size());
			for(ItemStack i : dimProperties.getRequiredArtifacts()) {
				NBTTagCompound nbt2 = new NBTTagCompound(); 
				i.writeToNBT(nbt2);
				packetBuffer.writeCompoundTag(nbt2);
			}
			
		} catch(NullPointerException e) {
			out.writeBoolean(true);
			e.printStackTrace();
			Logger.getLogger("advancedRocketry").warning("Dimension " + dimNumber + " has thrown an exception trying to write NBT, deleting!");
			DimensionManager.getInstance().deleteDimension(dimNumber);
		}
		
		if(!dimProperties.customIcon.isEmpty())
		{
			packetBuffer.writeShort(dimProperties.customIcon.length());
			packetBuffer.writeString(dimProperties.customIcon);
		}
		else
			packetBuffer.writeShort(0);

	}
	else
		out.writeBoolean(flag);

}
 
Example 13
Source File: MessageSyncSettings.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	buffer.writeCompoundTag(_data);
}
 
Example 14
Source File: MessageOpenGui.java    From WearableBackpacks with MIT License 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	PacketBuffer buffer = new PacketBuffer(buf);
	buffer.writeInt(_windowId);
	buffer.writeCompoundTag(_data);
}
 
Example 15
Source File: SyncableNBT.java    From OpenModsLib with MIT License 4 votes vote down vote up
@Override
public void writeToStream(PacketBuffer stream) {
	stream.writeCompoundTag(this.tag);
}