Search in sources :

Example 6 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.

the class Ghosthand method onTick.

@BleachSubscribe
public void onTick(EventTick event) {
    if (!mc.options.keyUse.isPressed() || mc.player.isSneaking())
        return;
    // Return if we are looking at any block entities
    BlockPos lookingPos = new BlockPos(mc.player.raycast(4.25, mc.getTickDelta(), false).getPos());
    for (BlockEntity b : WorldUtils.getBlockEntities()) {
        if (lookingPos.equals(b.getPos())) {
            return;
        }
    }
    Set<BlockPos> posList = new HashSet<>();
    Vec3d nextPos = new Vec3d(0, 0, 0.1).rotateX(-(float) Math.toRadians(mc.player.getPitch())).rotateY(-(float) Math.toRadians(mc.player.getYaw()));
    for (int i = 1; i < 50; i++) {
        BlockPos curPos = new BlockPos(mc.player.getCameraPosVec(mc.getTickDelta()).add(nextPos.multiply(i)));
        if (!posList.contains(curPos)) {
            posList.add(curPos);
            for (BlockEntity b : WorldUtils.getBlockEntities()) {
                if (b.getPos().equals(curPos)) {
                    mc.interactionManager.interactBlock(mc.player, mc.world, Hand.MAIN_HAND, new BlockHitResult(mc.player.getPos(), Direction.UP, curPos, true));
                    return;
                }
            }
        }
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) Vec3d(net.minecraft.util.math.Vec3d) BlockEntity(net.minecraft.block.entity.BlockEntity) HashSet(java.util.HashSet) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Example 7 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.

the class MixinChunkRebuildTask method newRender.

private Set<BlockEntity> newRender(float cameraX, float cameraY, float cameraZ, ChunkData data, BlockBufferBuilderStorage buffers) {
    BlockPos blockPos = field_20839.getOrigin().toImmutable();
    BlockPos blockPos2 = blockPos.add(15, 15, 15);
    ChunkOcclusionDataBuilder chunkOcclusionDataBuilder = new ChunkOcclusionDataBuilder();
    Set<BlockEntity> set = new HashSet<>();
    ChunkRendererRegion chunkRendererRegion = this.region;
    this.region = null;
    MatrixStack matrixStack = new MatrixStack();
    if (chunkRendererRegion != null) {
        BlockModelRenderer.enableBrightnessCache();
        Random random = new Random();
        BlockRenderManager blockRenderManager = MinecraftClient.getInstance().getBlockRenderManager();
        for (BlockPos blockPos3 : BlockPos.iterate(blockPos, blockPos2)) {
            BlockState blockState = chunkRendererRegion.getBlockState(blockPos3);
            if (blockState.isOpaqueFullCube(chunkRendererRegion, blockPos3)) {
                chunkOcclusionDataBuilder.markClosed(blockPos3);
            }
            if (blockState.hasBlockEntity()) {
                BlockEntity blockEntityx = chunkRendererRegion.getBlockEntity(blockPos3, WorldChunk.CreationType.CHECK);
                if (blockEntityx != null) {
                    this.addBlockEntity(data, set, blockEntityx);
                }
            }
            FluidState fluid = chunkRendererRegion.getFluidState(blockPos3);
            if (!fluid.isEmpty()) {
                RenderLayer renderLayer = RenderLayers.getFluidLayer(fluid);
                BufferBuilder bufferBuilder = buffers.get(renderLayer);
                if (data.initializedLayers.add(renderLayer)) {
                    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                }
                EventRenderFluid event = new EventRenderFluid(fluid, blockPos3, bufferBuilder);
                BleachHack.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                if (blockRenderManager.renderFluid(blockPos3, chunkRendererRegion, bufferBuilder, fluid)) {
                    data.empty = false;
                    data.nonEmptyLayers.add(renderLayer);
                }
            }
            if (blockState.getRenderType() != BlockRenderType.INVISIBLE) {
                RenderLayer renderLayer = RenderLayers.getBlockLayer(blockState);
                BufferBuilder bufferBuilder = buffers.get(renderLayer);
                if (data.initializedLayers.add(renderLayer)) {
                    bufferBuilder.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_LIGHT_NORMAL);
                }
                EventRenderBlock.Tesselate event = new EventRenderBlock.Tesselate(blockState, blockPos3, matrixStack, bufferBuilder);
                BleachHack.eventBus.post(event);
                if (event.isCancelled())
                    continue;
                matrixStack.push();
                matrixStack.translate(blockPos3.getX() & 15, blockPos3.getY() & 15, blockPos3.getZ() & 15);
                if (blockRenderManager.renderBlock(blockState, blockPos3, chunkRendererRegion, matrixStack, bufferBuilder, true, random)) {
                    data.empty = false;
                    data.nonEmptyLayers.add(renderLayer);
                }
                bufferBuilder.unfixColor();
                matrixStack.pop();
            }
        }
        if (data.nonEmptyLayers.contains(RenderLayer.getTranslucent())) {
            BufferBuilder bufferBuilder2 = buffers.get(RenderLayer.getTranslucent());
            bufferBuilder2.setCameraPosition(cameraX - (float) blockPos.getX(), cameraY - (float) blockPos.getY(), cameraZ - (float) blockPos.getZ());
            data.bufferState = bufferBuilder2.popState();
        }
        Stream<RenderLayer> var10000 = data.initializedLayers.stream();
        Objects.requireNonNull(buffers);
        var10000.map(buffers::get).forEach(BufferBuilder::end);
        BlockModelRenderer.disableBrightnessCache();
    }
    data.occlusionGraph = chunkOcclusionDataBuilder.build();
    return set;
}
Also used : ChunkRendererRegion(net.minecraft.client.render.chunk.ChunkRendererRegion) MatrixStack(net.minecraft.client.util.math.MatrixStack) BufferBuilder(net.minecraft.client.render.BufferBuilder) RenderLayer(net.minecraft.client.render.RenderLayer) ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockRenderManager(net.minecraft.client.render.block.BlockRenderManager) EventRenderBlock(org.bleachhack.event.events.EventRenderBlock) EventRenderFluid(org.bleachhack.event.events.EventRenderFluid) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity) HashSet(java.util.HashSet) FluidState(net.minecraft.fluid.FluidState)

Example 8 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project BleachHack by BleachDrinker420.

the class CmdNBT method getNbt.

private NbtCompound getNbt(String arg) {
    if (arg.equalsIgnoreCase("hand")) {
        return mc.player.getMainHandStack().getOrCreateNbt();
    } else if (arg.equalsIgnoreCase("block")) {
        HitResult target = mc.crosshairTarget;
        if (target.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = ((BlockHitResult) target).getBlockPos();
            BlockEntity be = mc.world.getBlockEntity(pos);
            if (be != null) {
                return be.writeNbt(new NbtCompound());
            } else {
                return new NbtCompound();
            }
        }
        BleachLogger.error("Not looking at a block.");
        return null;
    } else if (arg.equalsIgnoreCase("entity")) {
        HitResult target = mc.crosshairTarget;
        if (target.getType() == HitResult.Type.ENTITY) {
            return ((EntityHitResult) target).getEntity().writeNbt(new NbtCompound());
        }
        BleachLogger.error("Not looking at an entity.");
        return null;
    }
    throw new CmdSyntaxException();
}
Also used : BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) EntityHitResult(net.minecraft.util.hit.EntityHitResult) NbtCompound(net.minecraft.nbt.NbtCompound) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) BlockPos(net.minecraft.util.math.BlockPos) BlockEntity(net.minecraft.block.entity.BlockEntity)

Example 9 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project fabric by FabricMC.

the class MixinMinecraftClient method fabric_doItemPickWrapper.

@Inject(at = @At("HEAD"), method = "doItemPick", cancellable = true)
private void fabric_doItemPickWrapper(CallbackInfo info) {
    MinecraftClient client = (MinecraftClient) (Object) this;
    // Do a "best effort" emulation of the old events.
    ItemStack stack = ClientPickBlockGatherCallback.EVENT.invoker().pick(client.player, client.hitResult);
    // TODO: Remove in 0.3.0
    if (stack.isEmpty()) {
        stack = fabric_emulateOldPick();
    }
    if (stack.isEmpty()) {
    // fall through
    } else {
        info.cancel();
        // I don't like that we clone vanilla logic here, but it's our best bet for now.
        PlayerInventory playerInventory = client.player.inventory;
        if (client.player.abilities.creativeMode && Screen.hasControlDown() && client.hitResult.getType() == HitResult.Type.BLOCK) {
            BlockEntity be = client.world.getBlockEntity(((BlockHitResult) client.hitResult).getBlockPos());
            if (be != null) {
                stack = addBlockEntityNbt(stack, be);
            }
        }
        stack = ClientPickBlockApplyCallback.EVENT.invoker().pick(client.player, client.hitResult, stack);
        if (stack.isEmpty()) {
            return;
        }
        if (client.player.abilities.creativeMode) {
            playerInventory.addPickBlock(stack);
            client.interactionManager.clickCreativeStack(client.player.getStackInHand(Hand.MAIN_HAND), 36 + playerInventory.selectedSlot);
        } else {
            int slot = playerInventory.getSlotWithStack(stack);
            if (slot >= 0) {
                if (PlayerInventory.isValidHotbarIndex(slot)) {
                    playerInventory.selectedSlot = slot;
                } else {
                    client.interactionManager.pickFromInventory(slot);
                }
            }
        }
    }
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ItemStack(net.minecraft.item.ItemStack) BlockEntity(net.minecraft.block.entity.BlockEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 10 with BlockEntity

use of net.minecraft.block.entity.BlockEntity in project VeinMining by TheIllusiveC4.

the class VeinMiningLogic method harvest.

public static boolean harvest(ServerPlayerEntity player, BlockPos pos, BlockPos originPos) {
    ServerWorld world = player.getWorld();
    BlockState blockState = world.getBlockState(pos);
    GameMode gameMode = player.interactionManager.getGameMode();
    if (!player.getMainHandStack().getItem().canMine(blockState, world, pos, player)) {
        return false;
    } else {
        BlockEntity blockEntity = world.getBlockEntity(pos);
        Block block = blockState.getBlock();
        if ((block instanceof CommandBlock || block instanceof StructureBlock || block instanceof JigsawBlock) && !player.isCreativeLevelTwoOp()) {
            world.updateListeners(pos, blockState, blockState, 3);
            return false;
        } else if (player.isBlockBreakingRestricted(world, pos, gameMode)) {
            return false;
        } else {
            block.onBreak(world, pos, blockState, player);
            boolean bl = world.removeBlock(pos, false);
            if (bl) {
                block.onBroken(world, pos, blockState);
            }
            if (gameMode != GameMode.CREATIVE) {
                ItemStack itemStack = player.getMainHandStack();
                ItemStack itemStack2 = itemStack.copy();
                boolean bl2 = player.canHarvest(blockState);
                if (VeinMiningConfig.VeinMining.addToolDamage) {
                    postMine(itemStack, world, blockState, pos, player);
                }
                BlockPos spawnPos = VeinMiningConfig.VeinMining.relocateDrops ? originPos : pos;
                if (bl && bl2) {
                    afterBreak(block, world, player, pos, spawnPos, blockState, blockEntity, itemStack2);
                }
            }
            return true;
        }
    }
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) JigsawBlock(net.minecraft.block.JigsawBlock) GameMode(net.minecraft.world.GameMode) BlockState(net.minecraft.block.BlockState) StructureBlock(net.minecraft.block.StructureBlock) CommandBlock(net.minecraft.block.CommandBlock) Block(net.minecraft.block.Block) JigsawBlock(net.minecraft.block.JigsawBlock) StructureBlock(net.minecraft.block.StructureBlock) BlockPos(net.minecraft.util.math.BlockPos) CommandBlock(net.minecraft.block.CommandBlock) ItemStack(net.minecraft.item.ItemStack) BlockEntity(net.minecraft.block.entity.BlockEntity)

Aggregations

BlockEntity (net.minecraft.block.entity.BlockEntity)61 BlockPos (net.minecraft.util.math.BlockPos)26 BlockState (net.minecraft.block.BlockState)19 BlockHitResult (net.minecraft.util.hit.BlockHitResult)13 ItemStack (net.minecraft.item.ItemStack)10 ChestBlockEntity (net.minecraft.block.entity.ChestBlockEntity)8 Vec3d (net.minecraft.util.math.Vec3d)8 World (net.minecraft.world.World)7 Block (net.minecraft.block.Block)6 Inject (org.spongepowered.asm.mixin.injection.Inject)6 MatrixStack (net.minecraft.client.util.math.MatrixStack)5 FluidState (net.minecraft.fluid.FluidState)5 Random (java.util.Random)4 AbstractFurnaceBlockEntity (net.minecraft.block.entity.AbstractFurnaceBlockEntity)4 CommandBlockBlockEntity (net.minecraft.block.entity.CommandBlockBlockEntity)4 BlockRenderManager (net.minecraft.client.render.block.BlockRenderManager)4 ChunkRendererRegion (net.minecraft.client.render.chunk.ChunkRendererRegion)4 Inventory (net.minecraft.inventory.Inventory)4 NbtCompound (net.minecraft.nbt.NbtCompound)4 ServerWorld (net.minecraft.server.world.ServerWorld)4