Java Code Examples for com.nukkitx.math.vector.Vector3f#add()

The following examples show how to use com.nukkitx.math.vector.Vector3f#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaintingEntity.java    From Geyser with MIT License 6 votes vote down vote up
public Vector3f fixOffset(boolean toBedrock) {
    if (toBedrock) {
        Vector3f position = super.position;
        position = position.add(0.5, 0.5, 0.5);
        double widthOffset = paintingName.getWidth() > 1 ? 0.5 : 0;
        double heightOffset = paintingName.getHeight() > 1 && paintingName.getHeight() != 3 ? 0.5 : 0;

        switch (direction) {
            case 0: return position.add(widthOffset, heightOffset, OFFSET);
            case 1: return position.add(-OFFSET, heightOffset, widthOffset);
            case 2: return position.add(-widthOffset, heightOffset, -OFFSET);
            case 3: return position.add(OFFSET, heightOffset, -widthOffset);
        }
    }
    return position;
}
 
Example 2
Source File: ArmorStandEntity.java    From Geyser with MIT License 5 votes vote down vote up
@Override
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
    // Fake the height to be above where it is so the nametag appears in the right location for invisible non-marker armour stands
    if (!isMarker && isInvisible) {
        position = position.add(0d, entityType.getHeight() * (isSmall ? 0.55d : 1d), 0d);
    }

    super.moveAbsolute(session, position, rotation, isOnGround, teleported);
}
 
Example 3
Source File: LeashKnotEntity.java    From Geyser with MIT License 4 votes vote down vote up
public LeashKnotEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
    // Position is incorrect by default
    super(entityId, geyserId, entityType, position.add(0.5f, 0.25f, 0.5f), motion, rotation);
}
 
Example 4
Source File: MinecartEntity.java    From Geyser with MIT License 4 votes vote down vote up
public MinecartEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
    super(entityId, geyserId, entityType, position.add(0d, entityType.getOffset(), 0d), motion, rotation);
}
 
Example 5
Source File: MinecartEntity.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
    super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), rotation, isOnGround, teleported);
}
 
Example 6
Source File: BoatEntity.java    From Geyser with MIT License 4 votes vote down vote up
public BoatEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
    super(entityId, geyserId, entityType, position.add(0d, entityType.getOffset(), 0d), motion, rotation.add(90, 0, 90));
}
 
Example 7
Source File: BoatEntity.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rotation, boolean isOnGround, boolean teleported) {
    // We don't include the rotation (y) as it causes the boat to appear sideways
    super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), Vector3f.from(rotation.getX() + 90, 0, rotation.getX() + 90), isOnGround, teleported);
}
 
Example 8
Source File: PlayerEntity.java    From Geyser with MIT License 4 votes vote down vote up
@Override
public void setPosition(Vector3f position) {
    this.position = position.add(0, entityType.getOffset(), 0);
}
 
Example 9
Source File: JavaEntitySetPassengersTranslator.java    From Geyser with MIT License 4 votes vote down vote up
private void updateOffset(Entity passenger, EntityType mountType, GeyserSession session, boolean rider, boolean riding, boolean moreThanOneEntity) {
    // Without the Y offset, Bedrock players will find themselves in the floor when mounting
    float yOffset = 0;
    switch (mountType) {
        case BOAT:
            yOffset = passenger.getEntityType() == EntityType.PLAYER ? 1.02001f : -0.2f;
            break;
        case MINECART:
            yOffset = passenger.getEntityType() == EntityType.PLAYER ? 1.02001f : 0f;
            break;
        case DONKEY:
            yOffset = 2.1f;
            break;
        case HORSE:
        case SKELETON_HORSE:
        case ZOMBIE_HORSE:
        case MULE:
            yOffset = 2.3f;
            break;
        case LLAMA:
        case TRADER_LLAMA:
            yOffset = 2.5f;
            break;
        case PIG:
            yOffset = 1.85001f;
            break;
        case ARMOR_STAND:
            yOffset = 1.3f;
            break;
    }
    Vector3f offset = Vector3f.from(0f, yOffset, 0f);
    // Without the X offset, more than one entity on a boat is stacked on top of each other
    if (rider && moreThanOneEntity) {
        offset = offset.add(Vector3f.from(0.2, 0, 0));
    } else if (moreThanOneEntity) {
        offset = offset.add(Vector3f.from(-0.6, 0, 0));
    }
    passenger.getMetadata().getFlags().setFlag(EntityFlag.RIDING, riding);
    if (riding) {
        passenger.getMetadata().put(EntityData.RIDER_SEAT_POSITION, offset);
    }
    passenger.updateBedrockMetadata(session);
}