Java Code Examples for cpw.mods.fml.common.network.ByteBufUtils#writeTag()

The following examples show how to use cpw.mods.fml.common.network.ByteBufUtils#writeTag() . 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: Debug.java    From ehacks-pro with GNU General Public License v3.0 5 votes vote down vote up
public static void sendProxyPacket(String channel, Object... data) {
    ByteBuf buf = Unpooled.buffer();
    for (Object o : data) {
        if (o instanceof Integer) {
            buf.writeInt(((int) o));
            continue;
        }
        if (o instanceof Byte) {
            buf.writeByte(((byte) o));
            continue;
        }
        if (o instanceof Short) {
            buf.writeShort(((short) o));
            continue;
        }
        if (o instanceof String) {
            ByteBufUtils.writeUTF8String(buf, ((String) o));
            continue;
        }
        if (o instanceof ItemStack) {
            ByteBufUtils.writeItemStack(buf, ((ItemStack) o));
            continue;
        }
        if (!(o instanceof NBTTagCompound)) {
            continue;
        }
        ByteBufUtils.writeTag(buf, ((NBTTagCompound) o));
    }
    NetworkDispatcher.get(Wrapper.INSTANCE.mc().getNetHandler().getNetworkManager()).sendProxy(new FMLProxyPacket(buf, channel));
}
 
Example 2
Source File: PacketTileEntityNBT.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
public static FMLProxyPacket createPacket(int xPos, int yPos, int zPos, NBTTagCompound nbt, int dim) {
	// This line may look like black magic (and, well, it is), but it's actually just returning a class reference for this class. Copy-paste safe.
	ByteBuf data = PacketHandlerBase.createDataBuffer((Class<? extends PacketHandlerBase>) new Object() {}.getClass().getEnclosingClass());

	data.writeInt(dim);
	data.writeInt(xPos);
	data.writeInt(yPos);
	data.writeInt(zPos);
	ByteBufUtils.writeTag(data, nbt);

	return buildPacket(data);
}
 
Example 3
Source File: PacketSingleBlockSync.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {

    super.toBytes(buf);

    buf.writeInt(block.getX());
    buf.writeInt(block.getY());
    buf.writeInt(block.getZ());
    NBTTagCompound t = FrameMovementRegistry.instance().writeInfo(block);
    ByteBufUtils.writeTag(buf, t);
}
 
Example 4
Source File: PacketBlockSync.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {

    super.toBytes(buf);

    List<IMovingBlock> l = structure.getBlocks();
    buf.writeInt(l.size());
    for (IMovingBlock b : l) {
        buf.writeInt(b.getX());
        buf.writeInt(b.getY());
        buf.writeInt(b.getZ());
        NBTTagCompound t = FrameMovementRegistry.instance().writeInfo(b);
        ByteBufUtils.writeTag(buf, t);
    }
}
 
Example 5
Source File: PacketDescription.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    super.toBytes(buf);
    buf.writeByte(type.ordinal());
    buf.writeInt(values.length);
    for(int i = 0; i < types.length; i++) {
        buf.writeByte(types[i]);
        PacketUpdateGui.writeField(buf, values[i], types[i]);
    }
    ByteBufUtils.writeTag(buf, extraData);
}
 
Example 6
Source File: PacketSetLogisticsFluidFilterStack.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    super.toBytes(buf);
    buf.writeBoolean(settingStack != null);
    if(settingStack != null) {
        ByteBufUtils.writeUTF8String(buf, settingStack.getFluid().getName());
        buf.writeInt(settingStack.amount);
        ByteBufUtils.writeTag(buf, settingStack.tag);
    }
    buf.writeInt(settingIndex);
}
 
Example 7
Source File: PacketSyncAmadronOffers.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static void writeFluidOrItemStack(Object object, ByteBuf buf){
    if(object instanceof ItemStack) {
        buf.writeByte(0);
        ByteBufUtils.writeItemStack(buf, (ItemStack)object);
    } else {
        buf.writeByte(1);
        FluidStack stack = (FluidStack)object;
        ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName());
        buf.writeInt(stack.amount);
        ByteBufUtils.writeTag(buf, stack.tag);
    }
}
 
Example 8
Source File: PacketSyncDroneEntityProgWidgets.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    NBTTagCompound tag = new NBTTagCompound();
    TileEntityProgrammer.setWidgetsToNBT(progWidgets, tag);
    ByteBufUtils.writeTag(buf, tag);

    buf.writeInt(entityId);
}
 
Example 9
Source File: PacketUpdateGui.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static void writeField(ByteBuf buf, Object value, int type){
    switch(type){
        case 0:
            buf.writeInt((Integer)value);
            break;
        case 1:
            buf.writeFloat((Float)value);
            break;
        case 2:
            buf.writeDouble((Double)value);
            break;
        case 3:
            buf.writeBoolean((Boolean)value);
            break;
        case 4:
            ByteBufUtils.writeUTF8String(buf, (String)value);
            break;
        case 5:
            buf.writeByte((Byte)value);
            break;
        case 6:
            ByteBufUtils.writeItemStack(buf, (ItemStack)value);
            break;
        case 7:
            buf.writeBoolean(value != null);
            if(value != null) {
                FluidStack stack = (FluidStack)value;
                ByteBufUtils.writeUTF8String(buf, stack.getFluid().getName());
                buf.writeInt(stack.amount);
                ByteBufUtils.writeTag(buf, stack.tag);
            }
            break;
    }
}
 
Example 10
Source File: PacketTransformationInfo.java    From Gadomancy with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
    NBTTagCompound compound = new NBTTagCompound();
    golem.writeEntityToNBT(compound);
    ByteBufUtils.writeTag(buf, compound);
}
 
Example 11
Source File: MessageConfigSync.java    From SimplyJetpacks with MIT License 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
    NBTTagCompound toSend = new NBTTagCompound();
    PackBase.writeAllConfigsToNBT(toSend);
    ByteBufUtils.writeTag(buf, toSend);
}
 
Example 12
Source File: PacketUpdateRemoteLayout.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf){
    ByteBufUtils.writeTag(buf, layout);
}
 
Example 13
Source File: DeviceUpdateMessage.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
public void toBytes(ByteBuf buf) {
	super.toBytes(buf);
    ByteBufUtils.writeTag(buf, compound);
}