Modding:Garbage cans: Difference between revisions
imported>VulpesLucida m zh link |
imported>Pathoschild use {{Content Patcher example}}, fix incorrect syntaxhighlight langs |
||
| Line 73: | Line 73: | ||
You can add garbage cans using only [[Modding:Content Patcher|Content Patcher]] or [[Modding:Modder Guide/APIs/Content|SMAPI's content API]]. For example, this content pack adds a new garbage can entry with the ID <samp>Example.ModId_Carpenter</samp>: | You can add garbage cans using only [[Modding:Content Patcher|Content Patcher]] or [[Modding:Modder Guide/APIs/Content|SMAPI's content API]]. For example, this content pack adds a new garbage can entry with the ID <samp>Example.ModId_Carpenter</samp>: | ||
{{Content Patcher example|<nowiki> | |||
"Changes": [ | "Changes": [ | ||
{ | { | ||
| Line 101: | Line 99: | ||
} | } | ||
] | ] | ||
</nowiki>}} | |||
Then you'd place an <code>Action: Garbage Example.ModId_Carpenter</code> [[Modding:Maps|map tile property]] to mark a tile as a garbage can using this data. | Then you'd place an <code>Action: Garbage Example.ModId_Carpenter</code> [[Modding:Maps|map tile property]] to mark a tile as a garbage can using this data. | ||
| Line 110: | Line 108: | ||
Note that this uses <samp>TargetField</samp> to 'move into' the item list for the saloon, and then treat those items as the entry list being edited. Specifying an ID which isn't in the list will add a new entry, just like when editing a regular list asset. | Note that this uses <samp>TargetField</samp> to 'move into' the item list for the saloon, and then treat those items as the entry list being edited. Specifying an ID which isn't in the list will add a new entry, just like when editing a regular list asset. | ||
{{Content Patcher example|<nowiki> | |||
"Changes": [ | "Changes": [ | ||
{ | { | ||
| Line 132: | Line 128: | ||
} | } | ||
] | ] | ||
</nowiki>}} | |||
==Changes for C# mods== | ==Changes for C# mods== | ||
| Line 145: | Line 141: | ||
|- | |- | ||
| check if a garbage can was searched | | check if a garbage can was searched | ||
| <syntaxhighlight lang=" | | <syntaxhighlight lang="c#"> | ||
Town town = (Town)Game1.getLocationFromName("Town"); | Town town = (Town)Game1.getLocationFromName("Town"); | ||
if (town.garbageChecked[5]) | if (town.garbageChecked[5]) | ||
... | ... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| <syntaxhighlight lang=" | | <syntaxhighlight lang="c#"> | ||
if (Game1.netWorldState.Value.CheckedGarbage.Contains("Saloon")) | if (Game1.netWorldState.Value.CheckedGarbage.Contains("Saloon")) | ||
... | ... | ||
| Line 156: | Line 152: | ||
|- | |- | ||
| mark a garbage can searched | | mark a garbage can searched | ||
| <syntaxhighlight lang=" | | <syntaxhighlight lang="c#"> | ||
Town town = (Town)Game1.getLocationFromName("Town"); | Town town = (Town)Game1.getLocationFromName("Town"); | ||
town.garbageChecked[5] = true; | town.garbageChecked[5] = true; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| <syntaxhighlight lang=" | | <syntaxhighlight lang="c#"> | ||
Game1.netWorldState.Value.CheckedGarbage.Add("Saloon"); | Game1.netWorldState.Value.CheckedGarbage.Add("Saloon"); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 20:09, 1 February 2025
← Index
This page explains garbage cans. This is an advanced guide for mod developers.
Format
You can add or edit garbage cans on any map by editing the new Data/GarbageCans asset (see examples below).
The asset consists of a data model with these fields:
| field | effect | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| DefaultBaseChance | The probability that an item will be found when searching garbage cans, as a value between 0 (never) and 1 (always). If the probability check fails, only items that set IgnoreBaseChance can spawn. This can be overridden by the per-garbage-can BaseChance field. Default 0.2. | ||||||||||||||||||||||
| BeforeAll AfterAll |
The items to prepend (BeforeAll) or append (AfterAll) to the GarbageCans → Items field for all garbage cans. These work exactly like the items in that field (e.g. subject to the garbage can's base chance). | ||||||||||||||||||||||
| GarbageCans | The data for individual garbage cans. This consists of a string → model lookup with these fields:
If the garbage can being searched doesn't have its own entry under GarbageCans, the game will just use the BeforeAll and AfterAll fields. | ||||||||||||||||||||||
| CustomFields | The custom fields for this entry. |
Example new garbage can
You can add garbage cans using only Content Patcher or SMAPI's content API. For example, this content pack adds a new garbage can entry with the ID Example.ModId_Carpenter:
{
"Format": "2.8.0",
"Changes": [
{
"Action": "EditData",
"Target": "Data/GarbageCans",
"TargetField": [ "GarbageCans" ],
"Entries": {
"{{ModId}}_Carpenter": {
"Items": [
// 25% chance of pufferfish
{
"ID": "{{ModId}}_Pufferfish",
"Condition": "RANDOM 0.25",
"ItemId": "(O)128"
},
// else guaranteed random House Plant item
{
"ID": "{{ModId}}_RandomHousePlant",
"ItemID": "RANDOM_ITEMS (F) 1376 1390"
}
]
}
}
}
]
}
Then you'd place an Action: Garbage Example.ModId_Carpenter map tile property to mark a tile as a garbage can using this data.
Example change for existing garbage can
You can edit an existing garbage cans using only Content Patcher or SMAPI's content API. For example, this content pack adds pufferfish to the Saloon garbage can, and moves it above the dish of the day.
Note that this uses TargetField to 'move into' the item list for the saloon, and then treat those items as the entry list being edited. Specifying an ID which isn't in the list will add a new entry, just like when editing a regular list asset.
{
"Format": "2.8.0",
"Changes": [
{
"Action": "EditData",
"Target": "Data/GarbageCans",
"TargetField": [ "GarbageCans", "Saloon", "Items" ],
"Entries": {
// 25% chance of pufferfish
"{{ModId}}_Pufferfish":{
"ID": "{{ModId}}_Pufferfish",
"Condition": "RANDOM 0.25",
"ItemId": "(O)128"
}
},
"MoveEntries": [
{ "ID": "{{ModId}}_Pufferfish", "BeforeId": "Base_DishOfTheDay" }
]
}
]
}
Changes for C# mods
Previously garbage cans were tracked by Town.garbageChecked, an array of boolean fields. That approach doesn't work in Stardew Valley 1.6, since we're no longer limited to a specific set of garbage cans in the town map. This has been replaced by Game1.netWorldState.Value.CheckedGarbage, which is a hash set of garbage can IDs.
To migrate code:
| action | code in 1.5.6 | code in 1.6 |
|---|---|---|
| check if a garbage can was searched | Town town = (Town)Game1.getLocationFromName("Town");
if (town.garbageChecked[5])
...
|
if (Game1.netWorldState.Value.CheckedGarbage.Contains("Saloon"))
...
|
| mark a garbage can searched | Town town = (Town)Game1.getLocationFromName("Town");
town.garbageChecked[5] = true;
|
Game1.netWorldState.Value.CheckedGarbage.Add("Saloon");
|
To migrate former vanilla trash can IDs:
| position | ID in 1.5.6 | ID in 1.6 |
|---|---|---|
| Near Jodi and Kent's house | 0
|
JodiAndKent
|
| Near Emily and Haley's house | 1
|
EmilyAndHaley
|
| Near Lewis' house | 2
|
Mayor
|
| Near Museum | 3
|
Museum
|
| Near Clint's blacksmith | 4
|
Blacksmith
|
| Near the Saloon | 5
|
Saloon
|
| Near Evelyn and George's house | 6
|
Evelyn
|
| Near JojaMart | 7
|
JojaMart
|