Add Sticky Card (#371)

Co-authored-by: NotMyWing <winwyv@gmail.com>
This commit is contained in:
Serenibyss
2024-01-15 19:27:13 -06:00
committed by GitHub
parent dd3cdfcec5
commit a8f0bbe06b
23 changed files with 187 additions and 11 deletions
@@ -50,6 +50,9 @@ public class ContainerStorageBus extends ContainerUpgradeable {
@GuiSync(4)
public StorageFilter storageFilter = StorageFilter.EXTRACTABLE_ONLY;
@GuiSync(7)
public YesNo stickyMode = YesNo.NO;
public ContainerStorageBus(final InventoryPlayer ip, final PartStorageBus te) {
super(ip, te);
this.storageBus = te;
@@ -111,6 +114,7 @@ public class ContainerStorageBus extends ContainerUpgradeable {
this.setFuzzyMode((FuzzyMode) this.getUpgradeable().getConfigManager().getSetting(Settings.FUZZY_MODE));
this.setReadWriteMode((AccessRestriction) this.getUpgradeable().getConfigManager().getSetting(Settings.ACCESS));
this.setStorageFilter((StorageFilter) this.getUpgradeable().getConfigManager().getSetting(Settings.STORAGE_FILTER));
this.setStickyMode((YesNo) this.getUpgradeable().getConfigManager().getSetting(Settings.STICKY_MODE));
}
this.standardDetectAndSendChanges();
@@ -168,4 +172,12 @@ public class ContainerStorageBus extends ContainerUpgradeable {
private void setStorageFilter(final StorageFilter storageFilter) {
this.storageFilter = storageFilter;
}
public YesNo getStickyMode() {
return this.stickyMode;
}
private void setStickyMode(final YesNo stickyMode) {
this.stickyMode = stickyMode;
}
}
@@ -364,15 +364,19 @@ final class Registration {
// Storage Cells
Upgrades.FUZZY.registerItem(items.cell1k(), 1);
Upgrades.INVERTER.registerItem(items.cell1k(), 1);
Upgrades.STICKY.registerItem(items.cell1k(), 1);
Upgrades.FUZZY.registerItem(items.cell4k(), 1);
Upgrades.INVERTER.registerItem(items.cell4k(), 1);
Upgrades.STICKY.registerItem(items.cell4k(), 1);
Upgrades.FUZZY.registerItem(items.cell16k(), 1);
Upgrades.INVERTER.registerItem(items.cell16k(), 1);
Upgrades.STICKY.registerItem(items.cell16k(), 1);
Upgrades.FUZZY.registerItem(items.cell64k(), 1);
Upgrades.INVERTER.registerItem(items.cell64k(), 1);
Upgrades.STICKY.registerItem(items.cell64k(), 1);
Upgrades.FUZZY.registerItem(items.portableCell(), 1);
Upgrades.INVERTER.registerItem(items.portableCell(), 1);
@@ -387,10 +391,12 @@ final class Registration {
Upgrades.FUZZY.registerItem(parts.storageBus(), 1);
Upgrades.INVERTER.registerItem(parts.storageBus(), 1);
Upgrades.CAPACITY.registerItem(parts.storageBus(), 5);
Upgrades.STICKY.registerItem(parts.storageBus(), 1);
// Storage Bus Fluids
Upgrades.INVERTER.registerItem(parts.fluidStorageBus(), 1);
Upgrades.CAPACITY.registerItem(parts.fluidStorageBus(), 5);
Upgrades.STICKY.registerItem(parts.fluidStorageBus(), 1);
// Formation Plane
Upgrades.FUZZY.registerItem(parts.formationPlane(), 1);
@@ -60,6 +60,10 @@ public class ApiClientHelper implements IClientHelper {
lines.add("[" + GuiText.Partitioned.getLocal() + "]" + " - " + list + ' ' + GuiText.Precise.getLocal());
}
if (handler.isSticky()) {
lines.add(GuiText.Sticky.getLocal());
}
if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
IItemHandler inv = cellInventory.getConfigInventory();
cellInventory.getAvailableItems((IItemList) itemList);
@@ -90,6 +90,7 @@ public final class ApiMaterials implements IMaterials {
private final IItemDefinition cardFuzzy;
private final IItemDefinition cardInverter;
private final IItemDefinition cardCrafting;
private final IItemDefinition cardSticky;
private final IItemDefinition enderDust;
private final IItemDefinition flour;
@@ -208,6 +209,7 @@ public final class ApiMaterials implements IMaterials {
this.cardFuzzy = new DamagedItemDefinition("material.card.fuzzy", materials.createMaterial(MaterialType.CARD_FUZZY));
this.cardInverter = new DamagedItemDefinition("material.card.inverter", materials.createMaterial(MaterialType.CARD_INVERTER));
this.cardCrafting = new DamagedItemDefinition("material.card.crafting", materials.createMaterial(MaterialType.CARD_CRAFTING));
this.cardSticky = new DamagedItemDefinition("material.card.sticky", materials.createMaterial(MaterialType.CARD_STICKY));
this.enderDust = new DamagedItemDefinition("material.dust.ender", materials.createMaterial(MaterialType.ENDER_DUST));
this.flour = new DamagedItemDefinition("material.flour", materials.createMaterial(MaterialType.FLOUR));
@@ -425,6 +427,11 @@ public final class ApiMaterials implements IMaterials {
return this.cardCrafting;
}
@Override
public IItemDefinition cardSticky() {
return this.cardSticky;
}
@Override
public IItemDefinition enderDust() {
return this.enderDust;
@@ -195,6 +195,7 @@ public enum GuiText {
Partitioned,
Precise,
Fuzzy,
Sticky,
// Used in a terminal to indicate that an item is craftable
SmallFontCraft,
@@ -437,6 +437,10 @@ public class PartFluidStorageBus extends PartUpgradeable implements IGridTickabl
}
}
if (this.getInstalledUpgrades(Upgrades.STICKY) > 0) {
this.handler.setSticky(true);
}
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
this.handler.setPartitionList(new FuzzyPriorityList<IAEFluidStack>(priorityList, (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
} else {
@@ -166,6 +166,8 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent,
return Upgrades.MAGNET;
case CARD_QUANTUM_LINK:
return Upgrades.QUANTUM_LINK;
case CARD_STICKY:
return Upgrades.STICKY;
default:
return null;
}
@@ -120,7 +120,9 @@ public enum MaterialType {
CARD_PATTERN_EXPANSION(58, "material_card_pattern_expansion", EnumSet.of(AEFeature.ADVANCED_CARDS)),
CARD_QUANTUM_LINK(59, "material_card_quantum_link", EnumSet.of(AEFeature.ADVANCED_CARDS, AEFeature.QUANTUM_LINKING_CARD)),
CARD_MAGNET(60, "material_card_magnet", EnumSet.of(AEFeature.BASIC_CARDS));
CARD_MAGNET(60, "material_card_magnet", EnumSet.of(AEFeature.BASIC_CARDS)),
CARD_STICKY(61, "material_card_sticky", EnumSet.of(AEFeature.BASIC_CARDS)),
;
private final Set<AEFeature> features;
@@ -160,4 +160,8 @@ public class MEMonitorHandler<T extends IAEStack<T>> implements IMEMonitor<T> {
return this.getHandler().validForPass(i);
}
@Override
public boolean isSticky() {
return this.internalHandler.isSticky();
}
}
@@ -56,6 +56,7 @@ public class BasicCellInventoryHandler<T extends IAEStack<T>> extends MEInventor
boolean hasInverter = false;
boolean hasFuzzy = false;
boolean hasSticky = false;
for (int x = 0; x < upgrades.getSlots(); x++) {
final ItemStack is = upgrades.getStackInSlot(x);
@@ -69,6 +70,9 @@ public class BasicCellInventoryHandler<T extends IAEStack<T>> extends MEInventor
case INVERTER:
hasInverter = true;
break;
case STICKY:
hasSticky = true;
break;
default:
}
}
@@ -87,6 +91,10 @@ public class BasicCellInventoryHandler<T extends IAEStack<T>> extends MEInventor
this.setWhitelist(hasInverter ? IncludeExclude.BLACKLIST : IncludeExclude.WHITELIST);
if (hasSticky) {
setSticky(true);
}
if (!priorityList.isEmpty()) {
if (hasFuzzy) {
this.setPartitionList(new FuzzyPriorityList<>(priorityList, fzMode));
@@ -40,7 +40,6 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T> {
private final ICellHandler handler;
private final TileDrive drive;
private final IActionSource source;
public DriveWatcher(final ICellInventoryHandler<T> i, final ItemStack is, final ICellHandler han, final TileDrive drive) {
super(i, i.getChannel());
this.is = is;
@@ -100,4 +99,13 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T> {
return extractable;
}
@Override
public boolean isSticky() {
if (this.getInternal() instanceof ICellInventoryHandler<?> cellInventoryHandler) {
return cellInventoryHandler.isSticky();
}
return super.isSticky();
}
}
@@ -43,6 +43,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
private AccessRestriction cachedAccessRestriction;
private boolean hasReadAccess;
private boolean hasWriteAccess;
private boolean isSticky;
public MEInventoryHandler(final IMEInventory<T> i, final IStorageChannel<T> channel) {
if (i instanceof IMEInventoryHandler) {
@@ -166,4 +167,13 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
public IMEInventory<T> getInternal() {
return this.internal;
}
@Override
public boolean isSticky() {
return isSticky;
}
public void setSticky(boolean isSticky) {
this.isSticky = isSticky;
}
}
@@ -31,6 +31,7 @@ import appeng.api.storage.IStorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
import appeng.me.cache.SecurityCache;
import net.minecraft.network.Packet;
import java.util.*;
@@ -45,19 +46,24 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
private final IStorageChannel<T> myChannel;
private final SecurityCache security;
private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> stickyPriorityInventory;
private int myPass = 0;
public NetworkInventoryHandler(final IStorageChannel<T> chan, final SecurityCache security) {
this.myChannel = chan;
this.security = security;
this.priorityInventory = new TreeMap<>(PRIORITY_SORTER);
this.stickyPriorityInventory = new TreeMap<>(PRIORITY_SORTER);
}
public void addNewStorage(final IMEInventoryHandler<T> h) {
final int priority = h.getPriority();
List<IMEInventoryHandler<T>> list = this.priorityInventory.get(priority);
if (list == null) {
this.priorityInventory.put(priority, list = new ArrayList<>());
final List<IMEInventoryHandler<T>> list;
if (h.isSticky()) {
list = this.stickyPriorityInventory.computeIfAbsent(priority, $ -> new ArrayList<>());
} else {
list = this.priorityInventory.computeIfAbsent(priority, $ -> new ArrayList<>());
}
list.add(h);
@@ -74,6 +80,25 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
return input;
}
boolean stickyInventoryFound = false;
// For this pass we do return input if the item is able to go into a sticky inventory. We NEVER want to try and
// insert the item into a non-sticky inventory if it could already go into a sticky inventory.
for (final List<IMEInventoryHandler<T>> stickyInvList : this.stickyPriorityInventory.values()) {
Iterator<IMEInventoryHandler<T>> ii = stickyInvList.iterator();
while (ii.hasNext() && input != null) {
final IMEInventoryHandler<T> inv = ii.next();
if (inv.validForPass(1) && inv.canAccept(input) && (inv.isPrioritized(input) || inv.extractItems(input, Actionable.SIMULATE, src) != null)) {
input = inv.injectItems(input, type, src);
stickyInventoryFound = true;
}
}
}
if (stickyInventoryFound) {
this.surface(this, type);
return input;
}
for (final List<IMEInventoryHandler<T>> invList : this.priorityInventory.values()) {
Iterator<IMEInventoryHandler<T>> ii = invList.iterator();
while (ii.hasNext() && input != null) {
@@ -186,6 +211,16 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
}
}
for (List<IMEInventoryHandler<T>> invList : this.stickyPriorityInventory.descendingMap().values()) {
final Iterator<IMEInventoryHandler<T>> jj = invList.iterator();
while (jj.hasNext() && output.getStackSize() < req) {
final IMEInventoryHandler<T> inv = jj.next();
request.setStackSize(req - output.getStackSize());
output.add(inv.extractItems(request, mode, src));
}
}
this.surface(this, mode);
if (output.getStackSize() <= 0) {
@@ -201,15 +236,21 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
return out;
}
// for (Entry<Integer, IMEInventoryHandler<T>> h : priorityInventory.entries())
for (final List<IMEInventoryHandler<T>> i : this.priorityInventory.values()) {
out = iterateInventories(out, priorityInventory);
out = iterateInventories(out, stickyPriorityInventory);
this.surface(this, Actionable.SIMULATE);
return out;
}
private IItemList<T> iterateInventories(IItemList<T> out, final NavigableMap<Integer, List<IMEInventoryHandler<T>>> map) {
for (final List<IMEInventoryHandler<T>> i : map.values()) {
for (final IMEInventoryHandler<T> j : i) {
out = j.getAvailableItems(out);
}
}
this.surface(this, Actionable.SIMULATE);
return out;
}
@@ -48,6 +48,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
private int patternExpansionUpgrades = 0;
private int magnetUpgrades = 0;
private int quantumUpgrades = 0;
private int stickyUpgrades = 0;
public UpgradeInventory(final IAEAppEngInventory parent, final int s) {
super(null, s, 1);
@@ -85,6 +86,8 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
return this.magnetUpgrades;
case QUANTUM_LINK:
return this.quantumUpgrades;
case STICKY:
return this.stickyUpgrades;
default:
return 0;
}
@@ -94,7 +97,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
private void updateUpgradeInfo() {
this.cached = true;
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = magnetUpgrades = quantumUpgrades = 0;
this.patternExpansionUpgrades = this.inverterUpgrades = this.capacityUpgrades = this.redstoneUpgrades = this.speedUpgrades = this.fuzzyUpgrades = this.craftingUpgrades = magnetUpgrades = quantumUpgrades = stickyUpgrades = 0;
for (final ItemStack is : this) {
if (is == null || is.getItem() == Items.AIR || !(is.getItem() instanceof IUpgradeModule)) {
@@ -129,6 +132,10 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
break;
case QUANTUM_LINK:
this.quantumUpgrades++;
break;
case STICKY:
this.stickyUpgrades++;
break;
default:
break;
}
@@ -143,6 +150,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement
this.patternExpansionUpgrades = Math.min(this.patternExpansionUpgrades, this.getMaxInstalled(Upgrades.PATTERN_EXPANSION));
this.magnetUpgrades = Math.min(this.magnetUpgrades, this.getMaxInstalled(Upgrades.MAGNET));
this.quantumUpgrades = Math.min(this.quantumUpgrades, this.getMaxInstalled(Upgrades.QUANTUM_LINK));
this.stickyUpgrades = Math.min(this.stickyUpgrades, this.getMaxInstalled(Upgrades.STICKY));
}
@Override
@@ -113,6 +113,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
this.getConfigManager().registerSetting(Settings.ACCESS, AccessRestriction.READ_WRITE);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
this.getConfigManager().registerSetting(Settings.STORAGE_FILTER, StorageFilter.EXTRACTABLE_ONLY);
this.getConfigManager().registerSetting(Settings.STICKY_MODE, YesNo.NO);
this.mySrc = new MachineSource(this);
}
@@ -467,6 +468,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
}
}
if (this.getInstalledUpgrades(Upgrades.STICKY) > 0) {
this.handler.setSticky(true);
}
if (this.getInstalledUpgrades(Upgrades.FUZZY) > 0) {
this.handler.setPartitionList(new FuzzyPriorityList<>(priorityList, (FuzzyMode) this.getConfigManager().getSetting(Settings.FUZZY_MODE)));
} else {