Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a27ebb1b5c | ||
|
|
afafd86eaf | ||
|
|
49a2713017 | ||
|
|
a4263e8397 | ||
|
|
17f3aa8862 | ||
|
|
c94024ea19 | ||
|
|
1daa52e1f4 | ||
|
|
a06808f802 | ||
|
|
91cf08f0ac | ||
|
|
9a7ff1760c | ||
|
|
f2c3f569b7 | ||
|
|
508cb3e216 | ||
|
|
5f998f4bad | ||
|
|
e4b468b0da | ||
|
|
675d2b8508 | ||
|
|
edddd67f58 | ||
|
|
ed676e50c7 | ||
|
|
b36551a179 | ||
|
|
0bb4aa6d51 |
@@ -4,7 +4,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +48,12 @@ allprojects {
|
||||
|
||||
dependencies {
|
||||
compileOnly 'com.willfp:eco:6.37.1'
|
||||
implementation 'com.willfp:libreforge:3.73.0'
|
||||
implementation 'com.willfp:libreforge:3.77.0'
|
||||
implementation 'org.joml:joml:1.10.4'
|
||||
|
||||
compileOnly 'org.jetbrains:annotations:23.0.0'
|
||||
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.6.21'
|
||||
compileOnly 'org.jetbrains.kotlin:kotlin-stdlib:1.7.10'
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile) {
|
||||
|
||||
@@ -19,7 +19,7 @@ class PetDisplay(
|
||||
) : Listener {
|
||||
private var tick = 0
|
||||
|
||||
private val trackedEntities = mutableMapOf<UUID, ArmorStand>()
|
||||
private val trackedEntities = mutableMapOf<UUID, PetArmorStand>()
|
||||
|
||||
fun tickAll() {
|
||||
for (player in Bukkit.getOnlinePlayers()) {
|
||||
@@ -55,15 +55,30 @@ class PetDisplay(
|
||||
private fun getLocation(player: Player): Location {
|
||||
val offset = player.eyeLocation.direction.clone().normalize()
|
||||
.multiply(-1)
|
||||
.apply { y = abs(y) }
|
||||
.apply {
|
||||
y = abs(y)
|
||||
|
||||
if (abs(x) < 0.5) {
|
||||
x = 0.5
|
||||
}
|
||||
|
||||
if (abs(z) < 0.5) {
|
||||
z = 0.5
|
||||
}
|
||||
}
|
||||
.rotateAroundY(PI / 6)
|
||||
|
||||
return player.eyeLocation.clone().add(offset)
|
||||
}
|
||||
|
||||
private fun getOrNew(player: Player): ArmorStand? {
|
||||
val existing = trackedEntities[player.uniqueId]
|
||||
val tracked = trackedEntities[player.uniqueId]
|
||||
val existing = tracked?.stand
|
||||
|
||||
val pet = player.activePet
|
||||
if (pet != tracked?.pet) {
|
||||
tracked?.stand?.remove()
|
||||
}
|
||||
|
||||
if (existing == null || existing.isDead || pet == null) {
|
||||
existing?.remove()
|
||||
@@ -76,15 +91,15 @@ class PetDisplay(
|
||||
val location = getLocation(player)
|
||||
val stand = pet.makePetEntity().spawn(location)
|
||||
|
||||
trackedEntities[player.uniqueId] = stand
|
||||
trackedEntities[player.uniqueId] = PetArmorStand(stand, pet)
|
||||
}
|
||||
|
||||
return trackedEntities[player.uniqueId]
|
||||
return trackedEntities[player.uniqueId]?.stand
|
||||
}
|
||||
|
||||
fun shutdown() {
|
||||
for (stand in trackedEntities.values) {
|
||||
stand.remove()
|
||||
stand.stand.remove()
|
||||
}
|
||||
|
||||
trackedEntities.clear()
|
||||
@@ -92,7 +107,12 @@ class PetDisplay(
|
||||
|
||||
@EventHandler
|
||||
fun onLeave(event: PlayerQuitEvent) {
|
||||
trackedEntities[event.player.uniqueId]?.remove()
|
||||
trackedEntities[event.player.uniqueId]?.stand?.remove()
|
||||
trackedEntities.remove(event.player.uniqueId)
|
||||
}
|
||||
|
||||
private data class PetArmorStand(
|
||||
val stand: ArmorStand,
|
||||
val pet: Pet
|
||||
)
|
||||
}
|
||||
|
||||
@@ -4,34 +4,18 @@ 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,
|
||||
private val modelID: String
|
||||
) : 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 stand = emptyArmorStandAt(location, pet)
|
||||
|
||||
val model = ModelEngineAPI.createActiveModel(modelID)
|
||||
val modelled = ModelEngineAPI.createModeledEntity(stand)
|
||||
modelled.addActiveModel(model)
|
||||
|
||||
stand.isCustomNameVisible = true
|
||||
stand.customName = pet.name
|
||||
|
||||
return stand
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.willfp.ecopets.pets.entity
|
||||
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
|
||||
|
||||
abstract class PetEntity(
|
||||
val pet: Pet
|
||||
@@ -31,3 +33,23 @@ abstract class PetEntity(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun emptyArmorStandAt(location: Location, pet: Pet): ArmorStand {
|
||||
val stand = location.world!!.spawnEntity(location, EntityType.ARMOR_STAND) as ArmorStand
|
||||
|
||||
stand.isVisible = false
|
||||
stand.isInvulnerable = true
|
||||
stand.isSmall = true
|
||||
stand.setGravity(false)
|
||||
stand.isCollidable = false
|
||||
stand.isPersistent = false
|
||||
|
||||
for (slot in EquipmentSlot.values()) {
|
||||
stand.addEquipmentLock(slot, ArmorStand.LockType.ADDING_OR_CHANGING)
|
||||
}
|
||||
|
||||
stand.isCustomNameVisible = true
|
||||
stand.customName = pet.name
|
||||
|
||||
return stand
|
||||
}
|
||||
|
||||
@@ -4,35 +4,18 @@ 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 stand = emptyArmorStandAt(location, pet)
|
||||
|
||||
val skull: ItemStack = SkullBuilder()
|
||||
.setSkullTexture(pet.entityTexture)
|
||||
.build()
|
||||
|
||||
newStand.equipment?.helmet = skull
|
||||
newStand.isCustomNameVisible = true
|
||||
newStand.customName = pet.name
|
||||
stand.equipment?.helmet = skull
|
||||
|
||||
return newStand
|
||||
return stand
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#libreforge-updater
|
||||
#Sat Jul 09 12:11:27 BST 2022
|
||||
version=1.9.0
|
||||
#Sun Jul 24 22:49:45 BST 2022
|
||||
version=1.13.0
|
||||
plugin-name=EcoPets
|
||||
|
||||
Reference in New Issue
Block a user