forked from mirrors/cobblemon
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1258baad6b | ||
|
|
e8b940ebad |
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
+20
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
+65
@@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user