Skip to content

Commit 26e0bf9

Browse files
authored
Merge pull request #598 from pylonmc/human/guides-and-hints
Guides and hints
2 parents 01d6069 + 88cd8c7 commit 26e0bf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+535
-102
lines changed

rebar/src/main/kotlin/io/github/pylonmc/rebar/addon/RebarAddon.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ interface RebarAddon : Keyed {
4141
val material: Material
4242

4343
/**
44-
* The name used to represent this addon in the item tooltips.
45-
* By default, a blue italic `<your-addon-key>.addon` translation key.
44+
* The name used to represent this addon in the guide and other places.
4645
*/
4746
val displayName: TranslatableComponent
4847
get() = Component.translatable("${key.namespace}.addon")
48+
49+
/**
50+
* The name used to represent this addon in the item tooltips.
51+
* By default, a blue italic `<your-addon-key>.addon` translation key.
52+
*/
53+
val footerName: TranslatableComponent
54+
get() = displayName
4955
.decoration(TextDecoration.ITALIC, true)
5056
.color(NamedTextColor.BLUE)
5157

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import io.github.pylonmc.rebar.util.position.ChunkPosition
2323
import io.github.pylonmc.rebar.util.position.position
2424
import io.github.pylonmc.rebar.util.rebarKey
2525
import io.github.pylonmc.rebar.util.rotateVectorToFace
26+
import io.github.pylonmc.rebar.waila.WailaDisplay
2627
import kotlinx.coroutines.delay
28+
import net.kyori.adventure.text.Component
2729
import org.bukkit.Color
2830
import org.bukkit.Material
2931
import org.bukkit.NamespacedKey
@@ -33,6 +35,7 @@ import org.bukkit.block.data.BlockData
3335
import org.bukkit.entity.BlockDisplay
3436
import org.bukkit.entity.Display
3537
import org.bukkit.entity.ItemDisplay
38+
import org.bukkit.entity.Player
3639
import org.bukkit.event.EventHandler
3740
import org.bukkit.event.Listener
3841
import org.bukkit.event.player.PlayerInteractEntityEvent
@@ -104,19 +107,26 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar
104107
* A block display that represents this block, showing the player what block
105108
* needs to be placed in a specific location.
106109
*/
107-
class MultiblockGhostBlock(entity: Display, val name: String) :
110+
class MultiblockGhostBlock(entity: Display, val displayName: Component) :
108111
RebarEntity<Display>(KEY, entity) {
109112

113+
constructor(entity: Display, displayName: String)
114+
: this(entity, Component.text(displayName))
115+
110116
constructor(entity: Display)
111-
: this(entity, entity.persistentDataContainer.get(NAME_KEY, RebarSerializers.STRING)!!)
117+
: this(entity, entity.persistentDataContainer.get(NAME_KEY, RebarSerializers.COMPONENT)!!)
118+
119+
override fun getWaila(player: Player): WailaDisplay {
120+
return WailaDisplay(displayName)
121+
}
112122

113123
override fun write(pdc: PersistentDataContainer) {
114-
pdc.set(NAME_KEY, RebarSerializers.STRING, name)
124+
pdc.set(NAME_KEY, RebarSerializers.COMPONENT, displayName)
115125
}
116126

117127
companion object {
118128
val KEY = rebarKey("multiblock_ghost_block")
119-
val NAME_KEY = rebarKey("name")
129+
val NAME_KEY = rebarKey("display_name")
120130
}
121131
}
122132

@@ -143,6 +153,8 @@ interface RebarSimpleMultiblock : RebarMultiblock, RebarEntityHolderBlock, Rebar
143153
.material(materials.first())
144154
.glow(Color.WHITE)
145155
.transformation(TransformBuilder().scale(0.5))
156+
.displayWidth(0.5f)
157+
.displayHeight(0.5f)
146158
.build(block.location.toCenterLocation())
147159
EntityStorage.add(MultiblockGhostBlock(display, materials.joinToString(", ") { it.key.toString() }))
148160

rebar/src/main/kotlin/io/github/pylonmc/rebar/config/ConfigSection.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.pylonmc.rebar.config
22

3+
import com.google.common.base.Defaults.defaultValue
34
import io.github.pylonmc.rebar.config.adapter.ConfigAdapter
45
import org.bukkit.configuration.ConfigurationSection
56
import java.lang.reflect.ParameterizedType
@@ -65,6 +66,13 @@ open class ConfigSection(val internalSection: ConfigurationSection) {
6566
return get(key, adapter) ?: defaultValue
6667
}
6768

69+
/**
70+
* Returns the computed [defaultValue] if the key does not exist or if the value cannot be converted to the desired type.
71+
*/
72+
fun <T> get(key: String, adapter: ConfigAdapter<T>, defaultValue: () -> T): T {
73+
return get(key, adapter) ?: defaultValue.invoke()
74+
}
75+
6876
/**
6977
* Throws an error if the key does not exist or if the value cannot be converted to the desired type.
7078
*/
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.pylonmc.rebar.config
2+
3+
import org.bukkit.Bukkit
4+
import java.util.UUID
5+
6+
data class ContributorConfig(
7+
val displayName: String,
8+
val description: String?,
9+
val minecraftUUID: UUID? = Bukkit.getOfflinePlayer(displayName).uniqueId,
10+
val githubUsername: String?,
11+
val link: String?
12+
) {
13+
constructor(displayName: String) : this(
14+
displayName,
15+
description = null,
16+
githubUsername = displayName,
17+
link = "https://github.com/$displayName"
18+
)
19+
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/config/RebarConfig.kt

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,6 @@ object RebarConfig {
3333
@JvmField
3434
val ENTITY_DATA_AUTOSAVE_INTERVAL_SECONDS = config.getOrThrow("entity-data-autosave-interval-seconds", ConfigAdapter.LONG)
3535

36-
@JvmField
37-
val RESEARCHES_ENABLED = config.getOrThrow("research.enabled", ConfigAdapter.BOOLEAN)
38-
39-
@JvmField
40-
val RESEARCH_BASE_CONFETTI_AMOUNT = config.get("research.confetti.base-amount", ConfigAdapter.DOUBLE, 70.0)
41-
42-
@JvmField
43-
val RESEARCH_MULTIPLIER_CONFETTI_AMOUNT = config.get("research.confetti.multiplier", ConfigAdapter.DOUBLE, 0.2)
44-
45-
@JvmField
46-
val RESEARCH_MAX_CONFETTI_AMOUNT = config.get("research.confetti.max-amount", ConfigAdapter.INTEGER, 700)
47-
48-
@JvmField
49-
val RESEARCH_SOUNDS = config.getOrThrow("research.sounds", ConfigAdapter.MAP.from(ConfigAdapter.LONG, ConfigAdapter.RANDOMIZED_SOUND))
50-
5136
@JvmField
5237
val PIPE_PLACEMENT_TASK_INTERVAL_TICKS = config.getOrThrow("pipe-placement.tick-interval", ConfigAdapter.LONG)
5338

@@ -75,6 +60,25 @@ object RebarConfig {
7560
@JvmField
7661
val CARGO_TRANSFER_RATE_MULTIPLIER = config.getOrThrow("cargo-transfer-rate-multiplier", ConfigAdapter.INTEGER)
7762

63+
object ResearchConfig {
64+
65+
@JvmField
66+
val ENABLED = config.getOrThrow("research.enabled", ConfigAdapter.BOOLEAN)
67+
68+
@JvmField
69+
val BASE_CONFETTI_AMOUNT = config.get("research.confetti.base-amount", ConfigAdapter.DOUBLE, 70.0)
70+
71+
@JvmField
72+
val MULTIPLIER_CONFETTI_AMOUNT = config.get("research.confetti.multiplier", ConfigAdapter.DOUBLE, 0.2)
73+
74+
@JvmField
75+
val MAX_CONFETTI_AMOUNT = config.get("research.confetti.max-amount", ConfigAdapter.INTEGER, 700)
76+
77+
@JvmField
78+
val SOUNDS = config.getOrThrow("research.sounds", ConfigAdapter.MAP.from(ConfigAdapter.LONG, ConfigAdapter.RANDOMIZED_SOUND))
79+
80+
}
81+
7882
object WailaConfig {
7983

8084
@JvmStatic
@@ -111,6 +115,13 @@ object RebarConfig {
111115
}
112116
}
113117

118+
object GuideConfig {
119+
120+
@JvmField
121+
val DISCORD_BUTTON = config.getOrThrow("guide.discord-button", ConfigAdapter.BOOLEAN)
122+
123+
}
124+
114125
object ArmorTextureConfig {
115126

116127
@JvmField

rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ConfigAdapter.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.pylonmc.rebar.config.adapter
22

3+
import io.github.pylonmc.rebar.datatypes.RebarSerializers.KEYED
34
import io.github.pylonmc.rebar.fluid.tags.FluidTemperature
45
import io.github.pylonmc.rebar.registry.RebarRegistry
56
import io.github.pylonmc.rebar.util.RandomizedSound
@@ -44,6 +45,8 @@ interface ConfigAdapter<T> {
4445
@JvmField val MAP = MapConfigAdapter
4546
@JvmField val ENUM = EnumConfigAdapter
4647

48+
@JvmField val UUID = UUIDConfigAdapter
49+
4750
@JvmField val KEYED = KeyedConfigAdapter
4851
@JvmField val NAMESPACED_KEY = ConfigAdapter { NamespacedKey.fromString(STRING.convert(it))!! }
4952
@JvmField val MATERIAL = KEYED.fromRegistry(Registry.MATERIAL)
@@ -135,6 +138,7 @@ interface ConfigAdapter<T> {
135138
@JvmField val CULLING_PRESET = CullingPresetConfigAdapter
136139
@JvmField val WAILA_DISPLAY = WailaDisplayConfigAdapter
137140
@JvmField val CONFIG_SECTION = ConfigSectionConfigAdapter
141+
@JvmField val CONTRIBUTOR = ContributorConfigAdapter
138142
// @formatter:on
139143
}
140144
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.github.pylonmc.rebar.config.adapter
2+
3+
import io.github.pylonmc.rebar.config.ContributorConfig
4+
import org.bukkit.Bukkit
5+
import java.lang.reflect.Type
6+
7+
object ContributorConfigAdapter : ConfigAdapter<ContributorConfig> {
8+
override val type: Type = ContributorConfig::class.java
9+
10+
override fun convert(value: Any): ContributorConfig {
11+
if (value is String) {
12+
return ContributorConfig(displayName = value)
13+
}
14+
15+
val section = ConfigAdapter.CONFIG_SECTION.convert(value)
16+
val displayName = section.getOrThrow("display-name", ConfigAdapter.STRING)
17+
val description = section.get("description", ConfigAdapter.STRING)
18+
val minecraftUUID = section.get("minecraft-uuid", ConfigAdapter.UUID) { Bukkit.getOfflinePlayer(displayName).uniqueId }
19+
val githubUsername = section.get("github", ConfigAdapter.STRING, displayName)
20+
val link = section.get("link", ConfigAdapter.STRING, "https://github.com/$githubUsername")
21+
return ContributorConfig(displayName, description, minecraftUUID, githubUsername, link)
22+
}
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.pylonmc.rebar.config.adapter
2+
3+
import java.util.UUID
4+
5+
object UUIDConfigAdapter : ConfigAdapter<UUID> {
6+
private val longListAdapter = ConfigAdapter.LIST.from(ConfigAdapter.LONG)
7+
8+
override val type: Class<UUID> = UUID::class.java
9+
10+
override fun convert(value: Any): UUID {
11+
return if (value is String) {
12+
UUID.fromString(value)
13+
} else {
14+
val longs = longListAdapter.convert(value)
15+
require(longs.size == 2) { "Expected a list of 2 longs for UUID, got ${longs.size}" }
16+
UUID(longs[0], longs[1])
17+
}
18+
}
19+
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/content/cargo/CargoDuct.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class CargoDuct : RebarBlock, RebarBreakHandler, RebarEntityHolderBlock, RebarEn
150150
}
151151
for (entity in heldEntities.keys.toList()) { // clone to prevent concurrent modification exception
152152
getHeldEntity(entity)?.scheduleRemove()
153+
heldEntities.remove(entity)
153154
}
154155
faceGroups.clear()
155156

rebar/src/main/kotlin/io/github/pylonmc/rebar/content/guide/RebarGuide.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import io.github.pylonmc.rebar.event.api.annotation.MultiHandler
66
import io.github.pylonmc.rebar.guide.button.BackButton
77
import io.github.pylonmc.rebar.guide.button.FluidButton
88
import io.github.pylonmc.rebar.guide.button.PageButton
9-
import io.github.pylonmc.rebar.guide.button.ResearchesButton
9+
import io.github.pylonmc.rebar.guide.button.AddonPageButton
1010
import io.github.pylonmc.rebar.guide.pages.RootPage
1111
import io.github.pylonmc.rebar.guide.pages.SearchItemsAndFluidsPage
1212
import io.github.pylonmc.rebar.guide.pages.base.GuidePage
1313
import io.github.pylonmc.rebar.guide.pages.base.SimpleDynamicGuidePage
14-
import io.github.pylonmc.rebar.guide.pages.base.SimpleStaticGuidePage
14+
import io.github.pylonmc.rebar.guide.pages.info.InfoPage
1515
import io.github.pylonmc.rebar.guide.pages.item.ItemIngredientsPage
1616
import io.github.pylonmc.rebar.guide.pages.research.AddonResearchesPage
1717
import io.github.pylonmc.rebar.guide.pages.research.ResearchItemsPage
@@ -110,7 +110,7 @@ class RebarGuide(stack: ItemStack) : RebarItem(stack), RebarInteractor {
110110
val fluidsButton = PageButton(Material.WATER_BUCKET, fluidsPage)
111111

112112
@JvmStatic
113-
val infoPage = SimpleStaticGuidePage(rebarKey("info"))
113+
val infoPage = InfoPage
114114

115115
@JvmStatic
116116
val infoButton = PageButton(Material.LANTERN, infoPage)
@@ -125,7 +125,7 @@ class RebarGuide(stack: ItemStack) : RebarItem(stack), RebarInteractor {
125125
fun addonResearchesPage(addon: RebarAddon) = AddonResearchesPage(addon)
126126

127127
@JvmStatic
128-
fun addonResearchesButton(addon: RebarAddon) = ResearchesButton(addon)
128+
fun addonResearchesButton(addon: RebarAddon) = AddonPageButton(addon, addonResearchesPage(addon))
129129

130130
@JvmStatic
131131
fun researchItemsPage(research: Research) = ResearchItemsPage(research)

0 commit comments

Comments
 (0)