Skip to content

Instantly share code, notes, and snippets.

@WillR27
Created July 4, 2014 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillR27/a4fafe8ee92a1e85fd8b to your computer and use it in GitHub Desktop.
Save WillR27/a4fafe8ee92a1e85fd8b to your computer and use it in GitHub Desktop.
package com.blocklings.network;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.entity.Entity;
import com.blocklings.entity.EntityBlockling;
import com.blocklings.main.Blocklings;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
public class CreatePacketServerSide {
public CreatePacketServerSide() {
}
public static FMLProxyPacket createEntityPacket(Entity parEntity) throws IOException {
ByteBufOutputStream bbos = new ByteBufOutputStream(Unpooled.buffer());
bbos.writeInt(Blocklings.PACKET_TYPE_ENTITY_SYNC);
bbos.writeInt(parEntity.getEntityId());
if (parEntity instanceof EntityBlockling) {
EntityBlockling blockling = (EntityBlockling) parEntity;
bbos.writeInt(blockling.getLevel());
bbos.writeInt(blockling.getCurrentUpgradeTier());
bbos.writeFloat(blockling.getAttackTimer());
}
FMLProxyPacket thePacket = new FMLProxyPacket(bbos.buffer(), Blocklings.networkChannelName);
bbos.close();
return thePacket;
}
public static void sendToAll(FMLProxyPacket parPacket) {
Blocklings.channel.sendToAll(parPacket);
}
public static void sendS2CEntitySync(Entity parEntity) {
try {
sendToAll(createEntityPacket(parEntity));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment