Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement interface of various inventories #196

Merged
merged 15 commits into from
Jun 5, 2024
Merged
16 changes: 15 additions & 1 deletion Sources/Core/Sources/GUI/GUISprite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ public enum GUISprite {
/// these to be separate sprites.
case singleChestTopHalf
case singleChestBottomHalf

case doubleChest // No top/bottom half since it just uses the full image
case generic9x1
case generic9x2
case generic9x4
case generic9x5
/// The descriptor for the sprite.
public var descriptor: GUISpriteDescriptor {
switch self {
Expand Down Expand Up @@ -61,6 +65,16 @@ public enum GUISprite {
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 0], size: [176, 71])
case .singleChestBottomHalf:
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 125], size: [176, 97])
case .doubleChest:
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 0], size: [176, 222])
case .generic9x1:
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 0], size: [176, 35])
case .generic9x2:
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 0], size: [176, 53])
case .generic9x4:
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 0], size: [176, 89])
case .generic9x5:
return GUISpriteDescriptor(slice: .genericContainer, position: [0, 0], size: [176, 107])
}
}
}
157 changes: 156 additions & 1 deletion Sources/Core/Sources/GUI/WindowType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,167 @@ public struct WindowType {
]
)

public static let doubleChest = WindowType(
id: .vanilla(5),
identifier: Identifier(namespace: "minecraft", name: "generic_9x6"),
background: GUIElement.list(spacing: 0) {
GUIElement.sprite(.doubleChest)
},
slotCount: 90,
areas: [
WindowArea(
startIndex: 0,
width: 9,
height: 6,
position: Vec2i(8, 18)
),
WindowArea(
startIndex: 54,
width: 9,
height: 3,
position: Vec2i(8, 140)
),
WindowArea(
startIndex: 81,
width: 9,
height: 1,
position: Vec2i(8, 198)
),
]
)

// Generic window types
public static let generic9x1 = WindowType(
id: .vanilla(0),
identifier: Identifier(namespace: "minecraft", name: "generic_9x1"),
background: GUIElement.list(spacing: 0) {
GUIElement.sprite(.generic9x1)
GUIElement.sprite(.singleChestBottomHalf)
},
FloofyPlasma marked this conversation as resolved.
Show resolved Hide resolved
slotCount: 45,
areas: [
WindowArea(
startIndex: 0,
width: 9,
height: 1,
position: Vec2i(8, 18)
),
WindowArea(
startIndex: 9,
width: 9,
height: 3,
position: Vec2i(8, 50)
),
WindowArea(
startIndex: 36,
width: 9,
height: 1,
position: Vec2i(8, 108)
)
]
)

public static let generic9x2 = WindowType(
id: .vanilla(1),
identifier: Identifier(namespace: "minecraft", name: "generic_9x2"),
background: GUIElement.list(spacing: 0) {
GUIElement.sprite(.generic9x2)
GUIElement.sprite(.singleChestBottomHalf)
},
slotCount: 54,
areas: [
WindowArea(
startIndex: 0,
width: 9,
height: 2,
position: Vec2i(8, 18)
),
WindowArea(
startIndex: 18,
width: 9,
height: 3,
position: Vec2i(8, 68)
),
WindowArea(
startIndex: 45,
width: 9,
height: 1,
position: Vec2i(8, 126)
)
]
)

public static let generic9x4 = WindowType(
id: .vanilla(3),
identifier: Identifier(namespace: "minecraft", name: "generic_9x4"),
background: GUIElement.list(spacing: 0) {
GUIElement.sprite(.generic9x4)
GUIElement.sprite(.singleChestBottomHalf) // Use the inventory section of the bottom half of the chest, wouldn't a more generic name for it be better?
},
slotCount: 72,
areas: [
WindowArea(
startIndex: 0,
width: 9,
height: 4,
position: Vec2i(8, 18)
),
WindowArea(
startIndex: 36,
width: 9,
height: 3,
position: Vec2i(8, 104)
),
WindowArea(
startIndex: 63,
width: 9,
height: 1,
position: Vec2i(8, 162)
)
]
)

public static let generic9x5 = WindowType(
id: .vanilla(4),
identifier: Identifier(namespace: "minecraft", name:"generic_9x5"),
background: GUIElement.list(spacing: 0) {
GUIElement.sprite(.generic9x5)
GUIElement.sprite(.singleChestBottomHalf) // Same reasoning as 9x4
},
slotCount: 81,
areas: [
WindowArea(
startIndex: 0,
width: 9,
height: 5,
position: Vec2i(8, 18)
),
WindowArea(
startIndex: 45,
width: 9,
height: 3,
position: Vec2i(8, 122)
),
WindowArea(
startIndex: 72,
width: 9,
height: 1,
position: Vec2i(8, 180)
)
]
)

/// The window types understood by vanilla.
public static let types = [Id: Self](
values: [
inventory,
craftingTable,
chest
chest,
doubleChest,
generic9x1,
generic9x2,
generic9x4,
generic9x5
],
keyedBy: \.id
)
Expand Down
Loading