diff --git a/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/DefaultGameEventHandlers.kt b/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/DefaultGameEventHandlers.kt index afba0a7c0..7735ffad6 100644 --- a/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/DefaultGameEventHandlers.kt +++ b/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/DefaultGameEventHandlers.kt @@ -1,6 +1,6 @@ /* * Minosoft - * Copyright (C) 2021 Moritz Zwerger + * Copyright (C) 2020-2022 Moritz Zwerger * * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * @@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.registries.other.game.event.handlers.gradients.R import de.bixilon.minosoft.data.registries.other.game.event.handlers.gradients.ThunderGradientSetGameEventHandler import de.bixilon.minosoft.data.registries.other.game.event.handlers.rain.RainStartGameEventHandler import de.bixilon.minosoft.data.registries.other.game.event.handlers.rain.RainStopGameEventHandler +import de.bixilon.minosoft.data.registries.other.game.event.handlers.win.WinGameEventHandler object DefaultGameEventHandlers : DefaultFactory( GamemodeChangeGameEventHandler, @@ -27,4 +28,5 @@ object DefaultGameEventHandlers : DefaultFactory( RainStopGameEventHandler, RainGradientSetGameEventHandler, ThunderGradientSetGameEventHandler, + WinGameEventHandler, ) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/handlers/win/WinGameEvent.kt b/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/handlers/win/WinGameEvent.kt new file mode 100644 index 000000000..9c00458ec --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/handlers/win/WinGameEvent.kt @@ -0,0 +1,24 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.data.registries.other.game.event.handlers.win + +import de.bixilon.minosoft.modding.event.EventInitiators +import de.bixilon.minosoft.modding.event.events.connection.play.PlayConnectionEvent +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection + +class WinGameEvent( + connection: PlayConnection, + initiator: EventInitiators, + val showCredits: Boolean, +) : PlayConnectionEvent(connection, initiator) diff --git a/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/handlers/win/WinGameEventHandler.kt b/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/handlers/win/WinGameEventHandler.kt new file mode 100644 index 000000000..327c0b3ec --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/data/registries/other/game/event/handlers/win/WinGameEventHandler.kt @@ -0,0 +1,33 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.data.registries.other.game.event.handlers.win + +import de.bixilon.minosoft.data.registries.ResourceLocation +import de.bixilon.minosoft.data.registries.other.game.event.handlers.GameEventHandler +import de.bixilon.minosoft.modding.event.EventInitiators +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection +import de.bixilon.minosoft.protocol.packets.c2s.play.ClientActionC2SP +import de.bixilon.minosoft.util.KUtil.toResourceLocation + +object WinGameEventHandler : GameEventHandler { + override val RESOURCE_LOCATION: ResourceLocation = "minecraft:win_game".toResourceLocation() + + override fun handle(data: Float, connection: PlayConnection) { + val credits = data.toInt() == 0x01 + connection.fireEvent(WinGameEvent(connection, EventInitiators.SERVER, credits)) + if (!credits) { + connection.sendPacket(ClientActionC2SP(ClientActionC2SP.ClientActions.PERFORM_RESPAWN)) + } + } +} diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt index b51625832..942a4c1fd 100644 --- a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/GUIManager.kt @@ -27,6 +27,7 @@ import de.bixilon.minosoft.gui.rendering.gui.elements.Element import de.bixilon.minosoft.gui.rendering.gui.elements.LayoutedElement import de.bixilon.minosoft.gui.rendering.gui.elements.Pollable import de.bixilon.minosoft.gui.rendering.gui.gui.dragged.Dragged +import de.bixilon.minosoft.gui.rendering.gui.gui.screen.CreditsScreen import de.bixilon.minosoft.gui.rendering.gui.gui.screen.SignEditorScreen import de.bixilon.minosoft.gui.rendering.gui.gui.screen.container.ContainerGUIManager import de.bixilon.minosoft.gui.rendering.gui.gui.screen.menu.pause.PauseMenu @@ -60,6 +61,7 @@ class GUIManager( ContainerGUIManager.register(guiRenderer) SignEditorScreen.register(guiRenderer) RespawnMenu.register(guiRenderer) + CreditsScreen.register(guiRenderer) } override fun postInit() { diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/CreditsScreen.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/CreditsScreen.kt new file mode 100644 index 000000000..bf35738bd --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/gui/rendering/gui/gui/screen/CreditsScreen.kt @@ -0,0 +1,63 @@ +/* + * Minosoft + * Copyright (C) 2020-2022 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.gui.rendering.gui.gui.screen + +import de.bixilon.kotlinglm.vec2.Vec2i +import de.bixilon.minosoft.data.registries.other.game.event.handlers.win.WinGameEvent +import de.bixilon.minosoft.gui.rendering.gui.GUIRenderer +import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments +import de.bixilon.minosoft.gui.rendering.gui.elements.HorizontalAlignments.Companion.getOffset +import de.bixilon.minosoft.gui.rendering.gui.elements.text.TextElement +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexConsumer +import de.bixilon.minosoft.gui.rendering.gui.mesh.GUIVertexOptions +import de.bixilon.minosoft.modding.event.invoker.CallbackEventInvoker +import de.bixilon.minosoft.protocol.packets.c2s.play.ClientActionC2SP + +@Deprecated("ToDo") +class CreditsScreen( + guiRenderer: GUIRenderer, +) : Screen(guiRenderer) { + private val headerElement = TextElement(guiRenderer, "Minecraft", background = false, scale = 3.0f, parent = this) + private val textElement = TextElement(guiRenderer, "Ähm, yes. This is not yet implemented -/-\nI am so sorry...", background = false, parent = this) + + + override fun forceRender(offset: Vec2i, consumer: GUIVertexConsumer, options: GUIVertexOptions?) { + super.forceRender(offset, consumer, options) + + val size = size + + headerElement.render(offset + HorizontalAlignments.CENTER.getOffset(size, headerElement.size), consumer, options) + offset.y += headerElement.size.y + + offset.y += size.y / 30 + textElement.render(offset + HorizontalAlignments.CENTER.getOffset(size, textElement.size), consumer, options) + } + + override fun onClose() { + super.onClose() + guiRenderer.connection.sendPacket(ClientActionC2SP(ClientActionC2SP.ClientActions.PERFORM_RESPAWN)) + } + + companion object { + + fun register(guiRenderer: GUIRenderer) { + guiRenderer.connection.registerEvent(CallbackEventInvoker.of { + if (!it.showCredits) { + return@of + } + guiRenderer.gui.push(CreditsScreen(guiRenderer)) + }) + } + } +} diff --git a/src/main/resources/assets/minosoft/mapping/default_registries.json b/src/main/resources/assets/minosoft/mapping/default_registries.json index dbeefe74b..6b2d6666b 100644 --- a/src/main/resources/assets/minosoft/mapping/default_registries.json +++ b/src/main/resources/assets/minosoft/mapping/default_registries.json @@ -527,7 +527,7 @@ "minecraft:gamemode_change": { "id": 3 }, - "minecraft:show_credits": { + "minecraft:win_game": { "id": 4 }, "minecraft:hide_demo_messages": { @@ -562,7 +562,7 @@ "minecraft:gamemode_change": { "id": 3 }, - "minecraft:show_credits": { + "minecraft:win_game": { "id": 4 }, "minecraft:hide_demo_messages": {