mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-27 07:27:15 +01:00
rework ThresholdSwitch compat
- adds better support for SophisticatedStorage and FunctionalStorage
This commit is contained in:
parent
75d337ba8c
commit
d9198f678e
8 changed files with 120 additions and 50 deletions
|
@ -53,6 +53,7 @@ minecraft {
|
|||
workingDirectory project.file('run')
|
||||
arg '-mixin.config=create.mixins.json'
|
||||
//jvmArgs '-XX:+UnlockCommercialFeatures' // uncomment for profiling
|
||||
//jvmArgs '-XX:+IgnoreUnrecognizedVMOptions', '-XX:+AllowEnhancedClassRedefinition' // uncomment with jbr
|
||||
property 'forge.logging.console.level', 'info'
|
||||
mods {
|
||||
create {
|
||||
|
@ -206,6 +207,11 @@ dependencies {
|
|||
// runtimeOnly fg.deobf("maven.modrinth:spark:1.10.38-forge")
|
||||
//runtimeOnly fg.deobf("curse.maven:forbidden-arcanus-309858:4729924")
|
||||
//runtimeOnly fg.deobf("curse.maven:valhelsia-core-416935:3886212")
|
||||
// runtimeOnly fg.deobf("curse.maven:sophisticated-storage-619320:5194748")
|
||||
// runtimeOnly fg.deobf("curse.maven:sophisticated-core-618298:5296312")
|
||||
// runtimeOnly fg.deobf("curse.maven:functional-storage-556861:5271589")
|
||||
// runtimeOnly fg.deobf("curse.maven:titanium-287342:5151207")
|
||||
// runtimeOnly fg.deobf("curse.maven:storage-drawers-223852:3807626")
|
||||
|
||||
// https://discord.com/channels/313125603924639766/725850371834118214/910619168821354497
|
||||
// Prevent Mixin annotation processor from getting into IntelliJ's annotation processor settings
|
||||
|
|
|
@ -18,8 +18,11 @@ public enum Mods {
|
|||
CONNECTIVITY,
|
||||
CURIOS,
|
||||
DYNAMICTREES,
|
||||
FUNCTIONALSTORAGE,
|
||||
OCCULTISM,
|
||||
PACKETFIXER,
|
||||
SOPHISTICATEDBACKPACKS,
|
||||
SOPHISTICATEDSTORAGE,
|
||||
STORAGEDRAWERS,
|
||||
TCONSTRUCT,
|
||||
XLPACKETS;
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package com.simibubi.create.compat.storageDrawers;
|
||||
|
||||
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 StorageDrawers {
|
||||
|
||||
public static boolean isDrawer(BlockEntity be) {
|
||||
return be != null && Mods.STORAGEDRAWERS.id()
|
||||
.equals(be.getType()
|
||||
.getRegistryName()
|
||||
.getNamespace());
|
||||
}
|
||||
|
||||
public static float getTrueFillLevel(IItemHandler inv, FilteringBehaviour filtering) {
|
||||
float occupied = 0;
|
||||
float totalSpace = 0;
|
||||
|
||||
for (int slot = 1; 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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.simibubi.create.compat.thresholdSwitch;
|
||||
|
||||
import com.simibubi.create.compat.Mods;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class FunctionalStorage implements ThresholdSwitchCompat {
|
||||
|
||||
@Override
|
||||
public boolean isFromThisMod(BlockEntity blockEntity) {
|
||||
return blockEntity != null && Mods.FUNCTIONALSTORAGE.id()
|
||||
.equals(blockEntity.getType()
|
||||
.getRegistryName()
|
||||
.getNamespace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSpaceInSlot(IItemHandler inv, int slot) {
|
||||
return inv.getSlotLimit(slot);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.simibubi.create.compat.thresholdSwitch;
|
||||
|
||||
import com.simibubi.create.compat.Mods;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class SophisticatedStorage implements ThresholdSwitchCompat {
|
||||
|
||||
@Override
|
||||
public boolean isFromThisMod(BlockEntity be) {
|
||||
if (be == null)
|
||||
return false;
|
||||
|
||||
String namespace = be.getType()
|
||||
.getRegistryName()
|
||||
.getNamespace();
|
||||
|
||||
return
|
||||
Mods.SOPHISTICATEDSTORAGE.id().equals(namespace)
|
||||
|| Mods.SOPHISTICATEDBACKPACKS.id().equals(namespace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSpaceInSlot(IItemHandler inv, int slot) {
|
||||
return ((long) inv.getSlotLimit(slot) * inv.getStackInSlot(slot).getMaxStackSize()) / 64;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.simibubi.create.compat.thresholdSwitch;
|
||||
|
||||
import com.simibubi.create.compat.Mods;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class StorageDrawers implements ThresholdSwitchCompat {
|
||||
|
||||
@Override
|
||||
public boolean isFromThisMod(BlockEntity blockEntity) {
|
||||
return blockEntity != null && Mods.STORAGEDRAWERS.id()
|
||||
.equals(blockEntity.getType()
|
||||
.getRegistryName()
|
||||
.getNamespace());
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSpaceInSlot(IItemHandler inv, int slot) {
|
||||
if (slot == 0)
|
||||
return 0;
|
||||
|
||||
return inv.getSlotLimit(slot);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.simibubi.create.compat.thresholdSwitch;
|
||||
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public interface ThresholdSwitchCompat {
|
||||
|
||||
boolean isFromThisMod(BlockEntity blockEntity);
|
||||
|
||||
long getSpaceInSlot(IItemHandler inv, int slot);
|
||||
|
||||
}
|
|
@ -2,7 +2,10 @@ package com.simibubi.create.content.redstone.thresholdSwitch;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import com.simibubi.create.compat.storageDrawers.StorageDrawers;
|
||||
import com.simibubi.create.compat.thresholdSwitch.FunctionalStorage;
|
||||
import com.simibubi.create.compat.thresholdSwitch.SophisticatedStorage;
|
||||
import com.simibubi.create.compat.thresholdSwitch.StorageDrawers;
|
||||
import com.simibubi.create.compat.thresholdSwitch.ThresholdSwitchCompat;
|
||||
import com.simibubi.create.content.redstone.DirectedDirectionalBlock;
|
||||
import com.simibubi.create.content.redstone.FilteredDetectorFilterSlot;
|
||||
import com.simibubi.create.content.redstone.displayLink.DisplayLinkBlock;
|
||||
|
@ -42,6 +45,12 @@ public class ThresholdSwitchBlockEntity extends SmartBlockEntity {
|
|||
private TankManipulationBehaviour observedTank;
|
||||
private VersionedInventoryTrackerBehaviour invVersionTracker;
|
||||
|
||||
private static final List<ThresholdSwitchCompat> COMPAT = List.of(
|
||||
new FunctionalStorage(),
|
||||
new SophisticatedStorage(),
|
||||
new StorageDrawers()
|
||||
);
|
||||
|
||||
public ThresholdSwitchBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
|
||||
super(type, pos, state);
|
||||
onWhenAbove = .75f;
|
||||
|
@ -104,27 +113,32 @@ public class ThresholdSwitchBlockEntity extends SmartBlockEntity {
|
|||
if (targetBlockEntity instanceof ThresholdSwitchObservable observable) {
|
||||
currentLevel = observable.getPercent() / 100f;
|
||||
|
||||
} else if (StorageDrawers.isDrawer(targetBlockEntity) && observedInventory.hasInventory()) {
|
||||
currentLevel = StorageDrawers.getTrueFillLevel(observedInventory.getInventory(), filtering);
|
||||
|
||||
} else if (observedInventory.hasInventory() || observedTank.hasInventory()) {
|
||||
if (observedInventory.hasInventory()) {
|
||||
|
||||
|
||||
// Item inventory
|
||||
IItemHandler inv = observedInventory.getInventory();
|
||||
if (invVersionTracker.stillWaiting(inv)) {
|
||||
occupied = prevLevel;
|
||||
totalSpace = 1f;
|
||||
|
||||
|
||||
} else {
|
||||
invVersionTracker.awaitNewVersion(inv);
|
||||
for (int slot = 0; slot < inv.getSlots(); slot++) {
|
||||
ItemStack stackInSlot = inv.getStackInSlot(slot);
|
||||
int space = Math.min(stackInSlot.getMaxStackSize(), inv.getSlotLimit(slot));
|
||||
|
||||
int finalSlot = slot;
|
||||
long space = COMPAT
|
||||
.stream()
|
||||
.filter(compat -> compat.isFromThisMod(targetBlockEntity))
|
||||
.map(compat -> compat.getSpaceInSlot(inv, finalSlot))
|
||||
.findFirst()
|
||||
.orElseGet(() -> (long) Math.min(stackInSlot.getMaxStackSize(), inv.getSlotLimit(finalSlot)));
|
||||
|
||||
int count = stackInSlot.getCount();
|
||||
if (space == 0)
|
||||
continue;
|
||||
|
||||
|
||||
totalSpace += 1;
|
||||
if (filtering.test(stackInSlot))
|
||||
occupied += count * (1f / space);
|
||||
|
@ -209,7 +223,7 @@ public class ThresholdSwitchBlockEntity extends SmartBlockEntity {
|
|||
this.updateCurrentLevel();
|
||||
invVersionTracker.reset();
|
||||
}));
|
||||
|
||||
|
||||
behaviours.add(invVersionTracker = new VersionedInventoryTrackerBehaviour(this));
|
||||
|
||||
InterfaceProvider towardBlockFacing =
|
||||
|
|
Loading…
Reference in a new issue