mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-06-02 18:59:19 +02:00
add functional storage compat for threshold switch
This commit is contained in:
parent
d66170c8fe
commit
005c16e249
|
@ -21,6 +21,7 @@ public enum Mods {
|
|||
OCCULTISM,
|
||||
PACKETFIXER,
|
||||
STORAGEDRAWERS,
|
||||
FUNCTIONALSTORAGE,
|
||||
TCONSTRUCT,
|
||||
XLPACKETS;
|
||||
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package com.simibubi.create.compat.functionalStorage;
|
||||
|
||||
import com.simibubi.create.compat.Mods;
|
||||
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour;
|
||||
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class FunctionalStorage {
|
||||
|
||||
public static boolean isDrawer(BlockEntity be) {
|
||||
return be != null && Mods.FUNCTIONALSTORAGE.id()
|
||||
.equals(be.getType()
|
||||
.getRegistryName()
|
||||
.getNamespace());
|
||||
}
|
||||
|
||||
public static float getTrueFillLevel(IItemHandler inv, FilteringBehaviour filtering) {
|
||||
float occupied = 0;
|
||||
float totalSpace = 0;
|
||||
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
ItemStack stackInSlot = inv.getStackInSlot(slot);
|
||||
int space = inv.getSlotLimit(slot);
|
||||
int count = stackInSlot.getCount();
|
||||
if (space == 0)
|
||||
continue;
|
||||
|
||||
totalSpace += 1;
|
||||
if (filtering.test(stackInSlot))
|
||||
occupied += count * (1f / space);
|
||||
}
|
||||
|
||||
if (totalSpace == 0)
|
||||
return 0;
|
||||
|
||||
return occupied / totalSpace;
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.simibubi.create.content.redstone.thresholdSwitch;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.compat.functionalStorage.FunctionalStorage;
|
||||
import com.simibubi.create.compat.storageDrawers.StorageDrawers;
|
||||
import com.simibubi.create.content.redstone.DirectedDirectionalBlock;
|
||||
import com.simibubi.create.content.redstone.FilteredDetectorFilterSlot;
|
||||
|
@ -107,6 +108,9 @@ public class ThresholdSwitchBlockEntity extends SmartBlockEntity {
|
|||
} else if (StorageDrawers.isDrawer(targetBlockEntity) && observedInventory.hasInventory()) {
|
||||
currentLevel = StorageDrawers.getTrueFillLevel(observedInventory.getInventory(), filtering);
|
||||
|
||||
} else if (FunctionalStorage.isDrawer(targetBlockEntity) && observedInventory.hasInventory()) {
|
||||
currentLevel = FunctionalStorage.getTrueFillLevel(observedInventory.getInventory(), filtering);
|
||||
|
||||
} else if (observedInventory.hasInventory() || observedTank.hasInventory()) {
|
||||
if (observedInventory.hasInventory()) {
|
||||
|
||||
|
|
Loading…
Reference in a new issue