Skip to content

Fix false "Bad custom block" errors for CraftEngine blocks on startup#511

Merged
tastybento merged 2 commits intodevelopfrom
copilot/fix-bad-custom-block
Apr 29, 2026
Merged

Fix false "Bad custom block" errors for CraftEngine blocks on startup#511
tastybento merged 2 commits intodevelopfrom
copilot/fix-bad-custom-block

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

AOneBlock's onEnable runs before CraftEngine populates its block registry, so CraftEngineHook.exists(id) returns false for every valid type: craftengine block — flooding the log with ERROR: Bad custom block on every phase that uses CraftEngine blocks. The blocks work fine because CraftEngineListener triggers a full phase reload on CraftEngineReloadEvent, at which point the registry is ready.

Changes

  • CraftEngineCustomBlock.fromMap() — decoupled from fromId(). When a YAML entry explicitly declares type: craftengine, the block type is unambiguous; the object is now created directly from the id field without consulting the registry:

    // Before: delegated to fromId() → CraftEngineHook.exists() → false at startup → Bad custom block
    public static Optional<CraftEngineCustomBlock> fromMap(Map<?, ?> map) {
        return Optional.ofNullable(Objects.toString(map.get("id"), null))
                .flatMap(CraftEngineCustomBlock::fromId);
    }
    
    // After: create directly; runtime execute() handles invalid IDs gracefully
    public static Optional<CraftEngineCustomBlock> fromMap(Map<?, ?> map) {
        String id = Objects.toString(map.get("id"), null);
        if (id == null) return Optional.empty();
        return Optional.of(new CraftEngineCustomBlock(id));
    }
  • fromId() retains the exists() check — it doubles as the short-form creator and must not greedily match vanilla material names.

  • Added fromMapReturnsPresentWhenIdProvided test to cover the previously broken path.

Copilot AI linked an issue Apr 28, 2026 that may be closed by this pull request
…initial load

CraftEngineCustomBlock.fromMap() no longer delegates to fromId() (which
calls CraftEngineHook.exists()). When a YAML entry explicitly declares
type: craftengine the block type is already unambiguous, so the
CraftEngineCustomBlock is created directly from the id field without
requiring CraftEngine's block registry to be populated yet.

The fromId() path (used by the short-form creator) keeps the exists()
check so it can still distinguish CraftEngine IDs from vanilla material
names.

Fixes: invalid runtime error on startup when CraftEngine fires its reload
event after AOneBlock has already attempted to load phases.

Agent-Logs-Url: https://github.com/BentoBoxWorld/AOneBlock/sessions/7e16e2d1-e9ec-4551-b155-ebb10c178074

Co-authored-by: tastybento <4407265+tastybento@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix bad custom block error in CraftEngine Fix false "Bad custom block" errors for CraftEngine blocks on startup Apr 28, 2026
Copilot AI requested a review from tastybento April 28, 2026 23:46
@tastybento tastybento marked this pull request as ready for review April 29, 2026 00:05
@sonarqubecloud
Copy link
Copy Markdown

@tastybento tastybento merged commit 59ae640 into develop Apr 29, 2026
3 checks passed
@tastybento tastybento deleted the copilot/fix-bad-custom-block branch April 29, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad custom block

2 participants