Add SkinGrid, make SkinElement not be a data class

This commit is contained in:
DBotThePony 2022-06-21 22:46:36 +07:00
parent 5cc5829456
commit 1599dd39c9
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 58 additions and 54 deletions

View File

@ -4,8 +4,40 @@ import com.mojang.blaze3d.systems.RenderSystem
import com.mojang.blaze3d.vertex.PoseStack import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.resources.ResourceLocation import net.minecraft.resources.ResourceLocation
@JvmRecord class SkinGrid(
data class SkinElement @JvmOverloads constructor( val texture: ResourceLocation,
val width: Float,
val height: Float,
val rows: Int = 16,
val columns: Int = 16,
) {
private var row = 0
private var column = 0
val imageWidth get() = width * columns
val imageHeight get() = height * rows
fun skip() {
column++
if (column >= columns) {
jump()
}
}
fun jump() {
row++
column = 0
}
fun next(): SkinElement {
val element = SkinElement(texture, column * width, row * height, width, height, imageWidth, imageHeight)
skip()
return element
}
}
class SkinElement @JvmOverloads constructor(
val texture: ResourceLocation = RenderHelper.WIDGETS, val texture: ResourceLocation = RenderHelper.WIDGETS,
val image_x: Float, val image_x: Float,
val image_y: Float, val image_y: Float,

View File

@ -14,6 +14,7 @@ import ru.dbotthepony.mc.otm.android.AndroidResearchBuilder
import ru.dbotthepony.mc.otm.android.AndroidResearchType import ru.dbotthepony.mc.otm.android.AndroidResearchType
import ru.dbotthepony.mc.otm.android.feature.NanobotsArmor import ru.dbotthepony.mc.otm.android.feature.NanobotsArmor
import ru.dbotthepony.mc.otm.client.render.SkinElement import ru.dbotthepony.mc.otm.client.render.SkinElement
import ru.dbotthepony.mc.otm.client.render.SkinGrid
object AndroidResearch { object AndroidResearch {
val ICONS = ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/android_upgrades.png") val ICONS = ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/android_upgrades.png")
@ -44,62 +45,33 @@ object AndroidResearch {
val ICON_EXTENDED_REACH: SkinElement val ICON_EXTENDED_REACH: SkinElement
init { init {
var x = 0f val grid = SkinGrid(ICONS, 18f, 18f, 7, 7)
var y = 0f
ICON_TRANSFER = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_TRANSFER = grid.next()
x += 18f ICON_ATTACK_BOOST = grid.next()
ICON_ATTACK_BOOST = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_PLASMA_SHIELD_BOOST = grid.next()
x += 18f ICON_CLOAK = grid.next()
ICON_PLASMA_SHIELD_BOOST = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_GRAVITATIONAL_STABILIZER = grid.next()
x += 18f ICON_AIR_BAGS = grid.next()
ICON_CLOAK = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_JUMP_BOOST = grid.next()
x += 18f
ICON_GRAVITATIONAL_STABILIZER = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_AIR_BAGS = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_JUMP_BOOST = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
y += 18f ICON_FEATHER_FALLING = grid.next()
x = 0f ICON_ARC = grid.next()
ICON_ARROW = grid.next()
ICON_ARMOR = grid.next()
ICON_NANOBOTS = grid.next()
ICON_NIGHT_VISION = grid.next()
ICON_OXYGEN_SUPPLY = grid.next()
ICON_FEATHER_FALLING = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_PLASMA_SHIELD = grid.next()
x += 18f ICON_SHOCKWAVE = grid.next()
ICON_ARC = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_LIMB_OVERCLOCKING = grid.next()
x += 18f ICON_STEP_ASSIST = grid.next()
ICON_ARROW = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_ENDER_TELEPORT = grid.next()
x += 18f ICON_WIRELESS_CHARGING = grid.next()
ICON_ARMOR = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f) ICON_UNKNOWN = grid.next()
x += 18f
ICON_NANOBOTS = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_NIGHT_VISION = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_OXYGEN_SUPPLY = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
y += 18 ICON_EXTENDED_REACH = grid.next()
x = 0f
ICON_PLASMA_SHIELD = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_SHOCKWAVE = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_LIMB_OVERCLOCKING = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_STEP_ASSIST = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_ENDER_TELEPORT = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_WIRELESS_CHARGING = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
ICON_UNKNOWN = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
y += 18f
x = 0f
ICON_EXTENDED_REACH = SkinElement(ICONS, x, y, 18f, 18f, 126f, 126f)
x += 18f
} }
private val registry = DeferredRegister.create(AndroidResearchType::class.java, OverdriveThatMatters.MOD_ID) private val registry = DeferredRegister.create(AndroidResearchType::class.java, OverdriveThatMatters.MOD_ID)