Search in sources :

Example 61 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project Create by Creators-of-Create.

the class SchematicToolBase method updateTargetPos.

public void updateTargetPos() {
    LocalPlayer player = Minecraft.getInstance().player;
    // Select Blueprint
    if (schematicHandler.isDeployed()) {
        SchematicTransformation transformation = schematicHandler.getTransformation();
        AABB localBounds = schematicHandler.getBounds();
        Vec3 traceOrigin = RaycastHelper.getTraceOrigin(player);
        Vec3 start = transformation.toLocalSpace(traceOrigin);
        Vec3 end = transformation.toLocalSpace(RaycastHelper.getTraceTarget(player, 70, traceOrigin));
        PredicateTraceResult result = RaycastHelper.rayTraceUntil(start, end, pos -> localBounds.contains(VecHelper.getCenterOf(pos)));
        schematicSelected = !result.missed();
        selectedFace = schematicSelected ? result.getFacing() : null;
    }
    boolean snap = this.selectedPos == null;
    // Select location at distance
    if (selectIgnoreBlocks) {
        float pt = AnimationTickHolder.getPartialTicks();
        selectedPos = new BlockPos(player.getEyePosition(pt).add(player.getLookAngle().scale(selectionRange)));
        if (snap)
            lastChasingSelectedPos = chasingSelectedPos = Vec3.atLowerCornerOf(selectedPos);
        return;
    }
    // Select targeted Block
    selectedPos = null;
    BlockHitResult trace = RaycastHelper.rayTraceRange(player.level, player, 75);
    if (trace == null || trace.getType() != Type.BLOCK)
        return;
    BlockPos hit = new BlockPos(trace.getLocation());
    boolean replaceable = player.level.getBlockState(hit).getMaterial().isReplaceable();
    if (trace.getDirection().getAxis().isVertical() && !replaceable)
        hit = hit.relative(trace.getDirection());
    selectedPos = hit;
    if (snap)
        lastChasingSelectedPos = chasingSelectedPos = Vec3.atLowerCornerOf(selectedPos);
}
Also used : LocalPlayer(net.minecraft.client.player.LocalPlayer) Vec3(net.minecraft.world.phys.Vec3) SchematicTransformation(com.simibubi.create.content.schematics.client.SchematicTransformation) PredicateTraceResult(com.simibubi.create.foundation.utility.RaycastHelper.PredicateTraceResult) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) AABB(net.minecraft.world.phys.AABB)

Example 62 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project fabric-carpet by gnembon.

the class ServerGamePacketListenerImpl_scarpetEventsMixin method onBlockInteracted.

@Inject(method = "handleUseItemOn", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayerGameMode;useItemOn(Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/item/ItemStack;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;"))
private void onBlockInteracted(ServerboundUseItemOnPacket playerInteractBlockC2SPacket_1, CallbackInfo ci) {
    if (PLAYER_RIGHT_CLICKS_BLOCK.isNeeded()) {
        InteractionHand hand = playerInteractBlockC2SPacket_1.getHand();
        BlockHitResult hitRes = playerInteractBlockC2SPacket_1.getHitResult();
        PLAYER_RIGHT_CLICKS_BLOCK.onBlockHit(player, hand, hitRes);
    }
}
Also used : InteractionHand(net.minecraft.world.InteractionHand) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 63 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project RayTraceAntiXray by stonar96.

the class RayTraceAntiXray method getMaxZoom.

private double getMaxZoom(Entity entity, Location location, Vector direction, double maxZoom) {
    Vec3 position = new Vec3(location.getX(), location.getY(), location.getZ());
    for (int i = 0; i < 8; i++) {
        float edgeX = (float) ((i & 1) * 2 - 1);
        float edgeY = (float) ((i >> 1 & 1) * 2 - 1);
        float edgeZ = (float) ((i >> 2 & 1) * 2 - 1);
        edgeX = edgeX * 0.1f;
        edgeY = edgeY * 0.1f;
        edgeZ = edgeZ * 0.1f;
        Vec3 edge = position.add(edgeX, edgeY, edgeZ);
        Vec3 edgeMoved = new Vec3(position.x - direction.getX() * maxZoom + (double) edgeX + (double) edgeZ, position.y - direction.getY() * maxZoom + (double) edgeY, position.z - direction.getZ() * maxZoom + (double) edgeZ);
        BlockHitResult result = ((CraftWorld) location.getWorld()).getHandle().clip(new ClipContext(edge, edgeMoved, ClipContext.Block.VISUAL, ClipContext.Fluid.NONE, ((CraftEntity) entity).getHandle()));
        if (result.getType() != HitResult.Type.MISS) {
            double zoom = result.getLocation().distanceTo(position);
            if (zoom < maxZoom) {
                maxZoom = zoom;
            }
        }
    }
    return maxZoom;
}
Also used : ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) CraftEntity(org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 64 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project Mohist by MohistMC.

the class CraftRayTraceResult method fromNMS.

public static RayTraceResult fromNMS(World world, HitResult nmsHitResult) {
    if (nmsHitResult == null || nmsHitResult.getType() == Type.MISS)
        return null;
    Vec3 nmsHitPos = nmsHitResult.getLocation();
    Vector hitPosition = new Vector(nmsHitPos.x, nmsHitPos.y, nmsHitPos.z);
    BlockFace hitBlockFace = null;
    if (nmsHitResult.getType() == Type.ENTITY) {
        Entity hitEntity = ((EntityHitResult) nmsHitResult).getEntity().getBukkitEntity();
        return new RayTraceResult(hitPosition, hitEntity, null);
    }
    Block hitBlock = null;
    BlockPos nmsBlockPos = null;
    if (nmsHitResult.getType() == Type.BLOCK) {
        BlockHitResult blockHitResult = (BlockHitResult) nmsHitResult;
        hitBlockFace = CraftBlock.notchToBlockFace(blockHitResult.getDirection());
        nmsBlockPos = blockHitResult.getBlockPos();
    }
    if (nmsBlockPos != null && world != null) {
        hitBlock = world.getBlockAt(nmsBlockPos.getX(), nmsBlockPos.getY(), nmsBlockPos.getZ());
    }
    return new RayTraceResult(hitPosition, hitBlock, hitBlockFace);
}
Also used : Entity(org.bukkit.entity.Entity) BlockFace(org.bukkit.block.BlockFace) Vec3(net.minecraft.world.phys.Vec3) RayTraceResult(org.bukkit.util.RayTraceResult) Block(org.bukkit.block.Block) CraftBlock(org.bukkit.craftbukkit.v1_18_R2.block.CraftBlock) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Vector(org.bukkit.util.Vector)

Example 65 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project AkashicTome by VazkiiMods.

the class HUDHandler method onDrawScreen.

@SubscribeEvent
public void onDrawScreen(RenderGameOverlayEvent.Post event) {
    if (event.getType() != ElementType.ALL)
        return;
    Minecraft mc = Minecraft.getInstance();
    HitResult pos = mc.hitResult;
    Window res = event.getWindow();
    if (pos != null && pos instanceof BlockHitResult) {
        BlockHitResult bpos = (BlockHitResult) pos;
        ItemStack tomeStack = mc.player.getMainHandItem();
        boolean hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome;
        if (!hasTome) {
            tomeStack = mc.player.getOffhandItem();
            hasTome = !tomeStack.isEmpty() && tomeStack.getItem() == ModItems.tome;
        }
        if (!hasTome)
            return;
        tomeStack = tomeStack.copy();
        BlockState state = mc.level.getBlockState(bpos.getBlockPos());
        if (!state.isAir()) {
            ItemStack drawStack = ItemStack.EMPTY;
            String line1 = "";
            String line2 = "";
            String mod = MorphingHandler.getModFromState(state);
            ItemStack morphStack = MorphingHandler.getShiftStackForMod(tomeStack, mod);
            if (!morphStack.isEmpty() && !ItemStack.isSame(morphStack, tomeStack)) {
                drawStack = morphStack;
                line1 = ItemNBTHelper.getCompound(morphStack, MorphingHandler.TAG_TOME_DISPLAY_NAME, false).getString("text");
                line2 = ChatFormatting.GRAY + I18n.get("akashictome.click_morph");
            }
            if (!drawStack.isEmpty()) {
                RenderSystem.enableBlend();
                RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                int sx = res.getGuiScaledWidth() / 2 - 17;
                int sy = res.getGuiScaledHeight() / 2 + 2;
                mc.getItemRenderer().renderGuiItem(drawStack, sx, sy);
                mc.font.drawShadow(event.getMatrixStack(), line1, sx + 20, sy + 4, 0xFFFFFFFF);
                mc.font.drawShadow(event.getMatrixStack(), line2, sx + 25, sy + 14, 0xFFFFFFFF);
            }
        }
    }
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) Window(com.mojang.blaze3d.platform.Window) BlockState(net.minecraft.world.level.block.state.BlockState) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

BlockHitResult (net.minecraft.world.phys.BlockHitResult)181 BlockPos (net.minecraft.core.BlockPos)117 Vec3 (net.minecraft.world.phys.Vec3)79 BlockState (net.minecraft.world.level.block.state.BlockState)66 ItemStack (net.minecraft.world.item.ItemStack)63 HitResult (net.minecraft.world.phys.HitResult)51 Direction (net.minecraft.core.Direction)46 Level (net.minecraft.world.level.Level)41 ClipContext (net.minecraft.world.level.ClipContext)33 Player (net.minecraft.world.entity.player.Player)32 ServerLevel (net.minecraft.server.level.ServerLevel)23 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)20 Entity (net.minecraft.world.entity.Entity)19 InteractionHand (net.minecraft.world.InteractionHand)18 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)18 ServerPlayer (net.minecraft.server.level.ServerPlayer)17 LivingEntity (net.minecraft.world.entity.LivingEntity)17 AABB (net.minecraft.world.phys.AABB)17 EntityHitResult (net.minecraft.world.phys.EntityHitResult)17 Minecraft (net.minecraft.client.Minecraft)16