forked from virt-mirrors/Sit
added sitLooking()
This commit is contained in:
parent
3f008635f0
commit
dd6567b671
2 changed files with 24 additions and 0 deletions
|
@ -42,6 +42,10 @@ public class Logic {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean sitLooking(ServerPlayerEntity player) {
|
||||
return sit(player, Utl.getBlockPosPlayerIsLookingAt(player.getServerWorld(),player,5),null);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks the hands of the player and the items in each hand and sees if the player can sit down
|
||||
*/
|
||||
|
|
|
@ -11,18 +11,23 @@ import net.minecraft.block.enums.BlockHalf;
|
|||
import net.minecraft.block.enums.SlabType;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.TypeFilter;
|
||||
import net.minecraft.util.UseAction;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
import one.oth3r.sit.file.*;
|
||||
import one.oth3r.sit.packet.SitPayloads;
|
||||
|
@ -369,4 +374,19 @@ public class Utl {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockPos getBlockPosPlayerIsLookingAt(ServerWorld world, PlayerEntity player, double range) {
|
||||
// pos, adjusted to player eye level
|
||||
Vec3d rayStart = player.getPos().add(0, player.getEyeHeight(player.getPose()), 0);
|
||||
// extend ray by the range
|
||||
Vec3d rayEnd = rayStart.add(player.getRotationVector().multiply(range));
|
||||
|
||||
BlockHitResult hitResult = world.raycast(new RaycastContext(rayStart, rayEnd, RaycastContext.ShapeType.OUTLINE, RaycastContext.FluidHandling.NONE, ShapeContext.absent()));
|
||||
|
||||
if (hitResult.getType() == HitResult.Type.BLOCK) {
|
||||
return hitResult.getBlockPos();
|
||||
}
|
||||
|
||||
return new BlockPos(player.getBlockPos());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue