mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
PacketPlayerAbilities (fly, etc)
This commit is contained in:
parent
c62132dc2f
commit
423e48a57a
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Codename 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.protocol.packets.clientbound.play;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.logging.Log;
|
||||||
|
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
import de.bixilon.minosoft.util.BitByte;
|
||||||
|
|
||||||
|
public class PacketPlayerAbilitiesReceiving implements ClientboundPacket {
|
||||||
|
boolean creative; // is this needed? receiving the gameMode in change Gamestate
|
||||||
|
boolean flying;
|
||||||
|
boolean canFly;
|
||||||
|
boolean godMode;
|
||||||
|
float flyingSpeed;
|
||||||
|
float walkingSpeed;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(InPacketBuffer buffer, ProtocolVersion v) {
|
||||||
|
switch (v) {
|
||||||
|
case VERSION_1_7_10:
|
||||||
|
byte flags = buffer.readByte();
|
||||||
|
creative = BitByte.isBitSet(flags, 0);
|
||||||
|
flying = BitByte.isBitSet(flags, 1);
|
||||||
|
canFly = BitByte.isBitSet(flags, 2);
|
||||||
|
godMode = BitByte.isBitSet(flags, 3);
|
||||||
|
flyingSpeed = buffer.readFloat();
|
||||||
|
walkingSpeed = buffer.readFloat();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log() {
|
||||||
|
Log.protocol(String.format("Received player abilities packet: (creative=%s, flying=%s, canFly=%s, godMode=%s, flyingSpeed=%s, walkingSpeed=%s)", creative, flying, canFly, godMode, flyingSpeed, walkingSpeed));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle(PacketHandler h) {
|
||||||
|
h.handle(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canFly() {
|
||||||
|
return canFly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCreative() {
|
||||||
|
return creative;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGodMode() {
|
||||||
|
return godMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFlying() {
|
||||||
|
return flying;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Codename 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.protocol.packets.serverbound.play;
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.logging.Log;
|
||||||
|
import de.bixilon.minosoft.protocol.packets.ServerboundPacket;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.OutPacketBuffer;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.Packets;
|
||||||
|
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||||
|
|
||||||
|
public class PacketPlayerAbilitiesSending implements ServerboundPacket {
|
||||||
|
boolean creative;
|
||||||
|
boolean flying;
|
||||||
|
boolean canFly;
|
||||||
|
boolean godMode;
|
||||||
|
float flyingSpeed;
|
||||||
|
float walkingSpeed;
|
||||||
|
|
||||||
|
public PacketPlayerAbilitiesSending(boolean creative, boolean flying, boolean canFly, boolean godMode, float flyingSpeed, float walkingSpeed) {
|
||||||
|
this.creative = creative;
|
||||||
|
this.flying = flying;
|
||||||
|
this.canFly = canFly;
|
||||||
|
this.godMode = godMode;
|
||||||
|
this.flyingSpeed = flyingSpeed;
|
||||||
|
this.walkingSpeed = walkingSpeed;
|
||||||
|
log();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PacketPlayerAbilitiesSending(boolean flying) {
|
||||||
|
this.creative = false;
|
||||||
|
this.flying = flying;
|
||||||
|
this.canFly = flying;
|
||||||
|
this.godMode = false;
|
||||||
|
this.flyingSpeed = 0.05F;
|
||||||
|
this.walkingSpeed = 0.1F;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public OutPacketBuffer write(ProtocolVersion v) {
|
||||||
|
OutPacketBuffer buffer = new OutPacketBuffer(v.getPacketCommand(Packets.Serverbound.PLAY_CLIENT_SETTINGS));
|
||||||
|
switch (v) {
|
||||||
|
case VERSION_1_7_10:
|
||||||
|
byte flags = 0;
|
||||||
|
if (creative) {
|
||||||
|
flags |= 0b1;
|
||||||
|
}
|
||||||
|
if (flying) {
|
||||||
|
flags |= 0b10;
|
||||||
|
}
|
||||||
|
if (canFly) {
|
||||||
|
flags |= 0b100;
|
||||||
|
}
|
||||||
|
if (godMode) {
|
||||||
|
flags |= 0b1000;
|
||||||
|
}
|
||||||
|
buffer.writeByte(flags);
|
||||||
|
buffer.writeFloat(flyingSpeed);
|
||||||
|
buffer.writeFloat(walkingSpeed);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void log() {
|
||||||
|
Log.protocol(String.format("Sending player abilities packet: (creative=%s, flying=%s, canFly=%s, godMode=%s, flyingSpeed=%s, walkingSpeed=%s)", creative, flying, canFly, godMode, flyingSpeed, walkingSpeed));
|
||||||
|
}
|
||||||
|
}
|
@ -267,4 +267,8 @@ public class PacketHandler {
|
|||||||
public void handle(PacketSoundEffect pkg) {
|
public void handle(PacketSoundEffect pkg) {
|
||||||
//ToDo
|
//ToDo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handle(PacketPlayerAbilitiesReceiving pkg) {
|
||||||
|
//ToDo: used to set fly abilities
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ public interface Protocol {
|
|||||||
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_ANIMATION, PacketEntityAnimation.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class);
|
||||||
packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class);
|
packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class);
|
||||||
|
packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_ABILITIES, PacketPlayerAbilitiesReceiving.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getProtocolVersion();
|
int getProtocolVersion();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user