diff options
Diffstat (limited to 'src/main/kotlin/gui/entity')
-rw-r--r-- | src/main/kotlin/gui/entity/EntityWidget.kt | 35 | ||||
-rw-r--r-- | src/main/kotlin/gui/entity/ModifyEquipment.kt | 70 |
2 files changed, 34 insertions, 71 deletions
diff --git a/src/main/kotlin/gui/entity/EntityWidget.kt b/src/main/kotlin/gui/entity/EntityWidget.kt deleted file mode 100644 index 2e49072..0000000 --- a/src/main/kotlin/gui/entity/EntityWidget.kt +++ /dev/null @@ -1,35 +0,0 @@ - -package moe.nea.firmament.gui.entity - -import me.shedaniel.math.Dimension -import me.shedaniel.math.Point -import me.shedaniel.math.Rectangle -import me.shedaniel.rei.api.client.gui.widgets.WidgetWithBounds -import net.minecraft.client.gui.DrawContext -import net.minecraft.client.gui.Element -import net.minecraft.entity.LivingEntity - -class EntityWidget(val entity: LivingEntity, val point: Point) : WidgetWithBounds() { - override fun children(): List<Element> { - return emptyList() - } - - var hasErrored = false - - override fun render(context: DrawContext, mouseX: Int, mouseY: Int, delta: Float) { - try { - if (!hasErrored) - EntityRenderer.renderEntity(entity, context, point.x, point.y, mouseX.toFloat(), mouseY.toFloat()) - } catch (ex: Exception) { - EntityRenderer.logger.error("Failed to render constructed entity: $entity", ex) - hasErrored = true - } - if (hasErrored) { - context.fill(point.x, point.y, point.x + 50, point.y + 80, 0xFFAA2222.toInt()) - } - } - - override fun getBounds(): Rectangle { - return Rectangle(point, Dimension(50, 80)) - } -} diff --git a/src/main/kotlin/gui/entity/ModifyEquipment.kt b/src/main/kotlin/gui/entity/ModifyEquipment.kt index 11dfb52..a558936 100644 --- a/src/main/kotlin/gui/entity/ModifyEquipment.kt +++ b/src/main/kotlin/gui/entity/ModifyEquipment.kt @@ -1,4 +1,3 @@ - package moe.nea.firmament.gui.entity import com.google.gson.JsonObject @@ -6,50 +5,49 @@ 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.ArmorItem import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraft.item.Items -import moe.nea.firmament.rei.SBItemStack +import moe.nea.firmament.repo.SBItemStack import moe.nea.firmament.util.SkyblockId import moe.nea.firmament.util.mc.setEncodedSkullOwner import moe.nea.firmament.util.mc.zeroUUID object ModifyEquipment : EntityModifier { - val names = mapOf( - "hand" to EquipmentSlot.MAINHAND, - "helmet" to EquipmentSlot.HEAD, - "chestplate" to EquipmentSlot.CHEST, - "leggings" to EquipmentSlot.LEGS, - "feet" to EquipmentSlot.FEET, - ) + val names = mapOf( + "hand" to EquipmentSlot.MAINHAND, + "helmet" to EquipmentSlot.HEAD, + "chestplate" to EquipmentSlot.CHEST, + "leggings" to EquipmentSlot.LEGS, + "feet" to EquipmentSlot.FEET, + ) - override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity { - names.forEach { (key, slot) -> - info[key]?.let { - entity.equipStack(slot, createItem(it.asString)) - } - } - return entity - } + override fun apply(entity: LivingEntity, info: JsonObject): LivingEntity { + names.forEach { (key, slot) -> + info[key]?.let { + entity.equipStack(slot, createItem(it.asString)) + } + } + return entity + } - 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) } - "LEATHER_LEGGINGS" -> coloredLeatherArmor(Items.LEATHER_LEGGINGS, data) - "LEATHER_BOOTS" -> coloredLeatherArmor(Items.LEATHER_BOOTS, data) - "LEATHER_HELMET" -> coloredLeatherArmor(Items.LEATHER_HELMET, data) - "LEATHER_CHESTPLATE" -> coloredLeatherArmor(Items.LEATHER_CHESTPLATE, data) - else -> error("Unknown leather piece: $type") - } - } + 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) } + "LEATHER_LEGGINGS" -> coloredLeatherArmor(Items.LEATHER_LEGGINGS, data) + "LEATHER_BOOTS" -> coloredLeatherArmor(Items.LEATHER_BOOTS, data) + "LEATHER_HELMET" -> coloredLeatherArmor(Items.LEATHER_HELMET, data) + "LEATHER_CHESTPLATE" -> coloredLeatherArmor(Items.LEATHER_CHESTPLATE, data) + else -> error("Unknown leather piece: $type") + } + } - private fun coloredLeatherArmor(leatherArmor: Item, data: String): ItemStack { - val stack = ItemStack(leatherArmor) - stack.set(DataComponentTypes.DYED_COLOR, DyedColorComponent(data.toInt(16), false)) - return stack - } + private fun coloredLeatherArmor(leatherArmor: Item, data: String): ItemStack { + val stack = ItemStack(leatherArmor) + stack.set(DataComponentTypes.DYED_COLOR, DyedColorComponent(data.toInt(16), false)) + return stack + } } |