Compare commits

...
Author SHA1 Message Date
tmetcalfe89 1258baad6b check arbitrary table actually exists 2024-06-18 11:01:36 -07:00
tmetcalfe89 e8b940ebad prototype
ported directly from my mods' solution.
could probably use clean-up with how the pools use air as a dummy "no result" item, a more Cobblemon-friendly loot table for Pickup, and I'd like to extend it with predicates that would need to match pokemonproperties for things like levels.
2024-06-15 16:50:25 -07:00
3 changed files with 137 additions and 0 deletions
@@ -123,8 +123,14 @@ import net.minecraft.command.argument.serialize.ConstantArgumentSerializer
import net.minecraft.entity.data.TrackedDataHandlerRegistry
import net.minecraft.item.Items
import net.minecraft.item.NameTagItem
import net.minecraft.loot.LootDataType
import net.minecraft.loot.context.LootContextParameterSet
import net.minecraft.loot.context.LootContextParameters
import net.minecraft.registry.RegistryKey
import net.minecraft.server.world.ServerWorld
import net.minecraft.util.Identifier
import net.minecraft.util.WorldSavePath
import net.minecraft.util.math.Vec3d
import net.minecraft.world.World
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
@@ -264,6 +270,52 @@ object Cobblemon {
event.newFriendship = event.pokemon.friendship + increment.roundToInt()
}
CobblemonEvents.BATTLE_VICTORY.subscribe(Priority.NORMAL) { evt ->
val world = evt.winners.flatMap { it.pokemonList }.firstNotNullOfOrNull { it.entity?.world }
if (world?.server == null) return@subscribe
for (winner in evt.winners) {
val position = winner.pokemonList.firstNotNullOf { it.entity }.blockPos
val vecPos = Vec3d(position.x.toDouble(), position.y.toDouble(), position.z.toDouble())
for (battlePokemon in winner.pokemonList) {
val pokemon = battlePokemon.effectedPokemon
// println("Rolling for ${pokemon.ability.name} on ${pokemon.getDisplayName().string}")
if (!pokemon.heldItem().isEmpty) {
// println("${pokemon.getDisplayName().string} is already holding an item")
continue
}
val identifier = Identifier("cobblemon", "gameplay/abilities/postbattle/${pokemon.ability.name}")
val lootManager = world.server!!.lootManager
if (!lootManager.getIds(LootDataType.LOOT_TABLES).contains(identifier)) {
// println("${pokemon.ability.name} doesn't have a postbattle loot table")
continue
}
val lootTable = lootManager.getLootTable(identifier)
val list = lootTable.generateLoot(
LootContextParameterSet(
world as ServerWorld,
mapOf(
LootContextParameters.ORIGIN to vecPos
),
mapOf(),
0F
)
)
if (list.isEmpty) {
// println("Attempted to roll for ability ${pokemon.ability.name} but nothing dropped.")
continue
}
pokemon.swapHeldItem(list.first())
}
}
}
HeldItemProvider.register(CobblemonHeldItemManager, Priority.LOWEST)
}
@@ -0,0 +1,20 @@
{
"type": "minecraft:generic",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:air",
"weight": 9
},
{
"type": "minecraft:item",
"weight": 1,
"name": "minecraft:honey_bottle"
}
]
}
]
}
@@ -0,0 +1,65 @@
{
"type": "minecraft:generic",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "minecraft:air",
"weight": 900
},
{
"type": "minecraft:item",
"weight": 30,
"name": "cobblemon:super_potion"
},
{
"type": "minecraft:item",
"weight": 10,
"name": "cobblemon:ultra_ball"
},
{
"type": "minecraft:item",
"weight": 10,
"name": "cobblemon:full_restore"
},
{
"type": "minecraft:item",
"weight": 10,
"name": "cobblemon:full_heal"
},
{
"type": "minecraft:item",
"weight": 10,
"name": "minecraft:gold_nugget"
},
{
"type": "minecraft:item",
"weight": 10,
"name": "cobblemon:revive"
},
{
"type": "minecraft:item",
"weight": 10,
"name": "cobblemon:rare_candy"
},
{
"type": "minecraft:item",
"weight": 5,
"name": "cobblemon:protein"
},
{
"type": "minecraft:item",
"weight": 4,
"name": "cobblemon:pp_up"
},
{
"type": "minecraft:item",
"weight": 1,
"name": "cobblemon:kings_rock"
}
]
}
]
}