Even better bed button handling
This commit is contained in:
parent
5f3a17da9f
commit
77e35917ba
@ -6,7 +6,6 @@ import net.minecraft.client.gui.screens.DeathScreen
|
|||||||
import net.minecraft.client.gui.screens.InBedChatScreen
|
import net.minecraft.client.gui.screens.InBedChatScreen
|
||||||
import net.minecraft.client.player.LocalPlayer
|
import net.minecraft.client.player.LocalPlayer
|
||||||
import net.minecraft.network.chat.Component
|
import net.minecraft.network.chat.Component
|
||||||
import net.minecraft.network.chat.contents.TranslatableContents
|
|
||||||
import net.minecraft.resources.ResourceLocation
|
import net.minecraft.resources.ResourceLocation
|
||||||
import net.minecraft.world.effect.MobEffects
|
import net.minecraft.world.effect.MobEffects
|
||||||
import net.minecraft.world.entity.LivingEntity
|
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.event.ScreenEvent
|
||||||
import net.minecraftforge.client.gui.overlay.ForgeGui
|
import net.minecraftforge.client.gui.overlay.ForgeGui
|
||||||
import net.minecraftforge.client.gui.overlay.GuiOverlayManager
|
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.OverdriveThatMatters
|
||||||
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
import ru.dbotthepony.mc.otm.core.TranslatableComponent
|
||||||
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
import ru.dbotthepony.mc.otm.capability.MatteryCapability
|
||||||
@ -31,67 +28,48 @@ import java.util.*
|
|||||||
object MatteryGUI {
|
object MatteryGUI {
|
||||||
val PLAYER_GUI_LOCATION = ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_gui.png")
|
val PLAYER_GUI_LOCATION = ResourceLocation(OverdriveThatMatters.MOD_ID, "textures/gui/player_gui.png")
|
||||||
|
|
||||||
private var knownButtonX = -1
|
private var originalBedButtonX = -1
|
||||||
private var knownButtonY = -1
|
private var originalBedButtonY = -1
|
||||||
private var knownButton: Button? = null
|
|
||||||
private var knownButtonScreen: InBedChatScreen? = null
|
|
||||||
|
|
||||||
private var lastState: MatteryPlayerCapability? = null
|
private var lastState: MatteryPlayerCapability? = null
|
||||||
|
|
||||||
private val button_shaker = Random()
|
private val button_shaker = Random()
|
||||||
|
|
||||||
fun onScreenRender(event: ScreenEvent.Render.Pre) {
|
fun onScreenRender(event: ScreenEvent.Render.Pre) {
|
||||||
if (knownButtonScreen != null && knownButton == null) {
|
val screen = minecraft.screen as? InBedChatScreen
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (knownButton == null) {
|
if (screen == null || (screen.leaveBedButton as Button?) == null) {
|
||||||
knownButtonScreen = null
|
originalBedButtonX = -1
|
||||||
}
|
originalBedButtonY = -1
|
||||||
}
|
|
||||||
|
|
||||||
if (knownButtonScreen != null && knownButtonScreen !== minecraft.screen) {
|
|
||||||
knownButtonX = -1
|
|
||||||
knownButtonY = -1
|
|
||||||
knownButton = null
|
|
||||||
knownButtonScreen = null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (knownButtonScreen == null || minecraft.player == null) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (originalBedButtonX == -1 && originalBedButtonY == -1) {
|
||||||
|
originalBedButtonX = screen.leaveBedButton.x
|
||||||
|
originalBedButtonY = screen.leaveBedButton.y
|
||||||
|
}
|
||||||
|
|
||||||
minecraft.player?.getCapability(MatteryCapability.MATTERY_PLAYER)?.ifPresentK {
|
minecraft.player?.getCapability(MatteryCapability.MATTERY_PLAYER)?.ifPresentK {
|
||||||
if (!it.willBecomeAndroid) {
|
if (!it.willBecomeAndroid) {
|
||||||
knownButton!!.x = knownButtonX
|
screen.leaveBedButton.x = originalBedButtonX
|
||||||
knownButton!!.y = knownButtonY
|
screen.leaveBedButton.y = originalBedButtonY
|
||||||
knownButtonX = -1
|
originalBedButtonX = -1
|
||||||
knownButtonY = -1
|
originalBedButtonY = -1
|
||||||
knownButton = null
|
|
||||||
knownButtonScreen = null
|
|
||||||
return@ifPresentK
|
return@ifPresentK
|
||||||
}
|
}
|
||||||
|
|
||||||
val dispersion = (10.0 * Math.max(0, it.sleepTicks - 20) / (MatteryPlayerCapability.SLEEP_TICKS_LIMIT - 20)).toInt()
|
val dispersion = (10.0 * Math.max(0, it.sleepTicks - 20) / (MatteryPlayerCapability.SLEEP_TICKS_LIMIT - 20)).toInt()
|
||||||
|
|
||||||
knownButton!!.x =
|
screen.leaveBedButton.x =
|
||||||
knownButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
|
originalBedButtonX - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
|
||||||
knownButton!!.y =
|
screen.leaveBedButton.y =
|
||||||
knownButtonY - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
|
originalBedButtonY - dispersion / 2 + (button_shaker.nextDouble() * dispersion).toInt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOpenGUIEvent(event: ScreenEvent.Opening) {
|
fun onOpenGUIEvent(event: ScreenEvent.Opening) {
|
||||||
knownButtonX = -1
|
originalBedButtonX = -1
|
||||||
knownButtonY = -1
|
originalBedButtonY = -1
|
||||||
knownButton = null
|
|
||||||
knownButtonScreen = null
|
|
||||||
|
|
||||||
if (minecraft.player == null) return
|
if (minecraft.player == null) return
|
||||||
|
|
||||||
@ -102,16 +80,6 @@ object MatteryGUI {
|
|||||||
if (it.isAndroid) screen.title = TranslatableComponent("otm.death_reason")
|
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 {
|
private val FOOD_LEVEL_ELEMENT by lazy {
|
||||||
|
@ -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_97723_ # doubleclick
|
||||||
protected net.minecraft.client.gui.screens.inventory.AbstractContainerScreen f_97724_ # lastQuickMoved
|
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.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
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user