Skip to content

Commit

Permalink
Fix mounted players teleported to void when ship is destroyed #601
Browse files Browse the repository at this point in the history
  • Loading branch information
StewStrong committed Oct 15, 2023
1 parent babd287 commit 4861dfb
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@ import net.minecraft.network.protocol.Packet
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket
import net.minecraft.world.entity.Entity
import net.minecraft.world.entity.EntityType
import net.minecraft.world.entity.LivingEntity
import net.minecraft.world.level.Level
import net.minecraft.world.phys.Vec3
import org.joml.Vector3f
import org.valkyrienskies.core.api.ships.LoadedServerShip
import org.valkyrienskies.core.api.ships.setAttachment
import org.valkyrienskies.core.impl.networking.simple.sendToServer
import org.valkyrienskies.mod.api.SeatedControllingPlayer
import org.valkyrienskies.mod.common.config.VSKeyBindings
import org.valkyrienskies.mod.common.getShipManagingPos
import org.valkyrienskies.mod.common.getShipObjectEntityMountedTo
import org.valkyrienskies.mod.common.getShipObjectManagingPos
import org.valkyrienskies.mod.common.isBlockInShipyard
import org.valkyrienskies.mod.common.networking.PacketPlayerDriving

open class ShipMountingEntity(type: EntityType<ShipMountingEntity>, level: Level) : Entity(type, level) {

// Decides if this entity controlls the ship it is in.
// Decides if this entity controls the ship it is in.
// Only needs to be set serverside
var isController = false

Expand All @@ -37,18 +41,36 @@ open class ShipMountingEntity(type: EntityType<ShipMountingEntity>, level: Level
return
}

if (level.getShipObjectManagingPos(blockPosition()!!) != null)
if (level.getShipObjectManagingPos(blockPosition()) != null)
sendDrivingPacket()
}

override fun readAdditionalSaveData(compound: CompoundTag?) {
// This is a partial fix for mounting ships that have been deleted
// TODO: Make a full fix eventually
override fun positionRider(entity: Entity) {
if (level.isBlockInShipyard(position()) && level.getShipManagingPos(position()) == null) {
// Stop rider positioning if we can't find the ship
entity.removeVehicle()
return
}
super.positionRider(entity)
}

override fun addAdditionalSaveData(compound: CompoundTag?) {
// This is a partial fix for mounting ships that have been deleted
// TODO: Make a full fix eventually
override fun getDismountLocationForPassenger(livingEntity: LivingEntity): Vec3 {
if (level.isBlockInShipyard(position()) && level.getShipManagingPos(position()) == null) {
// Don't teleport to the ship if we can't find the ship
return livingEntity.position()
}
return super.getDismountLocationForPassenger(livingEntity)
}

override fun defineSynchedData() {
}
override fun readAdditionalSaveData(compound: CompoundTag) {}

override fun addAdditionalSaveData(compound: CompoundTag) {}

override fun defineSynchedData() {}

override fun remove(removalReason: RemovalReason) {
if (this.isController && !level.isClientSide)
Expand Down

0 comments on commit 4861dfb

Please sign in to comment.