|
| 1 | +/** |
| 2 | + * The Main Class of the Generations-Core mod. (Common) |
| 3 | + * Registers the mod's items and blocks with Minecraft using Architectury. |
| 4 | + * @author Joseph T. McQuigg |
| 5 | + * |
| 6 | + * CopyRight (c) 2023 Generations-Mod |
| 7 | + */ |
| 8 | +package generations.gg.generations.core.generationscore.common |
| 9 | + |
| 10 | +import com.cobblemon.mod.common.api.data.DataProvider |
| 11 | +import com.cobblemon.mod.common.api.spawning.detail.SpawnDetail.Companion.registerSpawnType |
| 12 | +import com.cobblemon.mod.common.api.storage.player.PlayerDataExtensionRegistry.register |
| 13 | +import com.mojang.logging.LogUtils |
| 14 | +import dev.architectury.event.events.common.LootEvent |
| 15 | +import generations.gg.generations.core.generationscore.common.api.GenerationsMolangFunctions |
| 16 | +import generations.gg.generations.core.generationscore.common.api.data.GenerationsCoreEntityDataSerializers |
| 17 | +import generations.gg.generations.core.generationscore.common.api.player.AccountInfo |
| 18 | +import generations.gg.generations.core.generationscore.common.api.player.BiomesVisited |
| 19 | +import generations.gg.generations.core.generationscore.common.api.player.Caught |
| 20 | +import generations.gg.generations.core.generationscore.common.client.render.rarecandy.instanceOrNull |
| 21 | +import generations.gg.generations.core.generationscore.common.config.Config |
| 22 | +import generations.gg.generations.core.generationscore.common.config.ConfigLoader.loadConfig |
| 23 | +import generations.gg.generations.core.generationscore.common.recipe.GenerationsIngredidents |
| 24 | +import generations.gg.generations.core.generationscore.common.world.container.GenerationsContainers |
| 25 | +import generations.gg.generations.core.generationscore.common.world.entity.GenerationsEntities |
| 26 | +import generations.gg.generations.core.generationscore.common.world.item.GenerationsArmor |
| 27 | +import generations.gg.generations.core.generationscore.common.world.item.GenerationsCobblemonInteractions.registerDefaultCustomInteractions |
| 28 | +import generations.gg.generations.core.generationscore.common.world.item.GenerationsItems |
| 29 | +import generations.gg.generations.core.generationscore.common.world.item.GenerationsTools |
| 30 | +import generations.gg.generations.core.generationscore.common.world.item.components.GenerationsItemComponents |
| 31 | +import generations.gg.generations.core.generationscore.common.world.item.creativetab.GenerationsCreativeTabs |
| 32 | +import generations.gg.generations.core.generationscore.common.world.item.legends.EnchantableItem |
| 33 | +import generations.gg.generations.core.generationscore.common.world.item.legends.EnchantableItem.Companion.isEnchanted |
| 34 | +import generations.gg.generations.core.generationscore.common.world.item.legends.EnchantableItem.Companion.isUsed |
| 35 | +import generations.gg.generations.core.generationscore.common.world.item.legends.EnchantableItem.Companion.setEnchanted |
| 36 | +import generations.gg.generations.core.generationscore.common.world.level.block.* |
| 37 | +import generations.gg.generations.core.generationscore.common.world.level.block.entities.GenerationsBlockEntities |
| 38 | +import generations.gg.generations.core.generationscore.common.world.loot.LootItemConditionTypes |
| 39 | +import generations.gg.generations.core.generationscore.common.world.loot.LootPoolEntryTypes |
| 40 | +import generations.gg.generations.core.generationscore.common.world.recipe.GenerationsCoreRecipeSerializers |
| 41 | +import generations.gg.generations.core.generationscore.common.world.recipe.GenerationsCoreRecipeTypes |
| 42 | +import generations.gg.generations.core.generationscore.common.world.recipe.RksResultType |
| 43 | +import generations.gg.generations.core.generationscore.common.world.sound.GenerationsSounds |
| 44 | +import generations.gg.generations.core.generationscore.common.world.spawning.ZygardeCellDetail |
| 45 | +import net.minecraft.core.registries.Registries |
| 46 | +import net.minecraft.network.chat.MutableComponent |
| 47 | +import net.minecraft.resources.ResourceKey |
| 48 | +import net.minecraft.resources.ResourceLocation |
| 49 | +import net.minecraft.server.level.ServerPlayer |
| 50 | +import net.minecraft.server.packs.PackType |
| 51 | +import net.minecraft.world.entity.player.Player |
| 52 | +import net.minecraft.world.item.ItemStack |
| 53 | +import net.minecraft.world.level.storage.loot.LootPool |
| 54 | +import net.minecraft.world.level.storage.loot.LootTable |
| 55 | +import net.minecraft.world.level.storage.loot.entries.NestedLootTable |
| 56 | +import org.apache.logging.log4j.util.TriConsumer |
| 57 | +import org.slf4j.Logger |
| 58 | +import java.util.function.Consumer |
| 59 | +import java.util.function.IntConsumer |
| 60 | + |
| 61 | +/** |
| 62 | + * The Main Class of the Generations-Core mod. (Common) |
| 63 | + * Registers the mod's items and blocks with Minecraft using Architectury. |
| 64 | + * @author Joseph T. McQuigg, WaterPicker |
| 65 | + */ |
| 66 | +object GenerationsCore { |
| 67 | + /** The mod id of the Generations-Core mod. */ |
| 68 | + const val MOD_ID: String = "generations_core" |
| 69 | + |
| 70 | + /** The logger for the Generations-Core mod. */ |
| 71 | + @JvmField |
| 72 | + val LOGGER: Logger = LogUtils.getLogger() |
| 73 | + |
| 74 | + /** The config for the Generations-Core mod. */ |
| 75 | + @JvmField |
| 76 | + var CONFIG: Config? = null |
| 77 | + @JvmField |
| 78 | + var implementation: GenerationsImplementation? = null |
| 79 | + |
| 80 | + @JvmField |
| 81 | + var dataProvider: DataProvider = GenerationsDataProvider.INSTANCE |
| 82 | + |
| 83 | + /** |
| 84 | + * Initializes the Generations-Core mod. |
| 85 | + */ |
| 86 | + @JvmStatic |
| 87 | + fun init(implementation: GenerationsImplementation?) { |
| 88 | + CONFIG = loadConfig( |
| 89 | + Config::class.java, "core", "main" |
| 90 | + ) |
| 91 | + GenerationsCore.implementation = implementation |
| 92 | + |
| 93 | + |
| 94 | + // GenerationsDataProvider.INSTANCE.register(ShopPresets.instance()); |
| 95 | +// GenerationsDataProvider.INSTANCE.register(Shops.instance()); |
| 96 | + LootEvent.MODIFY_LOOT_TABLE.register(LootEvent.ModifyLootTable { lootId: ResourceKey<LootTable?>, context: LootEvent.LootTableModificationContext, builtin: Boolean -> |
| 97 | + val id = lootId.location() |
| 98 | + if (id.namespace == "minecraft" && id.path.contains("chests") && !id.path.contains("inject")) { |
| 99 | + val inject = |
| 100 | + ResourceLocation.fromNamespaceAndPath(id.namespace, id.path.replace("chests", "chests/inject")) |
| 101 | + context.addPool( |
| 102 | + LootPool.lootPool() |
| 103 | + .add(NestedLootTable.lootTableReference(ResourceKey.create(Registries.LOOT_TABLE, inject))) |
| 104 | + ) |
| 105 | + } else if (id.toString() == "minecraft:blocks/carrots") { |
| 106 | + context.addPool( |
| 107 | + LootPool.lootPool().add( |
| 108 | + NestedLootTable.lootTableReference( |
| 109 | + ResourceKey.create( |
| 110 | + Registries.LOOT_TABLE, |
| 111 | + id("blocks/calyrex_roots") |
| 112 | + ) |
| 113 | + ) |
| 114 | + ) |
| 115 | + ) |
| 116 | + } |
| 117 | + }) |
| 118 | + |
| 119 | + registerSpawnType( |
| 120 | + ZygardeCellDetail.TYPE, |
| 121 | + ZygardeCellDetail::class.java |
| 122 | + ) |
| 123 | + |
| 124 | + GenerationsItemComponents.init() |
| 125 | + |
| 126 | + GenerationsCoreEntityDataSerializers.init() |
| 127 | + GenerationsSounds.init() |
| 128 | + GenerationsBlocks.init() |
| 129 | + GenerationsPokeDolls.init() |
| 130 | + GenerationsWood.init() |
| 131 | + GenerationsOres.init() |
| 132 | + GenerationsDecorationBlocks.init() |
| 133 | + LootPoolEntryTypes.init() |
| 134 | + LootItemConditionTypes.init() |
| 135 | + GenerationsUtilityBlocks.init() |
| 136 | + GenerationsShrines.init() |
| 137 | + GenerationsItems.init() |
| 138 | + GenerationsBlockEntities.init() |
| 139 | + GenerationsEntities.init() |
| 140 | + GenerationsCreativeTabs.init() |
| 141 | + GenerationsArmor.init() |
| 142 | + GenerationsTools.init() |
| 143 | + GenerationsPaintings.init() |
| 144 | + GenerationsContainers.init() |
| 145 | + RksResultType.init() |
| 146 | + GenerationsIngredidents.init() |
| 147 | + GenerationsCoreRecipeTypes.init() |
| 148 | + GenerationsCoreRecipeSerializers.init() |
| 149 | + GenerationsCoreStats.init() |
| 150 | + |
| 151 | + GenerationsDataProvider.INSTANCE.registerDefaults() |
| 152 | + |
| 153 | + //TODO: Convert to our data thingy. |
| 154 | + register( |
| 155 | + AccountInfo.KEY, |
| 156 | + AccountInfo::class.java, false |
| 157 | + ) |
| 158 | + register( |
| 159 | + Caught.KEY, |
| 160 | + Caught::class.java, false |
| 161 | + ) |
| 162 | + register( |
| 163 | + BiomesVisited.KEY, |
| 164 | + BiomesVisited::class.java, false |
| 165 | + ) |
| 166 | + |
| 167 | + // PlayerDataExtensionRegistry.INSTANCE.register(CurryDex.KEY, CurryDex.class, false); |
| 168 | + GenerationsMolangFunctions.init() |
| 169 | + |
| 170 | + GenerationsCobblemonEvents.init() |
| 171 | + GenerationsArchitecturyEvents.init() |
| 172 | + |
| 173 | + registerDefaultCustomInteractions() |
| 174 | + |
| 175 | + |
| 176 | + // BuiltInRegistries.BLOCK.stream().map(a -> a.arch$registryName() + ": " + a.getLootTable()).forEach(a -> System.out.println(a)); |
| 177 | + } |
| 178 | + |
| 179 | + fun initBuiltinPacks(consumer: TriConsumer<PackType?, ResourceLocation?, MutableComponent?>?) { |
| 180 | +// consumer.accept(PackType.CLIENT_RESOURCES, GenerationsCore.id("smooth_pokemon"), Component.literal("Smooth Pokemon Models")); |
| 181 | + } |
| 182 | + |
| 183 | + fun onAnvilChange( |
| 184 | + left: ItemStack, |
| 185 | + right: ItemStack, |
| 186 | + player: Player?, |
| 187 | + output: Consumer<ItemStack?>, |
| 188 | + cost: IntConsumer, |
| 189 | + materialCost: IntConsumer |
| 190 | + ) { |
| 191 | + if (player is ServerPlayer && left.item.instanceOrNull<EnchantableItem>()?.neededEnchantmentLevel(player).orFalse { it > 0 } && !isEnchanted( |
| 192 | + left |
| 193 | + ) && !isUsed(left) && right.isEmpty |
| 194 | + ) { |
| 195 | + output.accept(setEnchanted(left.copy(), true)) |
| 196 | + cost.accept(Int.MAX_VALUE) |
| 197 | + materialCost.accept(0) |
| 198 | + } |
| 199 | + } |
| 200 | + |
| 201 | + /** |
| 202 | + * Creates a [ResourceLocation] with the Generations-Core Mod id. |
| 203 | + */ |
| 204 | + @JvmStatic |
| 205 | + fun id(path: String): ResourceLocation { |
| 206 | + return ResourceLocation.fromNamespaceAndPath(MOD_ID, path) |
| 207 | + } |
| 208 | +} |
| 209 | + |
| 210 | +fun <T> T?.orFalse(predicate: (T) -> Boolean): Boolean = this?.let(predicate) ?: false |
0 commit comments