Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some small features and custom item pets #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.willfp.ecopets.pets.Pets
import com.willfp.ecopets.pets.SpawnEggHandler
import com.willfp.ecopets.pets.activePet
import com.willfp.ecopets.pets.activePetLevel
import com.willfp.ecopets.pets.entity.ItemStackPetEntity
import com.willfp.ecopets.pets.hasPet
import com.willfp.ecopets.pets.entity.ModelEnginePetEntity
import com.willfp.ecopets.pets.entity.PetEntity
Expand Down Expand Up @@ -85,6 +86,10 @@ class EcoPetsPlugin : LibreforgePlugin() {
}
pets.toString()
}.register()

PetEntity.registerPetEntity("itemstack") { pet, itemStack ->
ItemStackPetEntity(pet, itemStack)
}
}

override fun handleReload() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class Pet(

val entityTexture = config.getString("entity-texture")

val offset = config.getDouble("offset")

val rotatable = config.getBool("rotatable")

private val levelXpRequirements = listOf(0) + config.getInts("level-xp-requirements")

val maxLevel = levelXpRequirements.size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ class PetDisplay(

val location = getLocation(player)

location.y += pet.offset
location.y += NumberUtils.fastSin(tick / (2 * PI) * 0.5) * 0.15

if (location.world != null) {
stand.teleport(location)
}

if (!pet.entityTexture.contains(":")) {
if (!pet.entityTexture.contains(":") && pet.rotatable) {
stand.setRotation((20 * tick / (2 * PI)).toFloat(), 0f)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class PetLevelGUI(
}

menu = menu(plugin.configYml.getInt("level-gui.rows")) {
title = pet.name
title = plugin.langYml.getString("menu.level-title").replace("%pet%", pet.name)

maxPages(component.pages)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.willfp.ecopets.pets.entity

import com.willfp.eco.core.items.Items
import com.willfp.ecopets.pets.Pet
import org.bukkit.Location
import org.bukkit.entity.ArmorStand
import org.bukkit.inventory.ItemStack

class ItemStackPetEntity(
pet: Pet,
private val itemStack: String
) : PetEntity(pet) {
override fun spawn(location: Location): ArmorStand {
val stand = emptyArmorStandAt(location, pet)

val itemStack: ItemStack = Items.lookup(itemStack).item

@Suppress("UNNECESSARY_SAFE_CALL") // Can be null.
stand.equipment?.helmet = itemStack

return stand
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal fun emptyArmorStandAt(location: Location, pet: Pet): ArmorStand {
stand.isCollidable = false
stand.isPersistent = false

for (slot in EquipmentSlot.values()) {
for (slot in EquipmentSlot.entries) {
stand.addEquipmentLock(slot, ArmorStand.LockType.ADDING_OR_CHANGING)
}

Expand Down
1 change: 1 addition & 0 deletions eco-core/core-plugin/src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ messages:

menu:
title: "Pets"
level-title: "%pet%"

infinity: "∞"
8 changes: 8 additions & 0 deletions eco-core/core-plugin/src/main/resources/pets/_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
# The display name of the pet
name: "&6Tiger"

# Offset of pet display position on the y-axis (default is 0.0)
offset: 0.0

# Whether the pet will rotate on its own (default is false)
rotatable: true

# The description of the pet
description: "&8&oLevel up by dealing melee damage"

Expand Down Expand Up @@ -115,6 +121,8 @@ conditions: [ ]

# The texture of the pet entity in game
# If you're using modelengine, use modelengine:id as the texture
# If you want to use custom item, use itemstack:<Item Lookup System String> as the texture (For example: itemstack:itemsadder:namespace__key)
# https://plugins.auxilor.io/all-plugins/the-item-lookup-system
entity-texture: "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvOTA5NWZjYzFlM2Q3Y2JkMzUwZjE5YjM4OTQ5OGFiOGJiOTZjNjVhZDE4NWQzNDU5MjA2N2E3ZDAzM2FjNDhkZSJ9fX0="

# The icon in GUIs
Expand Down