Skip to content

Commit

Permalink
fix: verify face configuration type
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus8448 committed Aug 22, 2024
1 parent fd19d2e commit bd7335f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -103,17 +105,20 @@ protected MachineBlockEntity(BlockEntityType<? extends MachineBlockEntity> type,
}

public static <T extends MachineBlockEntity> void registerProviders(@NotNull BlockEntityType<? extends T> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit bd7335f

Please sign in to comment.