Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -24,14 +24,14 @@ object ReadableItemStackPersistentDataType : PersistentDataType<PersistentDataCo
(serialized["count"] as? Int)?.let { primitive.set(countKey, PersistentDataType.INTEGER, it) }

val primitiveComponents = context.newPersistentDataContainer()
val components = serialized["components"] as? Map<String, Any>
@Suppress("UNCHECKED_CAST") val components = serialized["components"] as? Map<String, Any>
components?.forEach { (key, value) ->
primitiveComponents.set(NamespacedKey.fromString(key)!!, PersistentDataType.STRING, value as String)
}
primitive.set(componentsKey, PersistentDataType.TAG_CONTAINER, primitiveComponents)

primitive.set(dataVersionKey, PersistentDataType.INTEGER, serialized["DataVersion"] as Int)
return primitive
primitive
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.github.pylonmc.pylon.core.recipe.IngredientCalculator.calculateBase
import io.github.pylonmc.pylon.core.recipe.IngredientCalculator.calculate
import io.github.pylonmc.pylon.core.recipe.IngredientCalculator.checkRecursiveDepth
import io.github.pylonmc.pylon.core.registry.PylonRegistry
import io.github.pylonmc.pylon.core.util.isPylonSimilar
import net.kyori.adventure.key.Key
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.RecipeChoice
Expand Down Expand Up @@ -171,7 +170,7 @@ object IngredientCalculator {
for (outputResult in recipe.results) {
when (outputResult) {
is FluidOrItem.Item -> {
if (!outputResult.item.isPylonSimilar(pylonItem.stack)) {
if (!outputResult.item.isSimilar(pylonItem.stack)) {
baseResult.byproducts += Container.of(outputResult)
}
}
Expand All @@ -194,7 +193,7 @@ object IngredientCalculator {
var outputAmount = 0
recipe.results.forEach { outputResult ->
if (outputResult is FluidOrItem.Item &&
outputResult.item.isPylonSimilar(targetItem.stack)
outputResult.item.isSimilar(targetItem.stack)
) {
outputAmount += outputResult.item.amount
}
Expand Down Expand Up @@ -286,7 +285,7 @@ data class IngredientCalculation(
is Container.Fluid ->
Container.of(component.fluid, component.amountMillibuckets * multiplier)

is Container.Item ->
is Container.Item ->
Container.of(component.stack, component.amount * multiplier)
}
}
Expand Down Expand Up @@ -354,10 +353,10 @@ sealed class Container {
}
data class Fluid(val fluid: PylonFluid, var amountMillibuckets: Double) : Container()

fun isPylonSimilar(other: Container): Boolean {
fun isSimilar(other: Container): Boolean {
return when (this) {
is Item -> when (other) {
is Item -> stack.isPylonSimilar(other.stack)
is Item -> stack.isSimilar(other.stack)
is Fluid -> false
}

Expand Down Expand Up @@ -387,7 +386,7 @@ sealed class Container {
fun of(item: ItemStack, amount: Int): Container {
return Item(item.asOne(), amount)
}

fun of(item: ItemStack, amount: Double): Container {
return Item(item.asOne(), amount)
}
Expand Down Expand Up @@ -505,7 +504,7 @@ private fun flat(from: MutableList<Container>, to: MutableList<Container>) {
for (component in from) {
var isNewObject = true
for (exist in to) {
if (exist.isPylonSimilar(component)) {
if (exist.isSimilar(component)) {
if (exist is Container.Item && component is Container.Item) {
exist.amount += component.amount
isNewObject = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.pylonmc.pylon.core.recipe

import io.github.pylonmc.pylon.core.fluid.PylonFluid
import io.github.pylonmc.pylon.core.util.isPylonSimilar
import org.bukkit.Keyed
import org.bukkit.inventory.ItemStack
import xyz.xenondevs.invui.gui.Gui
Expand Down Expand Up @@ -30,7 +29,7 @@ interface PylonRecipe : Keyed {

fun isOutput(stack: ItemStack) = results.any {
when (it) {
is FluidOrItem.Item -> it.item.isPylonSimilar(stack)
is FluidOrItem.Item -> it.item.isSimilar(stack)
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.github.pylonmc.pylon.core.item.research.Research.Companion.canCraft
import io.github.pylonmc.pylon.core.recipe.vanilla.CookingRecipeWrapper
import io.github.pylonmc.pylon.core.recipe.vanilla.VanillaRecipeType
import io.github.pylonmc.pylon.core.util.isPylonAndIsNot
import io.github.pylonmc.pylon.core.util.isPylonSimilar
import io.papermc.paper.datacomponent.DataComponentTypes
import io.papermc.paper.event.player.CartographyItemEvent
import org.bukkit.Keyed
Expand All @@ -18,11 +17,7 @@ import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockCookEvent
import org.bukkit.event.block.CrafterCraftEvent
import org.bukkit.event.inventory.FurnaceBurnEvent
import org.bukkit.event.inventory.InventoryClickEvent
import org.bukkit.event.inventory.PrepareAnvilEvent
import org.bukkit.event.inventory.PrepareItemCraftEvent
import org.bukkit.event.inventory.PrepareSmithingEvent
import org.bukkit.event.inventory.*
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.StonecutterInventory

Expand Down Expand Up @@ -60,7 +55,7 @@ internal object PylonRecipeListener : Listener {
}
check(firstItem != null)
check(secondItem != null)
if (firstItem.isPylonSimilar(secondItem)) {
if (firstItem.isSimilar(secondItem)) {
val pylonItem = PylonItem.fromStack(firstItem)!!
if (pylonItem !is PylonUnmergeable) {
val result = pylonItem.schema.getItemStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,18 @@ import io.github.pylonmc.pylon.core.util.pylonKey
import org.bukkit.Keyed
import org.bukkit.NamespacedKey
import org.bukkit.Tag
import java.util.concurrent.ConcurrentHashMap
import java.util.stream.Stream

/**
* Represents a list of things that can be registered and looked up by [NamespacedKey].
* This class is not thread safe and any concurrent access must be synchronized externally.
*
* @param T the type of the registered values
* @property key the key of this registry
*/
class PylonRegistry<T : Keyed>(val key: NamespacedKey) : Iterable<T> {

private val values: MutableMap<NamespacedKey, T> = ConcurrentHashMap()
private val values: MutableMap<NamespacedKey, T> = LinkedHashMap()

fun register(vararg values: T) {
for (value in values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import net.kyori.adventure.text.minimessage.MiniMessage
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.attribute.Attribute
import org.bukkit.Registry
import org.bukkit.World
import org.bukkit.attribute.Attribute
import org.bukkit.block.Block
import org.bukkit.block.BlockFace
import org.bukkit.configuration.file.YamlConfiguration
Expand Down Expand Up @@ -322,39 +322,6 @@ fun findPylonItemInInventory(inventory: Inventory, targetItem: PylonItem): Int?
return null
}

/**
* Compares two Pylon items to check if they have the same Pylon ID. If
* neither item is a Pylon item, the material will be compared instead.
*
* @return Whether the items are the same.
*/
fun ItemStack?.isPylonSimilar(item2: ItemStack?): Boolean {
// Both items null
if (this == null && item2 == null) {
return true
}

// One item null, one not null
if (!(this != null && item2 != null)) {
return false
}

val pylonItem1 = PylonItem.fromStack(this)
val pylonItem2 = PylonItem.fromStack(item2)

// Both pylon items null
if (pylonItem1 == null && pylonItem2 == null) {
return this.isSimilar(item2)
}

// One pylon item null, one not null
if (!(pylonItem1 != null && pylonItem2 != null)) {
return false
}

return pylonItem1.schema.key == pylonItem2.schema.key
}

@JvmSynthetic
inline fun <reified T> ItemStack?.isPylonAndIsNot(): Boolean {
val pylonItem = PylonItem.fromStack(this)
Expand Down