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

The following examples show how to use cpw.mods.fml.common.network.ByteBufUtils#readTag() . 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: PacketUpdateGui.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
public static Object readField(ByteBuf buf, int type){
    switch(type){
        case 0:
            return buf.readInt();
        case 1:
            return buf.readFloat();
        case 2:
            return buf.readDouble();
        case 3:
            return buf.readBoolean();
        case 4:
            return ByteBufUtils.readUTF8String(buf);
        case 5:
            return buf.readByte();
        case 6:
            return ByteBufUtils.readItemStack(buf);
        case 7:
            if(!buf.readBoolean()) return null;
            return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
    }
    throw new IllegalArgumentException("Invalid sync type! " + type);
}
 
Example 2
Source File: PacketTileEntityNBT.java    From LookingGlass with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(ByteBuf data, EntityPlayer player) {
	int dimension = data.readInt();
	int xPos = data.readInt();
	int yPos = data.readInt();
	int zPos = data.readInt();
	NBTTagCompound nbt = ByteBufUtils.readTag(data);

	WorldClient proxyworld = ProxyWorldManager.getProxyworld(dimension);
	if (proxyworld == null) return;
	if (proxyworld.provider.dimensionId != dimension) return;
	if (proxyworld.blockExists(xPos, yPos, zPos)) {
		TileEntity tileentity = proxyworld.getTileEntity(xPos, yPos, zPos);

		if (tileentity != null) {
			tileentity.readFromNBT(nbt);
		} else {
			//Create tile entity from data
			tileentity = TileEntity.createAndLoadEntity(nbt);
			if (tileentity != null) {
				proxyworld.addTileEntity(tileentity);
			}
		}
		proxyworld.markTileEntityChunkModified(xPos, yPos, zPos, tileentity);
		proxyworld.setTileEntity(xPos, yPos, zPos, tileentity);
		proxyworld.markBlockForUpdate(xPos, yPos, zPos);
	}
}
 
Example 3
Source File: PacketSingleBlockSync.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {

    super.fromBytes(buf);

    v = new Vec3i(buf.readInt(), buf.readInt(), buf.readInt());
    t = ByteBufUtils.readTag(buf);
}
 
Example 4
Source File: PacketBlockSync.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {

    super.fromBytes(buf);

    int count = buf.readInt();
    for (int i = 0; i < count; i++) {
        Vec3i v = new Vec3i(buf.readInt(), buf.readInt(), buf.readInt());
        NBTTagCompound t = ByteBufUtils.readTag(buf);
        data.put(v, 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 fromBytes(ByteBuf buf){
    super.fromBytes(buf);
    type = IDescSynced.Type.values()[buf.readByte()];
    int dataAmount = buf.readInt();
    types = new byte[dataAmount];
    values = new Object[dataAmount];
    for(int i = 0; i < dataAmount; i++) {
        types[i] = buf.readByte();
        values[i] = PacketUpdateGui.readField(buf, types[i]);
    }
    extraData = ByteBufUtils.readTag(buf);
}
 
Example 6
Source File: PacketSyncAmadronOffers.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
public static Object getFluidOrItemStack(ByteBuf buf){
    if(buf.readByte() == 0) {
        return ByteBufUtils.readItemStack(buf);
    } else {
        return new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
    }
}
 
Example 7
Source File: MessageConfigSync.java    From SimplyJetpacks with MIT License 4 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
    this.recv = ByteBufUtils.readTag(buf);
}
 
Example 8
Source File: PacketSetLogisticsFluidFilterStack.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf){
    super.fromBytes(buf);
    if(buf.readBoolean()) settingStack = new FluidStack(FluidRegistry.getFluid(ByteBufUtils.readUTF8String(buf)), buf.readInt(), ByteBufUtils.readTag(buf));
    settingIndex = buf.readInt();
}
 
Example 9
Source File: PacketUpdateRemoteLayout.java    From PneumaticCraft with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf){
    layout = ByteBufUtils.readTag(buf);
}
 
Example 10
Source File: DeviceUpdateMessage.java    From BigReactors with MIT License 4 votes vote down vote up
@Override
public void fromBytes(ByteBuf buf) {
	super.fromBytes(buf);
    compound = ByteBufUtils.readTag(buf);
}