diff --git a/build.gradle b/build.gradle index 48452ee..b1f23c6 100644 --- a/build.gradle +++ b/build.gradle @@ -34,6 +34,7 @@ allprojects { maven { url 'https://repo.codemc.io/repository/maven-public/' } maven { url 'https://repo.dmulloy2.net/repository/public/' } maven { url 'https://repo.essentialsx.net/releases/' } + maven { url 'https://mvn.lumine.io/repository/maven-public/' } } jar { diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index be19ded..294a270 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -7,6 +7,7 @@ dependencies { compileOnly 'net.kyori:adventure-api:4.10.1' compileOnly 'net.essentialsx:EssentialsX:2.19.0' compileOnly 'com.github.ben-manes.caffeine:caffeine:3.0.6' + compileOnly 'com.ticxo.modelengine:api:R2.5.0' } build.dependsOn publishToMavenLocal diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt index 92dea62..a9c3e52 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt @@ -9,7 +9,6 @@ import com.willfp.eco.core.fast.fast import com.willfp.eco.core.items.CustomItem import com.willfp.eco.core.items.Items import com.willfp.eco.core.items.builder.ItemStackBuilder -import com.willfp.eco.core.items.builder.SkullBuilder import com.willfp.eco.core.placeholder.PlayerPlaceholder import com.willfp.eco.core.placeholder.PlayerStaticPlaceholder import com.willfp.eco.core.placeholder.PlayerlessPlaceholder @@ -21,6 +20,9 @@ import com.willfp.eco.util.toNiceString import com.willfp.ecopets.EcoPetsPlugin import com.willfp.ecopets.api.event.PlayerPetExpGainEvent import com.willfp.ecopets.api.event.PlayerPetLevelUpEvent +import com.willfp.ecopets.pets.entity.ModelEnginePetEntity +import com.willfp.ecopets.pets.entity.PetEntity +import com.willfp.ecopets.pets.entity.SkullPetEntity import com.willfp.libreforge.conditions.Conditions import com.willfp.libreforge.conditions.ConfiguredCondition import com.willfp.libreforge.effects.ConfiguredEffect @@ -112,9 +114,7 @@ class Pet( } } - val petEntityItem: ItemStack = SkullBuilder() - .setSkullTexture(config.getString("entity-texture")) - .build() + val entityTexture = config.getString("entity-texture") private val levelXpRequirements = listOf(0) + config.getInts("level-xp-requirements") @@ -239,6 +239,14 @@ class Pet( }.register() } + fun makePetEntity(): PetEntity { + if (entityTexture.startsWith("modelengine:")) { + return ModelEnginePetEntity(this) + } else { + return SkullPetEntity(this) + } + } + fun getLevel(level: Int): PetLevel = levels.get(level) { PetLevel(this, it, effects, conditions) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt index fa9a5ec..a68e552 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/PetDisplay.kt @@ -6,16 +6,13 @@ import com.willfp.eco.util.formatEco import org.bukkit.Bukkit import org.bukkit.Location import org.bukkit.entity.ArmorStand -import org.bukkit.entity.EntityType import org.bukkit.entity.Player import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerQuitEvent -import org.bukkit.inventory.EquipmentSlot import java.util.* import kotlin.math.PI import kotlin.math.abs -import kotlin.math.sin class PetDisplay( private val plugin: EcoPlugin @@ -37,7 +34,6 @@ class PetDisplay( val pet = player.activePet if (pet != null) { - stand.equipment?.helmet = pet.petEntityItem stand.customName = plugin.configYml.getString("pet-entity.name") .replace("%player%", player.displayName) .replace("%pet%", pet.name) @@ -49,7 +45,10 @@ class PetDisplay( location.y += NumberUtils.fastSin(tick / (2 * PI) * 0.5) * 0.15 stand.teleport(location) - stand.setRotation((20 * tick / (2 * PI)).toFloat(), 0f) + + if (!pet.entityTexture.contains(":")) { + stand.setRotation((20 * tick / (2 * PI)).toFloat(), 0f) + } } } @@ -75,24 +74,9 @@ class PetDisplay( } val location = getLocation(player) - val newStand = location.world!!.spawnEntity(location, EntityType.ARMOR_STAND) as ArmorStand - newStand.isVisible = false - newStand.isInvulnerable = true - newStand.isPersistent = true - newStand.removeWhenFarAway = false - newStand.isSmall = true - newStand.setGravity(false) - newStand.isCollidable = false + val stand = pet.makePetEntity().spawn(location) - for (slot in EquipmentSlot.values()) { - newStand.addEquipmentLock(slot, ArmorStand.LockType.ADDING_OR_CHANGING) - } - - newStand.equipment?.helmet = pet.petEntityItem - newStand.isCustomNameVisible = true - newStand.customName = pet.name - - trackedEntities[player.uniqueId] = newStand + trackedEntities[player.uniqueId] = stand } return trackedEntities[player.uniqueId] diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt new file mode 100644 index 0000000..026558b --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/ModelEnginePetEntity.kt @@ -0,0 +1,36 @@ +package com.willfp.ecopets.pets.entity + +import com.ticxo.modelengine.api.ModelEngineAPI +import com.willfp.ecopets.pets.Pet +import org.bukkit.Location +import org.bukkit.entity.ArmorStand +import org.bukkit.entity.EntityType +import org.bukkit.inventory.EquipmentSlot + +class ModelEnginePetEntity( + pet: Pet +) : PetEntity(pet) { + override fun spawn(location: Location): ArmorStand { + val stand = location.world!!.spawnEntity(location, EntityType.ARMOR_STAND) as ArmorStand + stand.isVisible = false + stand.isInvulnerable = true + stand.isPersistent = true + stand.removeWhenFarAway = false + stand.isSmall = true + stand.setGravity(false) + stand.isCollidable = false + + for (slot in EquipmentSlot.values()) { + stand.addEquipmentLock(slot, ArmorStand.LockType.ADDING_OR_CHANGING) + } + + val model = ModelEngineAPI.createActiveModel(pet.entityTexture.removePrefix("modelengine:")) + val modelled = ModelEngineAPI.createModeledEntity(stand) + modelled.addActiveModel(model) + + stand.isCustomNameVisible = true + stand.customName = pet.name + + return stand + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt new file mode 100644 index 0000000..9cd90f4 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/PetEntity.kt @@ -0,0 +1,11 @@ +package com.willfp.ecopets.pets.entity + +import com.willfp.ecopets.pets.Pet +import org.bukkit.Location +import org.bukkit.entity.ArmorStand + +abstract class PetEntity( + val pet: Pet +) { + abstract fun spawn(location: Location): ArmorStand +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/SkullPetEntity.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/SkullPetEntity.kt new file mode 100644 index 0000000..a4a19c7 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/entity/SkullPetEntity.kt @@ -0,0 +1,38 @@ +package com.willfp.ecopets.pets.entity + +import com.willfp.eco.core.items.builder.SkullBuilder +import com.willfp.ecopets.pets.Pet +import org.bukkit.Location +import org.bukkit.entity.ArmorStand +import org.bukkit.entity.Entity +import org.bukkit.entity.EntityType +import org.bukkit.inventory.EquipmentSlot +import org.bukkit.inventory.ItemStack + +class SkullPetEntity(pet: Pet) : PetEntity(pet) { + override fun spawn(location: Location): ArmorStand { + val newStand = location.world!!.spawnEntity(location, EntityType.ARMOR_STAND) as ArmorStand + newStand.isVisible = false + newStand.isInvulnerable = true + newStand.isPersistent = true + newStand.removeWhenFarAway = false + newStand.isSmall = true + newStand.setGravity(false) + newStand.isCollidable = false + + for (slot in EquipmentSlot.values()) { + newStand.addEquipmentLock(slot, ArmorStand.LockType.ADDING_OR_CHANGING) + } + + + val skull: ItemStack = SkullBuilder() + .setSkullTexture(pet.entityTexture) + .build() + + newStand.equipment?.helmet = skull + newStand.isCustomNameVisible = true + newStand.customName = pet.name + + return newStand + } +}