Yarn: Confusing method names for FishingBobberEntity

Created on 10 Aug 2020  路  7Comments  路  Source: FabricMC/yarn

method_6947: getOwner()PlayerEntity should be renamed to getPlayerEntity to remove confusion with method_24921: getOwner()Entity and annoying stack overflows

refactor

Most helpful comment

Then I'd suggest getPlayerOwner. A similar case where a type conversion from basic entity to a player entity also happens in server command source, though that method throws than return null.

All 7 comments

getPlayerEntity is definitely a bad name. What's the player's relation to the fishing bobber?

The player casted the fishing bobber

it could also be getCaster()

so getOwner is the entity the bobber stuck on? Needs a better name as well, like getStuckOnEntity (someone think of a more concise name)

no getOwner is from projectile entity, and that can be for arrows or fireballs etc. the getOwner from the bobber returns the the same the the other, just cast to a player entity

// FishingBobberEntity
public PlayerEntity getOwner() {
    Entity owner = this.getOwner();
    return owner instanceof PlayerEntity ? (PlayerEntity) owner : null;
}

// ProjectileEntity
public Entity getOwner() {
    if (this.ownerUuid != null && this.world instanceof ServerWorld) {
        return ((ServerWorld) this.world).getEntity(this.ownerUuid);
    } else {
        return this.ownerEntityId == 0 ? null : this.world.getEntityById(this.ownerEntityId);
    }
}

Then I'd suggest getPlayerOwner. A similar case where a type conversion from basic entity to a player entity also happens in server command source, though that method throws than return null.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Boundarybreaker picture Boundarybreaker  路  3Comments

ChloeDawn picture ChloeDawn  路  6Comments

Runemoro picture Runemoro  路  3Comments

altrisi picture altrisi  路  4Comments

Bixilon picture Bixilon  路  5Comments