Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,16 @@ interface PylonGuiBlock : PylonBreakHandler, PylonInteractableBlock {
if (
event.action.isRightClick &&
event.hand == EquipmentSlot.HAND &&
event.useInteractedBlock() != Event.Result.DENY
event.useInteractedBlock() != Event.Result.DENY &&
!event.player.isSneaking
) {
event.setUseInteractedBlock(Event.Result.DENY)
if (!event.player.isSneaking) {
event.setUseItemInHand(Event.Result.DENY)
val window = Window.single()
.setGui(gui)
.setTitle(AdventureComponentWrapper((this as PylonBlock).name))
.setViewer(event.player)
.build()
window.open()
}
event.setUseItemInHand(Event.Result.DENY)
val window = Window.single()
.setGui(gui)
.setTitle(AdventureComponentWrapper((this as PylonBlock).name))
.setViewer(event.player)
.build()
window.open()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlin.math.min

interface PylonSimpleMultiblock : PylonMultiblock, PylonEntityHolderBlock {

interface Component {
interface MultiblockComponent {
fun matches(block: Block): Boolean
fun spawnGhostBlock(block: Block): UUID
}
Expand All @@ -54,7 +54,7 @@ interface PylonSimpleMultiblock : PylonMultiblock, PylonEntityHolderBlock {
}
}

data class VanillaComponent(val material: Material) : Component {
data class VanillaMultiblockComponent(val material: Material) : MultiblockComponent {
override fun matches(block: Block): Boolean
= !BlockStorage.isPylonBlock(block) && block.type == material

Expand All @@ -68,7 +68,7 @@ interface PylonSimpleMultiblock : PylonMultiblock, PylonEntityHolderBlock {
}
}

data class PylonComponent(val key: NamespacedKey) : Component {
data class PylonMultiblockComponent(val key: NamespacedKey) : MultiblockComponent {
override fun matches(block: Block): Boolean
= BlockStorage.get(block)?.schema?.key == key

Expand All @@ -87,9 +87,9 @@ interface PylonSimpleMultiblock : PylonMultiblock, PylonEntityHolderBlock {
/**
* Rotation will automatically be accounted for.
*/
val components: Map<Vector3i, Component>
val components: Map<Vector3i, MultiblockComponent>

fun validStructures(): List<Map<Vector3i, Component>> = listOf(
fun validStructures(): List<Map<Vector3i, MultiblockComponent>> = listOf(
// 0 degrees
components,
// 90 degrees (anticlockwise)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.github.pylonmc.pylon.core.config

import com.google.common.base.CaseFormat
import io.github.pylonmc.pylon.core.registry.PylonRegistry
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.configuration.ConfigurationSection
import org.bukkit.inventory.ItemStack
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

Expand All @@ -26,6 +30,45 @@ open class ConfigSection(val internalSection: ConfigurationSection) {
fun getSectionOrThrow(key: String): ConfigSection =
getSection(key) ?: throw KeyNotFoundException(internalSection.currentPath, key)

fun getItem(key: String): ItemStack? {
if (key.contains(':')) {
val namespacedKey = NamespacedKey.fromString(key)
if (namespacedKey != null) {
val pylonItem = PylonRegistry.ITEMS[namespacedKey]
if (pylonItem != null) {
return pylonItem.itemStack
}
}
}

val material = Material.getMaterial(key.uppercase())
if (material != null) {
return ItemStack(material)
}

return null
}

fun getItemOrThrow(key: String): ItemStack {
if (key.contains(':')) {
val namespacedKey = NamespacedKey.fromString(key)
if (namespacedKey != null) {
val pylonItem = PylonRegistry.ITEMS[namespacedKey]
if (pylonItem != null) {
return pylonItem.itemStack
}
error("No such Pylon item $key")
}
}

val material = Material.getMaterial(key.uppercase())
if (material != null) {
return ItemStack(material)
}

error("No such material $key")
}

fun <T> get(key: String, type: Class<out T>): T? {
val value = internalSection.get(key) ?: return null
return type.cast(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,32 @@ class SearchItemsAndFluidsPage : SearchPage(

fun getItemButtons(player: Player): MutableList<Pair<Item, String>> = PylonRegistry.ITEMS.getKeys().filter {
!PylonGuide.hiddenItems.contains(it)
}.map {
}.mapNotNull {
val translator = AddonTranslator.translators[getAddon(it)]!!
val name = translator.translate(
Component.translatable("pylon.${it.namespace}.item.${it.key}.name"), player.locale()
)
check(name != null)
val plainTextName = serializer.serialize(name).lowercase()
Pair(ItemButton(it), plainTextName)
if (name == null) {
null
} else {
val plainTextName = serializer.serialize(name).lowercase()
Pair(ItemButton(it), plainTextName)
}
Comment thread
LordIdra marked this conversation as resolved.
Outdated
}.toMutableList()

fun getFluidButtons(player: Player): MutableList<Pair<Item, String>> = PylonRegistry.FLUIDS.getKeys().filter {
!PylonGuide.hiddenFluids.contains(it)
}.map {
}.mapNotNull {
val translator = AddonTranslator.translators[getAddon(it)]!!
val name = translator.translate(
Component.translatable("pylon.${it.namespace}.fluid.${it.key}"), player.locale()
)
check(name != null)
val plainTextName = serializer.serialize(name).lowercase()
Pair(FluidButton(it), plainTextName)
if (name == null) {
null
} else {
val plainTextName = serializer.serialize(name).lowercase()
Pair(FluidButton(it), plainTextName)
}
Comment thread
LordIdra marked this conversation as resolved.
Outdated
}.toMutableList()

override fun getItemNamePairs(player: Player, search: String): List<Pair<Item, String>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public TestPylonSimpleMultiblock(Block block, PersistentDataContainer pdc) {
}

@Override
public @NotNull Map<Vector3i, Component> getComponents() {
public @NotNull Map<Vector3i, MultiblockComponent> getComponents() {
return Map.of(
new Vector3i(1, 1, 4), new PylonComponent(Blocks.SIMPLE_BLOCK_KEY),
new Vector3i(2, -1, 0), new PylonComponent(Blocks.SIMPLE_BLOCK_KEY)
new Vector3i(1, 1, 4), new PylonMultiblockComponent(Blocks.SIMPLE_BLOCK_KEY),
new Vector3i(2, -1, 0), new PylonMultiblockComponent(Blocks.SIMPLE_BLOCK_KEY)
);
}
}
Loading