mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-19 23:19:17 +00:00
Added spawn totems
This commit is contained in:
@@ -11,6 +11,7 @@ import com.willfp.ecomobs.goals.entity.EntityGoalRandomTeleport
|
|||||||
import com.willfp.ecomobs.handler.DamageModifierHandler
|
import com.willfp.ecomobs.handler.DamageModifierHandler
|
||||||
import com.willfp.ecomobs.handler.MountHandler
|
import com.willfp.ecomobs.handler.MountHandler
|
||||||
import com.willfp.ecomobs.handler.SpawnEggHandler
|
import com.willfp.ecomobs.handler.SpawnEggHandler
|
||||||
|
import com.willfp.ecomobs.handler.SpawnTotemHandler
|
||||||
import com.willfp.ecomobs.handler.VanillaCompatibilityHandlers
|
import com.willfp.ecomobs.handler.VanillaCompatibilityHandlers
|
||||||
import com.willfp.ecomobs.integrations.levelledmobs.IntegrationLevelledMobs
|
import com.willfp.ecomobs.integrations.levelledmobs.IntegrationLevelledMobs
|
||||||
import com.willfp.ecomobs.integrations.libsdisguises.IntegrationLibsDisguises
|
import com.willfp.ecomobs.integrations.libsdisguises.IntegrationLibsDisguises
|
||||||
@@ -45,7 +46,8 @@ class EcoMobsPlugin : LibreforgePlugin() {
|
|||||||
MountHandler(),
|
MountHandler(),
|
||||||
VanillaCompatibilityHandlers(),
|
VanillaCompatibilityHandlers(),
|
||||||
DiscoverRecipeListener(this),
|
DiscoverRecipeListener(this),
|
||||||
SpawnEggHandler(this)
|
SpawnEggHandler(this),
|
||||||
|
SpawnTotemHandler()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
package com.willfp.ecomobs.handler
|
||||||
|
|
||||||
|
import com.willfp.ecomobs.mob.EcoMobs
|
||||||
|
import com.willfp.ecomobs.mob.SpawnReason
|
||||||
|
import com.willfp.ecomobs.mob.SpawnTotem
|
||||||
|
import com.willfp.libreforge.triggers.TriggerData
|
||||||
|
import org.bukkit.block.Block
|
||||||
|
import org.bukkit.event.EventHandler
|
||||||
|
import org.bukkit.event.Listener
|
||||||
|
import org.bukkit.event.block.BlockPlaceEvent
|
||||||
|
|
||||||
|
class SpawnTotemHandler : Listener {
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
fun handle(event: BlockPlaceEvent) {
|
||||||
|
val block = event.block
|
||||||
|
val blockBelow = block.getRelative(0, -1, 0)
|
||||||
|
val blockTwoBelow = block.getRelative(0, -2, 0)
|
||||||
|
val blockAbove = block.getRelative(0, 1, 0)
|
||||||
|
val blockTwoAbove = block.getRelative(0, 2, 0)
|
||||||
|
|
||||||
|
val player = event.player
|
||||||
|
val location = block.location.add(0.0, 1.5, 0.0)
|
||||||
|
|
||||||
|
val totemPositions = listOf(
|
||||||
|
SpawnTotem(block.type, blockBelow.type, blockTwoBelow.type),
|
||||||
|
SpawnTotem(blockTwoAbove.type, blockAbove.type, block.type),
|
||||||
|
SpawnTotem(blockAbove.type, block.type, blockBelow.type)
|
||||||
|
)
|
||||||
|
|
||||||
|
for (totem in totemPositions) {
|
||||||
|
for (mob in EcoMobs.values()) {
|
||||||
|
val options = mob.totemOptions ?: continue
|
||||||
|
|
||||||
|
if (options.totem != totem) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!options.conditions.areMetAndTrigger(
|
||||||
|
TriggerData(
|
||||||
|
player = player
|
||||||
|
).dispatch(player)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
mob.spawn(location, SpawnReason.TOTEM)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,6 +39,11 @@ interface EcoMob : KRegistrable {
|
|||||||
*/
|
*/
|
||||||
val spawnEgg: SpawnEgg?
|
val spawnEgg: SpawnEgg?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The spawn totem options.
|
||||||
|
*/
|
||||||
|
val totemOptions: SpawnTotemOptions?
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a living mob from a bukkit mob.
|
* Get a living mob from a bukkit mob.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.willfp.ecomobs.mob
|
||||||
|
|
||||||
|
import com.willfp.libreforge.conditions.ConditionList
|
||||||
|
import org.bukkit.Material
|
||||||
|
|
||||||
|
data class SpawnTotem(
|
||||||
|
val top: Material,
|
||||||
|
val middle: Material,
|
||||||
|
val bottom: Material
|
||||||
|
)
|
||||||
|
|
||||||
|
data class SpawnTotemOptions(
|
||||||
|
val conditions: ConditionList,
|
||||||
|
val totem: SpawnTotem
|
||||||
|
)
|
||||||
@@ -33,6 +33,8 @@ import com.willfp.ecomobs.mob.EcoMob
|
|||||||
import com.willfp.ecomobs.mob.EcoMobs
|
import com.willfp.ecomobs.mob.EcoMobs
|
||||||
import com.willfp.ecomobs.mob.LivingMob
|
import com.willfp.ecomobs.mob.LivingMob
|
||||||
import com.willfp.ecomobs.mob.SpawnReason
|
import com.willfp.ecomobs.mob.SpawnReason
|
||||||
|
import com.willfp.ecomobs.mob.SpawnTotem
|
||||||
|
import com.willfp.ecomobs.mob.SpawnTotemOptions
|
||||||
import com.willfp.ecomobs.mob.addGoal
|
import com.willfp.ecomobs.mob.addGoal
|
||||||
import com.willfp.ecomobs.mob.event.MobEvent
|
import com.willfp.ecomobs.mob.event.MobEvent
|
||||||
import com.willfp.ecomobs.mob.event.MobEvents
|
import com.willfp.ecomobs.mob.event.MobEvents
|
||||||
@@ -277,6 +279,26 @@ internal class ConfigDrivenEcoMob(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override val totemOptions = config.getBool("spawn.totem.enabled").ifTrue {
|
||||||
|
val conditions = Conditions.compile(
|
||||||
|
config.getSubsections("spawn.totem.conditions"),
|
||||||
|
context.with("spawn totem conditions")
|
||||||
|
)
|
||||||
|
|
||||||
|
val top = Items.lookup(config.getString("spawn.totem.top"))
|
||||||
|
val middle = Items.lookup(config.getString("spawn.totem.middle"))
|
||||||
|
val bottom = Items.lookup(config.getString("spawn.totem.bottom"))
|
||||||
|
|
||||||
|
SpawnTotemOptions(
|
||||||
|
conditions,
|
||||||
|
SpawnTotem(
|
||||||
|
top.item.type,
|
||||||
|
middle.item.type,
|
||||||
|
bottom.item.type
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
----------
|
----------
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user