Skip to content

Commit

Permalink
fixed main menu and ping mod, added translations for combo mod in mai…
Browse files Browse the repository at this point in the history
…n menu
  • Loading branch information
PepperLola committed Jan 2, 2022
1 parent 494d5d4 commit f7bea21
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 44 deletions.
15 changes: 7 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@ buildscript {
mavenLocal()
mavenCentral()

maven { url 'https://maven.minecraftforge.net' }
maven { url 'https://files.minecraftforge.net/maven' }
maven { url 'https://plugins.gradle.org/m2' }
maven { url 'https://repo.spongepowered.org/repository/maven-public/' }
maven { url 'https://jitpack.io' }
}

dependencies {
classpath('com.github.ReplayMod:ForgeGradle:' + (
'48c4f0c' // FG 2.1
) + ':all') {
exclude group: 'net.sf.trove4j', module: 'trove4j' // preprocessor/idea requires more recent one
exclude group: 'trove', module: 'trove' // different name same thing
}
// classpath('com.github.ReplayMod:ForgeGradle:ceb83c0:all') {
// exclude group: 'net.sf.trove4j', module: 'trove4j' // preprocessor/idea requires more recent one
// exclude group: 'trove', module: 'trove' // different name same thing
// }
classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
// classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT'
classpath "org.spongepowered:mixingradle:0.6-SNAPSHOT"
classpath "com.github.jengelman.gradle.plugins:shadow:1.2.3"
Expand All @@ -38,7 +37,7 @@ sourceSets {
main.resources.srcDirs += '../shared/main/resources'
}

version = "1.17.15"
version = "1.17.16"
group= "com.palight.playerinfo" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "playerinfo"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/palight/playerinfo/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PlayerInfo
//TODO update version here and in build.gradle
public static final String NAME = "playerinfo";
public static final String MODID = "playerinfo";
public static final String VERSION = "1.17.15";
public static final String VERSION = "1.17.16";
public static String commitHash;
public static String defaultBranchName = "master";
public static String githubAPIURL = "https://api.github.com/repos/PepperLola/playerinfo/git/refs/heads/" + defaultBranchName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
for (GuiCustomWidget guiElement : guiElements) {
if (NumberUtil.isBetween(guiElement.yPosition, (height - ySize) / 2 + headerHeight, (height + ySize) / 2 - footerHeight)) {
if (NumberUtil.isBetween(guiElement.yPosition, (height - ySize) / 2 + headerHeight, (height + ySize) / 2 - footerHeight - guiElement.height)) {
guiElement.drawWidget(mc, mouseX, mouseY);
}
guiElement.yPosition += getScrollAmount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MainGui extends CustomGuiScreenScrollable {
private final int hPadding = 4;
private final int columns = 2;
private int columnWidth;
private final int rowHeight = 104;
private final int ROW_HEIGHT = 52;

private int buttonX;
private int buttonY;
Expand All @@ -44,7 +44,7 @@ public class MainGui extends CustomGuiScreenScrollable {

private GuiTextField filterTextInput;

List<GuiModuleEntry> modules = new ArrayList<>();
private List<GuiModuleEntry> modules = new ArrayList<>();

public MainGui() {
super("screen.main");
Expand All @@ -66,7 +66,7 @@ public void initGui() {

this.menuBar = new GuiMenuBar(1, (width - xSize) / 2 + 67, (height - ySize) / 2 + 5, 180, 16, new CustomGuiScreen[]{new InfoGui(), new ServerSelector(), new LifxGui(), new CalculatorGui()});

this.settingsGuiButton = new GuiTexturedButton(2, (width - xSize) / 2 + 226 - 24, (this.height + ySize) / 2 - 24, 20, 20, 0, 0);
this.settingsGuiButton = new GuiTexturedButton(2, guiX + leftOffset + xSize - 110, (this.height + ySize) / 2 - 24, 20, 20, 0, 0);
this.editModsButton = new GuiButton(3, guiX + leftOffset + 2, (height + ySize) / 2 - 24, 48, 20, "Edit GUI");

this.buttonList.addAll(Arrays.asList(
Expand Down Expand Up @@ -100,8 +100,8 @@ private void renderModules() {
for (int i = 0; i < filteredModules.size(); i++) {
Module module = filteredModules.get(i);
int xPosition = guiX + leftOffset + hPadding + (columnWidth * (i % columns));
int yPosition = guiY + headerHeight + (i - (i / columns)) * rowHeight + 4;
GuiModuleEntry entry = new GuiModuleEntry(this, i, module, xPosition, yPosition, columnWidth, rowHeight);
int yPosition = guiY + headerHeight + (i / columns) * ROW_HEIGHT + 4;
GuiModuleEntry entry = new GuiModuleEntry(this, i, module, xPosition, yPosition, columnWidth, ROW_HEIGHT);
entry.init();
modules.add(entry);
}
Expand All @@ -121,8 +121,6 @@ protected void keyTyped(char typed, int modifier) throws IOException {

@Override
protected void actionPerformed(GuiButton b) {
System.out.println(b.id);

EntityPlayer player = Minecraft.getMinecraft().thePlayer;
World playerWorld = player.getEntityWorld();
BlockPos playerLocation = player.getPosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

public class GuiModuleEntry extends GuiCustomWidget {

private GuiButton toggleButton;
private final GuiButton toggleButton;
private GuiTexturedButton optionsButton;
private Module module;
private CustomGuiScreen owningScreen;
private final Module module;
private final CustomGuiScreen owningScreen;

private String formattedName;
private String formattedDescription;
private final String formattedName;
private final String formattedDescription;

private int buttonX;
private int buttonY;
Expand Down Expand Up @@ -52,13 +52,15 @@ public void init() {
public void drawWidget(Minecraft mc, int mouseX, int mouseY) {
super.drawWidget(mc, mouseX, mouseY);
this.drawGradientRect(xPosition, yPosition, xPosition + width, yPosition + height, 0x22ffffff, 0x22ffffff);

PlayerInfo.instance.fontRendererObj.drawString(formattedName, xPosition + (width - PlayerInfo.instance.fontRendererObj.getWidth(formattedName)) / 2, yPosition, 0xffffffff);
// this.drawString(mc.fontRendererObj, formattedName, xPosition + (width - mc.fontRendererObj.getStringWidth(formattedName)) / 2, yPosition, 0xffffffff);

List<String> lines = PlayerInfo.instance.fontRendererObj.splitString(formattedDescription, width);
PlayerInfo.instance.fontRendererObj.drawSplitString(lines, xPosition, yPosition + PlayerInfo.instance.fontRendererObj.FONT_HEIGHT, 0xffffff);
// owningScreen.drawTextMultiLine(formattedDescription, xPosition, yPosition + mc.fontRendererObj.FONT_HEIGHT + 4, 0xffffffff, width, true);

buttonX = xPosition;
buttonY = yPosition + 32;

this.toggleButton.yPosition = this.yPosition + 32;
this.toggleButton.drawWidget(mc, mouseX, mouseY);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.palight.playerinfo.mixin.client.network;

import com.palight.playerinfo.PlayerInfo;
import com.palight.playerinfo.modules.impl.gui.PingMod;
import com.palight.playerinfo.modules.impl.misc.ComboMod;
import com.palight.playerinfo.modules.impl.misc.TimeChangerMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.network.PacketThreadUtil;
import net.minecraft.network.play.server.S03PacketTimeUpdate;
import net.minecraft.network.play.server.S19PacketEntityStatus;
import net.minecraft.network.play.server.S37PacketStatistics;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -28,6 +30,11 @@ public void handleEntityStatus(S19PacketEntityStatus packet, CallbackInfo ci) {
((ComboMod) PlayerInfo.getModules().get("combo")).onEntityStatusPacket(packet);
}

@Inject(method = "handleStatistics", at = @At("HEAD"))
public void handleStatistics(S37PacketStatistics packet, CallbackInfo ci) {
((PingMod) PlayerInfo.getModules().get("ping")).onEntityStatisticsPacket(packet);
}

/**
* @author Finbarr-1
* @reason Ignore time changing when custom time is set.
Expand Down
43 changes: 23 additions & 20 deletions src/main/java/com/palight/playerinfo/modules/impl/gui/PingMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,46 @@
import com.palight.playerinfo.gui.ingame.widgets.impl.PingWidget;
import com.palight.playerinfo.modules.Module;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.util.Session;
import net.minecraft.network.play.client.C16PacketClientStatus;
import net.minecraft.network.play.server.S37PacketStatistics;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class PingMod extends Module {
public long currentPing = -1;
private int counter = 0;
private int updateTimeout = 100; // in ticks

private long lastPing = -1L;

public PingMod() {
super("ping", ModuleType.GUI, null, new PingWidget());
}

@SubscribeEvent
public void onTick(TickEvent.PlayerTickEvent event) {
if (counter == updateTimeout) {
updatePing();
counter %= updateTimeout;
// 5 seconds
if (System.nanoTime() - Math.abs(lastPing) > 1000000L * 5000) {
sendPacket();
}

counter ++;
}

public void updatePing() {
// TODO separate into multiple lines and add null checks
NetHandlerPlayClient netHandlerPlayClient = Minecraft.getMinecraft().getNetHandler();
if (netHandlerPlayClient == null) return;

Session session = Minecraft.getMinecraft().getSession();
if (session == null || session.getProfile() == null || session.getProfile().getId() == null) return;
private void sendPacket() {
Minecraft.getMinecraft().thePlayer.sendQueue.getNetworkManager().sendPacket(new C16PacketClientStatus(C16PacketClientStatus.EnumState.REQUEST_STATS));
lastPing = System.nanoTime();
}

NetworkPlayerInfo networkPlayerInfo = netHandlerPlayClient.getPlayerInfo(session.getProfile().getId());
@SubscribeEvent
public void onPlayerJoin(EntityJoinWorldEvent event) {
if (event.entity.getUniqueID().equals(Minecraft.getMinecraft().thePlayer.getUniqueID())) {
this.lastPing = -1L;
}
}

if (networkPlayerInfo != null) {
currentPing = networkPlayerInfo.getResponseTime();
public void onEntityStatisticsPacket (S37PacketStatistics packet) {
if (lastPing > 0) {
long diff = (Math.abs(System.nanoTime() - lastPing) / 1000000);
this.lastPing *= -1;
this.currentPing = diff;
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/playerinfo/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.timeChanger.name=Time Changer
module.toggleSprint.name=Toggle Sprint
module.noteBlockHelper.name=Note Block Helper
module.entityRenderTweaks.name=Entity Render Tweaks
module.combo.name=Combo

module.armor.description=Shows which type of armor you're wearing, as well as its durability.
module.resources.description=Shows a resources count for bedwars.
Expand Down Expand Up @@ -97,5 +98,6 @@ module.timeChanger.description=Lets you change the in game time for you.
module.toggleSprint.description=Toggle sprint and sneak.
module.noteBlockHelper.description=Shows the tuning of note blocks.
module.entityRenderTweaks.description=Some useful/cosmetic tweaks for rendering entities.
module.combo.description=Shows your current combo in PvP.

upload.success=Upload successful
2 changes: 2 additions & 0 deletions src/main/resources/assets/playerinfo/lang/es_es.lang
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ module.timeChanger.name=Cambiador de Tiempo
module.toggleSprint.name=Alternar Sprint
module.noteBlockHelper.name=Aydante de Bloque de Notas
module.entityRenderTweaks.name=Ajustes de Visualización de Entidades
module.combo.name=Combo

module.armor.description=Muestra qué tipo de armadura estás usando, así como su durabilidad.
module.resources.description=Muestra un recuento de recursos para bedwars.
Expand Down Expand Up @@ -97,5 +98,6 @@ module.timeChanger.description=Te permite cambiar el tiempo de juego por ti.
module.toggleSprint.description=Alternar sprint y sneak.
module.noteBlockHelper.description=Muestra la afinación de bloques de notas.
module.entityRenderTweaks.description=Algunos ajustes útiles/cosméticos para renderizar entidades.
module.combo.description=Muestra su combo actual.

upload.success=Subir con éxito

0 comments on commit f7bea21

Please sign in to comment.