Search in sources :

Example 16 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project fabric by FabricMC.

the class PickBlockEventModClient method onInitializeClient.

@Override
public void onInitializeClient() {
    ClientPickBlockGatherCallback.EVENT.register((player, result) -> {
        if (result instanceof BlockHitResult) {
            BlockView view = player.getEntityWorld();
            BlockPos pos = ((BlockHitResult) result).getBlockPos();
            BlockState state = view.getBlockState(pos);
            if (state.getBlock() == Blocks.STONE) {
                return new ItemStack(Blocks.OAK_WOOD);
            }
        }
        return ItemStack.EMPTY;
    });
    ClientPickBlockApplyCallback.EVENT.register((player, result, stack) -> {
        if (stack.getItem() == Item.getItemFromBlock(Blocks.OAK_WOOD)) {
            return new ItemStack(Blocks.ACACIA_WOOD);
        } else {
            return stack;
        }
    });
}
Also used : BlockView(net.minecraft.world.BlockView) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ItemStack(net.minecraft.item.ItemStack)

Example 17 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project KahzerxMod by otakucraft.

the class GuiPlayer method tick.

public void tick() {
    if (isOpen && shouldClose()) {
        closePanel();
    }
    if (scrolled > 0) {
        scrolled--;
    }
    if (isOpen) {
        if (gui != null && gui.shouldRender(this)) {
            gui.render(this);
            gui.setReRender(false);
        }
        BlockHitResult hit = Box.raycast(List.of(panelBox), player.getCameraPosVec(1f), player.getCameraPosVec(1f).add(player.getRotationVec(1f).multiply(20)), new BlockPos(0, 0, 0));
        int newX;
        int newY;
        if (hit != null && hit.getSide() == panelFacingSide) {
            double dx = panelCorner1.getX() - hit.getPos().getX();
            double dy = panelCorner1.getY() - hit.getPos().getY() + 1;
            double dz = panelCorner1.getZ() - hit.getPos().getZ();
            if (panelFacingSide != Direction.NORTH) {
                dx = -dx;
            } else {
                dx += 1;
            }
            if (panelFacingSide != Direction.EAST) {
                dz = -dz;
            } else {
                dz += 1;
            }
            newX = (int) ((panelFacingSide.getAxis() == Direction.Axis.Z ? dx : dz) * MapGui.MAP_WIDTH);
            newY = (int) (dy * MapGui.MAP_HEIGHT);
            if (newX != oldX || newY != oldY) {
                onMouseChange(newX, newY, oldX, oldY);
                oldX = newX;
                oldY = newY;
            }
            for (int i = 0; i < panelSize; i++) {
                MapGui g = maps.get(i);
                if (g.shouldUpdate()) {
                    g.sendData();
                }
            }
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 18 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project orion by AntiCope.

the class AutoBedCraft method openCraftingTable.

private void openCraftingTable(BlockPos tablePos) {
    Vec3d tableVec = new Vec3d(tablePos.getX(), tablePos.getY(), tablePos.getZ());
    BlockHitResult table = new BlockHitResult(tableVec, Direction.UP, tablePos, false);
    mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, table);
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 19 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project orion by AntiCope.

the class AutoCityPlus method getDirection.

private Direction getDirection(BlockPos pos) {
    // stolen from supakeks ez
    Vec3d eyesPos = new Vec3d(mc.player.getX(), mc.player.getY() + mc.player.getEyeHeight(mc.player.getPose()), mc.player.getZ());
    for (Direction direction : Direction.values()) {
        RaycastContext raycastContext = new RaycastContext(eyesPos, new Vec3d(pos.getX() + 0.5 + direction.getVector().getX() * 0.5, pos.getY() + 0.5 + direction.getVector().getY() * 0.5, pos.getZ() + 0.5 + direction.getVector().getZ() * 0.5), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, mc.player);
        BlockHitResult result = mc.world.raycast(raycastContext);
        if (result != null && result.getType() == HitResult.Type.BLOCK && result.getBlockPos().equals(pos)) {
            return direction;
        }
    }
    if ((double) pos.getY() > eyesPos.y) {
        // The player can never see the top of a block if they are under it
        return Direction.DOWN;
    }
    return Direction.UP;
}
Also used : RaycastContext(net.minecraft.world.RaycastContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Direction(net.minecraft.util.math.Direction) Vec3d(net.minecraft.util.math.Vec3d)

Example 20 with BlockHitResult

use of net.minecraft.util.hit.BlockHitResult in project wildmod by Osmiooo.

the class FrogSpawnItem method use.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    BlockHitResult blockHitResult = FrogSpawnItem.raycast(world, user, RaycastContext.FluidHandling.SOURCE_ONLY);
    BlockHitResult blockHitResult2 = blockHitResult.withBlockPos(blockHitResult.getBlockPos().up());
    ActionResult actionResult = super.useOnBlock(new ItemUsageContext(user, hand, blockHitResult2));
    return new TypedActionResult<ItemStack>(actionResult, user.getStackInHand(hand));
}
Also used : TypedActionResult(net.minecraft.util.TypedActionResult) ActionResult(net.minecraft.util.ActionResult) ItemUsageContext(net.minecraft.item.ItemUsageContext) BlockHitResult(net.minecraft.util.hit.BlockHitResult) TypedActionResult(net.minecraft.util.TypedActionResult)

Aggregations

BlockHitResult (net.minecraft.util.hit.BlockHitResult)83 BlockPos (net.minecraft.util.math.BlockPos)45 Vec3d (net.minecraft.util.math.Vec3d)36 Direction (net.minecraft.util.math.Direction)20 Hand (net.minecraft.util.Hand)17 BlockState (net.minecraft.block.BlockState)15 HitResult (net.minecraft.util.hit.HitResult)14 RaycastContext (net.minecraft.world.RaycastContext)13 BlockEntity (net.minecraft.block.entity.BlockEntity)12 ItemStack (net.minecraft.item.ItemStack)11 PlayerInteractBlockC2SPacket (net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket)11 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 Box (net.minecraft.util.math.Box)10 PlayerMoveC2SPacket (net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket)9 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)9 List (java.util.List)8 EventHandler (meteordevelopment.orbit.EventHandler)8 Entity (net.minecraft.entity.Entity)8 World (net.minecraft.world.World)6 ArrayList (java.util.ArrayList)5