oh i was only guessing =\ cuz that thing u posted has 73 and 241.
No worries.
Originally Posted by digistr
um but by "z" i meant where do you send your hieghtLevel aka "z" to the client?
In the player updating. That might/could be why then? It's not showing the correct height level so it's thinking that it's at -1? Also, the putBits, isEmpty, startBitAccess and finishBitAccess methods are messed up and might be reasons as to why I can't see the map regions and also as to why it's giving me errors upon errors in the client - because it's not reading it correctly. I tried finding a position() or even a location() or offset() method that gives the currentOffset in the ChannelBuffer, but no go. [Only registered and activated users can see links. ]
Code:
package com.emulation.net.packet;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import com.emulation.net.packet.Packet.Type;
public class PacketBuilder {
private static int[] BIT_MASK_OUT = new int[32];
private int opcode;
private ChannelBuffer payload = ChannelBuffers.dynamicBuffer();
private Type type;
private int bitPosition;
static {
for (int i = 0; i < PacketBuilder.BIT_MASK_OUT.length; i++) {
PacketBuilder.BIT_MASK_OUT[i] = (1 << i) - 1;
}
}
public PacketBuilder() {
this(-1);
}
public PacketBuilder(int opcode) {
this(opcode, Type.FIXED);
}
public PacketBuilder(int opcode, Type type) {
this.opcode = opcode;
this.type = type;
}
public Packet toPacket() {
return new Packet(this.opcode, this.type, this.payload);
}
public PacketBuilder putByte(byte b) {
this.payload.writeByte(b);
return this;
}
public PacketBuilder putByte(ChannelBuffer payload) {
this.payload.writeBytes(payload);
return this;
}
public PacketBuilder putBytes(byte[] b) {
this.payload.writeBytes(b);
return this;
}
public PacketBuilder putByteA(int b) {
this.payload.writeByte((byte) (b + 128));
return this;
}
public PacketBuilder putShort(int s) {
this.payload.writeShort((short) s);
return this;
}
public PacketBuilder putShortA(int s) {
this.payload.writeByte((byte) (s >> 8));
this.payload.writeByte((byte) (s + 128));
return this;
}
public PacketBuilder putLEShortA(int b) {
this.payload.writeByte((byte) (b + 128));
this.payload.writeByte((byte) (b >> 8));
return this;
}
public PacketBuilder putInt(int i) {
this.payload.writeInt(i);
return this;
}
public PacketBuilder putLong(long l) {
this.payload.writeLong(l);
return this;
}
public PacketBuilder putString(String s) {
this.payload.writeBytes(s.getBytes());
this.payload.writeByte((byte) 10);
return this;
}
public boolean isEmpty() {
return this.payload.arrayOffset() == 0;
}
public PacketBuilder startBitAccess() {
this.bitPosition = this.payload.arrayOffset() * 8;
return this;
}
public PacketBuilder finishBitAccess() {
this.payload.ensureWritableBytes((this.bitPosition + 7) / 8);
return this;
}
public PacketBuilder putBits(int numBits, int value) {
int bytes = (int) Math.ceil(numBits / 8D) + 1;
this.payload.ensureWritableBytes((this.bitPosition + 7) / 8 + bytes);
byte[] buffer = this.payload.array();
int bytePos = this.bitPosition >> 3;
int bitOffset = 8 - (this.bitPosition & 7);
this.bitPosition += numBits;
for (; numBits > bitOffset; bitOffset = 8) {
buffer[bytePos] &= ~PacketBuilder.BIT_MASK_OUT[bitOffset];
buffer[bytePos++] |= (value >> (numBits - bitOffset)) & PacketBuilder.BIT_MASK_OUT[bitOffset];
numBits -= bitOffset;
}
if (numBits == bitOffset) {
buffer[bytePos] &= ~PacketBuilder.BIT_MASK_OUT[bitOffset];
buffer[bytePos] |= value & PacketBuilder.BIT_MASK_OUT[bitOffset];
} else {
buffer[bytePos] &= ~(PacketBuilder.BIT_MASK_OUT[numBits] << (bitOffset - numBits));
buffer[bytePos] |= (value & PacketBuilder.BIT_MASK_OUT[numBits]) << (bitOffset - numBits);
}
return this;
}
public ChannelBuffer getPayload() {
return this.payload;
}
public Type getType() {
return this.type;
}
}
Having some trouble with that because as I said before, I debugged mine and a winterLove server and the bitPosition was completely off. On mine, it came out as 0 all the time. Found out that the arrayOffset() method in ChannelBuffer wasn't used at all, so yeah.. If someone could help me with those methods, I could probably get the maps loaded then.
EDIT: Finally got the startBitAccess and finishBitAccess methods correct. I just need the putBits method to be correct as well and I should be fine.
[Only registered and activated users can see links. ]
I am nerdier than 74% of all people. Are you a nerd? Click here to take the Nerd Test, get geeky images and jokes, and write on the nerd forum!
[Only registered and activated users can see links. ]