Even better bed button handling

This commit is contained in:
DBotThePony 2022-09-06 00:17:23 +07:00
parent 5f3a17da9f
commit 77e35917ba
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 23 additions and 53 deletions

View File

@ -6,7 +6,6 @@ import net.minecraft.client.gui.screens.DeathScreen
import net.minecraft.client.gui.screens.InBedChatScreen
import net.minecraft.client.player.LocalPlayer
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.contents.TranslatableContents
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.effect.MobEffects
import net.minecraft.world.entity.LivingEntity
@ -16,8 +15,6 @@ import net.minecraftforge.client.event.RenderGuiOverlayEvent
import net.minecraftforge.client.event.ScreenEvent
import net.minecraftforge.client.gui.overlay.ForgeGui
import net.minecraftforge.client.gui.overlay.GuiOverlayManager
import net.minecraftforge.eventbus.api.EventPriority
import net.minecraftforge.eventbus.api.SubscribeEvent
import ru.dbotthepony.mc.otm.OverdriveThatMatters
import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.capability.MatteryCapability
@ -31,67 +28,48 @@ import java.util.*
object MatteryGUI {
val PLAYER_GUI_LOCATION = ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_gui.png")
private var knownButtonX = -1
private var knownButtonY = -1
private var knownButton: Button? = null
private var knownButtonScreen: InBedChatScreen? = null
private var originalBedButtonX = -1
private var originalBedButtonY = -1
private var lastState: MatteryPlayerCapability? = null
private val button_shaker = Random()
fun onScreenRender(event: ScreenEvent.Render.Pre) {
if (knownButtonScreen != null && knownButton == null) {
for (widget in knownButtonScreen!!.renderables) {
if (widget is Button && (widget.message.contents as? TranslatableContents)?.key == "multiplayer.stopSleeping") {
knownButtonX = widget.x
knownButtonY = widget.y
knownButton = widget
break
}
}
val screen = minecraft.screen as? InBedChatScreen
if (knownButton == null) {
knownButtonScreen = null
}
}
if (knownButtonScreen != null && knownButtonScreen !== minecraft.screen) {
knownButtonX = -1
knownButtonY = -1
knownButton = null
knownButtonScreen = null
}
if (knownButtonScreen == null || minecraft.player == null) {
if (screen == null || (screen.leaveBedButton as Button?) == null) {
originalBedButtonX = -1
originalBedButtonY = -1
return
}
if (originalBedButtonX == -1 && originalBedButtonY == -1) {
originalBedButtonX = screen.leaveBedButton.x
originalBedButtonY = screen.leaveBedButton.y
}
minecraft.player?.getCapability(MatteryCapability.MATTERY_PLAYER)?.ifPresentK {
if (!it.willBecomeAndroid) {
knownButton!!.x = knownButtonX
knownButton!!.y = knownButtonY
knownButtonX = -1
knownButtonY = -1
knownButton = null
knownButtonScreen = null
screen.leaveBedButton.x = originalBedButtonX
screen.leaveBedButton.y = originalBedButtonY
originalBedButtonX = -1
originalBedButtonY = -1
return@ifPresentK
}
val dispersion = (10.0 * Math.max(0, it.sleepTicks - 20) / (MatteryPlayerCapability.SLEEP_TICKS_LIMIT - 20)).toInt()
knownButton!!.x =
knownButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
knownButton!!.y =
knownButtonY - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
screen.leaveBedButton.x =
originalBedButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
screen.leaveBedButton.y =
originalBedButtonY - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
}
}
fun onOpenGUIEvent(event: ScreenEvent.Opening) {
knownButtonX = -1
knownButtonY = -1
knownButton = null
knownButtonScreen = null
originalBedButtonX = -1
originalBedButtonY = -1
if (minecraft.player == null) return
@ -102,16 +80,6 @@ object MatteryGUI {
if (it.isAndroid) screen.title = TranslatableComponent("otm.death_reason")
}
}
if (screen is InBedChatScreen) {
knownButtonScreen = screen
minecraft.player?.getCapability(MatteryCapability.MATTERY_PLAYER)?.ifPresentK {
if (it.willBecomeAndroid) {
knownButtonScreen = screen
}
}
}
}
private val FOOD_LEVEL_ELEMENT by lazy {

View File

@ -30,6 +30,8 @@ protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_9
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97723_ # doubleclick
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97724_ # lastQuickMoved
public net.minecraft.client.gui.screens.InBedChatScreen f_242488_ # leaveBedButton
public net.minecraft.world.inventory.AbstractContainerMenu f_182405_ # stateId
public net.minecraft.world.inventory.CraftingMenu m_150546_(Lnet/minecraft/world/inventory/AbstractContainerMenu;Lnet/minecraft/world/level/Level;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/inventory/CraftingContainer;Lnet/minecraft/world/inventory/ResultContainer;)V # slotChangedCraftingGrid