Skip to content

Instantly share code, notes, and snippets.

@IamRob-
Created February 15, 2014 21:24
Show Gist options
  • Select an option

  • Save IamRob-/9025430 to your computer and use it in GitHub Desktop.

Select an option

Save IamRob-/9025430 to your computer and use it in GitHub Desktop.
public class PacketHandler implements IPacketHandler {
@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) {
ByteArrayDataInput reader = ByteStreams.newDataInput(packet.data);
EntityPlayer entityPlayer = (EntityPlayer) player;
byte packetId = reader.readByte();
System.out.println("Packet recieved");
switch (packetId) {
case 0:
int id = reader.readByte();
ItemStack is = entityPlayer.getCurrentEquippedItem();
if (is == null || !(is.getItem() instanceof ItemLinkHolder)) return;
ItemLinkHolder item = (ItemLinkHolder) is.getItem();
ItemStack[] items = item.getMyInventory(is);
if (items[id] == null || !(items[id].getItem() instanceof ItemLinkbook)) return;
ItemLinkbook link = (ItemLinkbook) items[id].getItem();
link.activate(is, entityPlayer.worldObj, entityPlayer);
break;
}
}
public static void sendActivatePacket(byte id) {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutputStream dataStream = new DataOutputStream(byteStream);
try {
dataStream.writeByte(0);
dataStream.writeByte(id);
System.out.println("Packet Sent");
PacketDispatcher.sendPacketToServer(PacketDispatcher.getPacket(ModInfo.Channel, byteStream.toByteArray()));
} catch (IOException e) {
System.err.append("Failed to send activate packet");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment