From bd7335f9cd86e492812c3e689a3fe0e89e9f7935 Mon Sep 17 00:00:00 2001 From: marcus8448 Date: Thu, 22 Aug 2024 11:51:56 -0700 Subject: [PATCH] fix: verify face configuration type --- .../api/block/entity/MachineBlockEntity.java | 23 +++++++++++-------- .../machinelib/api/config/Config.java | 6 ++--- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java b/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java index b5744ab..38daea9 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java +++ b/src/main/java/dev/galacticraft/machinelib/api/block/entity/MachineBlockEntity.java @@ -23,6 +23,7 @@ package dev.galacticraft.machinelib.api.block.entity; import dev.galacticraft.machinelib.api.machine.MachineStatus; +import dev.galacticraft.machinelib.api.machine.configuration.IOFace; import dev.galacticraft.machinelib.api.menu.MachineMenu; import dev.galacticraft.machinelib.api.storage.MachineEnergyStorage; import dev.galacticraft.machinelib.api.storage.MachineFluidStorage; @@ -31,6 +32,7 @@ import dev.galacticraft.machinelib.api.storage.slot.FluidResourceSlot; import dev.galacticraft.machinelib.api.storage.slot.ItemResourceSlot; import dev.galacticraft.machinelib.api.transfer.ResourceFlow; +import dev.galacticraft.machinelib.api.transfer.ResourceType; import dev.galacticraft.machinelib.api.util.BlockFace; import dev.galacticraft.machinelib.api.util.StorageHelper; import dev.galacticraft.machinelib.impl.Constant; @@ -103,17 +105,20 @@ protected MachineBlockEntity(BlockEntityType type, } public static void registerProviders(@NotNull BlockEntityType type) { - EnergyStorage.SIDED.registerForBlockEntity((blockEntity, direction) -> { - if (direction == null) return blockEntity.energyStorage().getExposedStorage(ResourceFlow.BOTH); - return blockEntity.energyStorage().getExposedStorage(blockEntity.getIOConfig().get(Objects.requireNonNull(BlockFace.from(blockEntity.getBlockState(), direction))).getFlow()); + EnergyStorage.SIDED.registerForBlockEntity((machine, direction) -> { + if (direction == null) return machine.energyStorage().getExposedStorage(ResourceFlow.BOTH); + IOFace ioFace = machine.getIOConfig().get(Objects.requireNonNull(BlockFace.from(machine.getBlockState(), direction))); + return ioFace.getType().willAcceptResource(ResourceType.FLUID) ? machine.energyStorage().getExposedStorage(ioFace.getFlow()) : null; }, type); - ItemStorage.SIDED.registerForBlockEntity((blockEntity, direction) -> { - if (direction == null) return blockEntity.itemStorage().getExposedStorage(ResourceFlow.BOTH); - return blockEntity.itemStorage().getExposedStorage(blockEntity.getIOConfig().get(Objects.requireNonNull(BlockFace.from(blockEntity.getBlockState(), direction))).getFlow()); + ItemStorage.SIDED.registerForBlockEntity((machine, direction) -> { + if (direction == null) return machine.itemStorage().getExposedStorage(ResourceFlow.BOTH); + IOFace ioFace = machine.getIOConfig().get(Objects.requireNonNull(BlockFace.from(machine.getBlockState(), direction))); + return ioFace.getType().willAcceptResource(ResourceType.ITEM) ? machine.itemStorage().getExposedStorage(ioFace.getFlow()) : null; }, type); - FluidStorage.SIDED.registerForBlockEntity((blockEntity, direction) -> { - if (direction == null) return blockEntity.fluidStorage().getExposedStorage(ResourceFlow.BOTH); - return blockEntity.fluidStorage().getExposedStorage(blockEntity.getIOConfig().get(Objects.requireNonNull(BlockFace.from(blockEntity.getBlockState(), direction))).getFlow()); + FluidStorage.SIDED.registerForBlockEntity((machine, direction) -> { + if (direction == null) return machine.fluidStorage().getExposedStorage(ResourceFlow.BOTH); + IOFace ioFace = machine.getIOConfig().get(Objects.requireNonNull(BlockFace.from(machine.getBlockState(), direction))); + return ioFace.getType().willAcceptResource(ResourceType.ENERGY) ? machine.fluidStorage().getExposedStorage(ioFace.getFlow()) : null; }, type); } diff --git a/src/main/java/dev/galacticraft/machinelib/api/config/Config.java b/src/main/java/dev/galacticraft/machinelib/api/config/Config.java index 3342133..7e76e5e 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/config/Config.java +++ b/src/main/java/dev/galacticraft/machinelib/api/config/Config.java @@ -61,14 +61,14 @@ static Config loadFrom(File file) { void setEnableColoredVanillaFluidNames(boolean enabled); /** - * {@return what unit fluids should be displayed in} + * {@return the unit that fluids should be displayed in} */ FluidUnits fluidUnits(); /** - * Sets what unit fluids should be displayed in. + * Sets the unit that fluids should be displayed in. * - * @param units what unit fluids should be displayed in + * @param units the unit that fluids should be displayed in */ void getFluidUnits(FluidUnits units);