All pastes #973777 Raw Edit

Someone

public java v1 · immutable
·published 2008-04-06 09:06 UTC
rendered paste body
    public Packet getPacket() {        StatefulEntityCollection watchedNPCs = player.getWatchedNpcs();        if (watchedNPCs.changed()) {            Collection<Npc> knownNpcs = watchedNPCs.getKnownEntities();            Collection<Npc> newNpcs = watchedNPCs.getNewEntities();            StaticPacketBuilder pb = new StaticPacketBuilder();            pb.setID(77);            pb.addBits(knownNpcs.size(), 8);            for (Npc n : knownNpcs) {                pb.addBits(n.getIndex(), 12);                if (watchedNPCs.isRemoving(n)) {                    pb.addBits(1, 1);                    pb.addBits(1, 1);                    pb.addBits(12, 4);                    System.out.printf("Removing NPC: ID = %d, Index = %d\n", n.getID(), n.getIndex());                } else if (n.hasMoved()) {                    pb.addBits(1, 1);                    pb.addBits(0, 1);                    pb.addBits(n.getSprite(), 3);                    System.out.printf("NPC has moved: ID = %d, Index = %d\n", n.getID(), n.getIndex());                /*} else if (n.spriteChanged()) {                    pb.addBits(1, 1);                    pb.addBits(1, 1);                    //int sprite = n.getState() == MobState.LEFT_FIGHTING ? 8 : (n.getState() == MobState.RIGHT_FIGHTING ? 9 : n.getSprite());                    pb.addBits(n.getSprite(), 4);*/                } else {                    pb.addBits(0, 1);                }            }            for (Npc n : newNpcs) {                pb.addBits(n.getIndex(), 12);                byte[] offsets = getPositionOffsets(n.getLocation());                pb.addBits(offsets[0], 5);                pb.addBits(offsets[1], 5);                pb.addBits(n.getSprite(), 4);                pb.addBits(n.getID(), 10);                System.out.printf("Adding new NPC: ID = %d, Index = %d\n", n.getID(), n.getIndex());            }            return pb.toPacket();        }        return null;    }    protected byte[] getPositionOffsets(Point p) {        byte[] rv = new byte[2];        rv[0] = getCoordOffset(player.getLocation().getX(), p.getX());        rv[1] = getCoordOffset(player.getLocation().getY(), p.getY());        return rv;    }    protected byte getCoordOffset(int coord1, int coord2) {        byte offset = (byte) (coord2 - coord1);        if (offset < 0) {            offset += 32;        }        return offset;    }