aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/moe/nea/firmament/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/gui')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt7
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/entity/EntityRenderer.kt4
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/entity/FakeWorld.kt70
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/entity/ModifyEquipment.kt7
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt14
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt2
6 files changed, 54 insertions, 50 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt b/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt
index 817c099..a1d4d68 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/WTitledItem.kt
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -11,13 +12,13 @@ import io.github.cottonmc.cotton.gui.client.BackgroundPainter
import io.github.cottonmc.cotton.gui.widget.TooltipBuilder
import io.github.cottonmc.cotton.gui.widget.WWidget
import net.minecraft.client.gui.DrawContext
-import net.minecraft.client.item.TooltipContext
+import net.minecraft.client.item.TooltipType
import net.minecraft.item.ItemStack
import net.minecraft.text.Text
import moe.nea.firmament.util.MC
open class WTitledItem(var stack: ItemStack, val countString: Text = Text.empty()) : WWidget() {
- var backgroundPainter:BackgroundPainter = BackgroundPainter.SLOT
+ var backgroundPainter: BackgroundPainter = BackgroundPainter.SLOT
override fun canResize(): Boolean = true
override fun paint(context: DrawContext, x: Int, y: Int, mouseX: Int, mouseY: Int) {
backgroundPainter.paintBackground(context, x, y, this)
@@ -32,7 +33,7 @@ open class WTitledItem(var stack: ItemStack, val countString: Text = Text.empty(
}
override fun addTooltip(tooltip: TooltipBuilder) {
- tooltip.add(*stack.getTooltip(null, TooltipContext.BASIC).toTypedArray())
+ tooltip.add(*stack.getTooltip(null, null, TooltipType.BASIC).toTypedArray())
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/entity/EntityRenderer.kt b/src/main/kotlin/moe/nea/firmament/gui/entity/EntityRenderer.kt
index 65b5d7d..44fd538 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/entity/EntityRenderer.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/entity/EntityRenderer.kt
@@ -136,7 +136,7 @@ object EntityRenderer {
posY,
posX + 50,
posY + 80,
- (minOf(2F / maxSize, 1F) * 30).toInt(),
+ minOf(2F / maxSize, 1F) * 30,
-bottomOffset,
mouseX,
mouseY,
@@ -155,7 +155,7 @@ object EntityRenderer {
y1: Int,
x2: Int,
y2: Int,
- size: Int,
+ size: Float,
bottomOffset: Float,
mouseX: Float,
mouseY: Float,
diff --git a/src/main/kotlin/moe/nea/firmament/gui/entity/FakeWorld.kt b/src/main/kotlin/moe/nea/firmament/gui/entity/FakeWorld.kt
index 4cdfc45..ac1b33b 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/entity/FakeWorld.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/entity/FakeWorld.kt
@@ -16,11 +16,13 @@ import kotlin.jvm.optionals.getOrNull
import kotlin.streams.asSequence
import net.minecraft.block.Block
import net.minecraft.block.BlockState
-import net.minecraft.client.world.ClientWorld
+import net.minecraft.component.type.MapIdComponent
import net.minecraft.entity.Entity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.fluid.Fluid
import net.minecraft.item.map.MapState
+import net.minecraft.recipe.BrewingRecipeRegistry
+import net.minecraft.recipe.Ingredient
import net.minecraft.recipe.RecipeManager
import net.minecraft.registry.BuiltinRegistries
import net.minecraft.registry.DynamicRegistryManager
@@ -29,10 +31,10 @@ import net.minecraft.registry.RegistryKey
import net.minecraft.registry.RegistryKeys
import net.minecraft.registry.RegistryWrapper
import net.minecraft.registry.entry.RegistryEntry
+import net.minecraft.registry.entry.RegistryEntryInfo
import net.minecraft.registry.entry.RegistryEntryList
import net.minecraft.registry.entry.RegistryEntryOwner
import net.minecraft.registry.tag.TagKey
-import net.minecraft.resource.featuretoggle.FeatureFlag
import net.minecraft.resource.featuretoggle.FeatureFlags
import net.minecraft.resource.featuretoggle.FeatureSet
import net.minecraft.scoreboard.Scoreboard
@@ -119,6 +121,10 @@ fun <T> makeRegistry(registryWrapper: RegistryWrapper.Impl<T>, key: RegistryKey<
return key
}
+ override fun getEntryInfo(key: RegistryKey<T>?): Optional<RegistryEntryInfo> {
+ TODO("Not yet implemented")
+ }
+
override fun getLifecycle(): Lifecycle {
return Lifecycle.stable()
}
@@ -194,18 +200,18 @@ fun <T> makeRegistry(registryWrapper: RegistryWrapper.Impl<T>, key: RegistryKey<
return registryWrapper.getOptional(key ?: return Optional.empty())
}
+ override fun getEntry(id: Identifier?): Optional<RegistryEntry.Reference<T>> {
+ TODO("Not yet implemented")
+ }
+
override fun createEntry(value: T): RegistryEntry.Reference<T> {
- TODO()
+ TODO("Not yet implemented")
}
override fun contains(key: RegistryKey<T>?): Boolean {
return getEntry(key).isPresent
}
- override fun getEntryLifecycle(entry: T): Lifecycle {
- return Lifecycle.stable()
- }
-
override fun getId(value: T): Identifier? {
return (inverseLookup[value] ?: return null).value
}
@@ -236,7 +242,9 @@ fun createDynamicRegistry(): DynamicRegistryManager.Immutable {
}
}
-class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegistry()) : World(
+class FakeWorld(
+ registries: DynamicRegistryManager.Immutable = createDynamicRegistry(),
+) : World(
Properties,
RegistryKey.of(RegistryKeys.WORLD, Identifier.of("firmament", "fakeworld")),
registries,
@@ -252,16 +260,8 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
0, 0
) {
object Properties : MutableWorldProperties {
- override fun getSpawnX(): Int {
- return 0
- }
-
- override fun getSpawnY(): Int {
- return 0
- }
-
- override fun getSpawnZ(): Int {
- return 0
+ override fun getSpawnPos(): BlockPos {
+ return BlockPos.ORIGIN
}
override fun getSpawnAngle(): Float {
@@ -303,17 +303,7 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
return false
}
- override fun setSpawnX(spawnX: Int) {
- }
-
- override fun setSpawnY(spawnY: Int) {
- }
-
- override fun setSpawnZ(spawnZ: Int) {
- }
-
- override fun setSpawnAngle(spawnAngle: Float) {
- }
+ override fun setSpawnPos(pos: BlockPos?, angle: Float) {}
}
override fun getPlayers(): List<PlayerEntity> {
@@ -361,7 +351,11 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
class FakeChunkManager(val world: FakeWorld) : ChunkManager() {
override fun getChunk(x: Int, z: Int, leastStatus: ChunkStatus?, create: Boolean): Chunk {
- return EmptyChunk(world, ChunkPos(x,z), world.registryManager.get(RegistryKeys.BIOME).entryOf(BiomeKeys.PLAINS))
+ return EmptyChunk(
+ world,
+ ChunkPos(x, z),
+ world.registryManager.get(RegistryKeys.BIOME).entryOf(BiomeKeys.PLAINS)
+ )
}
override fun getWorld(): BlockView {
@@ -406,7 +400,7 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
override fun syncWorldEvent(player: PlayerEntity?, eventId: Int, pos: BlockPos?, data: Int) {
}
- override fun emitGameEvent(event: GameEvent?, emitterPos: Vec3d?, emitter: GameEvent.Emitter?) {
+ override fun emitGameEvent(event: RegistryEntry<GameEvent>?, emitterPos: Vec3d?, emitter: GameEvent.Emitter?) {
}
override fun updateListeners(pos: BlockPos?, oldState: BlockState?, newState: BlockState?, flags: Int) {
@@ -435,15 +429,15 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
return TickManager()
}
- override fun getMapState(id: String?): MapState? {
+ override fun getMapState(id: MapIdComponent?): MapState? {
return null
}
- override fun putMapState(id: String?, state: MapState?) {
+ override fun putMapState(id: MapIdComponent?, state: MapState?) {
}
- override fun getNextMapId(): Int {
- return 0
+ override fun getNextMapId(): MapIdComponent {
+ return MapIdComponent(0)
}
override fun setBlockBreakingInfo(entityId: Int, pos: BlockPos?, progress: Int) {
@@ -454,7 +448,7 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
}
override fun getRecipeManager(): RecipeManager {
- return RecipeManager()
+ return RecipeManager(registryManager)
}
object FakeEntityLookup : EntityLookup<Entity> {
@@ -488,4 +482,8 @@ class FakeWorld(registries: DynamicRegistryManager.Immutable = createDynamicRegi
override fun getEntityLookup(): EntityLookup<Entity> {
return FakeEntityLookup
}
+
+ override fun getBrewingRecipeRegistry(): BrewingRecipeRegistry {
+ return BrewingRecipeRegistry.EMPTY
+ }
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/entity/ModifyEquipment.kt b/src/main/kotlin/moe/nea/firmament/gui/entity/ModifyEquipment.kt
index e438f59..261b8f5 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/entity/ModifyEquipment.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/entity/ModifyEquipment.kt
@@ -7,9 +7,11 @@
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.DyeableArmorItem
+import net.minecraft.item.ArmorItem
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.item.Items
@@ -51,9 +53,8 @@ object ModifyEquipment : EntityModifier {
}
private fun coloredLeatherArmor(leatherArmor: Item, data: String): ItemStack {
- require(leatherArmor is DyeableArmorItem)
val stack = ItemStack(leatherArmor)
- leatherArmor.setColor(stack, data.toInt(16))
+ stack.set(DataComponentTypes.DYED_COLOR, DyedColorComponent(data.toInt(16), false))
return stack
}
}
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
index 4248654..0c99f67 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/ProfileViewerLibrary.kt
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -12,9 +13,6 @@ import io.github.cottonmc.cotton.gui.client.LightweightGuiDescription
import io.github.cottonmc.cotton.gui.widget.WGridPanel
import io.github.cottonmc.cotton.gui.widget.WText
import io.github.cottonmc.cotton.gui.widget.data.VerticalAlignment
-import moe.nea.firmament.gui.WTitledItem
-import moe.nea.firmament.util.ScreenUtil
-import moe.nea.firmament.util.modifyLore
import moe.nea.lisp.LispData
import moe.nea.lisp.LispExecutionContext
import moe.nea.lisp.LispParser
@@ -23,16 +21,20 @@ import moe.nea.lisp.bind.LispBinding
import moe.nea.lisp.bind.UnmapForeignObject
import net.minecraft.command.argument.ItemStringReader
import net.minecraft.item.ItemStack
-import net.minecraft.registry.Registries
import net.minecraft.text.Text
+import moe.nea.firmament.gui.WTitledItem
+import moe.nea.firmament.util.MC
+import moe.nea.firmament.util.ScreenUtil
+import moe.nea.firmament.util.item.setCustomName
+import moe.nea.firmament.util.modifyLore
class ProfileViewerLibrary {
@LispBinding("mk-item")
fun makeItem(itemType: String, title: String, vararg lore: String): LispData.ForeignObject<ItemStack> {
- val item = ItemStringReader.item(Registries.ITEM.readOnlyWrapper, StringReader(itemType))
+ val item = ItemStringReader(MC.defaultRegistries).consume(StringReader(itemType))
val itemStack = ItemStack(item.item.value())
- itemStack.nbt = item.nbt
+ itemStack.applyComponentsFrom(item.components)
itemStack.modifyLore { lore.map { Text.literal(it) } }
itemStack.setCustomName(Text.literal(title))
return LispData.ForeignObject(itemStack)
diff --git a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt
index 76c88c2..64f4f2c 100644
--- a/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt
+++ b/src/main/kotlin/moe/nea/firmament/gui/profileviewer/SkillPage.kt
@@ -1,5 +1,6 @@
/*
* SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
+ * SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
@@ -32,6 +33,7 @@ import net.minecraft.text.Style
import net.minecraft.text.Text
import net.minecraft.util.DyeColor
import net.minecraft.util.Formatting
+import moe.nea.firmament.util.item.setCustomName
object SkillPage : ProfilePage {