use of net.minecraft.world.phys.BlockHitResult in project MC-Prefab by Brian-Wuest.
the class GuiStructure method rayTrace.
@Nullable
public static BlockHitResult rayTrace(Vec3 from, Vec3 to, BlockGetter world) {
ClipContext rayTraceContext = new ClipContext(from, to, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null);
BlockHitResult result = world.clip(rayTraceContext);
return result;
}
use of net.minecraft.world.phys.BlockHitResult in project MagicPlugin by elBukkit.
the class CompatibilityUtils method setAutoBlockState.
@Override
public boolean setAutoBlockState(Block block, Location target, BlockFace facing, boolean physics, Player originator) {
if (block == null || facing == null || target == null)
return false;
net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
if (blockState == null)
return false;
net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
ItemStack blockItem = new ItemStack(block.getType());
ServerPlayer originatorHandle = ((CraftPlayer) originator).getHandle();
ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(blockItem));
if (originatorHandle == null || world == null || item == null) {
return false;
}
BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
Vec3 vec3D = new Vec3(target.getX(), target.getY(), target.getZ());
Direction direction;
try {
direction = Direction.valueOf(facing.name());
} catch (Exception ex) {
platform.getLogger().log(Level.SEVERE, "Could not translate to NMS direction: " + facing);
return false;
}
BlockHitResult hitResult = new BlockHitResult(vec3D, direction, blockPosition, false);
BlockPlaceContext actionContext = new BlockPlaceContext(originatorHandle, InteractionHand.MAIN_HAND, (net.minecraft.world.item.ItemStack) item, hitResult);
net.minecraft.world.level.block.state.BlockState state = nmsBlock.getStateForPlacement(actionContext);
if (state == null)
return false;
((CraftBlock) block).setTypeAndData(state, physics);
return true;
}
use of net.minecraft.world.phys.BlockHitResult in project MagicPlugin by elBukkit.
the class CompatibilityUtils method setAutoBlockState.
@Override
public boolean setAutoBlockState(Block block, Location target, BlockFace facing, boolean physics, Player originator) {
if (block == null || facing == null || target == null)
return false;
net.minecraft.world.level.block.state.BlockState blockState = ((CraftBlock) block).getNMS();
if (blockState == null)
return false;
net.minecraft.world.level.block.Block nmsBlock = blockState.getBlock();
ItemStack blockItem = new ItemStack(block.getType());
ServerPlayer originatorHandle = ((CraftPlayer) originator).getHandle();
ServerLevel world = ((CraftWorld) block.getWorld()).getHandle();
Object item = platform.getItemUtils().getHandle(platform.getItemUtils().makeReal(blockItem));
if (originatorHandle == null || world == null || item == null) {
return false;
}
BlockPos blockPosition = new BlockPos(block.getX(), block.getY(), block.getZ());
Vec3 vec3D = new Vec3(target.getX(), target.getY(), target.getZ());
Direction direction;
try {
direction = Direction.valueOf(facing.name());
} catch (Exception ex) {
platform.getLogger().log(Level.SEVERE, "Could not translate to NMS direction: " + facing);
return false;
}
BlockHitResult hitResult = new BlockHitResult(vec3D, direction, blockPosition, false);
BlockPlaceContext actionContext = new BlockPlaceContext(originatorHandle, InteractionHand.MAIN_HAND, (net.minecraft.world.item.ItemStack) item, hitResult);
net.minecraft.world.level.block.state.BlockState state = nmsBlock.getStateForPlacement(actionContext);
if (state == null)
return false;
CraftBlock cBlock = (CraftBlock) block;
CraftBlock.setTypeAndData(cBlock.getHandle(), cBlock.getPosition(), cBlock.getNMS(), state, physics);
return true;
}
use of net.minecraft.world.phys.BlockHitResult in project AlexsMobs by Alex-the-666.
the class AnimalAILootChests method hasLineOfSightChest.
public boolean hasLineOfSightChest() {
HitResult raytraceresult = entity.level.clip(new ClipContext(entity.getEyePosition(1.0F), new Vec3(blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity));
if (raytraceresult instanceof BlockHitResult) {
BlockHitResult blockRayTraceResult = (BlockHitResult) raytraceresult;
BlockPos pos = blockRayTraceResult.getBlockPos();
return pos.equals(blockPos) || entity.level.isEmptyBlock(pos) || this.entity.level.getBlockEntity(pos) == this.entity.level.getBlockEntity(blockPos);
}
return true;
}
use of net.minecraft.world.phys.BlockHitResult in project AlexsMobs by Alex-the-666.
the class EntityVoidWorm method createPortal.
public void createPortal(Vec3 from, Vec3 to, @Nullable Direction outDir) {
if (!level.isClientSide && portalTarget == null) {
Vec3 Vector3d = new Vec3(this.getX(), this.getEyeY(), this.getZ());
HitResult result = this.level.clip(new ClipContext(Vector3d, from, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, this));
Vec3 vec = result.getLocation() != null ? result.getLocation() : this.position();
if (result instanceof BlockHitResult) {
BlockHitResult result1 = (BlockHitResult) result;
vec = vec.add(net.minecraft.world.phys.Vec3.atLowerCornerOf(result1.getDirection().getNormal()));
}
EntityVoidPortal portal = AMEntityRegistry.VOID_PORTAL.create(level);
portal.setPos(vec.x, vec.y, vec.z);
Vec3 dirVec = vec.subtract(this.position());
Direction dir = Direction.getNearest(dirVec.x, dirVec.y, dirVec.z);
portal.setAttachmentFacing(dir);
portal.setLifespan(10000);
if (!level.isClientSide) {
level.addFreshEntity(portal);
}
portalTarget = portal;
portal.setDestination(new BlockPos(to.x, to.y, to.z), outDir);
makePortalCooldown = 300;
}
}
Aggregations