Search in sources :

Example 96 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project refinedstorage by refinedmods.

the class ConstructorNetworkNode method extractAndPlaceBlock.

private void extractAndPlaceBlock(ItemStack stack) {
    ItemStack took = network.extractItem(stack, 1, compare, Action.SIMULATE);
    if (!took.isEmpty()) {
        BlockPlaceContext ctx = new ConstructorBlockItemUseContext(level, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()), InteractionHand.MAIN_HAND, took, new BlockHitResult(Vec3.ZERO, getDirection(), pos, false));
        InteractionResult result = ForgeHooks.onPlaceItemIntoWorld(ctx);
        if (result.consumesAction()) {
            network.extractItem(stack, 1, Action.PERFORM);
        }
    } else if (upgrades.hasUpgrade(UpgradeItem.Type.CRAFTING)) {
        ItemStack craft = itemFilters.getStackInSlot(0);
        network.getCraftingManager().request(this, craft, 1);
    }
}
Also used : InteractionResult(net.minecraft.world.InteractionResult) ServerLevel(net.minecraft.server.level.ServerLevel) BlockPlaceContext(net.minecraft.world.item.context.BlockPlaceContext) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 97 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project refinedstorage by refinedmods.

the class DestructorNetworkNode method breakBlock.

private void breakBlock() {
    BlockPos front = pos.relative(getDirection());
    BlockState frontBlockState = level.getBlockState(front);
    Block frontBlock = frontBlockState.getBlock();
    ItemStack frontStack = frontBlock.getCloneItemStack(frontBlockState, new BlockHitResult(Vec3.ZERO, getDirection().getOpposite(), front, false), level, front, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()));
    if (!frontStack.isEmpty() && IWhitelistBlacklist.acceptsItem(itemFilters, mode, compare, frontStack) && frontBlockState.getDestroySpeed(level, front) != -1.0) {
        List<ItemStack> drops = Block.getDrops(frontBlockState, (ServerLevel) level, front, level.getBlockEntity(front), LevelUtils.getFakePlayer((ServerLevel) level, getOwner()), tool);
        for (ItemStack drop : drops) {
            if (!network.insertItem(drop, drop.getCount(), Action.SIMULATE).isEmpty()) {
                return;
            }
        }
        BlockEvent.BreakEvent e = new BlockEvent.BreakEvent(level, front, frontBlockState, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()));
        if (!MinecraftForge.EVENT_BUS.post(e)) {
            frontBlock.playerWillDestroy(level, front, frontBlockState, LevelUtils.getFakePlayer((ServerLevel) level, getOwner()));
            level.removeBlock(front, false);
            for (ItemStack drop : drops) {
                // it will essentially remove this block itself from the network without knowing
                if (network == null) {
                    Containers.dropItemStack(level, front.getX(), front.getY(), front.getZ(), drop);
                } else {
                    network.insertItemTracked(drop, drop.getCount());
                }
            }
        }
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) BlockState(net.minecraft.world.level.block.state.BlockState) LiquidBlock(net.minecraft.world.level.block.LiquidBlock) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult) BlockEvent(net.minecraftforge.event.world.BlockEvent)

Example 98 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project Electrodynamics by aurilisdev.

the class ItemCanister method useCanister.

public void useCanister(Level world, Player player, InteractionHand hand) {
    ItemStack stack = player.getItemInHand(hand);
    HitResult trace = getPlayerPOVHitResult(world, player, net.minecraft.world.level.ClipContext.Fluid.ANY);
    if (!world.isClientSide && trace.getType() != Type.MISS && trace.getType() != Type.ENTITY) {
        BlockHitResult blockTrace = (BlockHitResult) trace;
        BlockPos pos = blockTrace.getBlockPos();
        BlockState state = world.getBlockState(pos);
        if (state.getFluidState().isSource() && !state.getFluidState().getType().isSame(Fluids.EMPTY)) {
            FluidStack sourceFluid = new FluidStack(state.getFluidState().getType(), 1000);
            boolean validFluid = CapabilityUtils.canFillItemStack(stack, sourceFluid);
            if (validFluid) {
                int amtFilled = CapabilityUtils.simFill(stack, sourceFluid);
                if (amtFilled >= 1000) {
                    CapabilityUtils.fill(stack, sourceFluid);
                    world.setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
                    world.playSound(null, player.blockPosition(), SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 1, 1);
                }
            }
        }
    }
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) BlockState(net.minecraft.world.level.block.state.BlockState) FluidStack(net.minecraftforge.fluids.FluidStack) BlockPos(net.minecraft.core.BlockPos) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) RestrictedFluidHandlerItemStack(electrodynamics.api.fluid.RestrictedFluidHandlerItemStack) ItemStack(net.minecraft.world.item.ItemStack) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 99 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project Supplementaries by MehVahdJukaar.

the class SlingshotRendererHelper method grabNewLookPos.

public static void grabNewLookPos(Player player) {
    float blockRange = 40;
    Level world = player.level;
    Vec3 start = player.position().add(0, player.getEyeHeight(), 0);
    Vec3 range = player.getLookAngle().scale(blockRange);
    BlockHitResult raytrace = world.clip(new ClipContext(start, start.add(range), ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player));
    if (raytrace.getType() == HitResult.Type.BLOCK && start.distanceToSqr(raytrace.getLocation()) > Mth.square(Minecraft.getInstance().gameMode.getPickRange())) {
        LOOK_POS = raytrace.getBlockPos().relative(raytrace.getDirection(), 0);
    }
}
Also used : ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) Level(net.minecraft.world.level.Level) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 100 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project Supplementaries by MehVahdJukaar.

the class BlackboardBlockTileRenderer method render.

@Override
public void render(BlackboardBlockTile tile, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
    Direction dir = tile.getDirection();
    float yaw = -dir.toYRot();
    Vec3 cameraPos = camera.getPosition();
    BlockPos pos = tile.getBlockPos();
    if (LOD.isOutOfFocus(cameraPos, pos, yaw, 0, dir, WIDTH / 16f))
        return;
    // TODO: add glow ink support
    matrixStackIn.pushPose();
    matrixStackIn.translate(0.5, 0.5, 0.5);
    matrixStackIn.mulPose(RotHlpr.rot(dir));
    matrixStackIn.mulPose(RotHlpr.XN90);
    matrixStackIn.translate(-0.5, -0.5, -0.1875);
    int lu = combinedLightIn & '\uffff';
    int lv = combinedLightIn >> 16 & '\uffff';
    HitResult hit = MC.hitResult;
    if (hit != null && hit.getType() == HitResult.Type.BLOCK) {
        BlockHitResult blockHit = (BlockHitResult) hit;
        if (blockHit.getBlockPos().equals(pos) && tile.getDirection() == blockHit.getDirection()) {
            Player player = MC.player;
            if (player != null) {
                if (BlackboardBlock.getStackChalkColor(player.getMainHandItem()) != null) {
                    Pair<Integer, Integer> pair = BlackboardBlock.getHitSubPixel(blockHit);
                    float p = 1 / 16f;
                    float x = pair.getFirst() * p;
                    float y = pair.getSecond() * p;
                    VertexConsumer builder2 = Materials.BLACKBOARD_OUTLINE.buffer(bufferIn, RenderType::entityCutout);
                    matrixStackIn.pushPose();
                    matrixStackIn.translate(x, 1 - y - p, 0.001);
                    RendererUtil.addQuadSide(builder2, matrixStackIn, 0, 0, 0, p, p, 0, 0, 0, 1, 1, 1, 1, 1, 1, lu, lv, 0, 0, 1, Materials.BLACKBOARD_OUTLINE.sprite());
                    matrixStackIn.popPose();
                }
            }
        }
    }
    // VertexConsumer builder = bufferIn.getBuffer(BlackboardTextureManager.INSTANCE.getBlackboardInstance(tile).getRenderType());
    // RendererUtil.addQuadSide(builder, matrixStackIn, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, lu, lv, 0, 0, 1);
    matrixStackIn.popPose();
}
Also used : BlockHitResult(net.minecraft.world.phys.BlockHitResult) HitResult(net.minecraft.world.phys.HitResult) Player(net.minecraft.world.entity.player.Player) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Direction(net.minecraft.core.Direction) RenderType(net.minecraft.client.renderer.RenderType)

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