entities wip (6): head rotation

This commit is contained in:
bixilon 2020-06-07 00:59:57 +02:00
parent 74d34a8078
commit 91e4f28a5f
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 88 additions and 0 deletions

View File

@ -19,4 +19,8 @@ public interface Mob extends Entity {
void setHealth(float health);
int getMaxHealth();
int getHeadYaw();
void setHeadYaw(int headYaw);
}

View File

@ -26,6 +26,7 @@ public class OtherPlayer implements Mob {
Location location;
int yaw;
int pitch;
int headYaw;
short currentItem;
EntityMetaData metaData;
float health;
@ -184,4 +185,14 @@ public class OtherPlayer implements Mob {
GLIDING,
SWIMMING
}
@Override
public int getHeadYaw() {
return headYaw;
}
@Override
public void setHeadYaw(int headYaw) {
this.headYaw = headYaw;
}
}

View File

@ -20,6 +20,7 @@ public class Zombie implements Mob {
Velocity velocity;
int yaw;
int pitch;
int headYaw;
EntityMetaData metaData;
float health;
@ -124,4 +125,14 @@ public class Zombie implements Mob {
public int getMaxHealth() {
return 40;
}
@Override
public int getHeadYaw() {
return headYaw;
}
@Override
public void setHeadYaw(int headYaw) {
this.headYaw = headYaw;
}
}

View File

@ -0,0 +1,56 @@
/*
* 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;
public class PacketEntityHeadRotation implements ClientboundPacket {
int entityId;
int headYaw;
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
this.entityId = buffer.readInteger();
this.headYaw = buffer.readByte(); //ToDo
break;
}
}
@Override
public void log() {
Log.protocol(String.format("Entity %d moved head %s", entityId, headYaw));
}
public int getEntityId() {
return entityId;
}
public int getHeadYaw() {
return headYaw;
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
}

View File

@ -16,6 +16,7 @@ package de.bixilon.minosoft.protocol.protocol;
import de.bixilon.minosoft.Minosoft;
import de.bixilon.minosoft.config.GameConfiguration;
import de.bixilon.minosoft.game.datatypes.GameMode;
import de.bixilon.minosoft.game.datatypes.entities.Mob;
import de.bixilon.minosoft.logging.Log;
import de.bixilon.minosoft.protocol.network.Connection;
import de.bixilon.minosoft.protocol.packets.clientbound.login.PacketEncryptionKeyRequest;
@ -182,4 +183,8 @@ public class PacketHandler {
connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).setYaw(pkg.getYaw());
connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).setPitch(pkg.getPitch());
}
public void handle(PacketEntityHeadRotation pkg) {
((Mob) connection.getPlayer().getWorld().getEntity(pkg.getEntityId())).setHeadYaw(pkg.getHeadYaw());
}
}

View File

@ -70,5 +70,6 @@ public interface Protocol {
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_VELOCITY, PacketEntityVelocity.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SPAWN_PLAYER, PacketSpawnPlayer.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_TELEPORT, PacketEntityTeleport.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_HEAD_LOOK, PacketEntityHeadRotation.class);
}
}