attach entity support

This commit is contained in:
bixilon 2020-06-16 16:47:53 +02:00
parent a51f78aeb1
commit fef2f20bc9
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 83 additions and 0 deletions

View File

@ -30,6 +30,7 @@ public abstract class Entity implements EntityInterface {
short yaw;
short pitch;
short headYaw;
int attachedTo = -1;
public Entity(int id, Location location, short yaw, short pitch, Velocity velocity) {
this.id = id;
@ -130,4 +131,20 @@ public abstract class Entity implements EntityInterface {
public void removeEffect(StatusEffects effect) {
effectList.removeIf(listEffect -> listEffect.getEffect() == effect);
}
public void attachTo(int vehicleId) {
this.attachedTo = vehicleId;
}
public boolean isAttached() {
return attachedTo != -1;
}
public int getAttachedEntity() {
return attachedTo;
}
public void deteach() {
attachedTo = -1;
}
}

View File

@ -0,0 +1,60 @@
/*
* 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 PacketAttachEntity implements ClientboundPacket {
int entityId;
int vehicleId;
boolean leash;
@Override
public void read(InPacketBuffer buffer, ProtocolVersion v) {
switch (v) {
case VERSION_1_7_10:
this.entityId = buffer.readInteger();
this.vehicleId = buffer.readInteger();
this.leash = buffer.readBoolean();
break;
}
}
@Override
public void log() {
Log.protocol(String.format("Attaching entity %d to entity %d (leash=%s)", entityId, vehicleId, leash));
}
@Override
public void handle(PacketHandler h) {
h.handle(this);
}
public int getEntityId() {
return entityId;
}
public int getVehicleId() {
return vehicleId;
}
public boolean isLeash() {
return leash;
}
}

View File

@ -282,4 +282,9 @@ public class PacketHandler {
connection.getPlayer().setSpawnConfirmed(true);
}
}
public void handle(PacketAttachEntity pkg) {
connection.getPlayer().getWorld().getEntity(pkg.getEntityId()).attachTo(pkg.getVehicleId());
//ToDo leash support
}
}

View File

@ -81,6 +81,7 @@ public interface Protocol {
packetClassMapping.put(Packets.Clientbound.PLAY_ENTITY_STATUS, PacketEntityStatus.class);
packetClassMapping.put(Packets.Clientbound.PLAY_SOUND_EFFECT, PacketSoundEffect.class);
packetClassMapping.put(Packets.Clientbound.PLAY_PLAYER_POSITION_AND_LOOK, PacketPlayerPositionAndRotation.class);
packetClassMapping.put(Packets.Clientbound.PLAY_ATTACH_ENTITY, PacketAttachEntity.class);
}
int getProtocolVersion();