Skip to content

Commit

Permalink
Updated to support Minecraft 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
Visual-Vincent committed Jul 13, 2022
1 parent dbbda17 commit 2360fc3
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 536 deletions.
2 changes: 1 addition & 1 deletion Build and copy to mods.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
set MCVERSION=1.18.1
set MCVERSION=1.19
set MODVERSION=1.1
gradlew build && copy "build\libs\PlayerStatisticsList-%MCVERSION%-%MODVERSION%.jar" "%AppData%\.minecraft\mods\PlayerStatisticsList-%MCVERSION%-%MODVERSION%.jar"
pause
4 changes: 2 additions & 2 deletions Forge-README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md

Additional Resources:
=========================
Community Documentation: http://mcforge.readthedocs.io/en/latest/gettingstarted/
Community Documentation: https://mcforge.readthedocs.io/en/latest/gettingstarted/
LexManos' Install Video: https://www.youtube.com/watch?v=8VEdtQLuLO0
Forge Forum: https://forums.minecraftforge.net/
Forge Discord: https://discord.gg/UvedJ9m
Forge Discord: https://discord.gg/UvedJ9m
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ A Minecraft Forge mod showing relevant statistics about the player and the world

This mod is client-side only, meaning the server(s) you are joining don't need to be modded in order for this mod to work for you.

The code in this project is several years old and in need of a huge refactor. Read it at your own risk. :)

## Requirements
For running:
- Minecraft Forge Client 39.0.10 or higher (MC version 1.18.1)
- Minecraft Forge Client 41.0.98 or higher (MC version 1.19)

For building:
- Java SE Development Kit 17 / OpenJDK 17 or higher
Expand Down
81 changes: 43 additions & 38 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
buildscript {
repositories {
// These repositories are only for Gradle plugins, put any other repositories in the repository block further below
maven { url = 'https://maven.minecraftforge.net' }
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
}
plugins {
id 'eclipse'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '5.1.+'
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.18.1-1.1'
version = '1.19-1.1'
group = 'com.mydoomsite.statsmod' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'PlayerStatisticsList'

// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)

println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}"
minecraft {
// The mappings can be changed at any time and must be in the following format.
// Channel: Version:
// snapshot YYYYMMDD Snapshot are built nightly.
// stable # Stables are built at the discretion of the MCP team.
// official MCVersion Official field/method names from Mojang mapping files
// official MCVersion Official field/method names from Mojang mapping files
// parchment YYYY.MM.DD-MCVersion Open community-sourced parameter names and javadocs layered on top of official
//
// You must be aware of the Mojang license when using the 'official' mappings.
// You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
// See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
//
// Parchment is an unofficial project maintained by ParchmentMC, separate from MinecraftForge
// Additional setup is needed to use their mappings: https://github.com/ParchmentMC/Parchment/wiki/Getting-Started
//
// Use non-default mappings at your own risk. They may not always work.
// Simply re-run your setup task after changing the mappings to update your workspace.
mappings channel: 'official', version: '1.18.1'
mappings channel: 'official', version: '1.19'

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.

Expand All @@ -55,8 +48,11 @@ minecraft {
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', 'mydoomsite_statsmod'

mods {
examplemod {
mydoomsite_statsmod {
source sourceSets.main
}
}
Expand All @@ -65,18 +61,31 @@ minecraft {
server {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

property 'forge.enabledGameTestNamespaces', 'mydoomsite_statsmod'

mods {
mydoomsite_statsmod {
source sourceSets.main
}
}
}

// This run config launches GameTestServer and runs all registered gametests, then exits.
// By default, the server will crash when no gametests are provided.
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
workingDirectory project.file('run')

property 'forge.logging.markers', 'REGISTRIES'

property 'forge.logging.console.level', 'debug'

property 'forge.enabledGameTestNamespaces', 'mydoomsite_statsmod'

mods {
mydoomsite_statsmod {
source sourceSets.main
Expand All @@ -87,16 +96,8 @@ minecraft {
data {
workingDirectory project.file('run')

// Recommended logging data for a userdev environment
// The markers can be added/remove as needed separated by commas.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'

// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'

// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
Expand Down Expand Up @@ -128,7 +129,7 @@ dependencies {
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
minecraft 'net.minecraftforge:forge:1.18.1-39.0.10'
minecraft 'net.minecraftforge:forge:1.19-41.0.98'

// Real mod deobf dependency examples - these get remapped to your current mappings
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
Expand Down Expand Up @@ -176,3 +177,7 @@ publishing {
}
}
}

tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 5 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
Expand Down
6 changes: 6 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/mydoomsite/statsmod/Main/Drawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mydoomsite.statsmod.lib.TextMetrics;

import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.network.chat.Component;

public class Drawing
{
Expand Down Expand Up @@ -97,6 +97,6 @@ public static void DrawTextScaled(PoseStack matrixStack, String text, float x, f

public static void sendChatMessageToClient(String message)
{
minecraft.player.sendMessage(new TextComponent("\u00A7l\u00A7e[Statistics List]\u00A7r " + message), null);
minecraft.player.displayClientMessage(Component.literal("\u00A7l\u00A7e[Statistics List]\u00A7r " + message), false); // false = Display in chat, true = Display above status bar
}
}
9 changes: 8 additions & 1 deletion src/main/java/com/mydoomsite/statsmod/Main/MainRegistry.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mydoomsite.statsmod.Main;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.IExtensionPoint;
Expand Down Expand Up @@ -29,6 +30,7 @@ public MainRegistry()
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::Setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::ClientSetup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::RegisterKeyBindings);
});
}

Expand All @@ -41,7 +43,12 @@ private void ClientSetup(final FMLClientSetupEvent event)
{
StringHelper.Initialize();
MinecraftForge.EVENT_BUS.register(RenderHandler.Instance);
MinecraftForge.EVENT_BUS.register(new KeyBindings());
MinecraftForge.EVENT_BUS.register(KeyBindings.Instance);
MinecraftForge.EVENT_BUS.register(new TickHandlers());
}

private void RegisterKeyBindings(RegisterKeyMappingsEvent event)
{
KeyBindings.RegisterKeyBindings(event);
}
}
23 changes: 15 additions & 8 deletions src/main/java/com/mydoomsite/statsmod/handlers/KeyBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ChatScreen;
import net.minecraftforge.client.ClientRegistry;
import net.minecraftforge.client.event.InputEvent.KeyInputEvent;
import net.minecraftforge.client.event.InputEvent.Key;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class KeyBindings
public final class KeyBindings
{
public static KeyBindings Instance = new KeyBindings();

public static final int ShowHideList = 0;
public static final int ShowHideCoords = 1;
public static final int ResetDistances = 2;
Expand Down Expand Up @@ -48,23 +50,29 @@ public class KeyBindings
GLFW.GLFW_KEY_KP_7
};

private final KeyMapping[] keys;
private static KeyMapping[] keys;

private static Minecraft minecraft = Minecraft.getInstance();

public KeyBindings()
private KeyBindings() {}

@SubscribeEvent
public static void RegisterKeyBindings(RegisterKeyMappingsEvent event)
{
if(keys != null)
return;

keys = new KeyMapping[desc.length];

for (int i = 0; i < desc.length; ++i)
{
keys[i] = new KeyMapping(desc[i], keyValues[i], "Player Statistics List");
ClientRegistry.registerKeyBinding(keys[i]);
event.register(keys[i]);
}
}

@SubscribeEvent
public void onKeyInput(KeyInputEvent event)
public void onKeyInput(Key event)
{
if ((minecraft.isWindowActive() || (minecraft.screen != null && (minecraft.screen instanceof ChatScreen))) && !minecraft.options.renderDebug)
{
Expand Down Expand Up @@ -124,5 +132,4 @@ else if(keys[StartStopMeasurement].isDown())
}
}
}

}
Loading

0 comments on commit 2360fc3

Please sign in to comment.