Modding:Garbage cans: Difference between revisions
imported>VulpesLucida m zh link |
imported>Sunbeam135 m added ru link |
||
| (3 intermediate revisions by one other user not shown) | |||
| Line 4: | Line 4: | ||
==Format== | ==Format== | ||
You can add or edit [[Garbage Can|garbage cans]] on any map by editing the | You can add or edit [[Garbage Can|garbage cans]] on any map by editing the <samp>Data/GarbageCans</samp> asset (see examples below). | ||
The asset consists of a data model with these fields: | The asset consists of a data model with these fields: | ||
| Line 70: | Line 70: | ||
|} | |} | ||
== | ==Examples== | ||
===New garbage can=== | |||
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 100: | ||
} | } | ||
] | ] | ||
</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. | ||
== | ===Change an existing garbage can=== | ||
You can edit an existing 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 pufferfish to the Saloon garbage can, and moves it above the dish of the day. | You can edit an existing 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 pufferfish to the Saloon garbage can, and moves it above the dish of the day. | ||
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 129: | ||
} | } | ||
] | ] | ||
</nowiki>}} | |||
==Changes for C# mods== | ==Changes for C# mods== | ||
| Line 145: | Line 142: | ||
|- | |- | ||
| 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 153: | ||
|- | |- | ||
| 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> | ||
| Line 207: | Line 204: | ||
[[Category:Modding]] | [[Category:Modding]] | ||
[[ru:Модификации:Мусорные баки]] | |||
[[zh:模组:垃圾桶]] | [[zh:模组:垃圾桶]] | ||
Latest revision as of 11:09, 9 March 2026
← 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 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. |
Examples
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.
Change an 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
|