use of net.minecraft.world.phys.BlockHitResult in project Denizen by DenizenScript.
the class EntityHelperImpl method mapTrace.
@Override
public MapTraceResult mapTrace(LivingEntity from, double range) {
Location start = from.getEyeLocation();
Vector startVec = start.toVector();
double xzLen = Math.cos((start.getPitch() % 360) * (Math.PI / 180));
double nx = xzLen * Math.sin(-start.getYaw() * (Math.PI / 180));
double ny = Math.sin(start.getPitch() * (Math.PI / 180));
double nz = xzLen * Math.cos(start.getYaw() * (Math.PI / 180));
Vector endVec = startVec.clone().add(new Vector(nx, -ny, nz).multiply(range));
HitResult l = rayTrace(start.getWorld(), startVec, endVec);
if (!(l instanceof BlockHitResult) || l.getLocation() == null) {
return null;
}
Vector finalVec = new Vector(l.getLocation().x, l.getLocation().y, l.getLocation().z);
MapTraceResult mtr = new MapTraceResult();
switch(((BlockHitResult) l).getDirection()) {
case NORTH:
mtr.angle = BlockFace.NORTH;
break;
case SOUTH:
mtr.angle = BlockFace.SOUTH;
break;
case EAST:
mtr.angle = BlockFace.EAST;
break;
case WEST:
mtr.angle = BlockFace.WEST;
break;
}
// wallPosition - ((end - start).normalize() * 0.072)
Vector hit = finalVec.clone().subtract((endVec.clone().subtract(startVec)).normalize().multiply(0.072));
mtr.hitLocation = new Location(start.getWorld(), hit.getX(), hit.getY(), hit.getZ());
return mtr;
}
use of net.minecraft.world.phys.BlockHitResult in project arnicalib-mcmod by auioc.
the class EntityUtils method getEntityHitResult.
@Nullable
static EntityHitResult getEntityHitResult(Entity entity, double rayLength, float pickRadiusAddition, boolean blockMode) {
Vec3[] viewRay = getEntityViewRay(entity, rayLength);
Vec3 to = viewRay[1];
if (blockMode) {
BlockHitResult rayHitBlock = getBlockHitResult(entity, rayLength, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE);
if (rayHitBlock.getType() != HitResult.Type.MISS) {
to = rayHitBlock.getLocation();
}
}
return getEntityHitResult(entity, viewRay[0], to, pickRadiusAddition);
}
use of net.minecraft.world.phys.BlockHitResult in project arnicalib-mcmod by auioc.
the class EntityUtils method rayHitEntityOrBlockOrMiss.
static int rayHitEntityOrBlockOrMiss(Entity entity, double rayLength, float pickRadiusAddition, ClipContext.Block blockMode, ClipContext.Fluid fluidMode, Function<EntityHitResult, Integer> e, Function<BlockHitResult, Integer> b, Function<BlockHitResult, Integer> m) {
EntityHitResult rayHitEntity = getEntityHitResult(entity, rayLength, pickRadiusAddition, false);
if (rayHitEntity != null) {
return e.apply(rayHitEntity);
}
BlockHitResult rayHitBlock = getBlockHitResult(entity, rayLength, blockMode, fluidMode);
if (rayHitBlock.getType() != HitResult.Type.MISS) {
return b.apply(rayHitBlock);
} else {
return m.apply(rayHitBlock);
}
}
use of net.minecraft.world.phys.BlockHitResult in project FastAsyncWorldEdit by IntellectualSites.
the class PaperweightAdapter method simulateItemUse.
@Override
public boolean simulateItemUse(org.bukkit.World world, BlockVector3 position, BaseItem item, Direction face) {
CraftWorld craftWorld = (CraftWorld) world;
ServerLevel worldServer = craftWorld.getHandle();
ItemStack stack = CraftItemStack.asNMSCopy(BukkitAdapter.adapt(item instanceof BaseItemStack ? ((BaseItemStack) item) : new BaseItemStack(item.getType(), item.getNbtData(), 1)));
stack.setTag((net.minecraft.nbt.CompoundTag) fromNative(item.getNbtData()));
PaperweightFakePlayer fakePlayer;
try {
fakePlayer = fakePlayers.get(worldServer);
} catch (ExecutionException ignored) {
return false;
}
fakePlayer.setItemInHand(InteractionHand.MAIN_HAND, stack);
fakePlayer.absMoveTo(position.getBlockX(), position.getBlockY(), position.getBlockZ(), (float) face.toVector().toYaw(), (float) face.toVector().toPitch());
final BlockPos blockPos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ());
final Vec3 blockVec = Vec3.atLowerCornerOf(blockPos);
final net.minecraft.core.Direction enumFacing = adapt(face);
BlockHitResult rayTrace = new BlockHitResult(blockVec, enumFacing, blockPos, false);
UseOnContext context = new UseOnContext(fakePlayer, InteractionHand.MAIN_HAND, rayTrace);
InteractionResult result = stack.useOn(context, InteractionHand.MAIN_HAND);
if (result != InteractionResult.SUCCESS) {
if (worldServer.getBlockState(blockPos).use(worldServer, fakePlayer, InteractionHand.MAIN_HAND, rayTrace).consumesAction()) {
result = InteractionResult.SUCCESS;
} else {
result = stack.getItem().use(worldServer, fakePlayer, InteractionHand.MAIN_HAND).getResult();
}
}
return result == InteractionResult.SUCCESS;
}
use of net.minecraft.world.phys.BlockHitResult in project Applied-Energistics-2 by AppliedEnergistics.
the class MemoryCardItem method onItemUseFirst.
@Override
public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
var player = context.getPlayer();
if (player != null && InteractionUtil.isInAlternateUseMode(player)) {
var level = context.getLevel();
if (!level.isClientSide()) {
var state = context.getLevel().getBlockState(context.getClickedPos());
var useResult = state.use(context.getLevel(), context.getPlayer(), context.getHand(), new BlockHitResult(context.getClickLocation(), context.getClickedFace(), context.getClickedPos(), context.isInside()));
if (!useResult.consumesAction()) {
clearCard(context.getPlayer(), context.getLevel(), context.getHand());
}
}
return InteractionResult.sidedSuccess(level.isClientSide());
}
return InteractionResult.PASS;
}
Aggregations