Fixes, whitelist mode for miner

This commit is contained in:
TomTom 2024-05-25 09:29:10 +02:00
parent f01db6ede0
commit 3072b0b97b
5 changed files with 66 additions and 47 deletions

View File

@ -17,6 +17,7 @@
<option value="$PROJECT_DIR$/nms/v1_20_R1" />
<option value="$PROJECT_DIR$/nms/v1_20_R2" />
<option value="$PROJECT_DIR$/nms/v1_20_R3" />
<option value="$PROJECT_DIR$/nms/v1_20_R4" />
</set>
</option>
</GradleProjectSettings>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.22" />
<option name="version" value="1.9.23" />
</component>
</project>

View File

@ -43,25 +43,21 @@ class AxMinionsCommand {
receiver.inventory.addItem(item)
}
@Subcommand("fuel")
@CommandPermission("axminions.command.fuel")
class Fuel {
@Subcommand("fuel give")
@CommandPermission("axminions.command.fuel.give")
fun give(sender: CommandSender, id: String, receiver: Player, @Default("1") amount: Int) {
val item = ItemBuilder(Config.CHARGE_ITEMS().getSection(id)).get()
item.amount = amount
receiver.inventory.addItem(item)
}
@Subcommand("give")
@CommandPermission("axminions.command.fuel.give")
fun give(sender: CommandSender, id: String, receiver: Player, @Default("1") amount: Int) {
val item = ItemBuilder(Config.CHARGE_ITEMS().getSection(id)).get()
item.amount = amount
receiver.inventory.addItem(item)
}
@Subcommand("add")
@CommandPermission("axminions.command.fuel.add")
fun add(player: Player, id: String, charge: Int) {
val item = ItemBuilder(player.inventory.itemInMainHand).serialize(true)
item["charge"] = charge
AxMinionsPlugin.config.getConfig().set("charge.items.$id", item)
}
@Subcommand("fuel add")
@CommandPermission("axminions.command.fuel.add")
fun add(player: Player, id: String, charge: Int) {
val item = ItemBuilder(player.inventory.itemInMainHand).serialize(true)
item["charge"] = charge
AxMinionsPlugin.config.getConfig().set("charge.items.$id", item)
AxMinionsPlugin.config.getConfig().save()
}

View File

@ -38,24 +38,8 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
}
}
// 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
// }
var generatorMode = false
val whitelist = arrayListOf<Material>()
override fun shouldRun(minion: Minion): Boolean {
return MinionTicker.getTick() % minion.getNextAction() == 0L
@ -67,6 +51,12 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
val tool = minion.getTool()?.getEnchantmentLevel(Enchantment.DIG_SPEED)?.div(10.0) ?: 0.1
val efficiency = 1.0 - if (tool > 0.9) 0.9 else tool
minionImpl.setNextAction((getLong("speed", minion.getLevel()) * efficiency).roundToInt())
generatorMode = getConfig().getString("break") == "generator"
whitelist.clear()
getConfig().getStringList("whitelist").fastFor {
whitelist.add(Material.matchMaterial(it) ?: return@fastFor)
}
}
override fun run(minion: Minion) {
@ -114,9 +104,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
}
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
val canBreak = if (generatorMode) {
MinionUtils.isStoneGenerator(location)
} else {
whitelist.contains(location.block.type)
}
if (isStoneGenerator) {
if (canBreak) {
val block = location.block
val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
@ -150,9 +144,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
}
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
val canBreak = if (generatorMode) {
MinionUtils.isStoneGenerator(location)
} else {
whitelist.contains(location.block.type)
}
if (isStoneGenerator) {
if (canBreak) {
Scheduler.get().run {
val block = location.block
val drops = block.getDrops(minion.getTool())
@ -181,9 +179,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
}
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
val canBreak = if (generatorMode) {
MinionUtils.isStoneGenerator(location)
} else {
whitelist.contains(location.block.type)
}
if (isStoneGenerator) {
if (canBreak) {
val block = location.block
val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
@ -212,9 +214,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
}
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
val canBreak = if (generatorMode) {
MinionUtils.isStoneGenerator(location)
} else {
whitelist.contains(location.block.type)
}
if (isStoneGenerator) {
if (canBreak) {
val block = location.block
val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)
@ -256,9 +262,13 @@ class MinerMinionType : MinionType("miner", AxMinionsPlugin.INSTANCE.getResource
}
}
val isStoneGenerator = MinionUtils.isStoneGenerator(location)
val canBreak = if (generatorMode) {
MinionUtils.isStoneGenerator(location)
} else {
whitelist.contains(location.block.type)
}
if (isStoneGenerator) {
if (canBreak) {
val block = location.block
val drops = block.getDrops(minion.getTool())
xp += NMSHandler.get().getExp(block, minion.getTool() ?: return)

View File

@ -21,6 +21,18 @@ tool:
# as it may cause some issues due to states being concurrently modified!
mode: line
# Can be generator or whitelist
# with generator mode the minion only mines blocks that are from a stone generator (water & lava on the sides of the block)
# with whitelist mode, it will break all blocks that match the whitelist
break: generator
whitelist:
- "stone"
- "cobblestone"
- "iron_ore"
- "gold_ore"
- "redstone_ore"
item:
type: "player_head"
texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzk2MjdiZTYyY2VkNzE0MTEzOWQzZjE1NTc5MGE1ZDQzNTZlYjdiOWVlOTVlNTA0YjMzMjI5NzRjYmM1MTVlYSJ9fX0="