Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reversed byte order in custom file protocol #66

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/src/main/java/net/pl3x/map/core/util/ByteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ private ByteUtil() {
}

public static byte[] toBytes(int packed) {
byte[] bytes = new byte[4];
for (int i = 0; i < 4; i++) {
bytes[i] = (byte) (packed >>> (i * 8));
byte[] bytes = new byte[Integer.BYTES];
for (int i = 0; i < Integer.BYTES; i++) {
bytes[i] = (byte) (packed >>> (Byte.SIZE * (Integer.BYTES - 1 - i)));
}
return bytes;
}

public static int getInt(@NotNull ByteBuffer buffer, int index) {
int value = 0;
for (int i = 0; i < 4; i++) {
value |= (buffer.get(index + i) & 0xFF) << (i * 8);
for (int i = 0; i < Integer.BYTES; i++) {
value |= (buffer.get(index + i) & 0xFF) << (Byte.SIZE * (Integer.BYTES - 1 - i));
}
return value;
}
Expand Down
7 changes: 5 additions & 2 deletions webmap/src/palette/BlockInfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Block} from "./Block";

export class BlockInfo {
public readonly BYTE_SIZE: number = 8;
public readonly INTEGER_BYTES: number = 4;

private readonly _data: Uint8Array;

constructor(data: Uint8Array) {
Expand All @@ -17,8 +20,8 @@ export class BlockInfo {

private getInt(position: number): number {
let val: number = 0;
for (let i: number = 0; i < 4; i++) {
val |= (this._data[position + i] & 0xFF) << (i * 8);
for (let i: number = 0; i < this.INTEGER_BYTES; i++) {
val |= (this._data[position + i] & 0xFF) << (this.BYTE_SIZE * ((this.INTEGER_BYTES - 1) - i));
}
return val;
}
Expand Down
Loading