Search in sources :

Example 51 with BlockHitResult

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

the class ArmInteractionPointHandler method checkForWrench.

private static void checkForWrench(ItemStack heldItem) {
    if (!AllItems.WRENCH.isIn(heldItem)) {
        return;
    }
    HitResult objectMouseOver = Minecraft.getInstance().hitResult;
    if (!(objectMouseOver instanceof BlockHitResult)) {
        return;
    }
    BlockHitResult result = (BlockHitResult) objectMouseOver;
    BlockPos pos = result.getBlockPos();
    BlockEntity te = Minecraft.getInstance().level.getBlockEntity(pos);
    if (!(te instanceof ArmTileEntity)) {
        lastBlockPos = -1;
        currentSelection.clear();
        return;
    }
    if (lastBlockPos == -1 || lastBlockPos != pos.asLong()) {
        currentSelection.clear();
        ArmTileEntity arm = (ArmTileEntity) te;
        arm.inputs.forEach(ArmInteractionPointHandler::put);
        arm.outputs.forEach(ArmInteractionPointHandler::put);
        lastBlockPos = pos.asLong();
    }
    if (lastBlockPos != -1) {
        drawOutlines(currentSelection);
    }
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 52 with BlockHitResult

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

the class EdgeInteractionHandler method onBlockActivated.

@SubscribeEvent
public static void onBlockActivated(PlayerInteractEvent.RightClickBlock event) {
    Level world = event.getWorld();
    BlockPos pos = event.getPos();
    Player player = event.getPlayer();
    InteractionHand hand = event.getHand();
    ItemStack heldItem = player.getItemInHand(hand);
    if (player.isShiftKeyDown() || player.isSpectator())
        return;
    EdgeInteractionBehaviour behaviour = TileEntityBehaviour.get(world, pos, EdgeInteractionBehaviour.TYPE);
    if (behaviour == null)
        return;
    BlockHitResult ray = RaycastHelper.rayTraceRange(world, player, 10);
    if (ray == null)
        return;
    if (behaviour.requiredItem.orElse(heldItem.getItem()) != heldItem.getItem())
        return;
    Direction activatedDirection = getActivatedDirection(world, pos, ray.getDirection(), ray.getLocation(), behaviour);
    if (activatedDirection == null)
        return;
    if (event.getSide() != LogicalSide.CLIENT)
        behaviour.connectionCallback.apply(world, pos, pos.relative(activatedDirection));
    event.setCanceled(true);
    event.setCancellationResult(InteractionResult.SUCCESS);
    world.playSound(null, pos, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, .25f, .1f);
}
Also used : Player(net.minecraft.world.entity.player.Player) InteractionHand(net.minecraft.world.InteractionHand) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Direction(net.minecraft.core.Direction) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 53 with BlockHitResult

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

the class EdgeInteractionRenderer method tick.

public static void tick() {
    Minecraft mc = Minecraft.getInstance();
    HitResult target = mc.hitResult;
    if (target == null || !(target instanceof BlockHitResult))
        return;
    BlockHitResult result = (BlockHitResult) target;
    ClientLevel world = mc.level;
    BlockPos pos = result.getBlockPos();
    Player player = mc.player;
    ItemStack heldItem = player.getMainHandItem();
    if (player.isShiftKeyDown())
        return;
    EdgeInteractionBehaviour behaviour = TileEntityBehaviour.get(world, pos, EdgeInteractionBehaviour.TYPE);
    if (behaviour == null)
        return;
    if (behaviour.requiredItem.orElse(heldItem.getItem()) != heldItem.getItem())
        return;
    Direction face = result.getDirection();
    List<Direction> connectiveSides = EdgeInteractionHandler.getConnectiveSides(world, pos, face, behaviour);
    if (connectiveSides.isEmpty())
        return;
    Direction closestEdge = connectiveSides.get(0);
    double bestDistance = Double.MAX_VALUE;
    Vec3 center = VecHelper.getCenterOf(pos);
    for (Direction direction : connectiveSides) {
        double distance = Vec3.atLowerCornerOf(direction.getNormal()).subtract(target.getLocation().subtract(center)).length();
        if (distance > bestDistance)
            continue;
        bestDistance = distance;
        closestEdge = direction;
    }
    AABB bb = EdgeInteractionHandler.getBB(pos, closestEdge);
    boolean hit = bb.contains(target.getLocation());
    ValueBox box = new ValueBox(TextComponent.EMPTY, bb.move(-pos.getX(), -pos.getY(), -pos.getZ()), pos);
    Vec3 textOffset = Vec3.ZERO;
    boolean positive = closestEdge.getAxisDirection() == AxisDirection.POSITIVE;
    if (positive) {
        if (face.getAxis().isHorizontal()) {
            if (closestEdge.getAxis().isVertical())
                textOffset = textOffset.add(0, -128, 0);
            else
                textOffset = textOffset.add(-128, 0, 0);
        } else
            textOffset = textOffset.add(-128, 0, 0);
    }
    box.offsetLabel(textOffset).withColors(0x7A6A2C, 0xB79D64).passive(!hit);
    CreateClient.OUTLINER.showValueBox("edge", box).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(face);
}
Also used : Player(net.minecraft.world.entity.player.Player) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Minecraft(net.minecraft.client.Minecraft) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection) BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) ValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) AABB(net.minecraft.world.phys.AABB)

Example 54 with BlockHitResult

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

the class FilteringHandler method onScroll.

@OnlyIn(Dist.CLIENT)
public static boolean onScroll(double delta) {
    HitResult objectMouseOver = Minecraft.getInstance().hitResult;
    if (!(objectMouseOver instanceof BlockHitResult))
        return false;
    BlockHitResult result = (BlockHitResult) objectMouseOver;
    Minecraft mc = Minecraft.getInstance();
    ClientLevel world = mc.level;
    BlockPos blockPos = result.getBlockPos();
    FilteringBehaviour filtering = TileEntityBehaviour.get(world, blockPos, FilteringBehaviour.TYPE);
    if (filtering == null)
        return false;
    if (mc.player.isShiftKeyDown())
        return false;
    if (!mc.player.mayBuild())
        return false;
    if (!filtering.isCountVisible())
        return false;
    if (!filtering.isActive())
        return false;
    if (filtering.slotPositioning instanceof ValueBoxTransform.Sided)
        ((Sided) filtering.slotPositioning).fromSide(result.getDirection());
    if (!filtering.testHit(objectMouseOver.getLocation()))
        return false;
    ItemStack filterItem = filtering.getFilter();
    filtering.ticksUntilScrollPacket = 10;
    int maxAmount = (filterItem.getItem() instanceof FilterItem) ? 64 : filterItem.getMaxStackSize();
    int prev = filtering.scrollableValue;
    filtering.scrollableValue = (int) Mth.clamp(filtering.scrollableValue + delta * (AllKeys.ctrlDown() ? 16 : 1), 0, maxAmount);
    if (prev != filtering.scrollableValue) {
        float pitch = (filtering.scrollableValue) / (float) (maxAmount);
        pitch = Mth.lerp(pitch, 1.5f, 2f);
        AllSoundEvents.SCROLL_VALUE.play(world, mc.player, blockPos, 1, pitch);
    }
    return true;
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) Minecraft(net.minecraft.client.Minecraft) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) OnlyIn(net.minecraftforge.api.distmarker.OnlyIn)

Example 55 with BlockHitResult

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

the class FilteringRenderer method tick.

public static void tick() {
    Minecraft mc = Minecraft.getInstance();
    HitResult target = mc.hitResult;
    if (target == null || !(target instanceof BlockHitResult))
        return;
    BlockHitResult result = (BlockHitResult) target;
    ClientLevel world = mc.level;
    BlockPos pos = result.getBlockPos();
    BlockState state = world.getBlockState(pos);
    FilteringBehaviour behaviour = TileEntityBehaviour.get(world, pos, FilteringBehaviour.TYPE);
    if (mc.player.isShiftKeyDown())
        return;
    if (behaviour == null)
        return;
    if (behaviour instanceof SidedFilteringBehaviour) {
        behaviour = ((SidedFilteringBehaviour) behaviour).get(result.getDirection());
        if (behaviour == null)
            return;
    }
    if (!behaviour.isActive())
        return;
    if (behaviour.slotPositioning instanceof ValueBoxTransform.Sided)
        ((Sided) behaviour.slotPositioning).fromSide(result.getDirection());
    if (!behaviour.slotPositioning.shouldRender(state))
        return;
    ItemStack filter = behaviour.getFilter();
    boolean isFilterSlotted = filter.getItem() instanceof FilterItem;
    boolean showCount = behaviour.isCountVisible();
    boolean fluids = behaviour.fluidFilter;
    Component label = isFilterSlotted ? TextComponent.EMPTY : Lang.translate(behaviour.recipeFilter ? "logistics.recipe_filter" : fluids ? "logistics.fluid_filter" : "logistics.filter");
    boolean hit = behaviour.slotPositioning.testHit(state, target.getLocation().subtract(Vec3.atLowerCornerOf(pos)));
    AABB emptyBB = new AABB(Vec3.ZERO, Vec3.ZERO);
    AABB bb = isFilterSlotted ? emptyBB.inflate(.45f, .31f, .2f) : emptyBB.inflate(.25f);
    ValueBox box = showCount ? new ItemValueBox(label, bb, pos, filter, behaviour.scrollableValue) : new ValueBox(label, bb, pos);
    box.offsetLabel(behaviour.textShift).withColors(fluids ? 0x407088 : 0x7A6A2C, fluids ? 0x70adb5 : 0xB79D64).scrollTooltip(showCount && !isFilterSlotted ? new TextComponent("[").append(Lang.translate("action.scroll")).append("]") : TextComponent.EMPTY).passive(!hit);
    CreateClient.OUTLINER.showValueBox(Pair.of("filter", pos), box.transform(behaviour.slotPositioning)).lineWidth(1 / 64f).withFaceTexture(hit ? AllSpecialTextures.THIN_CHECKERED : null).highlightFace(result.getDirection());
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Minecraft(net.minecraft.client.Minecraft) Sided(com.simibubi.create.foundation.tileEntity.behaviour.ValueBoxTransform.Sided) BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) FilterItem(com.simibubi.create.content.logistics.item.filter.FilterItem) BlockState(net.minecraft.world.level.block.state.BlockState) ValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox) ItemValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox.ItemValueBox) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) ItemStack(net.minecraft.world.item.ItemStack) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent) AABB(net.minecraft.world.phys.AABB) ItemValueBox(com.simibubi.create.foundation.tileEntity.behaviour.ValueBox.ItemValueBox)

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