Skip to content

Commit

Permalink
hud fixes and some events [OC-41], [OC-37], [OC-38]
Browse files Browse the repository at this point in the history
  • Loading branch information
nextdayy committed Dec 22, 2024
1 parent 5a5a965 commit 8476433
Show file tree
Hide file tree
Showing 13 changed files with 301 additions and 31 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name=OneConfig
mod_id=oneconfig
version_major=1
version_minor=0
version_patch=0-alpha.43
version_patch=0-alpha.44

polyfrost.defaults.loom=3

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.event.v1.events;

/**
* Called when the client successfully logs into a server.
*/
public class ServerJoinEvent implements Event {
public static final ServerJoinEvent INSTANCE = new ServerJoinEvent();

private ServerJoinEvent() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.event.v1.events;

/**
* Called when a sound is played.
* <br>
* Due to Minecraft versioning, the sound object can be of different types. it is safe to cast this to the appropriate type for your version (e.g. ISound for 1.8.9)
*/
public class SoundPlayEvent extends Event.Cancellable {
private final Object sound;

public SoundPlayEvent(Object sound) {
this.sound = sound;
}

public <T> T component1() {
return getSound();
}

/**
* Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version.
* <ul>
* <li>For modern forge, this will be a ClientLevel.</li>
* <li>For fabric & forge pre-1.17, this will be a ClientWorld.</li>
* </ul>
*/
@SuppressWarnings("unchecked")
public <T> T getSound() {
return (T) sound;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of OneConfig.
* OneConfig - Next Generation Config Library for Minecraft: Java Edition
* Copyright (C) 2021~2024 Polyfrost.
* <https://polyfrost.org> <https://github.com/Polyfrost/>
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* OneConfig is licensed under the terms of version 3 of the GNU Lesser
* General Public License as published by the Free Software Foundation, AND
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost,
* either version 1.0 of the Additional Terms, 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License. If not, see <https://www.gnu.org/licenses/>. You should
* have also received a copy of the Additional Terms Applicable
* to OneConfig, as published by Polyfrost. If not, see
* <https://polyfrost.org/legal/oneconfig/additional-terms>
*/

package org.polyfrost.oneconfig.api.event.v1.events;

/**
* Called when the world is unloaded.
*/
public class WorldUnloadEvent implements Event {
private final Object world;

public WorldUnloadEvent(Object world) {
this.world = world;
}

/**
* Due to differences across Minecraft versions, this is a Duck method, meaning that it will return the expected type for that minecraft version.
* <ul>
* <li>For modern forge, this will be a ClientLevel.</li>
* <li>For fabric & forge pre-1.17, this will be a ClientWorld.</li>
* </ul>
*/
@SuppressWarnings("unchecked")
public <T> T getWorld() {
return (T) world;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ private fun Drawable.addScaler(): Drawable {
return this
}

private fun Component.trySnapX(lx: Float): Boolean {
private fun Component.trySnapX(lx: Float, sw: Float): Boolean {
val low = lx - snapMargin
val high = lx + snapMargin
if (x + (width / 2f) in low..high) {
x = lx - (width / 2f)
if (x + (sw / 2f) in low..high) {
x = lx - (sw / 2f)
HudManager.slinex = lx
return true
}
Expand All @@ -238,19 +238,19 @@ private fun Component.trySnapX(lx: Float): Boolean {
HudManager.slinex = lx
return true
}
if (x + width in low..high) {
x = lx - width
if (x + sw in low..high) {
x = lx - sw
HudManager.slinex = lx
return true
}
return false
}

private fun Component.trySnapY(ly: Float): Boolean {
private fun Component.trySnapY(ly: Float, sh: Float): Boolean {
val low = ly - snapMargin
val high = ly + snapMargin
if (y + (height / 2f) in low..high) {
y = ly - (height / 2f)
if (y + (sh / 2f) in low..high) {
y = ly - (sh / 2f)
HudManager.sliney = ly
return true
}
Expand All @@ -259,8 +259,8 @@ private fun Component.trySnapY(ly: Float): Boolean {
HudManager.sliney = ly
return true
}
if (y + height in low..high) {
y = ly - height
if (y + sh in low..high) {
y = ly - sh
HudManager.sliney = ly
return true
}
Expand All @@ -270,12 +270,14 @@ private fun Component.trySnapY(ly: Float): Boolean {
/**
* Method to be used as the `onDrag` handler for HUD elements.
*/
fun Component.snapHandler() {
fun Drawable.snapHandler() {
val vs = visibleSize
val w = vs.x * scaleX
val h = vs.y * scaleY
if (cur === this) {
val vs = visibleSize
scaleBlob.let {
it.x = x + vs.x - (it.width / 2f)
it.y = y + vs.y - (it.height / 2f)
it.x = x + w - (it.width / 2f)
it.y = y + h - (it.height / 2f)
}
}
HudManager.slinex = -1f
Expand All @@ -284,13 +286,13 @@ fun Component.snapHandler() {

// asm: process screen edge snaps + center snap
// checking center snaps first seems to make it easier to use
var hran = trySnapX(polyUI.size.x / 2f) ||
trySnapX(1f) ||
trySnapX(polyUI.size.x - 1f)
var hran = trySnapX(polyUI.size.x / 2f, w) ||
trySnapX(1f, w) ||
trySnapX(polyUI.size.x - 1f, w)

var vran = trySnapY(polyUI.size.y / 2f) ||
trySnapY(1f) ||
trySnapY(polyUI.size.y - 1f)
var vran = trySnapY(polyUI.size.y / 2f, h) ||
trySnapY(1f, h) ||
trySnapY(polyUI.size.y - 1f, h)

// yipee!
if (hran && vran) return
Expand All @@ -300,24 +302,28 @@ fun Component.snapHandler() {
if (it === this) return@fastEach
if (it === HudManager.panel || it === scaleBlob) return@fastEach
if (!it.renders) return@fastEach
if (it !is Drawable) return@fastEach
val ivs = it.visibleSize
val iw = ivs.x * it.scaleX
val ih = ivs.y * it.scaleY

if (!hran) {
hran = trySnapX(it.x + (it.width / 2f)) ||
trySnapX(it.x) ||
trySnapX(it.x + it.width)
hran = trySnapX(it.x + (iw / 2f), w) ||
trySnapX(it.x, w) ||
trySnapX(it.x + iw, w)
}
if (!vran) {
vran = trySnapY(it.y + (it.height / 2f)) ||
trySnapY(it.y) ||
trySnapY(it.y + it.height)
vran = trySnapY(it.y + (ih / 2f), h) ||
trySnapY(it.y, h) ||
trySnapY(it.y + ih, h)
}

// YIPEEE!
if (hran && vran) return
}
}

fun Component.snapHandlerNew() {
fun Drawable.snapHandlerNew() {
// closes the hud manager and prepares the hud to be added once it is dragged outside of it
if (polyUI.mouseX !in (polyUI.size.x - HudManager.panel.width)..polyUI.size.x) {
if (HudManager.panelOpen) HudManager.toggle()
Expand Down
3 changes: 3 additions & 0 deletions versions/mappings/forge-1.16.5-1.12.2.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
net.minecraft.client.audio.SoundEngine net.minecraft.client.audio.SoundManager

net.minecraft.client.Minecraft gameRenderer entityRenderer
net.minecraft.client.Minecraft getInstance() getMinecraft()
net.minecraft.client.Minecraft isOnExecutionThread() isCallingFromMinecraftThread()
Expand All @@ -13,6 +15,7 @@ net.minecraft.client.gui.screen.Screen resize() onResize()
net.minecraft.client.gui.widget.button.Button net.minecraft.client.gui.GuiButton
net.minecraft.client.gui.widget.button.Button playDownSound() playPressSound()

net.minecraft.client.network.login.ClientLoginNetHandler net.minecraft.client.network.NetHandlerLoginClient
net.minecraft.client.network.play.ClientPlayNetHandler net.minecraft.client.network.NetHandlerPlayClient
net.minecraft.client.network.play.NetworkPlayerInfo net.minecraft.client.network.NetworkPlayerInfo

Expand Down
7 changes: 7 additions & 0 deletions versions/mappings/forge-1.17.1-1.16.5.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ com.mojang.blaze3d.vertex.Tesselator end() draw()
com.mojang.blaze3d.vertex.Tesselator getBuilder() getBuffer()
com.mojang.blaze3d.vertex.Tesselator net.minecraft.client.renderer.Tessellator

net.minecraft.client.sounds.SoundEngine net.minecraft.client.audio.SoundEngine

net.minecraft.ChatFormatting net.minecraft.util.text.TextFormatting
net.minecraft.ChatFormatting stripFormatting() getTextWithoutFormattingCodes()

Expand All @@ -48,6 +50,7 @@ net.minecraft.client.Minecraft options gameSettings
net.minecraft.client.Minecraft resizeDisplay() updateWindowSize()
net.minecraft.client.Minecraft runTick() runGameLoop()
net.minecraft.client.Minecraft screen currentScreen
net.minecraft.client.Minecraft setLevel() loadWorld()
net.minecraft.client.Minecraft setScreen() displayGuiScreen()

net.minecraft.client.MouseHandler net.minecraft.client.MouseHelper
Expand Down Expand Up @@ -84,6 +87,8 @@ net.minecraft.client.gui.screens.Screen net.minecraft.client.gui.screen.Screen
net.minecraft.client.multiplayer.ClientLevel$ClientLevelData net.minecraft.client.multiplayer.ClientLevel$ClientWorldInfo
net.minecraft.client.multiplayer.ClientLevel net.minecraft.client.world.ClientWorld

net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl net.minecraft.client.network.login.ClientLoginNetHandler
net.minecraft.client.multiplayer.ClientHandshakePacketListenerImpl handleGameProfile() handleLoginSuccess()
net.minecraft.client.multiplayer.ClientPacketListener commands commandDispatcher
net.minecraft.client.multiplayer.ClientPacketListener getSuggestionsProvider() getSuggestionProvider()
net.minecraft.client.multiplayer.ClientPacketListener handleCommands() handleCommandList()
Expand Down Expand Up @@ -114,6 +119,8 @@ net.minecraft.client.renderer.PostPass net.minecraft.client.shader.Shader

net.minecraft.client.resources.language.I18n get() format()
net.minecraft.client.resources.language.I18n net.minecraft.client.resources.I18n
net.minecraft.client.resources.sounds.SoundInstance net.minecraft.client.audio.ISound
net.minecraft.client.resources.sounds.SoundInstance getLocation() getSoundLocation()

net.minecraft.commands.SharedSuggestionProvider net.minecraft.command.ISuggestionProvider

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.polyfrost.oneconfig.api.event.v1.events.InitializationEvent;
import org.polyfrost.oneconfig.api.hud.v1.HudManager;
import org.polyfrost.oneconfig.api.hypixel.v1.HypixelUtils;
import org.polyfrost.oneconfig.api.platform.v1.LoaderPlatform;
import org.polyfrost.oneconfig.api.platform.v1.Platform;
import org.polyfrost.oneconfig.api.ui.v1.UIManager;
import org.polyfrost.oneconfig.api.ui.v1.internal.BlurHandler;
Expand Down Expand Up @@ -89,6 +90,9 @@ private void onInit(net.minecraftforge.fml.common.event.FMLPostInitializationEve


private void init() {
LoaderPlatform.ActiveMod self = Platform.loader().getLoadedMod("oneconfig");
String v = self == null ? "LOCAL" : self.version;
LOGGER.info("Loading OneConfig v{}", v);
BlurHandler.init();

preloadCopycat();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public List<String> getMixins() {
mixins.add("MouseMixin");
mixins.add("commands.ClientPlayNetworkHandlerMixin");
mixins.add("commands.HelpCommandAccessor");
if (version < 19000) {
if (version < 11900) {
// 1.16, 1.17, 1.18
mixins.add("SchemasMixin");
mixins.add("EntityPlayerSPMixin");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package org.polyfrost.oneconfig.internal.mixin;

import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.Timer;
import org.polyfrost.oneconfig.api.event.v1.EventManager;
import org.polyfrost.oneconfig.api.event.v1.events.*;
Expand All @@ -48,14 +49,16 @@ public abstract class MinecraftMixin {
@Shadow
private Timer timer;

//@formatter:off
//#if MC<11300
@Shadow public int displayWidth;
@Shadow public int displayHeight;
@Shadow private int tempDisplayWidth;
@Shadow private int tempDisplayHeight;
//#endif

//@formatter:off
@Shadow public WorldClient theWorld;

@Unique
private static final String UPDATE_CAMERA_AND_RENDER =
//#if MC>=11300
Expand Down Expand Up @@ -131,6 +134,11 @@ private void tickEndCallback(CallbackInfo ci) {
EventManager.INSTANCE.post(TickEvent.End.INSTANCE);
}

@Inject(method = "loadWorld(Lnet/minecraft/client/multiplayer/WorldClient;)V", at = @At("HEAD"))
private void onWorldUnloadCallback(WorldClient world, CallbackInfo ci) {
if (this.theWorld != null) EventManager.INSTANCE.post(new WorldUnloadEvent(this.theWorld));
}

//#if FORGE
@ModifyArg(method = "displayGuiScreen", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/common/eventhandler/EventBus;post(Lnet/minecraftforge/fml/common/eventhandler/Event;)Z", remap = false))
private Event screenOpenCallback(Event a) {
Expand Down
Loading

0 comments on commit 8476433

Please sign in to comment.