Created
July 4, 2014 21:14
-
-
Save WillR27/a4fafe8ee92a1e85fd8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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