Skip to content

Commit

Permalink
Add compacted crafting plan viewing mode
Browse files Browse the repository at this point in the history
This groups all missing and available ingredients per type,
which is more convenient to view at a glance what the problems are for
large and nested crafting jobs.

This is shown by default over the old tree-based view, but can be
toggled in-game.
This default can be changed using the `terminalStorageDefaultToCraftingPlanTree`
config option.

The tree-based view will be unavailable for very large crafting jobs as
it causes packets to become too large. The threshold for this can be
modified using the `terminalStorageMaxTreePlanSize` config option.

Closes #14
Closes CyclopsMC/IntegratedDynamics#1341
  • Loading branch information
rubensworks committed Jul 31, 2024
1 parent 1c2ec7c commit d5c531b
Show file tree
Hide file tree
Showing 19 changed files with 1,216 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class GeneralConfig extends DummyConfig {
public static int terminalStoragePacketMaxInstances = 512;
@ConfigurableProperty(category = "core", comment = "The maximum number of terminal storage crafting recipes that can be sent in a single packet. Reduce this when you have packet overflows.", isCommandable = true, configLocation = ModConfig.Type.SERVER)
public static int terminalStoragePacketMaxRecipes = 128;
@ConfigurableProperty(category = "core", comment = "If crafting plans should default to the tree-based view. If false, it will default to the flattened view.", isCommandable = true, configLocation = ModConfig.Type.COMMON)
public static boolean terminalStorageDefaultToCraftingPlanTree = false;
@ConfigurableProperty(category = "core", comment = "The limit for the number of leaves in a tree-based crafting plan after which it won't be sent to the client anymore.", isCommandable = true, configLocation = ModConfig.Type.SERVER)
public static int terminalStorageMaxTreePlanSize = 64;

@ConfigurableProperty(category = "machine", comment = "The number of items that should be selected when clicking on an item in the storage terminal.", isCommandable = true)
public static int guiStorageItemInitialQuantity = 64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ public interface ITerminalCraftingPlan<I> {
*/
public void setError(String unlocalizedError);

/**
* @return A flattened copy of this plan.
*/
public ITerminalCraftingPlanFlat<I> flatten();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.cyclops.integratedterminals.api.terminalstorage.crafting;

import org.cyclops.commoncapabilities.api.ingredient.IPrototypedIngredient;

import javax.annotation.Nullable;
import java.util.List;

/**
* A job for crafting a given instance.
* This is a flattened representation of {@link ITerminalCraftingPlan}.
*
* It is possible that a job requires no actual crafting,
* but can be fetched from storage completely.
*
* @param <I> The type of identifier.
* @author rubensworks
*/
public interface ITerminalCraftingPlanFlat<I> {

/**
* @return The unique id of this plan.
*/
public I getId();

/**
* @return The flattened entries that are crafted as part of this plan.
*/
public List<? extends IEntry> getEntries();

/**
* @return The final output instances of this job.
*/
public List<IPrototypedIngredient<?, ?>> getOutputs();

/**
* @return The job status.
*/
public TerminalCraftingJobStatus getStatus();

/**
* @return A visual label for this plan, such as an error or plan type.
*/
public String getUnlocalizedLabel();

/**
* @return The tick duration for this job. -1 indicates no duration.
*/
public long getTickDuration();

/**
* @return The channel id, or -1 for non-applicable.
*/
public int getChannel();

/**
* @return The initiator name of the crafting job.
*/
@Nullable
public String getInitiatorName();

/**
* Mark this plan as errored.
* @param unlocalizedError An unlocalized error message.
*/
public void setError(String unlocalizedError);

public static interface IEntry {

/**
* @return The entry instance.
*/
public IPrototypedIngredient<?, ?> getInstance();

/**
* @return The number of instances to craft.
*/
public long getQuantityToCraft();

/**
* @return The number of instances to craft.
*/
public long getQuantityCrafting();

/**
* @return The number of instances in storage.
*/
public long getQuantityInStorage();

/**
* @return The number of instances missing from storage.
*/
public long getQuantityMissing();

}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.cyclops.integratedterminals.api.terminalstorage.crafting;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import org.cyclops.commoncapabilities.api.ingredient.IngredientComponent;
import org.cyclops.integrateddynamics.api.network.INetwork;
import org.cyclops.integratedterminals.core.terminalstorage.TerminalStorageTabIngredientComponentServer;
Expand Down Expand Up @@ -91,6 +91,25 @@ public default ITerminalCraftingPlan<I> deserializeCraftingPlan(CompoundTag tag)
return TerminalCraftingPlanStatic.deserialize(tag, this);
}

/**
* Serialize a flat crafting plan to NBT.
* @param craftingPlan A flat crafting plan.
* @return An NBT tag.
*/
public default CompoundTag serializeCraftingPlanFlat(ITerminalCraftingPlanFlat<I> craftingPlan) {
return TerminalCraftingPlanFlatStatic.serialize((TerminalCraftingPlanFlatStatic) craftingPlan, this);
}

/**
* Deserialize a flat crafting plan from NBT.
* @param tag An NBT tag representing a flat crafting plan.
* @return A crafting option.
* @throws IllegalArgumentException If the given tag was invalid.
*/
public default ITerminalCraftingPlanFlat<I> deserializeCraftingPlanFlat(CompoundTag tag) throws IllegalArgumentException {
return TerminalCraftingPlanFlatStatic.deserialize(tag, this);
}

/**
* Serializes a crafting job id.
* @param id An id.
Expand Down
Loading

0 comments on commit d5c531b

Please sign in to comment.