Java Code Examples for net.minecraft.entity.Entity#refreshPositionAndAngles()

The following examples show how to use net.minecraft.entity.Entity#refreshPositionAndAngles() . 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: EntityValue.java    From fabric-carpet with MIT License 6 votes vote down vote up
private static void updatePosition(Entity e, double x, double y, double z, float yaw, float pitch)
{
    if (
            !Double.isFinite(x) || Double.isNaN(x) ||
            !Double.isFinite(y) || Double.isNaN(y) ||
            !Double.isFinite(z) || Double.isNaN(z) ||
            !Float.isFinite(yaw) || Float.isNaN(yaw) ||
            !Float.isFinite(pitch) || Float.isNaN(pitch)
    )
        return;
    if (e instanceof ServerPlayerEntity)
    {
        // this forces position but doesn't angles for some reason. Need both in the API in the future.
        EnumSet<PlayerPositionLookS2CPacket.Flag> set  = EnumSet.noneOf(PlayerPositionLookS2CPacket.Flag.class);
        set.add(PlayerPositionLookS2CPacket.Flag.X_ROT);
        set.add(PlayerPositionLookS2CPacket.Flag.Y_ROT);
        ((ServerPlayerEntity)e).networkHandler.teleportRequest(x, y, z, yaw, pitch, set );
    }
    else
    {
        e.refreshPositionAndAngles(x, y, z, yaw, pitch);
        ((ServerWorld) e.getEntityWorld()).getChunkManager().sendToNearbyPlayers(e, new EntityPositionS2CPacket(e));
    }

}
 
Example 2
Source File: Entity_portalSuffocationMixin.java    From fabric-carpet with MIT License 5 votes vote down vote up
@Redirect(method = "changeDimension", at = @At(
        value = "INVOKE",
        target = "Lnet/minecraft/entity/Entity;refreshPositionAndAngles(Lnet/minecraft/util/math/BlockPos;FF)V"
))
private void alternativeSetPositionAndAngles(Entity entity, BlockPos blockPos_1, float float_1, float float_2)
{
    if (CarpetSettings.portalSuffocationFix && CarpetSettings.fixedPosition != null)
        entity.refreshPositionAndAngles(CarpetSettings.fixedPosition.x, CarpetSettings.fixedPosition.y, CarpetSettings.fixedPosition.z, float_1, float_2);
    else
        entity.refreshPositionAndAngles(blockPos_1, float_1, float_2);
}