diff --git a/src/main/java/li/cil/oc2/common/bus/device/item/InventoryAutomationRobotModuleDevice.java b/src/main/java/li/cil/oc2/common/bus/device/item/InventoryAutomationRobotModuleDevice.java index c414f0cd..0c607567 100644 --- a/src/main/java/li/cil/oc2/common/bus/device/item/InventoryAutomationRobotModuleDevice.java +++ b/src/main/java/li/cil/oc2/common/bus/device/item/InventoryAutomationRobotModuleDevice.java @@ -28,14 +28,16 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; -public final class InventoryAutomationRobotModuleDevice extends IdentityProxy implements RPCDevice, ItemDevice { - private final T robot; +public final class InventoryAutomationRobotModuleDevice extends IdentityProxy implements RPCDevice, ItemDevice { + private final Entity entity; + private final Robot robot; private final ObjectDevice device; /////////////////////////////////////////////////////////////////// - public InventoryAutomationRobotModuleDevice(final ItemStack identity, final T robot) { + public InventoryAutomationRobotModuleDevice(final ItemStack identity, final Entity entity, final Robot robot) { super(identity); + this.entity = entity; this.robot = robot; this.device = new ObjectDevice(this, "inventory_automation"); } @@ -75,7 +77,7 @@ public final class InventoryAutomationRobotModuleDevice getItemStackHandlersInDirection(final Direction direction) { final Vector3i directionVec = direction.getDirectionVec(); - return getItemStackHandlersAt(robot.getPositionVec().add(Vector3d.copy(directionVec)), direction.getOpposite()); + return getItemStackHandlersAt(entity.getPositionVec().add(Vector3d.copy(directionVec)), direction.getOpposite()); } private Stream getItemStackHandlersAt(final Vector3d position, final Direction side) { @@ -252,7 +254,7 @@ public final class InventoryAutomationRobotModuleDevice getEntityItemHandlersAt(final Vector3d position, final Direction side) { final AxisAlignedBB bounds = AxisAlignedBB.fromVector(position.subtract(0.5, 0.5, 0.5)); - return robot.getEntityWorld().getEntitiesWithinAABBExcludingEntity(robot, bounds).stream() + return entity.getEntityWorld().getEntitiesWithinAABBExcludingEntity(entity, bounds).stream() .map(e -> e.getCapability(Capabilities.ITEM_HANDLER, side)) .filter(LazyOptional::isPresent) .map(c -> c.orElseThrow(AssertionError::new)); @@ -262,7 +264,7 @@ public final class InventoryAutomationRobotModuleDevice getItemDevice(final ItemDeviceQuery query) { - return query.getContainerEntity().filter(e -> e instanceof Robot).map(e -> - new InventoryAutomationRobotModuleDevice(query.getItemStack(), e)); + return query.getContainerEntity().flatMap(entity -> + entity.getCapability(Capabilities.ROBOT).map(robot -> + new InventoryAutomationRobotModuleDevice(query.getItemStack(), entity, robot))); } }