aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/gui/entity
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/gui/entity')
-rw-r--r--src/main/kotlin/gui/entity/EntityModifier.kt2
-rw-r--r--src/main/kotlin/gui/entity/EntityRenderer.kt168
-rw-r--r--src/main/kotlin/gui/entity/GuiPlayer.kt60
-rw-r--r--src/main/kotlin/gui/entity/ModifyAge.kt16
-rw-r--r--src/main/kotlin/gui/entity/ModifyCharged.kt8
-rw-r--r--src/main/kotlin/gui/entity/ModifyEquipment.kt24
-rw-r--r--src/main/kotlin/gui/entity/ModifyHorse.kt45
-rw-r--r--src/main/kotlin/gui/entity/ModifyInvisible.kt2
-rw-r--r--src/main/kotlin/gui/entity/ModifyName.kt6
-rw-r--r--src/main/kotlin/gui/entity/ModifyPlayerSkin.kt84
-rw-r--r--src/main/kotlin/gui/entity/ModifyRiding.kt4
-rw-r--r--src/main/kotlin/gui/entity/ModifyWither.kt8
12 files changed, 223 insertions, 204 deletions
diff --git a/src/main/kotlin/gui/entity/EntityModifier.kt b/src/main/kotlin/gui/entity/EntityModifier.kt
index 9623070..4915ebb 100644
--- a/src/main/kotlin/gui/entity/EntityModifier.kt
+++ b/src/main/kotlin/gui/entity/EntityModifier.kt
@@ -2,7 +2,7 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
+import net.minecraft.world.entity.LivingEntity
fun interface EntityModifier {
fun apply(entity: LivingEntity, info: JsonObject): LivingEntity
diff --git a/src/main/kotlin/gui/entity/EntityRenderer.kt b/src/main/kotlin/gui/entity/EntityRenderer.kt
index b4c1c7f..4972709 100644
--- a/src/main/kotlin/gui/entity/EntityRenderer.kt
+++ b/src/main/kotlin/gui/entity/EntityRenderer.kt
@@ -3,17 +3,18 @@ package moe.nea.firmament.gui.entity
import com.google.gson.Gson
import com.google.gson.JsonArray
import com.google.gson.JsonObject
+import me.shedaniel.math.Dimension
import org.joml.Quaternionf
import org.joml.Vector3f
import kotlin.math.atan
-import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.gui.screen.ingame.InventoryScreen
-import net.minecraft.entity.Entity
-import net.minecraft.entity.EntityType
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.SpawnReason
-import net.minecraft.util.Identifier
-import net.minecraft.world.World
+import net.minecraft.client.gui.GuiGraphics
+import net.minecraft.client.gui.screens.inventory.InventoryScreen
+import net.minecraft.world.entity.Entity
+import net.minecraft.world.entity.EntityType
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.entity.EntitySpawnReason
+import net.minecraft.resources.ResourceLocation
+import net.minecraft.world.level.Level
import moe.nea.firmament.util.ErrorUtil
import moe.nea.firmament.util.MC
import moe.nea.firmament.util.iterate
@@ -21,47 +22,87 @@ import moe.nea.firmament.util.openFirmamentResource
import moe.nea.firmament.util.render.enableScissorWithTranslation
object EntityRenderer {
- val fakeWorld: World get() = MC.lastWorld!!
+ val fakeWorld: Level get() = MC.lastWorld!!
private fun <T : Entity> t(entityType: EntityType<T>): () -> T {
- return { entityType.create(fakeWorld, SpawnReason.LOAD)!! }
+ return { entityType.create(fakeWorld, EntitySpawnReason.LOAD)!! }
}
val entityIds: Map<String, () -> LivingEntity> = mapOf(
- "Zombie" to t(EntityType.ZOMBIE),
+ "Armadillo" to t(EntityType.ARMADILLO),
+ "ArmorStand" to t(EntityType.ARMOR_STAND),
+ "Axolotl" to t(EntityType.AXOLOTL),
+ "Bat" to t(EntityType.BAT),
+ "Bee" to t(EntityType.BEE),
+ "Blaze" to t(EntityType.BLAZE),
+ "Bogged" to t(EntityType.BOGGED),
+ "Breeze" to t(EntityType.BREEZE),
+ "CaveSpider" to t(EntityType.CAVE_SPIDER),
"Chicken" to t(EntityType.CHICKEN),
- "Slime" to t(EntityType.SLIME),
- "Wolf" to t(EntityType.WOLF),
- "Skeleton" to t(EntityType.SKELETON),
+ "Cod" to t(EntityType.COD),
+ "Cow" to t(EntityType.COW),
+ "Creaking" to t(EntityType.CREAKING),
"Creeper" to t(EntityType.CREEPER),
+ "Dolphin" to t(EntityType.DOLPHIN),
+ "Donkey" to t(EntityType.DONKEY),
+ "Dragon" to t(EntityType.ENDER_DRAGON),
+ "Drowned" to t(EntityType.DROWNED),
+ "Eisengolem" to t(EntityType.IRON_GOLEM),
+ "Enderman" to t(EntityType.ENDERMAN),
+ "Endermite" to t(EntityType.ENDERMITE),
+ "Evoker" to t(EntityType.EVOKER),
+ "Fox" to t(EntityType.FOX),
+ "Frog" to t(EntityType.FROG),
+ "Ghast" to t(EntityType.GHAST),
+ "Giant" to t(EntityType.GIANT),
+ "GlowSquid" to t(EntityType.GLOW_SQUID),
+ "Goat" to t(EntityType.GOAT),
+ "Guardian" to t(EntityType.GUARDIAN),
+ "Horse" to t(EntityType.HORSE),
+ "Husk" to t(EntityType.HUSK),
+ "Illusioner" to t(EntityType.ILLUSIONER),
+ "LLama" to t(EntityType.LLAMA),
+ "MagmaCube" to t(EntityType.MAGMA_CUBE),
+ "Mooshroom" to t(EntityType.MOOSHROOM),
+ "Mule" to t(EntityType.MULE),
"Ocelot" to t(EntityType.OCELOT),
- "Blaze" to t(EntityType.BLAZE),
+ "Panda" to t(EntityType.PANDA),
+ "Phantom" to t(EntityType.PHANTOM),
+ "Pig" to t(EntityType.PIG),
+ "Piglin" to t(EntityType.PIGLIN),
+ "PiglinBrute" to t(EntityType.PIGLIN_BRUTE),
+ "Pigman" to t(EntityType.ZOMBIFIED_PIGLIN),
+ "Pillager" to t(EntityType.PILLAGER),
+ "Player" to { makeGuiPlayer(fakeWorld) },
+ "PolarBear" to t(EntityType.POLAR_BEAR),
+ "Pufferfish" to t(EntityType.PUFFERFISH),
"Rabbit" to t(EntityType.RABBIT),
+ "Salmom" to t(EntityType.SALMON),
+ "Salmon" to t(EntityType.SALMON),
"Sheep" to t(EntityType.SHEEP),
- "Horse" to t(EntityType.HORSE),
- "Eisengolem" to t(EntityType.IRON_GOLEM),
+ "Shulker" to t(EntityType.SHULKER),
"Silverfish" to t(EntityType.SILVERFISH),
- "Witch" to t(EntityType.WITCH),
- "Endermite" to t(EntityType.ENDERMITE),
+ "Skeleton" to t(EntityType.SKELETON),
+ "Slime" to t(EntityType.SLIME),
+ "Sniffer" to t(EntityType.SNIFFER),
"Snowman" to t(EntityType.SNOW_GOLEM),
- "Villager" to t(EntityType.VILLAGER),
- "Guardian" to t(EntityType.GUARDIAN),
- "ArmorStand" to t(EntityType.ARMOR_STAND),
- "Squid" to t(EntityType.SQUID),
- "Bat" to t(EntityType.BAT),
"Spider" to t(EntityType.SPIDER),
- "CaveSpider" to t(EntityType.CAVE_SPIDER),
- "Pigman" to t(EntityType.ZOMBIFIED_PIGLIN),
- "Ghast" to t(EntityType.GHAST),
- "MagmaCube" to t(EntityType.MAGMA_CUBE),
+ "Squid" to t(EntityType.SQUID),
+ "Stray" to t(EntityType.STRAY),
+ "Strider" to t(EntityType.STRIDER),
+ "Tadpole" to t(EntityType.TADPOLE),
+ "TropicalFish" to t(EntityType.TROPICAL_FISH),
+ "Turtle" to t(EntityType.TURTLE),
+ "Vex" to t(EntityType.VEX),
+ "Villager" to t(EntityType.VILLAGER),
+ "Vindicator" to t(EntityType.VINDICATOR),
+ "Warden" to t(EntityType.WARDEN),
+ "Witch" to t(EntityType.WITCH),
"Wither" to t(EntityType.WITHER),
- "Enderman" to t(EntityType.ENDERMAN),
- "Mooshroom" to t(EntityType.MOOSHROOM),
"WitherSkeleton" to t(EntityType.WITHER_SKELETON),
- "Cow" to t(EntityType.COW),
- "Dragon" to t(EntityType.ENDER_DRAGON),
- "Player" to { makeGuiPlayer(fakeWorld) },
- "Pig" to t(EntityType.PIG),
- "Giant" to t(EntityType.GIANT),
+ "Wolf" to t(EntityType.WOLF),
+ "Zoglin" to t(EntityType.ZOGLIN),
+ "Zombie" to t(EntityType.ZOMBIE),
+ "ZombieVillager" to t(EntityType.ZOMBIE_VILLAGER)
)
val entityModifiers: Map<String, EntityModifier> = mapOf(
"playerdata" to ModifyPlayerSkin,
@@ -83,7 +124,8 @@ object EntityRenderer {
for (modifierJson in modifiers) {
val modifier = ErrorUtil.notNullOr(
modifierJson["type"]?.asString?.let(entityModifiers::get),
- "Could not create entity with id $entityId. Failed to apply modifier $modifierJson") { return null }
+ "Could not create entity with id $entityId. Failed to apply modifier $modifierJson"
+ ) { return null }
entity = modifier.apply(entity, modifierJson)
}
return entity
@@ -98,7 +140,7 @@ object EntityRenderer {
}
private val gson = Gson()
- fun constructEntity(location: Identifier): LivingEntity? {
+ fun constructEntity(location: ResourceLocation): LivingEntity? {
return constructEntity(
gson.fromJson(
location.openFirmamentResource().bufferedReader(), JsonObject::class.java
@@ -108,7 +150,7 @@ object EntityRenderer {
fun renderEntity(
entity: LivingEntity,
- renderContext: DrawContext,
+ renderContext: GuiGraphics,
posX: Int,
posY: Int,
// TODO: Add width, height properties here
@@ -121,10 +163,10 @@ object EntityRenderer {
var bottomOffset = 0.0
var currentEntity = entity
val maxSize = entity.iterate { it.firstPassenger as? LivingEntity }
- .map { it.height }
+ .map { it.bbHeight }
.sum()
while (true) {
- currentEntity.age = MC.player?.age ?: 0
+ currentEntity.tickCount = MC.player?.tickCount ?: 0
drawEntity(
renderContext,
posX,
@@ -138,14 +180,14 @@ object EntityRenderer {
currentEntity
)
val next = currentEntity.firstPassenger as? LivingEntity ?: break
- bottomOffset += currentEntity.getPassengerRidingPos(next).y.toFloat() * 0.75F
+ bottomOffset += currentEntity.getPassengerRidingPosition(next).y.toFloat() * 0.75F
currentEntity = next
}
}
fun drawEntity(
- context: DrawContext,
+ context: GuiGraphics,
x1: Int,
y1: Int,
x2: Int,
@@ -162,38 +204,38 @@ object EntityRenderer {
val hw = (x2 - x1) / 2
val hh = (y2 - y1) / 2
val targetYaw = atan(((centerX - mouseX) / hw)).toFloat()
- val targetPitch = atan(((centerY - mouseY) / hh)).toFloat()
+ val targetPitch = atan(((centerY - mouseY) / hh - entity.eyeHeight * hh / 40)).toFloat()
val rotateToFaceTheFront = Quaternionf().rotateZ(Math.PI.toFloat())
val rotateToFaceTheCamera = Quaternionf().rotateX(targetPitch * 20.0f * (Math.PI.toFloat() / 180))
rotateToFaceTheFront.mul(rotateToFaceTheCamera)
- val oldBodyYaw = entity.bodyYaw
- val oldYaw = entity.yaw
- val oldPitch = entity.pitch
- val oldPrevHeadYaw = entity.lastHeadYaw
- val oldHeadYaw = entity.headYaw
- entity.bodyYaw = 180.0f + targetYaw * 20.0f
- entity.yaw = 180.0f + targetYaw * 40.0f
- entity.pitch = -targetPitch * 20.0f
- entity.headYaw = entity.yaw
- entity.lastHeadYaw = entity.yaw
- val vector3f = Vector3f(0.0f, (entity.height / 2.0f + bottomOffset).toFloat(), 0.0f)
- InventoryScreen.drawEntity(
+ val oldBodyYaw = entity.yBodyRot
+ val oldYaw = entity.yRot
+ val oldPitch = entity.xRot
+ val oldPrevHeadYaw = entity.yHeadRotO
+ val oldHeadYaw = entity.yHeadRot
+ entity.yBodyRot = 180.0f + targetYaw * 20.0f
+ entity.yRot = 180.0f + targetYaw * 40.0f
+ entity.xRot = -targetPitch * 20.0f
+ entity.yHeadRot = entity.yRot
+ entity.yHeadRotO = entity.yRot
+ val vector3f = Vector3f(0.0f, (entity.bbHeight / 2.0f + bottomOffset).toFloat(), 0.0f)
+ InventoryScreen.renderEntityInInventory( // TODO: fix multiple entities rendering the same entity
context,
- centerX,
- centerY,
+ x1, y1,
+ x2, y2,
size.toFloat(),
vector3f,
rotateToFaceTheFront,
rotateToFaceTheCamera,
entity
)
- entity.bodyYaw = oldBodyYaw
- entity.yaw = oldYaw
- entity.pitch = oldPitch
- entity.lastHeadYaw = oldPrevHeadYaw
- entity.headYaw = oldHeadYaw
+ entity.yBodyRot = oldBodyYaw
+ entity.yRot = oldYaw
+ entity.xRot = oldPitch
+ entity.yHeadRotO = oldPrevHeadYaw
+ entity.yHeadRot = oldHeadYaw
context.disableScissor()
}
-
+ val defaultSize = Dimension(50, 80)
}
diff --git a/src/main/kotlin/gui/entity/GuiPlayer.kt b/src/main/kotlin/gui/entity/GuiPlayer.kt
index f728dbf..b53f68c 100644
--- a/src/main/kotlin/gui/entity/GuiPlayer.kt
+++ b/src/main/kotlin/gui/entity/GuiPlayer.kt
@@ -1,62 +1,28 @@
package moe.nea.firmament.gui.entity
-import com.mojang.authlib.GameProfile
-import java.util.UUID
-import net.minecraft.client.network.AbstractClientPlayerEntity
-import net.minecraft.client.util.DefaultSkinHelper
-import net.minecraft.client.util.SkinTextures
-import net.minecraft.client.util.SkinTextures.Model
-import net.minecraft.client.world.ClientWorld
-import net.minecraft.util.Identifier
-import net.minecraft.util.math.BlockPos
-import net.minecraft.util.math.Vec3d
-import net.minecraft.world.World
+import net.minecraft.client.entity.ClientMannequin
+import net.minecraft.client.resources.DefaultPlayerSkin
+import net.minecraft.client.multiplayer.ClientLevel
+import net.minecraft.world.entity.player.PlayerSkin
+import net.minecraft.world.level.Level
+import moe.nea.firmament.util.MC
-/**
- * @see moe.nea.firmament.init.EarlyRiser
- */
-fun makeGuiPlayer(world: World): GuiPlayer {
- val constructor = GuiPlayer::class.java.getDeclaredConstructor(
- World::class.java,
- BlockPos::class.java,
- Float::class.javaPrimitiveType,
- GameProfile::class.java
- )
- val player = constructor.newInstance(world, BlockPos.ORIGIN, 0F, GameProfile(UUID.randomUUID(), "Linnea"))
- player.postInit()
+fun makeGuiPlayer(world: Level): GuiPlayer {
+ val player = GuiPlayer(MC.instance.level!!)
return player
}
-class GuiPlayer(world: ClientWorld?, profile: GameProfile?) : AbstractClientPlayerEntity(world, profile) {
+class GuiPlayer(world: ClientLevel?) : ClientMannequin(world, MC.instance.playerSkinRenderCache()) {
override fun isSpectator(): Boolean {
return false
}
- fun postInit() {
- skinTexture = DefaultSkinHelper.getSkinTextures(this.getUuid()).texture
- lastVelocity = Vec3d.ZERO
- model = Model.WIDE
- }
-
- override fun isCreative(): Boolean {
- return false
- }
-
- override fun shouldRenderName(): Boolean {
+ override fun shouldShowName(): Boolean {
return false
}
- lateinit var skinTexture: Identifier
- var capeTexture: Identifier? = null
- var model: Model = Model.WIDE
- override fun getSkinTextures(): SkinTextures {
- return SkinTextures(
- skinTexture,
- null,
- capeTexture,
- null,
- model,
- true
- )
+ var skinTextures: PlayerSkin = DefaultPlayerSkin.get(this.uuid) // TODO: 1.21.10
+ override fun getSkin(): PlayerSkin {
+ return skinTextures
}
}
diff --git a/src/main/kotlin/gui/entity/ModifyAge.kt b/src/main/kotlin/gui/entity/ModifyAge.kt
index a65c368..99154ef 100644
--- a/src/main/kotlin/gui/entity/ModifyAge.kt
+++ b/src/main/kotlin/gui/entity/ModifyAge.kt
@@ -2,19 +2,19 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.decoration.ArmorStandEntity
-import net.minecraft.entity.mob.ZombieEntity
-import net.minecraft.entity.passive.PassiveEntity
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.entity.decoration.ArmorStand
+import net.minecraft.world.entity.monster.Zombie
+import net.minecraft.world.entity.AgeableMob
object ModifyAge : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
val isBaby = info["baby"]?.asBoolean ?: false
- if (entity is PassiveEntity) {
- entity.breedingAge = if (isBaby) -1 else 1
- } else if (entity is ZombieEntity) {
+ if (entity is AgeableMob) {
+ entity.age = if (isBaby) -1 else 1
+ } else if (entity is Zombie) {
entity.isBaby = isBaby
- } else if (entity is ArmorStandEntity) {
+ } else if (entity is ArmorStand) {
entity.isSmall = isBaby
} else {
error("Cannot set age for $entity")
diff --git a/src/main/kotlin/gui/entity/ModifyCharged.kt b/src/main/kotlin/gui/entity/ModifyCharged.kt
index d22f6e3..23fd495 100644
--- a/src/main/kotlin/gui/entity/ModifyCharged.kt
+++ b/src/main/kotlin/gui/entity/ModifyCharged.kt
@@ -2,13 +2,13 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.mob.CreeperEntity
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.entity.monster.Creeper
object ModifyCharged : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
- require(entity is CreeperEntity)
- entity.dataTracker.set(CreeperEntity.CHARGED, true)
+ require(entity is Creeper)
+ entity.entityData.set(Creeper.DATA_IS_POWERED, true)
return entity
}
}
diff --git a/src/main/kotlin/gui/entity/ModifyEquipment.kt b/src/main/kotlin/gui/entity/ModifyEquipment.kt
index 712f5ca..9c43e73 100644
--- a/src/main/kotlin/gui/entity/ModifyEquipment.kt
+++ b/src/main/kotlin/gui/entity/ModifyEquipment.kt
@@ -1,17 +1,18 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.component.DataComponentTypes
-import net.minecraft.component.type.DyedColorComponent
-import net.minecraft.entity.EquipmentSlot
-import net.minecraft.entity.LivingEntity
-import net.minecraft.item.Item
-import net.minecraft.item.ItemStack
-import net.minecraft.item.Items
+import net.minecraft.core.component.DataComponents
+import net.minecraft.world.item.component.DyedItemColor
+import net.minecraft.world.entity.EquipmentSlot
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.item.Item
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.item.Items
+import moe.nea.firmament.repo.ExpensiveItemCacheApi
import moe.nea.firmament.repo.SBItemStack
import moe.nea.firmament.util.SkyblockId
+import moe.nea.firmament.util.mc.arbitraryUUID
import moe.nea.firmament.util.mc.setEncodedSkullOwner
-import moe.nea.firmament.util.mc.zeroUUID
object ModifyEquipment : EntityModifier {
val names = mapOf(
@@ -25,18 +26,19 @@ object ModifyEquipment : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
names.forEach { (key, slot) ->
info[key]?.let {
- entity.equipStack(slot, createItem(it.asString))
+ entity.setItemSlot(slot, createItem(it.asString))
}
}
return entity
}
+ @OptIn(ExpensiveItemCacheApi::class)
private fun createItem(item: String): ItemStack {
val split = item.split("#")
if (split.size != 2) return SBItemStack(SkyblockId(item)).asImmutableItemStack()
val (type, data) = split
return when (type) {
- "SKULL" -> ItemStack(Items.PLAYER_HEAD).also { it.setEncodedSkullOwner(zeroUUID, data) }
+ "SKULL" -> ItemStack(Items.PLAYER_HEAD).also { it.setEncodedSkullOwner(arbitraryUUID, data) }
"LEATHER_LEGGINGS" -> coloredLeatherArmor(Items.LEATHER_LEGGINGS, data)
"LEATHER_BOOTS" -> coloredLeatherArmor(Items.LEATHER_BOOTS, data)
"LEATHER_HELMET" -> coloredLeatherArmor(Items.LEATHER_HELMET, data)
@@ -47,7 +49,7 @@ object ModifyEquipment : EntityModifier {
private fun coloredLeatherArmor(leatherArmor: Item, data: String): ItemStack {
val stack = ItemStack(leatherArmor)
- stack.set(DataComponentTypes.DYED_COLOR, DyedColorComponent(data.toInt(16)))
+ stack.set(DataComponents.DYED_COLOR, DyedItemColor(data.toInt(16)))
return stack
}
}
diff --git a/src/main/kotlin/gui/entity/ModifyHorse.kt b/src/main/kotlin/gui/entity/ModifyHorse.kt
index 7c8baa7..a870bf1 100644
--- a/src/main/kotlin/gui/entity/ModifyHorse.kt
+++ b/src/main/kotlin/gui/entity/ModifyHorse.kt
@@ -2,29 +2,26 @@ package moe.nea.firmament.gui.entity
import com.google.gson.JsonNull
import com.google.gson.JsonObject
-import kotlin.experimental.and
-import kotlin.experimental.inv
-import kotlin.experimental.or
-import net.minecraft.entity.EntityType
-import net.minecraft.entity.EquipmentSlot
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.SpawnReason
-import net.minecraft.entity.passive.AbstractHorseEntity
-import net.minecraft.item.ItemStack
-import net.minecraft.item.Items
+import net.minecraft.world.entity.EntityType
+import net.minecraft.world.entity.EquipmentSlot
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.entity.EntitySpawnReason
+import net.minecraft.world.entity.animal.horse.AbstractHorse
+import net.minecraft.world.item.ItemStack
+import net.minecraft.world.item.Items
import moe.nea.firmament.gui.entity.EntityRenderer.fakeWorld
object ModifyHorse : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
- require(entity is AbstractHorseEntity)
- var entity: AbstractHorseEntity = entity
+ require(entity is AbstractHorse)
+ var entity: AbstractHorse = entity
info["kind"]?.let {
entity = when (it.asString) {
- "skeleton" -> EntityType.SKELETON_HORSE.create(fakeWorld, SpawnReason.LOAD)!!
- "zombie" -> EntityType.ZOMBIE_HORSE.create(fakeWorld, SpawnReason.LOAD)!!
- "mule" -> EntityType.MULE.create(fakeWorld, SpawnReason.LOAD)!!
- "donkey" -> EntityType.DONKEY.create(fakeWorld, SpawnReason.LOAD)!!
- "horse" -> EntityType.HORSE.create(fakeWorld, SpawnReason.LOAD)!!
+ "skeleton" -> EntityType.SKELETON_HORSE.create(fakeWorld, EntitySpawnReason.LOAD)!!
+ "zombie" -> EntityType.ZOMBIE_HORSE.create(fakeWorld, EntitySpawnReason.LOAD)!!
+ "mule" -> EntityType.MULE.create(fakeWorld, EntitySpawnReason.LOAD)!!
+ "donkey" -> EntityType.DONKEY.create(fakeWorld, EntitySpawnReason.LOAD)!!
+ "horse" -> EntityType.HORSE.create(fakeWorld, EntitySpawnReason.LOAD)!!
else -> error("Unknown horse kind $it")
}
}
@@ -48,12 +45,14 @@ object ModifyHorse : EntityModifier {
}
-fun AbstractHorseEntity.setIsSaddled(shouldBeSaddled: Boolean) {
- this.equipStack(EquipmentSlot.SADDLE,
- if (shouldBeSaddled) ItemStack(Items.SADDLE)
- else ItemStack.EMPTY)
+fun AbstractHorse.setIsSaddled(shouldBeSaddled: Boolean) {
+ this.setItemSlot(
+ EquipmentSlot.SADDLE,
+ if (shouldBeSaddled) ItemStack(Items.SADDLE)
+ else ItemStack.EMPTY
+ )
}
-fun AbstractHorseEntity.setHorseArmor(itemStack: ItemStack) {
- this.equipBodyArmor(itemStack)
+fun AbstractHorse.setHorseArmor(itemStack: ItemStack) {
+ bodyArmorItem = itemStack
}
diff --git a/src/main/kotlin/gui/entity/ModifyInvisible.kt b/src/main/kotlin/gui/entity/ModifyInvisible.kt
index 8d36991..7a54ab1 100644
--- a/src/main/kotlin/gui/entity/ModifyInvisible.kt
+++ b/src/main/kotlin/gui/entity/ModifyInvisible.kt
@@ -2,7 +2,7 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
+import net.minecraft.world.entity.LivingEntity
object ModifyInvisible : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
diff --git a/src/main/kotlin/gui/entity/ModifyName.kt b/src/main/kotlin/gui/entity/ModifyName.kt
index a03da96..6def0b4 100644
--- a/src/main/kotlin/gui/entity/ModifyName.kt
+++ b/src/main/kotlin/gui/entity/ModifyName.kt
@@ -2,12 +2,12 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
-import net.minecraft.text.Text
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.network.chat.Component
object ModifyName : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
- entity.customName = Text.literal(info.get("name").asString)
+ entity.customName = Component.literal(info.get("name").asString)
return entity
}
diff --git a/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt b/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt
index 28f0070..0b393bb 100644
--- a/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt
+++ b/src/main/kotlin/gui/entity/ModifyPlayerSkin.kt
@@ -1,47 +1,57 @@
-
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
import com.google.gson.JsonPrimitive
import kotlin.experimental.and
import kotlin.experimental.or
-import net.minecraft.client.util.SkinTextures
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.player.PlayerEntity
-import net.minecraft.entity.player.PlayerModelPart
-import net.minecraft.util.Identifier
+import net.minecraft.client.entity.ClientAvatarEntity
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.entity.Avatar
+import net.minecraft.world.entity.player.Player
+import net.minecraft.world.entity.player.PlayerModelPart
+import net.minecraft.world.entity.player.PlayerModelType
+import net.minecraft.world.entity.player.PlayerSkin
+import net.minecraft.core.ClientAsset
+import net.minecraft.resources.ResourceLocation
object ModifyPlayerSkin : EntityModifier {
- val playerModelPartIndex = PlayerModelPart.entries.associateBy { it.getName() }
- override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
- require(entity is GuiPlayer)
- info["cape"]?.let {
- entity.capeTexture = Identifier.of(it.asString)
- }
- info["skin"]?.let {
- entity.skinTexture = Identifier.of(it.asString)
- }
- info["slim"]?.let {
- entity.model = if (it.asBoolean) SkinTextures.Model.SLIM else SkinTextures.Model.WIDE
- }
- info["parts"]?.let {
- var trackedData = entity.dataTracker.get(PlayerEntity.PLAYER_MODEL_PARTS)
- if (it is JsonPrimitive && it.isBoolean) {
- trackedData = (if (it.asBoolean) -1 else 0).toByte()
- } else {
- val obj = it.asJsonObject
- for ((k, v) in obj.entrySet()) {
- val part = playerModelPartIndex[k]!!
- trackedData = if (v.asBoolean) {
- trackedData and (part.bitFlag.inv().toByte())
- } else {
- trackedData or (part.bitFlag.toByte())
- }
- }
- }
- entity.dataTracker.set(PlayerEntity.PLAYER_MODEL_PARTS, trackedData)
- }
- return entity
- }
+ val playerModelPartIndex = PlayerModelPart.entries.associateBy { it.id }
+ override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
+ require(entity is GuiPlayer)
+ var capeTexture = entity.skinTextures.cape
+ var model = entity.skinTextures.model
+ var bodyTexture = entity.skinTextures.body
+ fun mkTexAsset(id: ResourceLocation) = ClientAsset.ResourceTexture(id, id)
+ info["cape"]?.let {
+ capeTexture = mkTexAsset(ResourceLocation.parse(it.asString))
+ }
+ info["skin"]?.let {
+ bodyTexture = mkTexAsset(ResourceLocation.parse(it.asString))
+ }
+ info["slim"]?.let {
+ model = if (it.asBoolean) PlayerModelType.SLIM else PlayerModelType.WIDE
+ }
+ info["parts"]?.let {
+ var trackedData = entity.entityData.get(Avatar.DATA_PLAYER_MODE_CUSTOMISATION)
+ if (it is JsonPrimitive && it.isBoolean) {
+ trackedData = (if (it.asBoolean) -1 else 0).toByte()
+ } else {
+ val obj = it.asJsonObject
+ for ((k, v) in obj.entrySet()) {
+ val part = playerModelPartIndex[k]!!
+ trackedData = if (v.asBoolean) {
+ trackedData and (part.mask.inv().toByte())
+ } else {
+ trackedData or (part.mask.toByte())
+ }
+ }
+ }
+ entity.entityData.set(Player.DATA_PLAYER_MODE_CUSTOMISATION, trackedData)
+ }
+ entity.skinTextures = PlayerSkin(
+ bodyTexture, capeTexture, null, model, true
+ )
+ return entity
+ }
}
diff --git a/src/main/kotlin/gui/entity/ModifyRiding.kt b/src/main/kotlin/gui/entity/ModifyRiding.kt
index 5c4c78d..51fcfae 100644
--- a/src/main/kotlin/gui/entity/ModifyRiding.kt
+++ b/src/main/kotlin/gui/entity/ModifyRiding.kt
@@ -2,13 +2,13 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
+import net.minecraft.world.entity.LivingEntity
object ModifyRiding : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
val newEntity = EntityRenderer.constructEntity(info)
require(newEntity != null)
- newEntity.startRiding(entity, true)
+ newEntity.startRiding(entity, true, false)
return entity
}
diff --git a/src/main/kotlin/gui/entity/ModifyWither.kt b/src/main/kotlin/gui/entity/ModifyWither.kt
index 6083d88..67252b8 100644
--- a/src/main/kotlin/gui/entity/ModifyWither.kt
+++ b/src/main/kotlin/gui/entity/ModifyWither.kt
@@ -2,14 +2,14 @@
package moe.nea.firmament.gui.entity
import com.google.gson.JsonObject
-import net.minecraft.entity.LivingEntity
-import net.minecraft.entity.boss.WitherEntity
+import net.minecraft.world.entity.LivingEntity
+import net.minecraft.world.entity.boss.wither.WitherBoss
object ModifyWither : EntityModifier {
override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity {
- require(entity is WitherEntity)
+ require(entity is WitherBoss)
info["tiny"]?.let {
- entity.setInvulTimer(if (it.asBoolean) 800 else 0)
+ entity.invulnerableTicks = if (it.asBoolean) 800 else 0
}
info["armored"]?.let {
entity.health = if (it.asBoolean) 1F else entity.maxHealth