Repository: PaperMC/Paper
File: paper-server/src/main/java/org/bukkit/craftbukkit/inventory/view/builder/CraftBlockEntityInventoryViewBuilder.java (Java)

Code before:
        if (this.position == null) {
            this.position = player.blockPosition();
        }

        final BlockEntity entity = this.world.getBlockEntity(position);
        if (!(entity instanceof final MenuConstructor container)) {
            return buildFakeTile(player);
        }

        final AbstractContainerMenu atBlock = container.createMenu(player.nextContainerCounter(), player.getInventory(), player);
        if (atBlock.getType() != super.handle) {
            return buildFakeTile(player);
        }

        trySetDefaultTitle(entity);
        return atBlock;
    }

    private AbstractContainerMenu buildFakeTile(final ServerPlayer player) {
        final MenuProvider inventory = this.builder.build(this.position, this.block.defaultBlockState());
        if (inventory instanceof final BlockEntity tile) {
            tile.setLevel(this.world);
            trySetDefaultTitle(tile);
        }

        if (!this.forceTile) { // gets around open noise for chest
            return handle.create(player.nextContainerCounter(), player.getInventory());
        }

        return inventory.createMenu(player.nextContainerCounter(), player.getInventory(), player);
    }

    private void trySetDefaultTitle(BlockEntity blockEntity) {
        if (blockEntity instanceof Nameable nameable) {
            super.defaultTitle = nameable.getDisplayName();
            return;
        }

        throw new IllegalStateException("Provided blockEntity during MenuType creation can not find a default title! This is a bug!");
    }

    @Override
    public LocationInventoryViewBuilder<V> copy() {
        final CraftBlockEntityInventoryViewBuilder<V> copy = new CraftBlockEntityInventoryViewBuilder<>(super.handle, this.block, this.builder, this.forceTile);
        copy.world = this.world;
        copy.position = this.position;
        copy.checkReachable = super.checkReachable;
        copy.title = title;
        return copy;
    }


Review comment (suggestion):
We can get a better name here I am sure.
Mostly because I guess all the other "tile" references in the code here were not caught in the initial review xD
`forceBlockEntityUsage`, `useBlockEntityMenuCreation`, whatever.
If you are at it, there are a couple of other `tile` names around, might be a vibe to update those to `blockEntity` too :)

Code after:
    }

    @Override
    protected AbstractContainerMenu buildContainer(final ServerPlayer player) {
        if (this.world == null) {
            this.world = player.level();
        }

        if (this.position == null) {
            this.position = player.blockPosition();
            return buildFakeBlockEntity(player);
        }

        final BlockEntity entity = this.world.getBlockEntity(position);
        if (!(entity instanceof final MenuConstructor container)) {
            return buildFakeBlockEntity(player);
        }

        final AbstractContainerMenu atBlock = container.createMenu(player.nextContainerCounter(), player.getInventory(), player);
        if (atBlock.getType() != super.handle) {
            return buildFakeBlockEntity(player);
        }

        if (!(entity instanceof final MenuProvider provider)) {
            throw new IllegalStateException("Provided blockEntity during MenuType creation can not find a default title! This is a bug!");
        }

        super.defaultTitle = provider.getDisplayName();
        return atBlock;
    }

    private AbstractContainerMenu buildFakeBlockEntity(final ServerPlayer player) {
        final MenuProvider inventory = this.builder.build(this.position, this.block.defaultBlockState());
        if (inventory instanceof final BlockEntity blockEntity) {
            blockEntity.setLevel(this.world);
            super.defaultTitle = inventory.getDisplayName();
        }

        if (!this.useFakeBlockEntity) { // gets around open noise for chest
            return handle.create(player.nextContainerCounter(), player.getInventory());
        }

        return inventory.createMenu(player.nextContainerCounter(), player.getInventory(), player);
    }

    @Override
    public LocationInventoryViewBuilder<V> copy() {
        final CraftBlockEntityInventoryViewBuilder<V> copy = new CraftBlockEntityInventoryViewBuilder<>(super.handle, this.block, this.builder, this.useFakeBlockEntity);
        copy.world = this.world;
        copy.position = this.position;
        copy.checkReachable = super.checkReachable;