feat: Add screen type matching to Custom Screen Layouts (#177)
This commit is contained in:
@@ -8,6 +8,7 @@ import net.minecraft.client.gui.DrawContext
|
|||||||
import net.minecraft.client.gui.screen.Screen
|
import net.minecraft.client.gui.screen.Screen
|
||||||
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
import net.minecraft.client.gui.screen.ingame.HandledScreen
|
||||||
import net.minecraft.client.render.RenderLayer
|
import net.minecraft.client.render.RenderLayer
|
||||||
|
import net.minecraft.registry.Registries
|
||||||
import net.minecraft.resource.ResourceManager
|
import net.minecraft.resource.ResourceManager
|
||||||
import net.minecraft.resource.SinglePreparationResourceReloader
|
import net.minecraft.resource.SinglePreparationResourceReloader
|
||||||
import net.minecraft.screen.slot.Slot
|
import net.minecraft.screen.slot.Slot
|
||||||
@@ -49,11 +50,16 @@ object CustomScreenLayouts : SinglePreparationResourceReloader<List<CustomScreen
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class Preds(
|
data class Preds(
|
||||||
val label: StringMatcher,
|
val label: StringMatcher,
|
||||||
|
@Serializable(with = IdentifierSerializer::class)
|
||||||
|
val screenType: Identifier? = null,
|
||||||
) {
|
) {
|
||||||
fun matches(screen: Screen): Boolean {
|
fun matches(screen: Screen): Boolean {
|
||||||
// TODO: does this deserve the restriction to handled screen
|
// TODO: does this deserve the restriction to handled screen
|
||||||
val s = screen as? HandledScreen<*>? ?: return false
|
val s = screen as? HandledScreen<*>? ?: return false
|
||||||
return label.matches(s.title)
|
val typeMatches = screenType == null || s.screenHandler.type.equals(Registries.SCREEN_HANDLER
|
||||||
|
.get(screenType));
|
||||||
|
|
||||||
|
return label.matches(s.title) && typeMatches
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,5 +221,4 @@ object CustomScreenLayouts : SinglePreparationResourceReloader<List<CustomScreen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -577,7 +577,7 @@ not screens from other mods. You can also target specific texts via a [string ma
|
|||||||
|
|
||||||
## Screen Layout Replacement
|
## Screen Layout Replacement
|
||||||
|
|
||||||
You can change the layout of an entire screen by using screen layout overrides. These get placed in `firmskyblock:overrides/screen_layout/*.json`, with one file per screen. You can match on the title of a screen, replace the background texture (including extending the background canvas further than vanilla allows you) and move slots around.
|
You can change the layout of an entire screen by using screen layout overrides. These get placed in `firmskyblock:overrides/screen_layout/*.json`, with one file per screen. You can match on the title of a screen, the type of screen, replace the background texture (including extending the background canvas further than vanilla allows you) and move slots around.
|
||||||
|
|
||||||
### Selecting a screen
|
### Selecting a screen
|
||||||
|
|
||||||
@@ -586,13 +586,16 @@ You can change the layout of an entire screen by using screen layout overrides.
|
|||||||
"predicates": {
|
"predicates": {
|
||||||
"label": {
|
"label": {
|
||||||
"regex": "Hyper Furnace"
|
"regex": "Hyper Furnace"
|
||||||
}
|
},
|
||||||
|
"screenType": "minecraft:furnace"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `label` property is a regular [string matcher](#string-matcher) and matches against the screens title (typically the chest title, or "Crafting" for the players inventory).
|
The `label` property is a regular [string matcher](#string-matcher) and matches against the screens title (typically the chest title, or "Crafting" for the players inventory).
|
||||||
|
|
||||||
|
The `screenType` property is an optional namespaced identifier that allows matching to a [screen type](https://minecraft.wiki/w/Java_Edition_protocol/Inventory#Types).
|
||||||
|
|
||||||
### Changing the background
|
### Changing the background
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|||||||
Reference in New Issue
Block a user