mirror of
https://github.com/Artillex-Studios/AxMinions.git
synced 2024-11-29 12:45:18 +01:00
Add xp to miner, cap correctly
This commit is contained in:
parent
86d85ede6b
commit
fb2a999cc7
@ -17,14 +17,16 @@ class MinionDamageListener : Listener {
|
||||
fun onMinionKillEntityEvent(event: MinionKillEntityEvent) {
|
||||
val entitySize = AxMinionsPlugin.integrations.getStackerIntegration().getStackSize(event.target)
|
||||
|
||||
val amount = ThreadLocalRandom.current().nextInt(1, 4) * entitySize
|
||||
event.minion.setActions(event.minion.getActionAmount() + entitySize)
|
||||
if (event.minion.getStorage() + amount < event.minion.getType().getDouble("storage", event.minion.getLevel())) {
|
||||
event.minion.setStorage(event.minion.getStorage() + amount * entitySize)
|
||||
}
|
||||
val coerced = (event.minion.getStorage() + ThreadLocalRandom.current().nextInt(1, 4) * entitySize).coerceIn(
|
||||
0.0,
|
||||
event.minion.getType().getLong("storage", event.minion.getLevel()).toDouble()
|
||||
)
|
||||
event.minion.setStorage(coerced)
|
||||
|
||||
Scheduler.get().runLaterAt(event.target.location, {
|
||||
event.target.location.world!!.getNearbyEntities(event.target.location, 4.0, 4.0, 4.0).filterIsInstance<Item>().fastFor { item ->
|
||||
event.target.location.world!!.getNearbyEntities(event.target.location, 4.0, 4.0, 4.0)
|
||||
.filterIsInstance<Item>().fastFor { item ->
|
||||
if (event.minion.getLinkedInventory()?.firstEmpty() == -1) {
|
||||
Warnings.CONTAINER_FULL.display(event.minion)
|
||||
return@runLaterAt
|
||||
|
@ -76,9 +76,9 @@ class FisherMinionType : MinionType("fisher", AxMinionsPlugin.INSTANCE.getResour
|
||||
val xp = ThreadLocalRandom.current().nextInt(6) + 1
|
||||
|
||||
minion.addToContainerOrDrop(loot)
|
||||
if (minion.getStorage() + xp < minion.getType().getDouble("storage", minion.getLevel())) {
|
||||
minion.setStorage(minion.getStorage() + xp)
|
||||
}
|
||||
val coerced = (minion.getStorage() + xp).coerceIn(0.0, minion.getType().getLong("storage", minion.getLevel()).toDouble())
|
||||
minion.setStorage(coerced)
|
||||
|
||||
minion.setActions(minion.getActionAmount() + 1)
|
||||
minion.damageTool()
|
||||
}
|
||||
|
@ -10,19 +10,52 @@ import com.artillexstudios.axminions.api.utils.MinionUtils
|
||||
import com.artillexstudios.axminions.api.utils.fastFor
|
||||
import com.artillexstudios.axminions.api.warnings.Warnings
|
||||
import com.artillexstudios.axminions.minions.MinionTicker
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import dev.lone.itemsadder.api.CustomBlock
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
import kotlin.math.roundToInt
|
||||
import me.kryniowesegryderiusz.kgenerators.Main
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.block.BlockFace
|
||||
import org.bukkit.enchantments.Enchantment
|
||||
import org.bukkit.inventory.FurnaceRecipe
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource("minions/miner.yml")!!) {
|
||||
private var asyncExecutor: ExecutorService? = null
|
||||
private val faces = arrayOf(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST)
|
||||
companion object {
|
||||
private var asyncExecutor: ExecutorService? = null
|
||||
private val smeltingRecipes = ArrayList<FurnaceRecipe>()
|
||||
private val faces = arrayOf(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST)
|
||||
|
||||
init {
|
||||
Bukkit.recipeIterator().forEachRemaining {
|
||||
if (it is FurnaceRecipe) {
|
||||
smeltingRecipes.add(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private fun toSmelted(minion: Minion, drops: Collection<ItemStack>): MutableList<ItemStack> {
|
||||
// if (minion.getType().getConfig().getBoolean("gui.autosmelt.enabled")) {
|
||||
// val dropsList = ArrayList<ItemStack>(drops.size)
|
||||
// drops.forEach { item ->
|
||||
// smeltingRecipes.fastFor {
|
||||
// if (it.inputChoice.test(item)) {
|
||||
// dropsList.add(it.result)
|
||||
// } else {
|
||||
// dropsList.add(item)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return dropsList
|
||||
// }
|
||||
|
||||
override fun shouldRun(minion: Minion): Boolean {
|
||||
return MinionTicker.getTick() % minion.getNextAction() == 0L
|
||||
@ -65,6 +98,7 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
Warnings.remove(minion, Warnings.NO_TOOL)
|
||||
|
||||
var amount = 0
|
||||
var xp = 0
|
||||
when (getConfig().getString("mode").lowercase(Locale.ENGLISH)) {
|
||||
"sphere" -> {
|
||||
LocationUtils.getAllBlocksInRadius(minion.getLocation(), minion.getRange(), false).fastFor { location ->
|
||||
@ -83,7 +117,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
val drops = location.block.getDrops(minion.getTool())
|
||||
val block = location.block
|
||||
val drops = block.getDrops(minion.getTool())
|
||||
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
|
||||
drops.forEach {
|
||||
amount += it.amount
|
||||
}
|
||||
@ -118,7 +154,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
|
||||
if (isStoneGenerator) {
|
||||
Scheduler.get().run {
|
||||
val drops = location.block.getDrops(minion.getTool())
|
||||
val block = location.block
|
||||
val drops = block.getDrops(minion.getTool())
|
||||
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return@run)
|
||||
drops.forEach {
|
||||
amount += it.amount
|
||||
}
|
||||
@ -146,7 +184,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
val drops = location.block.getDrops(minion.getTool())
|
||||
val block = location.block
|
||||
val drops = block.getDrops(minion.getTool())
|
||||
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
|
||||
drops.forEach {
|
||||
amount += it.amount
|
||||
}
|
||||
@ -175,7 +215,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
val drops = location.block.getDrops(minion.getTool())
|
||||
val block = location.block
|
||||
val drops = block.getDrops(minion.getTool())
|
||||
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
|
||||
drops.forEach { item ->
|
||||
amount += item.amount
|
||||
}
|
||||
@ -217,10 +259,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
|
||||
|
||||
if (isStoneGenerator) {
|
||||
val drops = location.block.getDrops(minion.getTool())
|
||||
val block = location.block
|
||||
val drops = block.getDrops(minion.getTool())
|
||||
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
|
||||
drops.forEach {
|
||||
amount += it.amount
|
||||
}
|
||||
|
||||
minion.addToContainerOrDrop(drops)
|
||||
location.block.type = Material.AIR
|
||||
}
|
||||
@ -228,6 +273,9 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
|
||||
}
|
||||
}
|
||||
|
||||
val coerced =
|
||||
(minion.getStorage() + xp).coerceIn(0.0, minion.getType().getLong("storage", minion.getLevel()).toDouble())
|
||||
minion.setStorage(coerced)
|
||||
minion.setActions(minion.getActionAmount() + amount)
|
||||
minion.damageTool(amount)
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package com.artillexstudios.axminions.nms
|
||||
import com.artillexstudios.axapi.utils.Version
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@ -21,4 +22,6 @@ interface NMSHandler {
|
||||
fun generateRandomFishingLoot(minion: Minion, waterLocation: Location): List<ItemStack>
|
||||
|
||||
fun isAnimal(entity: Entity): Boolean
|
||||
|
||||
fun getExp(block: Block, itemStack: ItemStack): Int
|
||||
}
|
@ -53,15 +53,29 @@ gui:
|
||||
- " <gray>- <white>Killed mobs: <#FF3333><actions>"
|
||||
- " <gray>- <white>Stored exp: <#CC00FF><storage>"
|
||||
- ""
|
||||
autosmelt:
|
||||
enabled: true
|
||||
slot: 9
|
||||
material: "lava_bucket"
|
||||
name: "<gold>Autosmelt"
|
||||
lore:
|
||||
- ""
|
||||
- "<gray> Click to purchase! "
|
||||
- ""
|
||||
- "<white>Price: <green>$1,000"
|
||||
requirements:
|
||||
money: 1000
|
||||
actions: 100
|
||||
|
||||
upgrades:
|
||||
1:
|
||||
range: 3
|
||||
speed: 200
|
||||
storage: 200
|
||||
items:
|
||||
helmet:
|
||||
type: "player_head"
|
||||
texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTc1MzJlOTBjNTczYTM5NGM3ODAyYWE0MTU4MzA1ODAyYjU5ZTY3ZjJhMmI3ZTNmZDAzNjNhYTZlYTQyYjg0MSJ9fX0="
|
||||
texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI 6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTc1MzJlOTBjNTczYTM5NGM3ODAyYWE0MTU4MzA1ODAyYjU5ZTY3ZjJhMmI3ZTNmZDAzNjNhYTZlYTQyYjg0MSJ9fX0="
|
||||
chestplate:
|
||||
type: "leather_chestplate"
|
||||
color: "0, 150, 255"
|
||||
|
@ -4,7 +4,12 @@ import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import net.minecraft.world.entity.MobCategory
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlock
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.CraftBlockState
|
||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_20_R1.util.CraftLocation
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@ -21,4 +26,9 @@ class NMSHandler : NMSHandler {
|
||||
override fun isAnimal(entity: Entity): Boolean {
|
||||
return (entity as CraftEntity).handle.type.category == MobCategory.CREATURE
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.asNMSCopy(itemStack), true)
|
||||
}
|
||||
}
|
@ -4,7 +4,12 @@ import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import net.minecraft.world.entity.MobCategory
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock
|
||||
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlockState
|
||||
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_20_R2.util.CraftLocation
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@ -21,4 +26,9 @@ class NMSHandler : NMSHandler {
|
||||
override fun isAnimal(entity: Entity): Boolean {
|
||||
return (entity as CraftEntity).handle.type.category == MobCategory.CREATURE
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.unwrap(itemStack), true)
|
||||
}
|
||||
}
|
@ -2,9 +2,15 @@ package com.artillexstudios.axminions.nms.v1_20_R3
|
||||
|
||||
import com.artillexstudios.axminions.api.minions.Minion
|
||||
import com.artillexstudios.axminions.nms.NMSHandler
|
||||
import net.minecraft.core.BlockPos
|
||||
import net.minecraft.world.entity.MobCategory
|
||||
import org.bukkit.Location
|
||||
import org.bukkit.block.Block
|
||||
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock
|
||||
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlockState
|
||||
import org.bukkit.craftbukkit.v1_20_R3.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_20_R3.util.CraftLocation
|
||||
import org.bukkit.entity.Entity
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
@ -21,4 +27,9 @@ class NMSHandler : NMSHandler {
|
||||
override fun isAnimal(entity: Entity): Boolean {
|
||||
return (entity as CraftEntity).handle.type.category == MobCategory.CREATURE
|
||||
}
|
||||
|
||||
override fun getExp(block: Block, itemStack: ItemStack): Int {
|
||||
val craftBlock = block as CraftBlock
|
||||
return craftBlock.nms.block.getExpDrop((block.state as CraftBlockState).handle, craftBlock.handle.minecraftWorld, CraftLocation.toBlockPosition(block.location), CraftItemStack.unwrap(itemStack), true)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user