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/2b89357f27fcdb27e020 to your computer and use it in GitHub Desktop.
Save WillR27/2b89357f27fcdb27e020 to your computer and use it in GitHub Desktop.
package com.blocklings.network;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.world.World;
import com.blocklings.entity.EntityBlockling;
import com.blocklings.main.Blocklings;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ProcessPacketClientSide {
public ProcessPacketClientSide() {
}
@SideOnly(Side.CLIENT)
public static void processPacketOnClient(ByteBuf parBB, Side parSide) throws IOException {
if (parSide == Side.CLIENT) {
World world = Minecraft.getMinecraft().theWorld;
ByteBufInputStream bbis = new ByteBufInputStream(parBB);
int packetTypeID = bbis.readInt();
switch (packetTypeID) {
case Blocklings.PACKET_TYPE_ENTITY_SYNC:
{
int entityID = bbis.readInt();
Entity foundEntity = world.getEntityByID(entityID);
if (foundEntity != null) {
} else {
}
if (foundEntity instanceof EntityBlockling) {
EntityBlockling blockling = (EntityBlockling) foundEntity;
blockling.setLevel(bbis.readInt());
blockling.setCurrentUpgradeTier(bbis.readInt());
blockling.setAttackTimer(bbis.readFloat());
}
break;
}
}
bbis.close();
}
}
public static Entity getEntityByID(int entityID, World world) {
for (Object o : world.getLoadedEntityList()) {
if (((Entity) o).getEntityId() == entityID) {
return ((Entity) o);
}
}
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment