Changes

→‎Custom machines: update for build 22276: lots of changes
Line 557: Line 557:  
|-
 
|-
 
| <samp>OutputRules</samp>
 
| <samp>OutputRules</samp>
| ''(Optional)'' The rules which define how to process input items. This consists of a list of models with these fields:
+
| The output produced by this machine. This consists of a list of models with these fields:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 563: Line 563:  
! effect
 
! effect
 
|-
 
|-
| <samp>RequiredItemId</samp>
+
| <samp>Triggers</samp>
| ''(Optional)'' The qualified or unqualified item ID for the item to match, or omit to allow any item ID.
+
| When to apply this output rule. This can list any number of triggers; the output will apply if any of them match.
|-
  −
| <samp>RequiredTags</samp>
  −
| ''(Optional)'' A list of [[Modding:Context tags|context tags]] to match against input items. An item must have all of the listed tags to select this rule. You can negate a tag with <samp>!</samp> (like <code>"RequiredTags": [ "bone_item", "!fossil_item" ]</code> for bone items that aren't fossils).
  −
|-
  −
| <samp>RequiredCount</samp>
  −
| ''(Optional)'' The required stack size for the selected item. Default 1.
  −
|-
  −
| <samp>Condition</samp>
  −
| ''(Optional)'' A [[#Game state queries|game state query]] which indicates whether the given input should be matched (if the other requirements are matched too). Item-only tokens are valid for this check. Defaults to always true.
  −
|-
  −
| <samp>OverrideOutputs</samp>
  −
| ''(Optional)'' The output items produced by this conversion rule. This uses the same format as <samp>Outputs</samp> on the machine itself. Defaults to the machine's <samp>Outputs</samp> field if omitted.
  −
|-
  −
| <samp>UseFirstValidOutput</samp>
  −
| ''(Optional)'' If multiple <samp>Outputs</samp> or <samp>OverrideOutputs</samp> entries match, whether to use the first match instead of choosing one randomly. Default false.
  −
|-
  −
| <samp>OverrideMinutesUntilReady</samp><br /><samp>OverrideDaysUntilReady</samp>
  −
| ''(Optional)'' If set, overrides the machine's main <samp>MinutesUntilReady</samp> or <samp>DaysUntilReady</samp> fields.
  −
|-
  −
| <samp>InvalidCountMessage</samp>
  −
| ''(Optional)'' If set, overrides the machine's main <samp>InvalidCountMessage</samp> field.
  −
|}
  −
|-
  −
| <samp>AdditionalConsumedItems</samp>
  −
| ''(Optional)'' A list of extra items required before <samp>OutputRules</samp> or <samp>ConversionMethod</samp> will be checked. If specified, every listed item must be present in the player, [[hopper]], or chest inventory (depending how the machine is being loaded).
      
This consists of a list of models with these fields:
 
This consists of a list of models with these fields:
Line 597: Line 572:  
! effect
 
! effect
 
|-
 
|-
| <samp>ItemId</samp>
+
| <samp>Trigger</samp>
| The [[#Custom items|qualified or unqualified item ID]] for the required item.
+
| ''(Optional)'' When this output rule applies. Defaults to <samp>ItemPlacedInMachine</samp>. The possible values are...
 +
* <samp>ItemPlacedInMachine</samp>: apply this rule when an item is placed into the machine. This is the most common machine behavior.
 +
* <samp>OutputCollected</samp>: apply this rule when the machine's previous output is collected. An output-collected rule won't require or consume the input items, and the input item will be the previous output. For example, this is used to reload the [[crystalarium]].
 +
* <samp>MachinePutDown</samp>: apply this rule when the machine is put down. For example, this is used to start the [[Worm Bin|worm bin]].
 +
* <samp>DayUpdate</samp>: apply this rule when a new day starts, if it isn't already processing output. For example, this is used for the [[Soda Machine|soda machine]].
 +
|-
 +
| <samp>RequiredItemId</samp>
 +
| ''(Optional)'' The qualified or unqualified item ID for the item to match, if the trigger is <samp>ItemPlacedInMachine</samp> or <samp>OutputCollected</samp>. Defaults to allowing any item ID.
 +
|-
 +
| <samp>RequiredTags</samp>
 +
| ''(Optional)'' The [[Modding:Context tags|context tags]] to match against input items, if the trigger is <samp>ItemPlacedInMachine</samp> or <samp>OutputCollected</samp>. An item must have all of the listed tags to select this rule. You can negate a tag with <samp>!</samp> (like <code>"RequiredTags": [ "bone_item", "!fossil_item" ]</code> for bone items that aren't fossils).
 
|-
 
|-
 
| <samp>RequiredCount</samp>
 
| <samp>RequiredCount</samp>
| ''(Optional)'' The required stack size for the item matching <samp>ItemId</samp>. Default 1.
+
| ''(Optional)'' The required stack size for the input item, if the trigger is <samp>ItemPlacedInMachine</samp> or <samp>OutputCollected</samp>. Default 1.
 
|-
 
|-
| <samp>InvalidCountMessage</samp>
+
| <samp>Condition</samp>
| ''(Optional)'' If set, overrides the machine's main <samp>InvalidCountMessage</samp> field.
+
| ''(Optional)'' A [[#Game state queries|game state query]] which indicates whether this trigger should be checked. Item-only tokens are valid for this check if the trigger is <samp>ItemPlacedInMachine</samp> or <samp>OutputCollected</samp>. Defaults to always true.
 
|}
 
|}
 
|-
 
|-
| <samp>Outputs</samp>
+
| <samp>OutputItem</samp>
| ''(Optional)'' The items produced by this machine, unless overridden by <samp>OverrideOutputs</samp> under <samp>OutputRules</samp>. If multiple output entries match, one will be selected randomly unless you specify <samp>UseFirstValidOutput</samp>. This consists of a list of models with these fields:
+
| The items produced by this machine. If multiple output entries match, one will be selected randomly unless you specify <samp>UseFirstValidOutput</samp>. This consists of a list of models with these fields:
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 634: Line 619:  
|-
 
|-
 
| <samp>MinCount</samp><br /><samp>MaxCount</samp>
 
| <samp>MinCount</samp><br /><samp>MaxCount</samp>
| ''(Optional)'' The minimum and maximum number of this item produced. A value in this range will chosen randomly each time it's produced. If the maximum is set to <samp>-1</samp>, it'll match the minimum automatically. Defaults to 1 (minimum) and -1 (maximum).
+
| ''(Optional)'' The minimum and maximum number of this item produced. A value in this range will be chosen randomly each time it's produced. If the maximum is set to <samp>-1</samp>, it'll match the minimum automatically. Defaults to 1 (minimum) and -1 (maximum).
 
|-
 
|-
 
| <samp>Quality</samp>
 
| <samp>Quality</samp>
Line 659: Line 644:  
| <samp>IncrementMachineParentSheetIndex</samp>
 
| <samp>IncrementMachineParentSheetIndex</samp>
 
| ''(Optional)'' Whether to increment the machine's spritesheet index by one while it's processing this output. This stacks with the <samp>ShowNextIndexWhenLoaded</samp> field (''i.e.'' setting both to true will increment the index by two). Default false.
 
| ''(Optional)'' Whether to increment the machine's spritesheet index by one while it's processing this output. This stacks with the <samp>ShowNextIndexWhenLoaded</samp> field (''i.e.'' setting both to true will increment the index by two). Default false.
 +
|-
 +
| <samp>OutputMethod</samp>
 +
| ''(Optional, specialized)'' A C# method which decides which item to produce. If set, the <samp>ItemId</samp> field is optional and ignored.
 +
 +
This must be specified in the form <samp>{{t|full type name}}.{{t|method name}}</samp> (like <samp>StardewValley.Object.OutputSolarPanel</samp>). The method must be static and match the game's <samp>MachineOutputDelegate</samp> method signature:
 +
<syntaxhighlight lang="c#">
 +
/// <summary>Get the output item to produce.</summary>
 +
/// <param name="machine">The machine instance for which to produce output.</param>
 +
/// <param name="location">The location containing the machine.</param>
 +
/// <param name="player">The player using the machine.</param>
 +
/// <param name="inputItem">The item being dropped into the machine, if applicable.</param>
 +
/// <param name="probe">Whether the machine is only checking whether the input is valid. If so, the input/machine shouldn't be changed and no animations/sounds should play.</param>
 +
/// <param name="overrideMinutesUntilReady">The in-game minutes until the item will be ready to collect, if set. This overrides the equivalent fields in the machine data if set.</param>
 +
/// <returns>Returns the item to produce, or <c>null</c> if none should be produced.</returns>
 +
public static Item GetOutput(Object machine, GameLocation location, Farmer player, Item inputItem, bool probe, out int? overrideMinutesUntilReady);
 +
</syntaxhighlight>
 +
 +
If this method returns null, the machine won't output anything.
 
|}
 
|}
 +
|-
 +
| <samp>UseFirstValidOutput</samp>
 +
| ''(Optional)'' If multiple <samp>OutputItem</samp> entries match, whether to use the first match instead of choosing one randomly. Default false.
 
|-
 
|-
 
| <samp>MinutesUntilReady</samp><br /><samp>DaysUntilReady</samp>
 
| <samp>MinutesUntilReady</samp><br /><samp>DaysUntilReady</samp>
| ''(Optional)'' The number of in-game minutes or days until the output is ready to collect, unless overridden by <samp>OverrideMinutesUntilReady</samp> or <samp>OverrideDaysUntilReady</samp> under <samp>OutputRules</samp>. If both days and minutes are specified, days are used. If none are specified, the item will be ready instantly.
+
| ''(Optional)'' The number of in-game minutes or days until the output is ready to collect. If both days and minutes are specified, days are used. If none are specified, the item will be ready instantly.
 +
|-
 +
| <samp>InvalidCountMessage</samp>
 +
| ''(Optional)'' If set, overrides the machine's main <samp>InvalidCountMessage</samp> field.
 +
|}
 
|-
 
|-
| <samp>UseFirstValidOutput</samp>
+
| <samp>AdditionalConsumedItems</samp>
| ''(Optional)'' If multiple <samp>Output</samp> entries match, whether to use the first match instead of choosing one randomly. Default false.
+
| ''(Optional)'' A list of extra items required before <samp>OutputRules</samp> will be checked. If specified, every listed item must be present in the player, [[hopper]], or chest inventory (depending how the machine is being loaded).
   −
This has no effect if <samp>OutputRules</samp> is set; use the separate <samp>UseFirstValidOutput</samp> field on each item conversion entry instead in that case.
+
This consists of a list of models with these fields:
 +
{| class="wikitable"
 +
|-
 +
! field
 +
! effect
 +
|-
 +
| <samp>ItemId</samp>
 +
| The [[#Custom items|qualified or unqualified item ID]] for the required item.
 +
|-
 +
| <samp>RequiredCount</samp>
 +
| ''(Optional)'' The required stack size for the item matching <samp>ItemId</samp>. Default 1.
 +
|-
 +
| <samp>InvalidCountMessage</samp>
 +
| ''(Optional)'' If set, overrides the machine's main <samp>InvalidCountMessage</samp> field.
 +
|}
 
|-
 
|-
 
| <samp>QualityModifiers</samp><br /><samp>QuantityModifiers</samp><br /><samp>ReadyTimeModifiers</samp>
 
| <samp>QualityModifiers</samp><br /><samp>QuantityModifiers</samp><br /><samp>ReadyTimeModifiers</samp>
Line 701: Line 725:  
| <samp>Always</samp>
 
| <samp>Always</samp>
 
| Always pause the machine. This is used in specialized cases where the timer is handled by [[#Advanced logic|advanced machine logic]].
 
| Always pause the machine. This is used in specialized cases where the timer is handled by [[#Advanced logic|advanced machine logic]].
|}
  −
|-
  −
| <samp>Trigger</samp>
  −
| ''(Optional)'' When the machine should start producing output. Possible values:
  −
{| class="wikitable"
  −
|-
  −
! value
  −
! effect
  −
|-
  −
| <samp>Conversion</samp>
  −
| After processing an item dropped in by a player based on the item conversion fields. This is the most common machine behavior.
  −
|-
  −
| <samp>Placement</samp>
  −
| After the item is placed. For example, the [[Worm Bin|worm bin]] uses this to start as soon as it's put down.
  −
|-
  −
| <samp>DayUpdate</samp>
  −
| After a new day starts. For example, the [[Soda Machine|soda machine]] does this.
  −
|-
  −
| <samp>DayUpdateOrPlacement</samp>
  −
| Combines the <samp>DayUpdate</samp> and <samp>Placement</samp> triggers.
   
|}
 
|}
 
|-
 
|-
 
| <samp>AllowLoadWhenFull</samp>
 
| <samp>AllowLoadWhenFull</samp>
 
| ''(Optional)'' Whether the player can drop a new item into the machine before it's done processing the last one (like the [[crystalarium]]). The previous item will be lost. Default false.
 
| ''(Optional)'' Whether the player can drop a new item into the machine before it's done processing the last one (like the [[crystalarium]]). The previous item will be lost. Default false.
|-
  −
| <samp>ReloadOnCollect</samp>
  −
| ''(Optional)'' Whether to restart the machine with the same input when the player collects the output (like the [[crystalarium]]). Default false.
   
|-
 
|-
 
| <samp>ClearContentsOvernightCondition</samp>
 
| <samp>ClearContentsOvernightCondition</samp>
Line 860: Line 861:  
! field
 
! field
 
! effect
 
! effect
|-
  −
| <samp>ConversionMethod</samp>
  −
| ''(Optional)'' A C# method which applies custom processing logic when the player tries to drop an item into the machine.
  −
  −
This must be specified in the form <samp>{{t|full type name}}.{{t|method name}}</samp> (like <samp>StardewValley.Object.DropInDeconstructor</samp>). The method must be static, take six arguments (<code>Object machine, Item dropped_in_item, Farmer player, bool probe, ref Item output, ref int minutes_until_ready</code>), and return a boolean indicating whether the input was successfully processed.
  −
  −
⚠️ Caveats:
  −
* This will completely disable the <samp>OutputRules</samp>, <samp>InvalidItemMessage</samp>, <samp>InvalidCountMessage</samp>, and <samp>Outputs</samp> fields.
  −
* This will prevent any other mod from registering their own processing rules for this machine.
  −
* This will prevent {{nexus mod|1063|Automate}} from automating the machine, since it has no way to know which items will be accepted by the method. For Automate support, you'd need to [https://github.com/Pathoschild/StardewMods/blob/develop/Automate/docs/technical.md#extensibility-for-modders use Automate's API] to register a custom machine factory to handle it in code.
  −
* This should ''only'' perform conversion logic. Don't handle interaction logic like animations, sounds, or UI messages in this method, since that'll interfere with [[hopper]]s and other machine mods. See the other fields instead for that.
   
|-
 
|-
 
| <samp>InteractMethod</samp>
 
| <samp>InteractMethod</samp>
 
| ''(Optional)'' A C# method invoked when the player interacts with the machine when it doesn't have output ready to harvest.
 
| ''(Optional)'' A C# method invoked when the player interacts with the machine when it doesn't have output ready to harvest.
   −
This must be specified in the form <samp>{{t|full type name}}.{{t|method name}}</samp> (like <samp>StardewValley.Object.SomeInteractMethod</samp>). The method must be static, take three arguments (<code>Object machine, GameLocation location, Farmer player</code>), and return a boolean indicating whether the interaction succeeded.
+
This must be specified in the form <samp>{{t|full type name}}.{{t|method name}}</samp> (like <samp>StardewValley.Object.SomeInteractMethod</samp>). The method must be static and match the game's <samp>MachineInteractDelegate</samp> method signature:
|-
+
<syntaxhighlight lang="c#">
| <samp>OutputMethod</samp>
+
/// <summary>The method signature for a custom <see cref="MachineData.InteractMethod"/> method.</summary>
| ''(Optional)'' A C# method which produces the item to output.
+
/// <param name="machine">The machine instance for which to produce output.</param>
 
+
/// <param name="location">The location containing the machine.</param>
This must be specified in the form <samp>{{t|full type name}}.{{t|method name}}</samp> (like <samp>StardewValley.Object.OutputSolarPanel</samp>). The method must be static, take three arguments (<code>Object machine, GameLocation location, Farmer player</code>), and return the <samp>Item</samp> instance to output. If this method returns null, the machine won't output anything.
+
/// <param name="player">The player using the machine.</param>
 
+
/// <returns>Returns whether the interaction was handled.</returns>
⚠️ Caveats:
+
public static bool InteractWithMachine(Object machine, GameLocation location, Farmer player);
* If you also specify other fields like <samp>OutputRules</samp> or <samp>Outputs</samp>, any output they return will override this value.
+
</syntaxhighlight>
 
|-
 
|-
 
| <samp>HasInput</samp><br /><samp>HasOutput</samp>
 
| <samp>HasInput</samp><br /><samp>HasOutput</samp>
| ''(Optional)'' Whether to force adding the <samp>machine_input</samp> or <samp>machine_output</samp> [[#New context tags|context tags]] respectively. This isn't needed for most machines, since they'll be set based on the other fields. Default false.
+
| ''(Optional)'' Whether to force adding the <samp>machine_input</samp> or <samp>machine_output</samp> [[#New context tags|context tags]] respectively. This isn't needed for most machines, since they'll be set based on the <samp>OutputRules</samp> field. Default false.
 
|-
 
|-
 
| <samp>IsIncubator</samp>
 
| <samp>IsIncubator</samp>
translators
8,445

edits