    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common.network;
    014
    015import net.minecraft.network.INetworkManager;
    016import net.minecraft.network.packet.NetHandler;
    017
    018import com.google.common.io.ByteArrayDataInput;
    019import com.google.common.io.ByteArrayDataOutput;
    020import com.google.common.io.ByteStreams;
    021
    022import cpw.mods.fml.common.FMLCommonHandler;
    023
    024public class EntitySpawnAdjustmentPacket extends FMLPacket
    025{
    026
    027    public EntitySpawnAdjustmentPacket()
    028    {
    029        super(Type.ENTITYSPAWNADJUSTMENT);
    030    }
    031
    032    public int entityId;
    033    public int serverX;
    034    public int serverY;
    035    public int serverZ;
    036
    037    @Override
    038    public byte[] generatePacket(Object... data)
    039    {
    040        ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    041        dat.writeInt((Integer) data[0]);
    042        dat.writeInt((Integer) data[1]);
    043        dat.writeInt((Integer) data[2]);
    044        dat.writeInt((Integer) data[3]);
    045        return dat.toByteArray();
    046    }
    047
    048    @Override
    049    public FMLPacket consumePacket(byte[] data)
    050    {
    051        ByteArrayDataInput dat = ByteStreams.newDataInput(data);
    052        entityId = dat.readInt();
    053        serverX = dat.readInt();
    054        serverY = dat.readInt();
    055        serverZ = dat.readInt();
    056        return this;
    057    }
    058
    059    @Override
    060    public void execute(INetworkManager network, FMLNetworkHandler handler, NetHandler netHandler, String userName)
    061    {
    062        FMLCommonHandler.instance().adjustEntityLocationOnClient(this);
    063    }
    064
    065}