-
So, before 1.21 a had a lot of this code to register turtle upgrades1: val MIMIC = ModPlatform.registerTurtleUpgrade(
MimicPeripheral.upgradeID,
TurtleUpgradeSerialiser.simpleWithCustomItem { upgradeID, stack ->
PeripheralTurtleUpgrade.dynamic(stack.item, ::MimicPeripheral) { upgradeID }
},
) I liked this approach a lot, because it helped me to not create a lot of excessive classes. But now, Upgrade class should have a link that would point to the upgrade type. But there is not way to get upgrade type instance when you creating a Turtle/Pocket upgrade. Should I try to create custom UpgradeType for this or I can solve this issue in another way? Footnotes
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Yep! You can probably create a variant of fun <T : UpgradeBase> createWithCustomItem(factory: (ty: UpgradeType<T>, stack: ItemStack) -> T): UpgradeType<T> {
lateinit var type: UpgradeType<T>
type = UpgradeType.create(
BuiltInRegistries.ITEM.byNameCodec()
.xmap({ factory(type, ItemStack(it)) }, { it.craftingItem.item })
.fieldOf("item"),
)
return type
}
|
Beta Was this translation helpful? Give feedback.
Yep! You can probably create a variant of
simpleWithCustomItem
that constructs your upgrade with the type: