Skip to content

Commit

Permalink
Add SnowGolemEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
gabber235 committed Dec 16, 2024
1 parent 5eb3c72 commit e170372
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Int> = Optional.empty(),
) : EntityData<PumpkinHatProperty> {
override fun type(): KClass<PumpkinHatProperty> = PumpkinHatProperty::class

override fun build(player: Player): PumpkinHatProperty = PumpkinHatProperty(hasPumpkinHat)
}

data class PumpkinHatProperty(val hasPumpkinHat: Boolean) : EntityProperty {
companion object : SinglePropertyCollectorSupplier<PumpkinHatProperty>(PumpkinHatProperty::class, PumpkinHatProperty(true))
}

fun applyPumpkinHatData(entity: WrapperEntity, property: PumpkinHatProperty) {
entity.metas {
meta<SnowGolemMeta> { isHasPumpkinHat = property.hasPumpkinHat }
error("Could not apply PumpkinHatData to ${entity.entityType} entity.")
}
}
Original file line number Diff line number Diff line change
@@ -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<String> = ConstVar(""),
override val sound: Sound = Sound.EMPTY,
@OnlyTags("generic_entity_data", "living_entity_data", "mob_data", "snow_golem_data")
override val data: List<Ref<EntityData<*>>> = 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<SnowGolemDefinition> = emptyRef(),
override val spawnLocation: Position = Position.ORIGIN,
@OnlyTags("generic_entity_data", "living_entity_data", "mob_data", "snow_golem_data")
override val data: List<Ref<EntityData<*>>> = emptyList(),
override val activity: Ref<out SharedEntityActivityEntry> = 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
}
}

0 comments on commit e170372

Please sign in to comment.