From e170372e4f360251e8515b7839abdfac1b2361d9 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Mon, 16 Dec 2024 19:33:42 +0100 Subject: [PATCH] Add SnowGolemEntity --- .../living/snowgolem/PumpkinHatData.kt | 38 +++++++++++ .../entity/minecraft/SnowGolemEntity.kt | 65 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/data/minecraft/living/snowgolem/PumpkinHatData.kt create mode 100644 extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/entity/minecraft/SnowGolemEntity.kt diff --git a/extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/data/minecraft/living/snowgolem/PumpkinHatData.kt b/extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/data/minecraft/living/snowgolem/PumpkinHatData.kt new file mode 100644 index 0000000000..54554254f3 --- /dev/null +++ b/extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/data/minecraft/living/snowgolem/PumpkinHatData.kt @@ -0,0 +1,38 @@ +package com.typewritermc.entity.entries.data.minecraft.living.snowgolem + +import com.typewritermc.core.books.pages.Colors +import com.typewritermc.core.extension.annotations.Entry +import com.typewritermc.core.extension.annotations.Tags +import com.typewritermc.engine.paper.entry.entity.SinglePropertyCollectorSupplier +import com.typewritermc.engine.paper.entry.entries.EntityData +import com.typewritermc.engine.paper.entry.entries.EntityProperty +import com.typewritermc.engine.paper.extensions.packetevents.metas +import me.tofaa.entitylib.meta.mobs.golem.SnowGolemMeta +import me.tofaa.entitylib.wrapper.WrapperEntity +import org.bukkit.entity.Player +import java.util.* +import kotlin.reflect.KClass + +@Entry("pumpkin_hat_data", "The pumpkin hat state of the snow golem", Colors.RED, "game-icons:pumpkin") +@Tags("pumpkin_hat_data", "snow_golem_data") +class PumpkinHatData( + override val id: String = "", + override val name: String = "", + val hasPumpkinHat: Boolean = true, + override val priorityOverride: Optional = Optional.empty(), +) : EntityData { + override fun type(): KClass = PumpkinHatProperty::class + + override fun build(player: Player): PumpkinHatProperty = PumpkinHatProperty(hasPumpkinHat) +} + +data class PumpkinHatProperty(val hasPumpkinHat: Boolean) : EntityProperty { + companion object : SinglePropertyCollectorSupplier(PumpkinHatProperty::class, PumpkinHatProperty(true)) +} + +fun applyPumpkinHatData(entity: WrapperEntity, property: PumpkinHatProperty) { + entity.metas { + meta { isHasPumpkinHat = property.hasPumpkinHat } + error("Could not apply PumpkinHatData to ${entity.entityType} entity.") + } +} \ No newline at end of file diff --git a/extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/entity/minecraft/SnowGolemEntity.kt b/extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/entity/minecraft/SnowGolemEntity.kt new file mode 100644 index 0000000000..9d03844d8f --- /dev/null +++ b/extensions/EntityExtension/src/main/kotlin/com/typewritermc/entity/entries/entity/minecraft/SnowGolemEntity.kt @@ -0,0 +1,65 @@ +package com.typewritermc.entity.entries.entity.minecraft + +import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes +import com.typewritermc.core.books.pages.Colors +import com.typewritermc.core.entries.Ref +import com.typewritermc.core.entries.emptyRef +import com.typewritermc.core.extension.annotations.Entry +import com.typewritermc.core.extension.annotations.OnlyTags +import com.typewritermc.core.extension.annotations.Tags +import com.typewritermc.core.utils.point.Position +import com.typewritermc.engine.paper.entry.entity.FakeEntity +import com.typewritermc.engine.paper.entry.entity.SimpleEntityDefinition +import com.typewritermc.engine.paper.entry.entity.SimpleEntityInstance +import com.typewritermc.engine.paper.entry.entries.* +import com.typewritermc.engine.paper.utils.Sound +import com.typewritermc.entity.entries.data.minecraft.applyGenericEntityData +import com.typewritermc.entity.entries.data.minecraft.living.applyLivingEntityData +import com.typewritermc.entity.entries.data.minecraft.living.snowgolem.PumpkinHatProperty +import com.typewritermc.entity.entries.data.minecraft.living.snowgolem.applyPumpkinHatData +import com.typewritermc.entity.entries.entity.WrapperFakeEntity +import org.bukkit.entity.Player + +@Entry("snow_golem_definition", "A snow golem entity", Colors.ORANGE, "game-icons:snowman") +@Tags("snow_golem_definition") +/** + * The `SnowGolemDefinition` class is an entry that shows up as a snow golem in-game. + * + * ## How could this be used? + * This could be used to create a snow golem entity. + */ +class SnowGolemDefinition( + override val id: String = "", + override val name: String = "", + override val displayName: Var = ConstVar(""), + override val sound: Sound = Sound.EMPTY, + @OnlyTags("generic_entity_data", "living_entity_data", "mob_data", "snow_golem_data") + override val data: List>> = emptyList(), +) : SimpleEntityDefinition { + override fun create(player: Player): FakeEntity = SnowGolemEntity(player) +} + +@Entry("snow_golem_instance", "An instance of a snow golem entity", Colors.YELLOW, "game-icons:snowman") +class SnowGolemInstance( + override val id: String = "", + override val name: String = "", + override val definition: Ref = emptyRef(), + override val spawnLocation: Position = Position.ORIGIN, + @OnlyTags("generic_entity_data", "living_entity_data", "mob_data", "snow_golem_data") + override val data: List>> = emptyList(), + override val activity: Ref = emptyRef(), +) : SimpleEntityInstance + +private class SnowGolemEntity(player: Player) : WrapperFakeEntity( + EntityTypes.SNOW_GOLEM, + player, +) { + override fun applyProperty(property: EntityProperty) { + when (property) { + is PumpkinHatProperty -> applyPumpkinHatData(entity, property) + else -> {} + } + if (applyGenericEntityData(entity, property)) return + if (applyLivingEntityData(entity, property)) return + } +} \ No newline at end of file