e
This commit is contained in:
parent
0c2f13439f
commit
4c0b89de04
|
|
@ -80,7 +80,7 @@ public class BlockPeripheral extends WDBlockContainer {
|
|||
return ((TileEntityPeripheralBase) te).onRightClick(player, hand);
|
||||
else if(te instanceof TileEntityServer) {
|
||||
((TileEntityServer) te).onPlayerRightClick(player);
|
||||
return InteractionResult.PASS;
|
||||
return InteractionResult.SUCCESS;
|
||||
} else
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,17 @@ import java.util.function.Supplier;
|
|||
|
||||
public class BufferUtils {
|
||||
public static void writeUShort(FriendlyByteBuf buf, int v) {
|
||||
// TODO: write a pair of bytes manually
|
||||
buf.writeInt(v);
|
||||
short s = (short) (v + Short.MIN_VALUE);
|
||||
buf.writeByte((byte) (s & 0xFF));
|
||||
// I have no idea where this 128 came from
|
||||
buf.writeByte((byte) (((s + 128) >> 8) & 0xFF));
|
||||
}
|
||||
|
||||
public static int readUShort(FriendlyByteBuf buf) {
|
||||
return buf.readInt();
|
||||
int upack = (buf.readByte() + (buf.readByte() << 8)) - Short.MIN_VALUE;
|
||||
// ????
|
||||
if (upack < 0) upack += 65536;
|
||||
return upack;
|
||||
}
|
||||
|
||||
public static void writeBytes(FriendlyByteBuf buf, byte[] data) {
|
||||
|
|
|
|||
24
src/test/java/UShortToBytes.java
Normal file
24
src/test/java/UShortToBytes.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
public class UShortToBytes {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < Short.MAX_VALUE * 2; i++) {
|
||||
short s = (short) (i + Short.MIN_VALUE);
|
||||
|
||||
byte[] data = new byte[]{
|
||||
(byte) (s & 0xFF),
|
||||
(byte) (((s + 128) >> 8) & 0xFF),
|
||||
};
|
||||
|
||||
int upack = data[0] + (data[1] << 8);
|
||||
upack -= Short.MIN_VALUE;
|
||||
if (upack < 0)
|
||||
upack += 65536;
|
||||
|
||||
if (upack != i) {
|
||||
System.out.println(upack);
|
||||
System.out.println(i);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("done");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user