/**
 * Copyright (C) 2017 Le Thinh
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.lethinh.matterexpansion.network.packet;

import java.io.IOException;

import io.lethinh.matterexpansion.MatterExpansion;
import io.lethinh.matterexpansion.backend.helpers.IBlobsWrapper;
import io.lethinh.matterexpansion.network.EligiblePacketBuffer;
import io.lethinh.matterexpansion.network.GenericPacketClientToServer;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;

/**
 *
 * @author Le Thinh
 */
public class PacketTileUpdate extends GenericPacketClientToServer {

	private BlockPos pos;

	public PacketTileUpdate() {
	}

	public PacketTileUpdate(BlockPos pos) {
		this.pos = pos;
	}

	@Override
	protected void handleServerDelegate(NetHandlerPlayServer server) {
		final TileEntity tile = server.playerEntity.world.getTileEntity(this.pos);

		if (tile instanceof IBlobsWrapper) {
			try {
				((IBlobsWrapper) tile).loadBlobsTickets(this.packetBuffer);
			} catch (final IOException e) {
				MatterExpansion.LOGGER.error(
						"Blobs of the tile received from the packet wasn't valid ... Position: " + this.pos.toString(),
						e);
			}
		}
	}

	@Override
	public void loadBlobsTickets(EligiblePacketBuffer packet) throws IOException {
		this.pos = packet.readBlockPos();
	}

	@Override
	public void saveBlobsTickets(EligiblePacketBuffer packet) throws IOException {
		packet.writeBlockPos(this.pos);
	}

}

@@ -1180,16 +1180,45 @@
 Pos pos;
+%0A%09private NBTTagCompound tag;
 %0A%0A%09publi
@@ -1281,16 +1281,36 @@
 kPos pos
+, NBTTagCompound tag
 ) %7B%0A%09%09th
@@ -1323,16 +1323,34 @@
  = pos;%0A
+%09%09this.tag = tag;%0A
 %09%7D%0A%0A%09@Ov
@@ -1500,16 +1500,42 @@
 is.pos);
+%0A%09%09Validate.notNull(tile);
 %0A%0A%09%09if (
@@ -1961,16 +1961,55 @@
 kPos();%0A
+%09%09this.tag = packet.readCompoundTag();%0A
 %09%7D%0A%0A%09@Ov
@@ -2129,14 +2129,51 @@
 s.pos);%0A
+%09%09packet.writeCompoundTag(this.tag);%0A
 %09%7D%0A%0A%7D%0A

Update PacketTileUpdate.java