mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 09:26:11 -04:00
bitbyte: use own infix functions
This commit is contained in:
parent
b8e68126d2
commit
c7b8aa4094
@ -44,11 +44,12 @@ class RenderWindowInputHandler(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
registerKeyCallback(KeyBindingsNames.DEBUG_MOUSE_CATCH) {
|
registerKeyCallback(KeyBindingsNames.DEBUG_MOUSE_CATCH) {
|
||||||
if (it) {
|
val newCursorMode = if (it) {
|
||||||
glfwSetInputMode(renderWindow.windowId, GLFW_CURSOR, GLFW_CURSOR_DISABLED)
|
GLFW_CURSOR_DISABLED
|
||||||
} else {
|
} else {
|
||||||
glfwSetInputMode(renderWindow.windowId, GLFW_CURSOR, GLFW_CURSOR_NORMAL)
|
GLFW_CURSOR_NORMAL
|
||||||
}
|
}
|
||||||
|
glfwSetInputMode(renderWindow.windowId, GLFW_CURSOR, newCursorMode)
|
||||||
renderWindow.sendDebugMessage("Toggled mouse catch!")
|
renderWindow.sendDebugMessage("Toggled mouse catch!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -179,7 +180,7 @@ class RenderWindowInputHandler(
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log.debug("Changing $resourceLocation because of $keyCode -> $combinationDown")
|
// Log.debug("Changing $resourceLocation because of $keyCode -> $thisKeyBindingDown")
|
||||||
for (callback in pair.callback) {
|
for (callback in pair.callback) {
|
||||||
callback.invoke(thisKeyBindingDown)
|
callback.invoke(thisKeyBindingDown)
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ class ToggleFlyC2SP(val flying: Boolean) : PlayC2SPacket {
|
|||||||
buffer.writeByte(flags)
|
buffer.writeByte(flags)
|
||||||
if (buffer.versionId < ProtocolVersions.V_1_16_PRE4) {
|
if (buffer.versionId < ProtocolVersions.V_1_16_PRE4) {
|
||||||
// only fly matters, everything else ignored
|
// only fly matters, everything else ignored
|
||||||
buffer.writeFloat(0.0f) // flyingSpeed
|
buffer.writeFloat(1.0f) // flyingSpeed
|
||||||
buffer.writeFloat(0.0f) // walkingSpeed
|
buffer.writeFloat(1.0f) // walkingSpeed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import de.bixilon.minosoft.protocol.network.connection.PlayConnection
|
|||||||
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
|
||||||
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
|
||||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersions
|
||||||
import de.bixilon.minosoft.util.BitByte
|
import de.bixilon.minosoft.util.BitByte.isBit
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
|
|
||||||
class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
||||||
@ -29,17 +29,17 @@ class PlayerAbilitiesS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket() {
|
|||||||
val walkingSpeed: Float
|
val walkingSpeed: Float
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val flags = buffer.readByte()
|
val flags = buffer.readUnsignedByte()
|
||||||
if (buffer.versionId < ProtocolVersions.V_14W03B) { // ToDo: Find out correct version
|
if (buffer.versionId < ProtocolVersions.V_14W03B) { // ToDo: Find out correct version
|
||||||
isInvulnerable = BitByte.isBitSet(flags.toInt(), 0)
|
isInvulnerable = flags isBit (0)
|
||||||
isFlying = BitByte.isBitSet(flags.toInt(), 1)
|
isFlying = flags.isBit(1)
|
||||||
canFly = BitByte.isBitSet(flags.toInt(), 2)
|
canFly = flags.isBit(2)
|
||||||
canInstantBuild = BitByte.isBitSet(flags.toInt(), 3)
|
canInstantBuild = flags.isBit(3)
|
||||||
} else {
|
} else {
|
||||||
canInstantBuild = BitByte.isBitSet(flags.toInt(), 0)
|
canInstantBuild = flags.isBit(0)
|
||||||
isFlying = BitByte.isBitSet(flags.toInt(), 1)
|
isFlying = flags.isBit(1)
|
||||||
canFly = BitByte.isBitSet(flags.toInt(), 2)
|
canFly = flags.isBit(2)
|
||||||
isInvulnerable = BitByte.isBitSet(flags.toInt(), 3)
|
isInvulnerable = flags.isBit(3)
|
||||||
}
|
}
|
||||||
flyingSpeed = buffer.readFloat()
|
flyingSpeed = buffer.readFloat()
|
||||||
walkingSpeed = buffer.readFloat()
|
walkingSpeed = buffer.readFloat()
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Minosoft
|
|
||||||
* Copyright (C) 2020 Moritz Zwerger
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.bixilon.minosoft.util;
|
|
||||||
|
|
||||||
public final class BitByte {
|
|
||||||
public static boolean isBitSet(long in, int pos) {
|
|
||||||
long mask = 1L << pos;
|
|
||||||
return ((in & mask) == mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBitSet(int in, int pos) {
|
|
||||||
int mask = 1 << pos;
|
|
||||||
return ((in & mask) == mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBitMask(int in, int mask) {
|
|
||||||
return ((in & mask) == mask);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte getBitCount(long input) {
|
|
||||||
byte ret = 0;
|
|
||||||
for (byte i = 0; i < Long.SIZE; i++) {
|
|
||||||
if (isBitSet(input, i)) {
|
|
||||||
ret++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isBitSetShort(short in, int pos) {
|
|
||||||
int mask = 1 << pos;
|
|
||||||
return ((in & mask) == mask);
|
|
||||||
}
|
|
||||||
}
|
|
54
src/main/java/de/bixilon/minosoft/util/BitByte.kt
Normal file
54
src/main/java/de/bixilon/minosoft/util/BitByte.kt
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Minosoft
|
||||||
|
* Copyright (C) 2020 Moritz Zwerger
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
|
*/
|
||||||
|
package de.bixilon.minosoft.util
|
||||||
|
|
||||||
|
object BitByte {
|
||||||
|
fun isBitSet(`in`: Long, pos: Int): Boolean {
|
||||||
|
val mask = 1L shl pos
|
||||||
|
return `in` and mask == mask
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBitSet(`in`: Int, pos: Int): Boolean {
|
||||||
|
val mask = 1 shl pos
|
||||||
|
return `in` and mask == mask
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun isBitMask(`in`: Int, mask: Int): Boolean {
|
||||||
|
return `in` and mask == mask
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getBitCount(input: Long): Byte {
|
||||||
|
var ret: Byte = 0
|
||||||
|
for (i in 0 until java.lang.Long.SIZE) {
|
||||||
|
if (isBitSet(input, i)) {
|
||||||
|
ret++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
fun isBitSetShort(`in`: Short, pos: Int): Boolean {
|
||||||
|
val mask = 1 shl pos
|
||||||
|
return `in`.toInt() and mask == mask
|
||||||
|
}
|
||||||
|
|
||||||
|
infix fun Int.isBit(bit: Int): Boolean {
|
||||||
|
return isBitSet(this, bit)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmName("isBitMask1")
|
||||||
|
infix fun Int.isBitMask(bitMask: Int): Boolean {
|
||||||
|
return isBitMask(this, bitMask)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user