mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 17:07:55 -04:00
attach entity support
This commit is contained in:
parent
a51f78aeb1
commit
fef2f20bc9
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user