-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../kotlin/com/typewritermc/entity/entries/data/minecraft/living/snowgolem/PumpkinHatData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...nsion/src/main/kotlin/com/typewritermc/entity/entries/entity/minecraft/SnowGolemEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |