Skip to content

Commit 77dea56

Browse files
committed
Merge branch 'master' into hydraulic-machines-fixes
2 parents 77e1588 + 322f81f commit 77dea56

8 files changed

Lines changed: 23 additions & 74 deletions

File tree

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/block/BlockListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ internal object BlockListener : Listener {
5858
val relative = event.blockPlaced.position - event.blockAgainst.position
5959
val blockFace = BlockFace.entries.find { it.modX == relative.x && it.modY == relative.y && it.modZ == relative.z }
6060
?: BlockFace.SELF
61-
val pylonBlock = pylonItem.place(BlockCreateContext.PlayerPlace(player, item, event.blockPlaced, blockFace))
61+
val pylonBlock = pylonItem.place(BlockCreateContext.PlayerPlace(player, item, event))
6262

6363
if (pylonBlock == null) {
6464
event.isCancelled = true

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/block/PylonBlock.kt

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import io.github.pylonmc.pylon.core.datatypes.PylonSerializers
1010
import io.github.pylonmc.pylon.core.event.PylonBlockDeserializeEvent
1111
import io.github.pylonmc.pylon.core.event.PylonBlockSerializeEvent
1212
import io.github.pylonmc.pylon.core.i18n.AddonTranslator
13+
import io.github.pylonmc.pylon.core.item.PylonItemSchema
1314
import io.github.pylonmc.pylon.core.registry.PylonRegistry
1415
import io.github.pylonmc.pylon.core.util.position.BlockPosition
1516
import io.github.pylonmc.pylon.core.util.position.position
@@ -33,7 +34,7 @@ open class PylonBlock protected constructor(val block: Block) {
3334
@JvmSynthetic
3435
internal var errorBlock: BlockDisplay? = null
3536

36-
open val name: Component = Component.translatable("pylon.${schema.key.namespace}.item.${schema.key.key}.waila")
37+
open val name: Component = Component.translatable("pylon.${schema.key.namespace}.item.${schema.key.key}.waila", "pylon.${schema.key.namespace}.item.${schema.key.key}.name")
3738

3839
constructor(block: Block, context: BlockCreateContext) : this(block)
3940
constructor(block: Block, pdc: PersistentDataContainer) : this(block)
@@ -68,28 +69,9 @@ open class PylonBlock protected constructor(val block: Block) {
6869
private val pylonBlockPositionKey = pylonKey("position")
6970
private val pylonBlockErrorKey = pylonKey("error")
7071

71-
private val wailaWarningsSupressed: MutableSet<NamespacedKey> = mutableSetOf()
72-
73-
private fun checkWaila(schema: PylonBlockSchema) {
74-
val translator = AddonTranslator.translators[schema.addon]
75-
check(translator != null) {
76-
"Addon does not have a translator; did you forget to call registerWithPylon()?"
77-
}
78-
79-
for (locale in schema.addon.languages) {
80-
val translationKey = "pylon.${schema.key.namespace}.item.${schema.key.key}.waila"
81-
if (!translator.translationKeyExists(translationKey, locale)) {
82-
PylonCore.logger.warning("${schema.key.namespace} is missing a WAILA translation key for block ${schema.key} (locale: ${locale.displayName} | expected translation key: $translationKey")
83-
}
84-
}
85-
}
86-
8772
@JvmStatic
8873
fun register(key: NamespacedKey, material: Material, blockClass: Class<out PylonBlock>) {
8974
val schema = PylonBlockSchema(key, material, blockClass)
90-
if (key !in wailaWarningsSupressed) {
91-
checkWaila(schema)
92-
}
9375
PylonRegistry.BLOCKS.register(schema)
9476
}
9577

@@ -165,10 +147,5 @@ open class PylonBlock protected constructor(val block: Block) {
165147
}
166148
}
167149
}
168-
169-
@JvmStatic
170-
fun supressWailaWarnings(key: NamespacedKey) {
171-
wailaWarningsSupressed.add(key)
172-
}
173150
}
174151
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.github.pylonmc.pylon.core.block.context
22

33
import org.bukkit.block.Block
4-
import org.bukkit.block.BlockFace
54
import org.bukkit.entity.Player
5+
import org.bukkit.event.block.BlockPlaceEvent
66
import org.bukkit.inventory.ItemStack
77

88
interface BlockCreateContext {
@@ -12,9 +12,10 @@ interface BlockCreateContext {
1212
data class PlayerPlace(
1313
val player: Player,
1414
val item: ItemStack,
15-
override val block: Block,
16-
val clickedFace: BlockFace
17-
) : BlockCreateContext
15+
val event: BlockPlaceEvent
16+
) : BlockCreateContext {
17+
override val block = event.blockPlaced
18+
}
1819

1920
data class Default(override val block: Block) : BlockCreateContext
2021
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/i18n/AddonTranslator.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class AddonTranslator(private val addon: PylonAddon) : Translator {
3838
override fun translate(key: String, locale: Locale): MessageFormat? = null
3939

4040
override fun translate(component: TranslatableComponent, locale: Locale): Component? {
41-
var translated = getTranslation(component, locale) ?: return null
41+
val fallback = component.fallback()
42+
var translated = getTranslation(component, locale)
43+
?: fallback?.let { getTranslation(it, locale) ?: Component.text(fallback) } ?: return null
4244
for (arg in component.arguments()) {
4345
val component = arg.asComponent()
4446
if (component !is VirtualComponent) continue
@@ -76,7 +78,7 @@ class AddonTranslator(private val addon: PylonAddon) : Translator {
7678
}
7779

7880
fun translationKeyExists(key: String, locale: Locale): Boolean
79-
= getTranslation(key, locale) != null
81+
= getTranslation(key, locale) != null
8082

8183
companion object : Listener {
8284

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/PylonItem.kt

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,24 @@ open class PylonItem(val stack: ItemStack) : Keyed {
4141

4242
companion object {
4343

44-
private val nameAndLoreWarningsSupressed: MutableSet<NamespacedKey> = mutableSetOf()
44+
private val nameWarningsSupressed: MutableSet<NamespacedKey> = mutableSetOf()
4545

46-
private fun checkNameAndLore(schema: PylonItemSchema) {
46+
private fun checkName(schema: PylonItemSchema) {
4747
val translator = AddonTranslator.translators[schema.addon]
4848
check(translator != null) {
4949
"Addon does not have a translator; did you forget to call registerWithPylon()?"
5050
}
5151

5252
// Adventure is a perfect API with absolutely no problems whatsoever.
5353
val name = schema.itemStack.getData(DataComponentTypes.ITEM_NAME) as? TranslatableComponent
54-
val lore = schema.itemStack.getData(DataComponentTypes.LORE)?.lines()?.get(0) as? TranslatableComponent
5554

56-
var isNameAndLoreValid = true
55+
var isNameValid = true
5756
if (name == null || name.key() != ItemStackBuilder.nameKey(schema.key)) {
5857
PylonCore.logger.warning("Item ${schema.key}'s name is not a translation key; check your item uses ItemStackBuilder.pylonItem(...)")
59-
isNameAndLoreValid = false
58+
isNameValid = false
6059
}
6160

62-
if (lore == null || lore.key() != ItemStackBuilder.loreKey(schema.key)) {
63-
PylonCore.logger.warning("Item ${schema.key}'s lore is not a translation key; check your item uses ItemStackBuilder.pylonItem(...)")
64-
isNameAndLoreValid = false
65-
}
66-
67-
if (isNameAndLoreValid) {
61+
if (isNameValid) {
6862
for (locale in schema.addon.languages) {
6963
if (!translator.translationKeyExists(name!!.key(), locale)) {
7064
PylonCore.logger.warning(
@@ -75,22 +69,13 @@ open class PylonItem(val stack: ItemStack) : Keyed {
7569
}"
7670
)
7771
}
78-
if (!translator.translationKeyExists(lore!!.key(), locale)) {
79-
PylonCore.logger.warning(
80-
"${schema.key.namespace} is missing a lore translation key for item ${schema.key} (locale: ${locale.displayName} | expected translation key: ${
81-
ItemStackBuilder.loreKey(
82-
schema.key
83-
)
84-
}"
85-
)
86-
}
8772
}
8873
}
8974
}
9075

9176
private fun register(schema: PylonItemSchema) {
92-
if (schema.key !in nameAndLoreWarningsSupressed) {
93-
checkNameAndLore(schema)
77+
if (schema.key !in nameWarningsSupressed) {
78+
checkName(schema)
9479
}
9580
PylonRegistry.ITEMS.register(schema)
9681
}
@@ -122,8 +107,8 @@ open class PylonItem(val stack: ItemStack) : Keyed {
122107
}
123108

124109
@JvmStatic
125-
fun supressNameAndLoreWarnings(key: NamespacedKey) {
126-
nameAndLoreWarningsSupressed.add(key)
110+
fun supressNameWarnings(key: NamespacedKey) {
111+
nameWarningsSupressed.add(key)
127112
}
128113

129114
@JvmStatic

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/builder/ItemStackBuilder.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ open class ItemStackBuilder private constructor(val stack: ItemStack) : ItemProv
8383
fun lore(vararg lore: String) = lore(*lore.map(::fromMiniMessage).toTypedArray())
8484

8585
fun defaultTranslatableLore(key: NamespacedKey) =
86-
lore(Component.translatable(loreKey(key)))
86+
lore(Component.translatable(loreKey(key), ""))
8787

8888
fun build(): ItemStack = stack.clone()
8989

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/util/ItemUtils.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ inline fun <reified T> ItemStack?.isPylonAndIsNot(): Boolean {
5555
return pylonItem != null && pylonItem !is T
5656
}
5757

58+
@JvmName("recipeChoiceFromItem")
5859
fun ItemStack.asRecipeChoice(): RecipeChoice {
5960
return if (PylonItem.isPylonItem(this)) {
6061
RecipeChoice.ExactChoice(this)

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/util/PylonUtils.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ package io.github.pylonmc.pylon.core.util
44

55
import io.github.pylonmc.pylon.core.addon.PylonAddon
66
import io.github.pylonmc.pylon.core.entity.display.transform.TransformUtil.yawToCardinalDirection
7-
import net.kyori.adventure.text.Component
8-
import org.bukkit.Color
9-
import org.bukkit.Location
107
import org.bukkit.NamespacedKey
118
import org.bukkit.block.BlockFace
129
import org.bukkit.entity.Player
13-
import org.bukkit.entity.TextDisplay
1410
import org.bukkit.util.Vector
15-
import org.joml.Matrix4f
1611
import org.joml.RoundingMode
1712
import org.joml.Vector3f
1813
import org.joml.Vector3i
@@ -58,16 +53,4 @@ fun rotateToPlayerFacing(player: Player, face: BlockFace, allowVertical: Boolean
5853
vector = vector.rotateAroundNonUnitAxis(rightVector, -yawToCardinalDirection(player.eyeLocation.pitch).toDouble())
5954
}
6055
return vectorToBlockFace(vector)
61-
}
62-
63-
fun spawnUnitSquareTextDisplay(location: Location, color: Color): TextDisplay {
64-
val display = location.world!!.spawn(location, TextDisplay::class.java)
65-
display.setTransformationMatrix( // https://github.com/TheCymaera/minecraft-hologram/blob/d67eb43308df61bdfe7283c6821312cca5f9dea9/src/main/java/com/heledron/hologram/utilities/rendering/textDisplays.kt#L15
66-
Matrix4f()
67-
.translate(-0.1f + .5f, -0.5f + .5f, 0f)
68-
.scale(8.0f, 4.0f, 1f)
69-
)
70-
display.text(Component.text(" "))
71-
display.backgroundColor = color
72-
return display
7356
}

0 commit comments

Comments
 (0)