Add MBD compatibility support - Low-Drag-MC/Multiblocked GitHub Wiki

Adding mod capability support to MBD is as simple as implementing the class MultiblockCapability<T> and CapabilityProxy<K> for it and registering them.

Of these, the most important implementation function is IO handling. Here is an example for ForgeEnergy.

@Override
protected List<Integer> handleRecipeInner(IO io, Recipe recipe, List<Integer> left, boolean simulate) {
    IEnergyStorage capability = getCapability();
    if (capability == null) return left;
    int sum = left.stream().reduce(0, Integer::sum);
    if (io == IO.IN) {
        sum = sum - capability.extractEnergy(sum, simulate);
    } else if (io == IO.OUT) {
        sum = sum - capability.receiveEnergy(sum, simulate);
    }
    return sum <= 0 ? null : Collections.singletonList(sum);
}

Besides, you may need to implement the ContentWidget for GUI showing and configurator.

@Override
public ContentWidget<? super Integer> createContentWidget() {
    return new NumberContentWidget().setContentTexture(new TextTexture("FE", color)).setUnit("FE");
}

In the end, you'd better override and implement the hasInnerChaged. It checks the inner changed of this block to help recipe searching in asynchronous scheduling. Make sure don't do multithreaded race condition stuff here

int stored = -1;
boolean canExtract = false;
boolean canReceive = false;

@Override
protected boolean hasInnerChanged() {
    IEnergyStorage capability = getCapability();
    if (capability == null) return false;
    if (stored == capability.getEnergyStored() && canExtract == capability.canExtract() && canReceive == capability.canReceive()) {
        return false;
    }
    canExtract = capability.canExtract();
    canReceive = capability.canReceive();
    stored = capability.getEnergyStored();
    return true;
}

If you want MBD to be able to not only access a capability, but also to create a machine that have this capability, you need to implement the CapabilityTrait.

Check java code for more details.

⚠️ **GitHub.com Fallback** ⚠️