Skip to content

Commit

Permalink
Switch to using the ConfigInventory builder
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Mar 14, 2024
1 parent 2873505 commit 3e065bd
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ default boolean isEditable(ItemStack is) {
* onInventoryChange will be called when saving is needed.
*/
default ConfigInventory getConfigInventory(ItemStack is) {
return ConfigInventory.EMPTY_TYPES;
return ConfigInventory.emptyTypes();
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/appeng/helpers/InterfaceLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.api.stacks.AEKey;
import appeng.api.stacks.AEKeyTypes;
import appeng.api.stacks.GenericStack;
import appeng.api.storage.MEStorage;
import appeng.api.storage.StorageHelper;
Expand Down Expand Up @@ -103,9 +102,9 @@ public InterfaceLogic(IManagedGridNode gridNode, InterfaceLogicHost host, Item i

public InterfaceLogic(IManagedGridNode gridNode, InterfaceLogicHost host, Item is, int slots) {
this.host = host;
this.config = ConfigInventory.configStacks(AEKeyTypes.getAll(), slots, this::onConfigRowChanged, false);
this.storage = ConfigInventory.storage(AEKeyTypes.getAll(), this::isAllowedInStorageSlot, slots,
this::onStorageChanged);
this.config = ConfigInventory.configStacks(slots).changeListener(this::onConfigRowChanged).build();
this.storage = ConfigInventory.storage(slots).slotFilter(this::isAllowedInStorageSlot)
.changeListener(this::onStorageChanged).build();
this.mainNode = gridNode
.setFlags(GridFlags.REQUIRE_CHANNEL)
.addService(IGridTickable.class, new Ticker());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Function;

Expand All @@ -29,6 +28,7 @@
import appeng.api.integrations.emi.EmiStackConverters;
import appeng.core.AEConfig;
import appeng.core.AppEng;
import appeng.core.FacadeCreativeTab;
import appeng.core.definitions.AEBlocks;
import appeng.core.definitions.AEItems;
import appeng.core.definitions.AEParts;
Expand Down Expand Up @@ -106,7 +106,9 @@ public void register(EmiRegistry registry) {
adaptRecipeType(registry, TransformRecipe.TYPE, EmiTransformRecipe::new);

// Facades
registry.addDeferredRecipes(this::registerFacades);
if (AEConfig.instance().isEnableFacadeRecipesInJEI()) {
registry.addDeferredRecipes(this::registerFacades);
}

// Remove items
if (!AEConfig.instance().isEnableFacadesInJEI()) {
Expand Down Expand Up @@ -189,10 +191,8 @@ private void registerP2PAttunements(Consumer<EmiRecipe> recipeConsumer) {

private void registerFacades(Consumer<EmiRecipe> recipeConsumer) {
var generator = new EmiFacadeGenerator();
EmiApi.getIndexStacks().stream()
.map(generator::getRecipeFor)
.filter(Optional::isPresent)
.map(Optional::get)
.forEach(recipeConsumer);
for (var facade : FacadeCreativeTab.getDisplayItems()) {
generator.getRecipeFor(facade).ifPresent(recipeConsumer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,44 @@
* This plugin will dynamically add facade recipes for any item that can be turned into a facade.
*/
class EmiFacadeGenerator {
private final ItemStack cableAnchor;
private final EmiStack cableAnchor;

EmiFacadeGenerator() {
this.cableAnchor = AEParts.CABLE_ANCHOR.stack();
this.cableAnchor = EmiStack.of(AEParts.CABLE_ANCHOR.stack());
}

public Optional<EmiRecipe> getRecipeFor(EmiStack emiStack) {
var itemStack = emiStack.getItemStack();
if (itemStack.isEmpty()) {
public Optional<EmiRecipe> getRecipeFor(ItemStack potentialFacade) {
if (potentialFacade.isEmpty()) {
return Optional.empty(); // We only have items
}

// Looking up how a certain facade is crafted
if (itemStack.getItem() instanceof FacadeItem facadeItem) {
ItemStack textureItem = facadeItem.getTextureItem(itemStack);
return Optional.of(make(textureItem, this.cableAnchor, itemStack.copy()));
if (potentialFacade.getItem() instanceof FacadeItem facadeItem) {
ItemStack textureItem = facadeItem.getTextureItem(potentialFacade);
return Optional.of(make(textureItem, potentialFacade.copy()));
}

return Optional.empty();
}

private EmiRecipe make(ItemStack textureItem, ItemStack cableAnchor, ItemStack result) {
private EmiRecipe make(ItemStack textureItem, ItemStack result) {
var textureStack = EmiStack.of(textureItem);
var resultStack = EmiStack.of(result, 4);

var input = List.<EmiIngredient>of(
EmiStack.EMPTY,
EmiStack.of(cableAnchor),
cableAnchor,
EmiStack.EMPTY,
EmiStack.of(cableAnchor),
EmiStack.of(textureItem),
EmiStack.of(cableAnchor),
cableAnchor,
textureStack,
cableAnchor,
EmiStack.EMPTY,
EmiStack.of(cableAnchor),
cableAnchor,
EmiStack.EMPTY);

return new EmiCraftingRecipe(
input,
EmiStack.of(result, 4),
resultStack,
null,
false);
}

}
9 changes: 5 additions & 4 deletions src/main/java/appeng/items/contents/CellConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraft.world.item.ItemStack;

import appeng.api.stacks.AEKeyType;
import appeng.api.stacks.AEKeyTypes;
import appeng.util.ConfigInventory;

public final class CellConfig {
Expand All @@ -36,21 +35,23 @@ public static ConfigInventory create(Set<AEKeyType> supportedTypes, ItemStack is
Preconditions.checkArgument(size >= 1 && size <= 63,
"Config inventory must have between 1 and 63 slots inclusive.");
var holder = new Holder(is);
holder.inv = ConfigInventory.configTypes(supportedTypes, size, holder::save);
holder.inv = ConfigInventory.configTypes(size).supportedTypes(supportedTypes).changeListener(holder::save)
.build();
holder.load();
return holder.inv;
}

public static ConfigInventory create(Set<AEKeyType> supportedTypes, ItemStack is) {
var holder = new Holder(is);
holder.inv = ConfigInventory.configTypes(supportedTypes, 63, holder::save);
holder.inv = ConfigInventory.configTypes(63).supportedTypes(supportedTypes).changeListener(holder::save)
.build();
holder.load();
return holder.inv;
}

public static ConfigInventory create(ItemStack is) {
var holder = new Holder(is);
holder.inv = ConfigInventory.configTypes(AEKeyTypes.getAll(), 63, holder::save);
holder.inv = ConfigInventory.configTypes(63).changeListener(holder::save).build();
holder.load();
return holder.inv;
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/appeng/parts/automation/FormationPlanePart.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ public class FormationPlanePart extends UpgradeablePart implements IStorageProvi
public FormationPlanePart(IPartItem<?> partItem) {
super(partItem);
getMainNode().addService(IStorageProvider.class, this);
this.config = ConfigInventory.configTypes(StackWorldBehaviors.withPlacementStrategy(),
63, this::updateFilter);
this.config = ConfigInventory.configTypes(63)
.supportedTypes(StackWorldBehaviors.withPlacementStrategy())
.changeListener(this::updateFilter)
.build();

this.getConfigManager().registerSetting(Settings.PLACE_BLOCK, YesNo.YES);
this.getConfigManager().registerSetting(Settings.FUZZY_MODE, FuzzyMode.IGNORE_ALL);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/parts/automation/IOBusPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ public IOBusPart(TickRates tickRates, Set<AEKeyType> supportedKeyTypes, IPartIte
super(partItem);
this.tickRates = tickRates;
this.source = new MachineSource(this);
this.config = ConfigInventory.configTypes(supportedKeyTypes, 63, this::updateState);
this.config = ConfigInventory.configTypes(63).supportedTypes(supportedKeyTypes)
.changeListener(this::updateState).build();
getMainNode().addService(IGridTickable.class, this);

this.getConfigManager().registerSetting(Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public class StorageLevelEmitterPart extends AbstractLevelEmitterPart
public static final PartModel MODEL_ON_ON = new PartModel(MODEL_BASE_ON, MODEL_STATUS_ON);
public static final PartModel MODEL_ON_HAS_CHANNEL = new PartModel(MODEL_BASE_ON, MODEL_STATUS_HAS_CHANNEL);

private final ConfigInventory config = ConfigInventory.configTypes(1, this::configureWatchers);
private final ConfigInventory config = ConfigInventory.configTypes(1).changeListener(this::configureWatchers)
.build();
private IStackWatcher storageWatcher;
private IStackWatcher craftingWatcher;
private long lastUpdateTick = -1;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/appeng/parts/encoding/PatternEncodingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import appeng.api.crafting.PatternDetailsHelper;
import appeng.api.inventories.InternalInventory;
import appeng.api.stacks.AEItemKey;
import appeng.api.stacks.AEKeyTypes;
import appeng.api.stacks.GenericStack;
import appeng.core.definitions.AEItems;
import appeng.crafting.pattern.AECraftingPattern;
Expand All @@ -49,10 +48,11 @@ public class PatternEncodingLogic implements InternalInventoryHost {
AEProcessingPattern.MAX_INPUT_SLOTS);
private static final int MAX_OUTPUT_SLOTS = AEProcessingPattern.MAX_OUTPUT_SLOTS;

private final ConfigInventory encodedInputInv = ConfigInventory.configStacks(AEKeyTypes.getAll(), MAX_INPUT_SLOTS,
this::onEncodedInputChanged, true);
private final ConfigInventory encodedOutputInv = ConfigInventory.configStacks(AEKeyTypes.getAll(), MAX_OUTPUT_SLOTS,
this::onEncodedOutputChanged, true);
private final ConfigInventory encodedInputInv = ConfigInventory.configStacks(MAX_INPUT_SLOTS)
.changeListener(this::onEncodedInputChanged).allowOverstacking(true).build();
private final ConfigInventory encodedOutputInv = ConfigInventory.configStacks(MAX_OUTPUT_SLOTS)
.changeListener(this::onEncodedOutputChanged).allowOverstacking(true).build();

private final AppEngInternalInventory blankPatternInv = new AppEngInternalInventory(this, 1);
private final AppEngInternalInventory encodedPatternInv = new AppEngInternalInventory(this, 1);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/appeng/parts/storagebus/StorageBusPart.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public class StorageBusPart extends UpgradeablePart
new ResourceLocation(AppEng.MOD_ID, "part/storage_bus_has_channel"));

protected final IActionSource source;
private final ConfigInventory config = ConfigInventory.configTypes(63, this::onConfigurationChanged);
private final ConfigInventory config = ConfigInventory.configTypes(63).changeListener(this::onConfigurationChanged)
.build();
/**
* This is the virtual inventory this storage bus exposes to the network it belongs to. To avoid continuous
* cell-change notifications, we instead use a handler that will exist as long as this storage bus exists, while
Expand Down
Loading

0 comments on commit 3e065bd

Please sign in to comment.