Skip to content

Commit

Permalink
Added dupe patch for multiply_drops
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Mar 10, 2024
1 parent 30ce95b commit 0ae57e7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package com.willfp.libreforge.effects.impl

import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.items.Items
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.core.items.matches
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.arguments
import com.willfp.libreforge.effects.Effect
import com.willfp.libreforge.getDoubleFromExpression
import com.willfp.libreforge.getIntFromExpression
import com.willfp.libreforge.plugin
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
import com.willfp.libreforge.triggers.event.DropResult
Expand All @@ -22,9 +25,21 @@ object EffectMultiplyDrops : Effect<NoCompileData>("multiply_drops") {
require(listOf("multiplier", "fortune"), "You must specify a multiplier or level of fortune to mimic!")
}

private val whitelist = mutableListOf<TestableItem>()

override fun postRegister() {
plugin.onReload {
whitelist.clear()
whitelist.addAll(plugin.configYml.getStrings("effects.multiply_drops.whitelist").map { Items.lookup(it) })
}
}

override fun onTrigger(config: Config, data: TriggerData, compileData: NoCompileData): Boolean {
val event = data.event as? EditableDropEvent ?: return false

val isBlacklisting = plugin.configYml.getBool("effects.multiply_drops.prevent-duplication")
val whitelist = plugin.configYml.getStrings("effects.multiply_drops.whitelist").map { Items.lookup(it) }

val multiplier = if (config.has("fortune")) {
val fortune = config.getIntFromExpression("fortune", data)
(Math.random() * (fortune.toDouble() - 1) + 1.1).roundToInt()
Expand All @@ -40,6 +55,10 @@ object EffectMultiplyDrops : Effect<NoCompileData>("multiply_drops") {
}

if (it.maxStackSize > 1 && matches) {
if (it.type.isOccluding && isBlacklisting && !whitelist.matches(it)) {
return@addModifier DropResult(it, 0)
}

it.amount *= multiplier
}

Expand Down
8 changes: 8 additions & 0 deletions core/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ effects:
# Only set this option to true if you know what you're doing!
use-setblock-break: false

multiply_drops:
# Some items can be duplicated if they are placed on other blocks, e.g. torches, lanterns, etc.
# This option will prevent this from happening by blacklisting certain blocks from being multiplied.
prevent-duplication: true

# If you notice that some items are not being multiplied when you want them to be, you can add them to this list.
whitelist: []

conditions:
# Item display (things like EcoItem lore, EcoEnchants lore, etc.) are ran on a separate thread,
# and condition met state is cached from the main thread. Things like not-met-lines and show-not-met
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 4.56.3
version = 4.56.4
kotlin.code.style = official

0 comments on commit 0ae57e7

Please sign in to comment.