Compare commits

...

2 Commits

Author SHA1 Message Date
82c6da8ae6
feat: invidual difference 2023-07-02 22:25:50 +08:00
5e1661cff3
fix: name tag position 2023-07-02 21:41:30 +08:00

View File

@ -15,16 +15,16 @@ import net.minecraft.world.DifficultyInstance
import net.minecraft.world.SimpleContainer
import net.minecraft.world.entity.*
import net.minecraft.world.entity.ai.Brain
import net.minecraft.world.entity.ai.attributes.AttributeModifier
import net.minecraft.world.entity.ai.attributes.AttributeSupplier
import net.minecraft.world.entity.ai.attributes.Attributes
import net.minecraft.world.entity.ai.memory.MemoryModuleType
import net.minecraft.world.entity.item.ItemEntity
import net.minecraft.world.entity.npc.InventoryCarrier
import net.minecraft.world.level.Level
import net.minecraft.world.level.ServerLevelAccessor
import quaedam.Quaedam
import quaedam.projector.Projector
import kotlin.jvm.optionals.getOrNull
import kotlin.random.Random
class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Level) : PathfinderMob(entityType, level),
InventoryCarrier {
@ -37,6 +37,7 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
const val BOUNDING_WIDTH = 0.6f
const val BOUNDING_HEIGHT = 1.8f
const val INV_DIFF_NAME = "quaedam:Random Individual Differences"
val entity = Quaedam.entities.register(ID) {
EntityType.Builder.of(::ProjectedPersonEntity, MobCategory.CREATURE).canSpawnFarFromPlayer()
@ -54,8 +55,7 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
}
private fun createAttributes(): AttributeSupplier.Builder =
Mob.createMobAttributes().add(Attributes.ATTACK_DAMAGE, 1.5)
.add(Attributes.MOVEMENT_SPEED, 0.2)
Mob.createMobAttributes().add(Attributes.ATTACK_DAMAGE, 1.5).add(Attributes.MOVEMENT_SPEED, 0.2)
.add(Attributes.ATTACK_SPEED)
}
@ -67,7 +67,38 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
spawnGroupData: SpawnGroupData?,
compoundTag: CompoundTag?
): SpawnGroupData? {
shape = ProjectedPersonShape.create(serverLevelAccessor.random.nextLong())
val rand = Random(serverLevelAccessor.random.nextLong())
// random shape
shape = ProjectedPersonShape.create(rand.nextLong())
// random attributes
getAttribute(Attributes.MOVEMENT_SPEED)!!.addPermanentModifier(
AttributeModifier(
INV_DIFF_NAME,
rand.nextFloat() * 0.1,
AttributeModifier.Operation.ADDITION
)
)
getAttribute(Attributes.ATTACK_DAMAGE)!!.addPermanentModifier(
AttributeModifier(
INV_DIFF_NAME,
rand.nextFloat() * 1.5,
AttributeModifier.Operation.ADDITION
)
)
getAttribute(Attributes.ATTACK_SPEED)!!.addPermanentModifier(
AttributeModifier(
INV_DIFF_NAME,
rand.nextFloat() * -2.0,
AttributeModifier.Operation.ADDITION
)
)
getAttribute(Attributes.MAX_HEALTH)!!.addPermanentModifier(
AttributeModifier(
INV_DIFF_NAME,
rand.nextFloat() * 5.0,
AttributeModifier.Operation.ADDITION
)
)
return super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag)
}
@ -111,7 +142,7 @@ class ProjectedPersonEntity(entityType: EntityType<out PathfinderMob>, level: Le
override fun getTypeName(): Component =
shape.name.takeIf { it.isNotEmpty() }?.let { Component.literal(it) } ?: super.getTypeName()
override fun getNameTagOffsetY() = super.getNameTagOffsetY() - (BOUNDING_HEIGHT * (1.3f - shape.scaleY))
override fun getNameTagOffsetY() = super.getNameTagOffsetY() - (bbHeight * (1f - shape.scaleY))
override fun createNavigation(level: Level) = ProjectedPersonNavigation(this, level)