Add interface to allow bus elements to provide their location.

Allows controller to centrally track chunk load/unload for scheduling scans.
This commit is contained in:
Florian Nücke
2020-12-25 20:15:48 +01:00
parent cc6572aecb
commit 606add570d
2 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,21 @@
package li.cil.oc2.api.bus;
import net.minecraft.util.math.BlockPos;
/**
* Implementing this interface allows providing positional information to the {@link DeviceBusController}.
* <p>
* Controllers may use this information to automatically trigger bus scans when the chunk containing
* this element or a chunk adjacent to it gets unloaded / loaded. This convenience allows not having
* to implement logic in bus element implementations to trigger such scans themselves.
*/
public interface BlockDeviceBusElement extends DeviceBusElement {
// TODO Do we want to support multi-dimensional buses? (have a getWorld)
/**
* The position of this bus element.
*
* @return the position of this bus element.
*/
BlockPos getPosition();
}

View File

@@ -1,5 +1,6 @@
package li.cil.oc2.common.bus;
import li.cil.oc2.api.bus.BlockDeviceBusElement;
import li.cil.oc2.api.bus.DeviceBus;
import li.cil.oc2.api.bus.DeviceBusElement;
import li.cil.oc2.common.bus.device.BlockDeviceInfo;
@@ -22,7 +23,7 @@ import java.util.Optional;
import static java.util.Objects.requireNonNull;
public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusElement {
public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusElement implements BlockDeviceBusElement {
private static final int NEIGHBOR_COUNT = 6;
final Direction[] NEIGHBOR_DIRECTIONS = Direction.values();
@@ -39,6 +40,11 @@ public class TileEntityDeviceBusElement extends AbstractGroupingBlockDeviceBusEl
///////////////////////////////////////////////////////////////////
@Override
public BlockPos getPosition() {
return tileEntity.getPos();
}
@Override
public Optional<Collection<LazyOptional<DeviceBusElement>>> getNeighbors() {
final World world = tileEntity.getWorld();