Skip to content

Commit

Permalink
feat: Tooltips for upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Zekromaster committed Aug 3, 2024
1 parent d22873d commit 8bccd46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/main/kotlin/net/zekromaster/minecraft/ironchests/upgrades.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.world.World
import net.modificationstation.stationapi.api.client.item.CustomTooltipProvider
import net.modificationstation.stationapi.api.event.recipe.RecipeRegisterEvent
import net.modificationstation.stationapi.api.event.registry.ItemRegistryEvent
import net.modificationstation.stationapi.api.recipe.CraftingRegistry
Expand Down Expand Up @@ -100,7 +101,7 @@ abstract class ChestUpgrade(identifier: Identifier): TemplateItem(identifier) {
abstract fun upgrade(world: World, x: Int, y: Int, z: Int, player: PlayerEntity, blockEntity: ChestBlockEntity): Boolean
}

private sealed class TierUpgrade(identifier: Identifier, private val destination: IronChestMaterial): ChestUpgrade(identifier) {
private sealed class TierUpgrade(identifier: Identifier, protected val destination: IronChestMaterial): ChestUpgrade(identifier) {
override fun upgrade(world: World, x: Int, y: Int, z: Int, player: PlayerEntity, blockEntity: ChestBlockEntity): Boolean {
if (canUpgrade(blockEntity)) {
val oldBlockState = world.getBlockState(x, y, z)
Expand Down Expand Up @@ -132,15 +133,19 @@ private sealed class TierUpgrade(identifier: Identifier, private val destination
protected abstract fun canUpgrade(blockEntity: ChestBlockEntity): Boolean
}

private class WoodToIronUpgrade(identifier: Identifier, destination: IronChestMaterial): TierUpgrade(identifier, destination) {
private class WoodToIronUpgrade(identifier: Identifier, destination: IronChestMaterial): TierUpgrade(identifier, destination), CustomTooltipProvider {
override fun canUpgrade(blockEntity: ChestBlockEntity) = blockEntity.block == Block.CHEST

override fun getTooltip(stack: ItemStack, originalTooltip: String) = arrayOf(originalTooltip, "Wood to ${destination.displayName}")
}

private class IronToIronUpgrade(identifier: Identifier, val starting: IronChestMaterial, destination: IronChestMaterial): TierUpgrade(identifier, destination) {
private class IronToIronUpgrade(identifier: Identifier, val starting: IronChestMaterial, destination: IronChestMaterial): TierUpgrade(identifier, destination), CustomTooltipProvider {
override fun canUpgrade(blockEntity: ChestBlockEntity): Boolean = blockEntity is IronChestBlockEntity && blockEntity.material == starting

override fun getTooltip(stack: ItemStack, originalTooltip: String) = arrayOf(originalTooltip, "${starting.displayName} to ${destination.displayName}")
}

private class ObsidianUpgrade(identifier: Identifier): ChestUpgrade(identifier) {
private class ObsidianUpgrade(identifier: Identifier): ChestUpgrade(identifier), CustomTooltipProvider {
override fun upgrade(
world: World,
x: Int,
Expand All @@ -161,4 +166,6 @@ private class ObsidianUpgrade(identifier: Identifier): ChestUpgrade(identifier)
world.setBlockDirty(x, y, z)
return true
}

override fun getTooltip(stack: ItemStack, originalTooltip: String) = arrayOf(originalTooltip, "Makes any non-Wooden Chest blast resistant")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enum class IronChestMaterial(val id: String, val rows: Int, val columns: Int) {
DIAMOND("diamond", 9, 12);

val size = rows * columns
val chestName: String = "${id.replaceFirstChar(Char::uppercaseChar)} Chest"
val displayName: String = id.replaceFirstChar(Char::uppercaseChar)
val chestName: String = "$displayName Chest"

fun getBlock() =
when (this) {
Expand Down

0 comments on commit 8bccd46

Please sign in to comment.