add functional storage compat for threshold switch

This commit is contained in:
Sarim Khan 2024-04-20 02:58:30 +06:00
parent d66170c8fe
commit 005c16e249
No known key found for this signature in database
GPG key ID: C2A48D9592CD781F
3 changed files with 46 additions and 0 deletions

View file

@ -21,6 +21,7 @@ public enum Mods {
OCCULTISM,
PACKETFIXER,
STORAGEDRAWERS,
FUNCTIONALSTORAGE,
TCONSTRUCT,
XLPACKETS;

View file

@ -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;
}
}

View file

@ -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()) {