Split android gui atlas to separate files

This commit is contained in:
DBotThePony 2022-10-07 00:46:28 +07:00
parent f99ed19d9c
commit be8435655f
Signed by: DBot
GPG Key ID: DCC23B5715498507
37 changed files with 59 additions and 41 deletions

View File

@ -6,12 +6,14 @@ package ru.dbotthepony.mc.otm
import net.minecraft.client.server.IntegratedServer
import net.minecraft.server.MinecraftServer
import net.minecraft.world.level.Level
import net.minecraftforge.api.distmarker.Dist
import net.minecraftforge.event.TickEvent
import net.minecraftforge.event.TickEvent.ServerTickEvent
import net.minecraftforge.event.TickEvent.LevelTickEvent
import net.minecraftforge.event.server.ServerAboutToStartEvent
import net.minecraftforge.event.server.ServerStoppedEvent
import net.minecraftforge.event.server.ServerStoppingEvent
import net.minecraftforge.fml.loading.FMLLoader
import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.core.IConditionalTickable
@ -50,7 +52,7 @@ private var _server: MinecraftServer? = null
private var _serverThread: Thread? = null
private var _clientThread: Thread? = null
val isClient: Boolean get() = _clientThread !== null
val isClient: Boolean by lazy { FMLLoader.getDist() == Dist.CLIENT }
private val isPausedImpl: Boolean get() {
val server = _server

View File

@ -13,7 +13,8 @@ private val preTickList = TickList()
private val postTickList = TickList()
private val preTimerList = TimerQueue()
private val postTimerList = TimerQueue()
private var LOGGED_IN = false
var LOGGED_IN = false
private set
fun onceClient(ticker: ITickable) {
check(isClient) { "Illegal side" }

View File

@ -27,9 +27,14 @@ import ru.dbotthepony.mc.otm.core.RGBAColor
import ru.dbotthepony.mc.otm.core.formatPower
import ru.dbotthepony.mc.otm.core.ifPresentK
import java.util.*
import kotlin.math.ceil
object MatteryGUI {
val PLAYER_GUI_LOCATION = ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_gui.png")
val CHARGE = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_charge/android_charge"))
val CHARGE_BG = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_charge/android_charge_bg"))
val CHARGE_HUNGER = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_charge/android_charge_hunger"))
val CHARGE_HUNGER_BG = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_charge/android_charge_hunger_bg"))
private var originalBedButtonX = -1
private var originalBedButtonY = -1
@ -202,7 +207,6 @@ object MatteryGUI {
return
}
val yOffset = if (ply.hasEffect(MobEffects.HUNGER)) 18 else 0
var level: Float
if (mattery.androidEnergy.maxBatteryLevel.isZero) {
@ -216,7 +220,6 @@ object MatteryGUI {
gui.setupOverlayRenderState(true, false)
RenderSystem.setShaderColor(1.0f, 1.0f, 1.0f, 1.0f)
RenderSystem.setShaderTexture(0, PLAYER_GUI_LOCATION)
val width = event.window.guiScaledWidth
val height = event.window.guiScaledHeight
@ -224,12 +227,15 @@ object MatteryGUI {
val top: Int = height - gui.rightHeight
gui.rightHeight += 10
// Stack, x, y, blitOffset?, (float) image_x, (float) image_y, rect_x, rect_y, total_image_width, total_image_height
// Stack, x, y, image_x, image_y, rect_x, rect_y
gui.blit(event.poseStack, left, top, 0, yOffset, 80, 9)
val leftPadding = Math.ceil((level * 79f - 0.5f).toDouble()).toInt()
val leftPadding = ceil(level * 79f - 0.5f)
gui.blit(event.poseStack, left + 79 - leftPadding, top, 79 - leftPadding, yOffset + 9, leftPadding, 9)
if (ply.hasEffect(MobEffects.HUNGER)) {
CHARGE_HUNGER_BG.render(event.poseStack, left.toFloat(), top.toFloat())
CHARGE_HUNGER.renderPartial(event.poseStack, left.toFloat() - leftPadding + 79f, top.toFloat(), width = 79f - leftPadding)
} else {
CHARGE_BG.render(event.poseStack, left.toFloat(), top.toFloat())
CHARGE.renderPartial(event.poseStack, left.toFloat() - leftPadding + 79f, top.toFloat(), width = leftPadding)
}
val formattedPower = mattery.androidEnergy.batteryLevel.formatPower()

View File

@ -13,7 +13,6 @@ import com.google.gson.stream.JsonWriter
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.network.FriendlyByteBuf
import net.minecraft.resources.ResourceLocation
import ru.dbotthepony.mc.otm.client.onceClient
import ru.dbotthepony.mc.otm.isClient
import java.lang.reflect.Type
import java.util.stream.Stream
@ -83,7 +82,7 @@ class AtlasSkinElement private constructor(
companion object : TypeAdapter<AtlasSkinElement>(), JsonSerializer<AtlasSkinElement>, JsonDeserializer<AtlasSkinElement> {
private val skinElementCache = HashMap<ResourceLocation, AtlasSkinElement>()
val keys: Stream<ResourceLocation> get() = skinElementCache.keys.stream()
val keysStream: Stream<ResourceLocation> get() = skinElementCache.keys.stream()
private fun queueRebuild() {
WidgetAtlasHolder.INSTANCE.queueRebuild()

View File

@ -36,28 +36,28 @@ object ResearchIcons {
init {
var i = 0
ICON_TRANSFER = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_ATTACK_BOOST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_PLASMA_SHIELD_BOOST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_CLOAK = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_GRAVITATIONAL_STABILIZER = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_AIR_BAGS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_JUMP_BOOST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_FEATHER_FALLING = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_ITEM_MAGNET = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_ARROW = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_ARMOR = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_NANOBOTS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_NIGHT_VISION = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_OXYGEN_SUPPLY = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_PLASMA_SHIELD = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_SHOCKWAVE = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_LIMB_OVERCLOCKING = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_STEP_ASSIST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_ENDER_TELEPORT = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_WIRELESS_CHARGING = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_UNKNOWN = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_EXTENDED_REACH = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_PHANTOM_ATTRACTOR = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_stuff-${i++}"))
ICON_TRANSFER = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_ATTACK_BOOST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_PLASMA_SHIELD_BOOST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_CLOAK = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_GRAVITATIONAL_STABILIZER = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_AIR_BAGS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_JUMP_BOOST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_FEATHER_FALLING = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_ITEM_MAGNET = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_ARROW = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_ARMOR = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_NANOBOTS = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_NIGHT_VISION = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_OXYGEN_SUPPLY = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_PLASMA_SHIELD = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_SHOCKWAVE = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_LIMB_OVERCLOCKING = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_STEP_ASSIST = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_ENDER_TELEPORT = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_WIRELESS_CHARGING = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_UNKNOWN = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_EXTENDED_REACH = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
ICON_PHANTOM_ATTRACTOR = AtlasSkinElement(ResourceLocation(OverdriveThatMatters.MOD_ID, "android_research/android_stuff-${i++}"))
}
}

View File

@ -5,11 +5,11 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.client.renderer.texture.TextureManager
import net.minecraft.client.resources.TextureAtlasHolder
import net.minecraft.resources.ResourceLocation
import net.minecraft.server.packs.resources.ReloadableResourceManager
import net.minecraft.server.packs.resources.ResourceManager
import net.minecraft.util.profiling.ProfilerFiller
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.client.LOGGED_IN
import ru.dbotthepony.mc.otm.client.minecraft
import ru.dbotthepony.mc.otm.client.onceClient
import ru.dbotthepony.mc.otm.registry.WriteOnce
@ -25,14 +25,18 @@ class WidgetAtlasHolder private constructor(manager: TextureManager) : TextureAt
private var queued = false
private var once = false
private var demandsRebuild = false
private var resourceManager by Delegates.notNull<ResourceManager>()
private var profileManager by Delegates.notNull<ProfilerFiller>()
override fun prepare(p_118891_: ResourceManager, p_118892_: ProfilerFiller): TextureAtlas.Preparations {
once = true
demandsRebuild = false
queued = false
resourceManager = p_118891_
profileManager = p_118892_
changeset++
return super.prepare(p_118891_, p_118892_)
}
@ -41,6 +45,10 @@ class WidgetAtlasHolder private constructor(manager: TextureManager) : TextureAt
throw IllegalStateException("Trying to get sprite too early")
}
if (demandsRebuild) {
apply(prepare(resourceManager, profileManager), resourceManager, profileManager)
}
return super.getSprite(p_118902_)
}
@ -48,16 +56,18 @@ class WidgetAtlasHolder private constructor(manager: TextureManager) : TextureAt
if (!queued && once) {
queued = true
if (LOGGED_IN) {
onceClient(20) {
queued = false
apply(prepare(resourceManager, profileManager), resourceManager, profileManager)
}
} else {
demandsRebuild = true
}
}
}
override fun getResourcesToLoad(): Stream<ResourceLocation> {
changeset++
return AtlasSkinElement.keys
return AtlasSkinElement.keysStream
}
companion object {

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 407 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 932 B