Skip to content

Commit cab8866

Browse files
committed
HOPEFULLY world conversion for generations custom stuff is complete
1 parent dd3a5b4 commit cab8866

File tree

6 files changed

+79
-51
lines changed

6 files changed

+79
-51
lines changed

common/src/main/java/generations/gg/generations/core/generationscore/common/datafixer/GenerationsSchemas.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ object GenerationsSchemas {
6767
private fun appendSchemas(builder: DataFixerBuilder) {
6868
builder.addSchema(0, ::GenerationsRootSchema)
6969
val v1 = builder.addSchema(1, ::Generationsv1Schema)
70+
builder.addFixer(BotariumFix(v1))
7071
// builder.addFixer(ItemRenameFix.create(v1, "Remove items from generations added in 1.6 cobblemon") { name ->
7172
// print("Converted $name to ")
7273
//
@@ -76,6 +77,5 @@ object GenerationsSchemas {
7677
// return@create newName
7778
// })
7879
builder.addFixer(ItemStackComponentizationFix(v1))
79-
builder.addFixer(BotariumFix(v1))
8080
}
8181
}
Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
11
package generations.gg.generations.core.generationscore.common.datafixer.fixers
22

3+
import com.mojang.datafixers.DSL
34
import com.mojang.datafixers.DataFix
45
import com.mojang.datafixers.TypeRewriteRule
5-
import com.mojang.datafixers.schemas.Schema
6-
import generations.gg.generations.core.generationscore.common.datafixer.schema.GenerationsReferences
6+
import com.mojang.datafixers.types.Type
7+
import com.mojang.serialization.Dynamic
8+
import generations.gg.generations.core.generationscore.common.orFalse
9+
import net.minecraft.util.datafix.fixes.References
10+
11+
class BotariumFix(outputSchema: com.mojang.datafixers.schemas.Schema) :
12+
DataFix(outputSchema, false) {
13+
14+
private val TARGET_IDS = setOf(
15+
"generations_core:regigigas_shrine",
16+
"generations_core:cooking_pot"
17+
)
718

8-
class BotariumFix(outputSchema: Schema) : DataFix(outputSchema, false) {
919
override fun makeRule(): TypeRewriteRule {
10-
var oldForge = inputSchema.getType(GenerationsReferences.TERRAIUM_FORGE_INVENTORY)
11-
var oldFabric = inputSchema.getType(GenerationsReferences.TERRAIUM_FORGE_INVENTORY)
20+
val blockEntityType: Type<*> = outputSchema.getType(References.BLOCK_ENTITY)
21+
22+
return fixTypeEverywhereTyped(
23+
"BotariumItemsStructureFix",
24+
blockEntityType
25+
) { typed ->
26+
val dynamic = typed.get(DSL.remainderFinder())
27+
28+
val idOpt = dynamic.get("id").asString().result()
29+
if (idOpt != null && idOpt.filter { TARGET_IDS.contains(it) }.isPresent) {
30+
val updatedDynamic = moveBotariumItems(dynamic)
31+
typed.update(DSL.remainderFinder()) { updatedDynamic }
32+
} else {
33+
typed
34+
}
35+
}
36+
}
37+
38+
private fun moveBotariumItems(dynamic: Dynamic<*>): Dynamic<*> {
39+
val itemsOpt = dynamic
40+
.get("ForgeCaps")
41+
.get("botarium:item")
42+
.get("Items")
43+
.result()
44+
45+
return if (itemsOpt.isPresent) {
46+
val items = itemsOpt.get()
47+
48+
var updated = dynamic.set("Items", items)
1249

13-
// return this.fixTypeEverywhereTyped()
50+
// Clean out ForgeCaps.botarium
51+
val newForgeCaps = dynamic.get("ForgeCaps").map { forgeCaps ->
52+
forgeCaps.remove("botarium:item")
53+
}.result().orElse(dynamic.emptyMap())
1454

15-
return TypeRewriteRule.nop()
55+
updated.set("ForgeCaps", newForgeCaps)
56+
} else {
57+
dynamic
58+
}
1659
}
1760
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package generations.gg.generations.core.generationscore.common.datafixer.schema
22

33
import net.minecraft.util.datafix.fixes.References
4+
import net.minecraft.world.entity.player.Inventory
45

56
object GenerationsReferences {
67
val TERRAIUM_FORGE_INVENTORY = References.reference("terraium_forge_inventory")
78
val ITEM_RESOURCE = References.reference("item_resource")
89
val TERRAIUM_FABRIC_INVENTORY = References.reference("terraium_fabric_inventory")
10+
val INVENTORY = References.reference("inventory")
911
}

common/src/main/java/generations/gg/generations/core/generationscore/common/datafixer/schema/GenerationsRootSchema.kt

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@ class GenerationsRootSchema(versionKey: Int, parent: Schema?) : Schema(versionKe
1717
entityTypes: MutableMap<String, Supplier<TypeTemplate>>,
1818
blockEntityTypes: MutableMap<String, Supplier<TypeTemplate>>
1919
) {
20-
schema.registerType(true, GenerationsReferences.TERRAIUM_FORGE_INVENTORY) {
21-
DSL.optionalFields("ForgeCaps", DSL.optionalFields("botarium:item", DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) ))
22-
}
23-
24-
schema.registerType(true, GenerationsReferences.TERRAIUM_FABRIC_INVENTORY) {
25-
DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema)))
26-
}
2720

2821
//I'm not 100% sure what a recursive type is, but at least one is required
2922
//Maybe a type that can contain itself?
3023
schema.registerType(true, References.ENTITY) {
3124
DSL.taggedChoiceLazy("id", NamespacedSchema.namespacedString(), entityTypes)
3225
}
3326
schema.registerType(true, References.BLOCK_ENTITY) {
34-
//Tagged choice makes it so that the type is determined by a key of some other type
27+
//Tagged choice mak
28+
// es it so that the type is determined by a key of some other type
3529
//So the "id" of a block entity determines what type the actual block entity is
3630
DSL.taggedChoiceLazy(
3731
"id",
@@ -77,33 +71,32 @@ class GenerationsRootSchema(versionKey: Int, parent: Schema?) : Schema(versionKe
7771
}
7872

7973
override fun registerBlockEntities(schema: Schema): MutableMap<String, Supplier<TypeTemplate>> = mutableMapOf<String, Supplier<TypeTemplate>>().apply {
80-
val botarium = when(Cobblemon.implementation.modAPI) {
81-
ModAPI.FABRIC -> GenerationsReferences.TERRAIUM_FABRIC_INVENTORY
82-
ModAPI.NEOFORGE -> GenerationsReferences.TERRAIUM_FORGE_INVENTORY
74+
val botarium: () -> TypeTemplate = when(Cobblemon.implementation.modAPI) {
75+
ModAPI.FABRIC -> { { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) } }
76+
ModAPI.NEOFORGE -> { { DSL.optionalFields("ForgeCaps", DSL.optionalFields("botarium:item", DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) )) } }
8377
else -> throw RuntimeException("Forge isn't supported by Generations Core")
8478
}
8579

80+
val inventory: () -> TypeTemplate = { GenerationsReferences.INVENTORY.`in`(schema) }
81+
8682
simple("pokedoll")
8783
simple("generic_shrine")
8884
simple("abundant_shrne")
8985
simple("celestial_altar")
9086
simple("lunar_shrine")
91-
putGens("meloetta_music_box") {
92-
DSL.optionalFields("RecordItem", References.ITEM_STACK.`in`(schema))
93-
}
94-
95-
putGens("regigigas_shrine") { botarium.`in`(schema) }
87+
putGens("meloetta_music_box") { DSL.optionalFields("RecordItem", References.ITEM_STACK.`in`(schema)) }
88+
putGens("regigigas_shrine", botarium)
89+
putGens("cooking_pot", botarium)
9690
simple("tao_trio_shrine")
9791
simple("tapu_shrine")
9892
simple("interact_shrine")
99-
putGens("cooking_pot") { botarium.`in`(schema) }
100-
putGens("generic_chest") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
93+
putGens("generic_chest", inventory)
10194
simple("sign_block_entity")
10295
simple("hanging_sign_block_entity")
10396
simple("breeder")
104-
putGens("generic_furnace") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
105-
putGens("generic_blast_furnace") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
106-
putGens("generic_smoker") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
97+
putGens("generic_furnace", inventory)
98+
putGens("generic_blast_furnace", inventory)
99+
putGens("generic_smoker", inventory)
107100
simple("generic_dyed_variant")
108101
simple("generic_model_providing")
109102
simple("vending_machine")
@@ -114,12 +107,12 @@ class GenerationsRootSchema(versionKey: Int, parent: Schema?) : Schema(versionKe
114107
putGens("rks_machine") {
115108
DSL.optionalFields("Inventory", DSL.optionalFields(
116109
"Output", References.ITEM_STACK.`in`(schema),
117-
DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema)))
118-
))
110+
inventory.invoke())
111+
)
119112
}
120113

121114
simple("street_lamp")
122-
putGens("box") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
115+
putGens("box", inventory)
123116
}
124117

125118
override fun registerEntities(schema: Schema): MutableMap<String, Supplier<TypeTemplate>> = mutableMapOf<String, Supplier<TypeTemplate>>().apply {
@@ -132,7 +125,7 @@ class GenerationsRootSchema(versionKey: Int, parent: Schema?) : Schema(versionKe
132125
simple("zygarde_cell")
133126
}
134127

135-
private fun MutableMap<String, Supplier<TypeTemplate>>.simple(name: String) = registerSimple(this, "generations_core:$name")
128+
fun MutableMap<String, Supplier<TypeTemplate>>.simple(name: String) = registerSimple(this, "generations_core:$name")
136129

137-
private fun MutableMap<String, Supplier<TypeTemplate>>.putGens(k: String, function: () -> TypeTemplate) = put("generations_core:$k", function)
130+
fun MutableMap<String, Supplier<TypeTemplate>>.putGens(k: String, function: () -> TypeTemplate) = put("generations_core:$k", function)
138131
}

common/src/main/java/generations/gg/generations/core/generationscore/common/datafixer/schema/Generationsv1Schema.kt

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,14 @@ class Generationsv1Schema(versionKey: Int, parent: Schema) : Schema(versionKey,
2121
schema.registerType(true, References.ITEM_STACK) {
2222
vanillaSchema.getType(References.ITEM_STACK).buildTemplate()
2323
}
24+
}
2425

25-
schema.registerType(false, References.DATA_COMPONENTS) {
26-
vanillaSchema.getType(References.DATA_COMPONENTS).buildTemplate()
27-
}
28-
29-
schema.registerType(false, References.ITEM_NAME) { DSL.constType(NamespacedSchema.namespacedString()) }
30-
31-
schema.registerType(false, GenerationsReferences.TERRAIUM_FABRIC_INVENTORY, {
32-
DSL.optionalFields("fabric:attachments", DSL.optionalFields("generations_core:inventory", GenerationsReferences.ITEM_RESOURCE.`in`(schema)))
33-
})
34-
35-
schema.registerType(false, GenerationsReferences.TERRAIUM_FORGE_INVENTORY) {
36-
DSL.optionalFields("fabric:attachments", DSL.optionalFields("generations_core:inventory", GenerationsReferences.ITEM_RESOURCE.`in`(schema))) //TODO: Get back this when I have how this will look in 1.21.1
26+
override fun registerBlockEntities(schema: Schema): MutableMap<String, Supplier<TypeTemplate>> {
27+
return schema.registerBlockEntities(schema).apply {
28+
putGens("regigigas_shrine") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
29+
putGens("cooking_pot") { DSL.optionalFields("Items", DSL.list(References.ITEM_STACK.`in`(schema))) }
3730
}
38-
39-
schema.registerType(false, GenerationsReferences.ITEM_RESOURCE, {
40-
DSL.optionalFields("id", References.ITEM_NAME.`in`(schema), "components", References.DATA_COMPONENTS.`in`(schema), "amount", DSL.longType().template())
41-
})
4231
}
32+
33+
fun MutableMap<String, Supplier<TypeTemplate>>.putGens(k: String, function: () -> TypeTemplate) = put("generations_core:$k", function)
4334
}

common/src/main/java/generations/gg/generations/core/generationscore/common/mixin/NbtUtilsMixin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package generations.gg.generations.core.generationscore.common.mixin;
22

33
import generations.gg.generations.core.generationscore.common.datafixer.GenerationsSchemas;
4-
import generations.gg.generations.core.generationscore.common.datafixer.schema.GenerationsRootSchema;
54
import net.minecraft.nbt.CompoundTag;
65
import net.minecraft.nbt.NbtUtils;
76
import org.spongepowered.asm.mixin.Mixin;

0 commit comments

Comments
 (0)