Compare commits

..

45 commits
v1.1.0 ... main

Author SHA1 Message Date
68aac66094 Update ChestGUI to new LibZontreck API 2024-01-15 00:56:27 -07:00
dbd34125f8 Fix non-functional reset button 2024-01-10 03:48:53 -07:00
b6d5c0c502 Fix non-functional reset button 2024-01-10 03:46:34 -07:00
bf2d5c83d9 Add a basic config gui to WMD when the jar is on the server 2024-01-10 03:31:48 -07:00
131cd673f8 Restructure some stuff 2024-01-09 14:57:08 -07:00
d3cbcc3f36 Rename package! 2024-01-09 14:52:40 -07:00
bb135ebd65 Update libz reference 2024-01-07 17:39:52 -07:00
bdaa4328f4 Update repository 2024-01-07 17:35:49 -07:00
a4a961afcb Update LibZ version 2024-01-02 18:09:34 -07:00
ec14da3bfa Update LibZ version 2023-12-18 15:33:14 -07:00
1c8d56f5ae Move hearts render over to Aria's Essentials 2023-12-15 23:56:35 -07:00
80720c7fbf Get hearts working again 2023-12-15 23:53:57 -07:00
bbf4e41abc Start re-adding the extra hearts function 2023-12-15 19:41:18 -07:00
f1fce3fbaa Update libzontreck version 2023-12-14 22:19:05 -07:00
1b369a0db5 Update libzontreck version 2023-12-14 22:15:55 -07:00
d002986525 Finish updating to 1.20 2023-11-19 08:19:21 -07:00
5d62d175af Add a hunger watcher instead of just health 2023-11-19 08:00:37 -07:00
0b94cbbc2f Mod is now functional on 1.20, but hunger watch is not functional 2023-11-19 07:07:42 -07:00
928e57c104 Start updating to 1.20 2023-11-19 06:14:32 -07:00
b45e9c3fec Update to 1.19.3, update DelayedExecutorService references. 2023-05-15 22:06:21 -07:00
8289bdecaf Patch for mods.toml to support 1.19 (oops) 2023-04-22 03:47:29 -07:00
574faa7b8d Push update for 1.19.4 2023-04-22 03:31:22 -07:00
9f8b5582f1 Update WMD to new LibZontreck API 2023-03-06 02:26:39 -07:00
3aee097fbc Update pack mcmeta. 2023-02-22 02:45:41 -07:00
c07662bd29 Disable hearts renderer 2023-02-22 02:44:06 -07:00
5a47daf797 Upgrade to 1.18.2 2023-02-22 02:42:55 -07:00
0f250f76bb Make executable 2023-02-01 19:42:04 -07:00
af8e2906bd Compile against new LZ 2023-01-22 13:30:03 -07:00
b701e649af Add minecraft version prefix to jar 2023-01-22 03:32:51 -07:00
973653712c Update LibZontreck compatibility 2023-01-22 03:30:37 -07:00
b616eeeeb2 WMD 1124 2023-01-07 21:56:01 -07:00
c2e6804138 update libzontreck version 2023-01-07 18:14:52 -07:00
10f3f668dc increment version 2023-01-07 17:43:24 -07:00
06f2cbfe57 oops forgot to update that! 2023-01-07 17:42:25 -07:00
5832412102 Update LibZontreck version reference. 2023-01-07 17:41:52 -07:00
6d9ef958e5 Downgrade to 1.19.2 2023-01-06 23:10:35 -07:00
0a69d6b008 Make compatible with 1.19.3 2023-01-03 21:28:36 -07:00
347e4937d5 Update library dependency 2022-10-17 05:56:25 -07:00
e27badd976 Publish as new version due to a bad jar upload 2022-10-14 04:02:35 -07:00
5a70c8f072 Update to 1.1.1.2 2022-10-13 21:32:10 -07:00
9507923f86 WMD 1.1.1.1 update due to hearts issue 2022-10-13 01:02:48 -07:00
4e7e18e705
Merge pull request #1 from zontreck/develop
Release 1.1.1
2022-10-13 00:01:58 -07:00
a179e53790 Fix version in mods.toml 2022-10-12 23:50:45 -07:00
b8a065590c Push next version of WMD 2022-10-12 23:50:06 -07:00
689485e337 Add new roadmap item 2022-09-27 02:59:09 -07:00
29 changed files with 1278 additions and 460 deletions

View file

@ -3,7 +3,7 @@ HOW TO BUILD
On your platform of choice
```
gradlew clean jar
gradlew clean build
```
@ -16,3 +16,4 @@ The following is the possible roadmap:
1. Create a spigot plugin variant.
2. Explore possibly making a quilt mod variant.
3. Create a permission that a server owner can set to block this mod from functioning on the client.

View file

@ -1,12 +1,17 @@
plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.minecraftforge.gradle' version '5.1.+'
id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
}
version = '1.1.0'
group = 'dev.zontreck.mcmods' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'WatchMyDurability'
version = mod_version
group = mod_group_id
base {
archivesName = mod_id
}
// Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17.
java.toolchain.languageVersion = JavaLanguageVersion.of(17)
@ -22,18 +27,40 @@ minecraft {
// 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
// Additional setup is needed to use their mappings: https://parchmentmc.org/docs/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.19.2'
mappings channel: mapping_channel, version: mapping_version
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.
// When true, this property will have all Eclipse/IntelliJ IDEA run configurations run the "prepareX" task for the given run configuration before launching the game.
// In most cases, it is not necessary to enable.
// enableEclipsePrepareRuns = true
// enableIdeaPrepareRuns = true
// This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
// It is REQUIRED to be set to true for this template to function.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
copyIdeResources = true
// When true, this property will add the folder name of all declared run configurations to generated IDE run configurations.
// The folder name can be set on a run configuration using the "folderName" property.
// By default, the folder name of a run configuration is the name of the Gradle project containing it.
// generateRunFolders = true
// This property enables access transformers for use in development.
// They will be applied to the Minecraft artifact.
// The access transformer file can be anywhere in the project.
// However, it must be at "META-INF/accesstransformer.cfg" in the final mod jar to be loaded by Forge.
// This default location is a best practice to automatically put the file in the right place in the final jar.
// See https://docs.minecraftforge.net/en/latest/advanced/accesstransformers/ for more information.
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
// applies to all the run configs below
configureEach {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
@ -48,66 +75,36 @@ 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', 'watchmydurability'
mods {
watchmydurability {
"${mod_id}" {
source sourceSets.main
}
}
}
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id
}
server {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
property 'forge.enabledGameTestNamespaces', 'watchmydurability'
mods {
watchmydurability {
source sourceSets.main
}
}
property 'forge.enabledGameTestNamespaces', mod_id
args '--nogui'
}
// 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', 'watchmydurability'
mods {
watchmydurability {
source sourceSets.main
}
}
property 'forge.enabledGameTestNamespaces', mod_id
}
data {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
// example of overriding the workingDirectory set in configureEach above
workingDirectory project.file('run-data')
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', 'watchmydurability', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods {
watchmydurability {
source sourceSets.main
}
}
args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
}
}
}
@ -119,54 +116,105 @@ repositories {
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html#sub:flat_dir_resolver
// flatDir {
// dir 'libs'
// }
maven {
name = "Aria's Creations Caches"
url = "https://maven.zontreck.com/repository/internal"
}
// Put repositories for dependencies here
// ForgeGradle automatically adds the Forge maven and Maven Central for you
// If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
flatDir {
dir 'libs'
}
//maven {
// name = "CurseMaven"
// url = "https://cursemaven.com"
//}
maven {
name = "zontreck Maven"
url = "https://maven.zontreck.com/repository/zontreck"
}
}
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.19.2-43.1.1'
// Specify the version of Minecraft to use.
// Any artifact can be supplied so long as it has a "userdev" classifier artifact and is a compatible patcher artifact.
// The "userdev" classifier will be requested and setup by ForgeGradle.
// If the group id is "net.minecraft" and the artifact id is one of ["client", "server", "joined"],
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// 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
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
// implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency
implementation fg.deobf("dev.zontreck:LibZontreckMod:${libzontreck}")
// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-forge-api:${jei_version}")
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}-forge:${jei_version}")
// Examples using mod jars from ./libs
// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
// For more info...
// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
jar {
manifest {
attributes([
"Specification-Title" : "watchmydurability",
"Specification-Vendor" : "Zontreck",
"Specification-Version" : "1", // We are version 1 of ourselves
"Implementation-Title" : project.name,
"Implementation-Version" : project.jar.archiveVersion,
"Implementation-Vendor" : "ZNI Creations",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
// This block of code expands all declared replace properties in the specified resource targets.
// A missing property will result in an error. Properties are expanded using ${} Groovy notation.
// When "copyIdeResources" is enabled, this will also run before the game launches in IDE environments.
// See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
forge_version: forge_version, forge_version_range: forge_version_range,
loader_version_range: loader_version_range,
mod_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_authors: mod_authors, mod_description: mod_description,
]
inputs.properties replaceProperties
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
}
}
// Example configuration to allow publishing using the maven-publish plugin
// This is the preferred method to reobfuscate your jar file
jar.finalizedBy('reobfJar')
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing
// publish.dependsOn('reobfJar')
// Example for how to get properties into the manifest for reading at runtime.
tasks.named('jar', Jar).configure {
manifest {
attributes([
'Specification-Title' : mod_id,
'Specification-Vendor' : mod_authors,
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : project.name,
'Implementation-Version' : project.jar.archiveVersion,
'Implementation-Vendor' : mod_authors,
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
}
// However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing:
// tasks.named('publish').configure {
// dependsOn 'reobfJar'
// }
// Example configuration to allow publishing using the maven-publish plugin
publishing {
publications {
mavenJava(MavenPublication) {
register('mavenJava', MavenPublication) {
artifact jar
}
}

View file

@ -2,3 +2,59 @@
# This is required to provide enough memory for the Minecraft decompilation process.
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false
libzontreck=1.10.011524.0045
## Environment Properties
# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.1,1.21)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=47.2.0
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[47,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[47,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
#
# | Channel | Version | |
# |-----------|----------------------|--------------------------------------------------------------------------------|
# | 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' 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 Minecraft Forge.
# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started
mapping_channel=parchment
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=2023.09.03-1.20.1
## Mod Properties
# The unique mod identifier for the mod. Must be lowercase in English locale. Must fit the regex [a-z][a-z0-9_]{1,63}
# Must match the String constant located in the main mod class annotated with @Mod.
mod_id=watchmydurability
# The human-readable display name for the mod.
mod_name=WatchMyDurability
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=1.2.011524.0055
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_group_id=dev.zontreck
# The authors of the mod. This is a simple text string that is used for display purposes in the mod list.
mod_authors=zontreck
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Watches the durability tools, and or your hunger.

Binary file not shown.

View file

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

12
gradlew vendored
View file

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@ -80,10 +80,10 @@ do
esac
done
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
@ -143,12 +143,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac

1
gradlew.bat vendored
View file

@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

View file

@ -1,6 +1,10 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven { url = 'https://maven.minecraftforge.net/' }
maven { url = "https://maven.zontreck.com/repository/internal" }
}
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
}

View file

@ -1,33 +0,0 @@
package dev.zontreck.mcmods.configs;
import java.util.ArrayList;
import java.util.List;
import net.minecraftforge.common.ForgeConfigSpec;
public class WMDClientConfig {
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
public static ForgeConfigSpec.ConfigValue<List<Integer>> alertPercents;
public static ForgeConfigSpec.ConfigValue<List<String>> alertMessages;
public static ForgeConfigSpec.ConfigValue<Integer> TimerVal;
static{
List<Integer> alerts1 = new ArrayList<>();
alerts1.add(10);
List<String> alerts2 = new ArrayList<>();
alerts2.add("!item! is about to break");
BUILDER.push("Alerts");
BUILDER.comment("Both of the following lists must have the same number of entries. NOTE: Percents do NOT stack. After the first rule is applied, it will move to the next item, so please make the list ascend, and not descend. Example: 10, 50").define("VERSION", "1.0.0");
alertPercents = BUILDER.comment("The list of alerts you want at what percentages of remaining durability").define("Percents", alerts1);
alertMessages = BUILDER.comment("The messages you want displayed when a alert is triggered. You must have the same amount of messages as alerts").define("Messages", alerts2);
TimerVal = BUILDER.comment("How many seconds between timer ticks to check your inventory items?").define("Timer", 5);
BUILDER.pop();
SPEC=BUILDER.build();
}
}

View file

@ -1,10 +1,21 @@
package dev.zontreck.mcmods;
package dev.zontreck.wmd;
import com.mojang.logging.LogUtils;
import dev.zontreck.mcmods.configs.WMDClientConfig;
import dev.zontreck.ariaslib.util.DelayedExecutorService;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.wmd.checkers.CheckHealth;
import dev.zontreck.wmd.checkers.CheckHunger;
import dev.zontreck.wmd.checkers.CheckInventory;
import dev.zontreck.wmd.commands.ModCommands;
import dev.zontreck.wmd.configs.WMDClientConfig;
import dev.zontreck.wmd.networking.ModMessages;
import dev.zontreck.wmd.types.Health;
import dev.zontreck.wmd.types.Hunger;
import dev.zontreck.wmd.types.ItemRegistry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.User;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -34,11 +45,15 @@ public class WatchMyDurability
public static User CurrentUser = null; // This is initialized by the client
public static boolean isInGame = false; // This locks the timer thread
public static ItemRegistry REGISTRY;
public static Health LastHealth;
public static Hunger LastHunger;
public static boolean WMD_SERVER_AVAILABLE =false;
public WatchMyDurability()
{
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
// Register the commonSetup method for modloading
@ -47,14 +62,17 @@ public class WatchMyDurability
// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);
MinecraftForge.EVENT_BUS.register(new ModCommands());
}
private void commonSetup(final FMLCommonSetupEvent event)
{
// Some common setup code
//LOGGER.info("HELLO FROM COMMON SETUP");
ModMessages.register();
}
// You can use SubscribeEvent and let the Event Bus discover methods to call
@SubscribeEvent
public void onServerStarting(ServerStartingEvent event)
@ -64,7 +82,7 @@ public class WatchMyDurability
}
// You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public static class ClientModEvents
{
static Timer time = new Timer();
@ -77,15 +95,20 @@ public class WatchMyDurability
//LOGGER.info("HELLO FROM CLIENT SETUP");
//LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName());
WatchMyDurability.CurrentUser = Minecraft.getInstance().getUser();
DelayedExecutorService.setup();
time.schedule(new CheckInventory(), WMDClientConfig.TimerVal.get()*1000, WMDClientConfig.TimerVal.get()*1000);
//time.schedule(new CheckInventory(),
//WMDClientConfig.TimerVal.get()*1000,
//WMDClientConfig.TimerVal.get()*1000);
ItemRegistry.Initialize();
}
}
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public static class ClientEvents
{
@ -95,6 +118,11 @@ public class WatchMyDurability
//LOGGER.info("PLAYER LOGGED IN");
LOGGER.info(": : : PLAYER LOGGED IN : : :");
WatchMyDurability.isInGame=true;
DelayedExecutorService.start();
DelayedExecutorService.getInstance().scheduleRepeating(CheckInventory.getInstance(), WMDClientConfig.TimerVal.get());
DelayedExecutorService.getInstance().scheduleRepeating(CheckHealth.getInstance(), WMDClientConfig.TimerVal.get());
DelayedExecutorService.getInstance().scheduleRepeating(CheckHunger.getInstance(), WMDClientConfig.TimerVal.get());
}
@SubscribeEvent
@ -102,6 +130,8 @@ public class WatchMyDurability
//LOGGER.info("PLAYER LOGGED OUT");
LOGGER.info(": : : PLAYER LOGGED OUT : : :");
WatchMyDurability.isInGame=false;
WatchMyDurability.WMD_SERVER_AVAILABLE=false;
DelayedExecutorService.stop();
}
@SubscribeEvent

View file

@ -0,0 +1,52 @@
package dev.zontreck.wmd.checkers;
import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.wmd.types.Health;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.configs.WMDClientConfig;
import dev.zontreck.wmd.utils.client.Helpers;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
public class CheckHealth extends Task
{
private static CheckHealth inst = new CheckHealth();
public static CheckHealth getInstance()
{
return inst;
}
public CheckHealth() {
super("CheckHealth", true);
}
@Override
public void run() {
// Hijack this timer so we dont need to register yet another
if(!WMDClientConfig.EnableHealthAlert.get())return;
Health current = Health.of(Minecraft.getInstance().player);
if(WatchMyDurability.LastHealth == null)WatchMyDurability.LastHealth = current;
else{
if(current.identical(WatchMyDurability.LastHealth))return;
}
// Good to proceed
if(current.shouldGiveAlert())
{
String Msg = ChatColor.doColors("!Dark_Red!!bold!You need to eat!");
Component chat = Component.literal(Msg);
Minecraft.getInstance().player.displayClientMessage(chat, false);
SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach
Helpers.Soundify(sv);
}
WatchMyDurability.LastHealth=current;
}
}

View file

@ -0,0 +1,50 @@
package dev.zontreck.wmd.checkers;
import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.wmd.types.Hunger;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.configs.WMDClientConfig;
import dev.zontreck.wmd.utils.client.Helpers;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
public class CheckHunger extends Task
{
private static CheckHunger inst = new CheckHunger();
public static CheckHunger getInstance()
{
return inst;
}
public CheckHunger()
{
super("CheckHunger", true);
}
@Override
public void run() {
if(!WMDClientConfig.EnableHungerAlert.get()) return;
Hunger current = Hunger.of(Minecraft.getInstance().player);
if(WatchMyDurability.LastHunger == null)WatchMyDurability.LastHunger = new Hunger();
if(current.identical()) return;
if(current.shouldGiveAlert())
{
String Msg = ChatColor.doColors("!Dark_Red!!bold!You need to eat!");
Component chat = Component.literal(Msg);
Minecraft.getInstance().player.displayClientMessage(chat, false);
SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach
Helpers.Soundify(sv);
}
WatchMyDurability.LastHunger = current;
}
}

View file

@ -1,28 +1,47 @@
package dev.zontreck.mcmods;
package dev.zontreck.wmd.checkers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
import dev.zontreck.mcmods.configs.WMDClientConfig;
import dev.zontreck.ariaslib.terminal.Task;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chat.HoverTip;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.wmd.types.ItemRegistry;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.configs.WMDClientConfig;
import dev.zontreck.wmd.utils.client.Helpers;
import net.minecraft.client.Minecraft;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.Style;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.item.ItemStack;
public class CheckInventory extends TimerTask
{
public class CheckInventory extends Task {
private static final CheckInventory inst = new CheckInventory();
public CheckInventory() {
super("checkinv", true);
}
public static CheckInventory getInstance(){
return inst;
}
@Override
public void run() {
if(!WMDClientConfig.EnableToolWatcher.get()) return;
try {
if(!WatchMyDurability.isInGame)return;
//WatchMyDurability.LOGGER.info("TICKING CHECK INVENTORY EVENT");
// Get the player inventory
Inventory inv = Minecraft.getInstance().player.getInventory();
@ -40,6 +59,7 @@ public class CheckInventory extends TimerTask
WatchMyDurability.LOGGER.warn("A error in the WatchMyDurability timer code has occurred. This could happen with hub worlds and the server transfers that occur. If this happened in another instance, please report this error to the developer, along with what you were doing.");
}
}
public void PushItems(String type, List<ItemStack> stack)
@ -60,12 +80,6 @@ public class CheckInventory extends TimerTask
ItemRegistry.register(type,items);
}
public void Soundify(SoundEvent sound)
{
//WatchMyDurability.LOGGER.info("PLAY ALERT SOUND");
Minecraft.getInstance().player.playSound(sound, 1.0f, 1.0f);
}
public void checkList(String type, NonNullList<ItemStack> stacks){
Integer slotNum = 0;
//boolean ret=false;
@ -84,13 +98,21 @@ public class CheckInventory extends TimerTask
String entryStr = WMDClientConfig.alertMessages.get().get(idx);
if(percent <= entry){
String replaced = entryStr.replaceAll("!item!", is1.getDisplayName().getString());
String replaced = ChatColor.doColors(WMDClientConfig.WMD_PREFIX.get()) + ChatColor.DARK_RED + entryStr.replaceAll("!item!", is1.getDisplayName().getString());
WatchMyDurability.LOGGER.info("Enqueue alert for an item. Playing sound for item: "+is1.getDisplayName().getString());
SoundEvent theSound = SoundEvents.ITEM_BREAK;
Soundify(theSound);
Helpers.Soundify(theSound);
MutableComponent X = Component.literal(replaced);
HoverEvent he = HoverTip.getItem(is1);
Style s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(he);
X=X.withStyle(s);
Component X = Component.literal(replaced);
Minecraft.getInstance().player.displayClientMessage(X, false);
break; // Rule applies, break out of this loop, move to next item.
}

View file

@ -0,0 +1,14 @@
package dev.zontreck.wmd.commands;
import dev.zontreck.wmd.commands.impl.SettingsCommand;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class ModCommands
{
@SubscribeEvent
public void register(final RegisterCommandsEvent event)
{
SettingsCommand.register(event.getDispatcher());
}
}

View file

@ -0,0 +1,21 @@
package dev.zontreck.wmd.commands.impl;
import com.mojang.brigadier.CommandDispatcher;
import dev.zontreck.wmd.networking.ModMessages;
import dev.zontreck.wmd.networking.packets.s2c.RequestClientConfig;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
public class SettingsCommand
{
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
{
dispatcher.register(Commands.literal("wmdsettings").executes(c->settingsPrompt(c.getSource())));
}
public static int settingsPrompt(CommandSourceStack sender)
{
ModMessages.sendToPlayer(new RequestClientConfig(), sender.getPlayer());
return 0;
}
}

View file

@ -0,0 +1,78 @@
package dev.zontreck.wmd.configs;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.ForgeConfigSpec;
public class WMDClientConfig {
public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
public static final ForgeConfigSpec SPEC;
public static ForgeConfigSpec.ConfigValue<List<Integer>> alertPercents;
public static ForgeConfigSpec.ConfigValue<List<String>> alertMessages;
public static ForgeConfigSpec.ConfigValue<Integer> TimerVal;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableHealthAlert;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableHungerAlert;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableToolWatcher;
public static ForgeConfigSpec.ConfigValue<String> WMD_PREFIX;
static{
List<Integer> alerts1 = new ArrayList<>();
alerts1.add(10);
List<String> alerts2 = new ArrayList<>();
alerts2.add("!item! is about to break");
BUILDER.push("Alerts");
BUILDER.comment("Both of the following lists must have the same number of entries. NOTE: Percents do NOT stack. After the first rule is applied, it will move to the next item, so please make the list ascend, and not descend. Example: 10, 50").define("VERSION", "1.1.1.1");
alertPercents = BUILDER.comment("The list of alerts you want at what percentages of remaining durability").define("Percents", alerts1);
alertMessages = BUILDER.comment("The messages you want displayed when a alert is triggered. You must have the same amount of messages as alerts").define("Messages", alerts2);
TimerVal = BUILDER.comment("How many seconds between timer ticks to check your inventory items?").define("Timer", 5);
BUILDER.pop();
BUILDER.push("General");
EnableHealthAlert = BUILDER.comment("The following was added for a friend. If you need reminders to eat in order to heal, turn the below option on").define("watchMyHealth", false);
EnableHungerAlert = BUILDER.comment("This is a newer setting to watch your hunger status instead of your hunger to alert when you need to eat").define("watchMyHunger", false);
EnableToolWatcher = BUILDER.comment("Enable watching tool durability").define("watchDurability", true);
BUILDER.pop();
BUILDER.push("Messages");
WMD_PREFIX = BUILDER.comment("The prefix string for WMD").define("prefix", "!Dark_Gray![!Bold!!Dark_Green!WMD!Reset!!Dark_Gray!]!Reset!");
SPEC=BUILDER.build();
}
public static CompoundTag serialize()
{
CompoundTag ret = new CompoundTag();
ret.putBoolean("watchMyHealth", EnableHealthAlert.get());
ret.putBoolean("watchMyHunger", EnableHungerAlert.get());
ret.putBoolean("watchDurability", EnableToolWatcher.get());
return ret;
}
public static void deserialize(CompoundTag tag)
{
EnableHealthAlert.set(tag.getBoolean("watchMyHealth"));
EnableHealthAlert.save();
EnableHungerAlert.set(tag.getBoolean("watchMyHunger"));
EnableHungerAlert.save();
EnableToolWatcher.set(tag.getBoolean("watchDurability"));
EnableToolWatcher.save();
}
}

View file

@ -0,0 +1,17 @@
package dev.zontreck.wmd.events;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.networking.packets.s2c.WMDServerAvailable;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class EventHandler
{
@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event)
{
WMDServerAvailable avail = new WMDServerAvailable();
avail.send(event.getEntity().getUUID());
}
}

View file

@ -0,0 +1,76 @@
package dev.zontreck.wmd.networking;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.networking.packets.c2s.ClientConfigResponse;
import dev.zontreck.wmd.networking.packets.s2c.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.network.NetworkDirection;
import net.minecraftforge.network.NetworkRegistry;
import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.simple.SimpleChannel;
public class ModMessages
{
private static SimpleChannel channel;
private static int PACKET_ID = 0;
private static int id()
{
return PACKET_ID++;
}
public static void register()
{
SimpleChannel net = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(WatchMyDurability.MODID, "messages"))
.networkProtocolVersion(()->"1.0")
.clientAcceptedVersions(s->true)
.serverAcceptedVersions(s->true)
.simpleChannel();
channel = net;
net.messageBuilder(WMDServerAvailable.class, id(), NetworkDirection.PLAY_TO_CLIENT)
.encoder(WMDServerAvailable::toBytes)
.decoder(WMDServerAvailable::new)
.consumerMainThread(WMDServerAvailable::handle)
.add();
net.messageBuilder(S2CResetConfig.class, id(), NetworkDirection.PLAY_TO_CLIENT)
.encoder(S2CResetConfig::toBytes)
.decoder(S2CResetConfig::new)
.consumerMainThread(S2CResetConfig::handle)
.add();
net.messageBuilder(RequestClientConfig.class, id(), NetworkDirection.PLAY_TO_CLIENT)
.encoder(RequestClientConfig::toBytes)
.decoder(RequestClientConfig::new)
.consumerMainThread(RequestClientConfig::handle)
.add();
net.messageBuilder(ClientConfigResponse.class, id(), NetworkDirection.PLAY_TO_SERVER)
.encoder(ClientConfigResponse::toBytes)
.decoder(ClientConfigResponse::new)
.consumerMainThread(ClientConfigResponse::handle)
.add();
net.messageBuilder(PushClientConfigUpdate.class, id(), NetworkDirection.PLAY_TO_CLIENT)
.encoder(PushClientConfigUpdate::toBytes)
.decoder(PushClientConfigUpdate::new)
.consumerMainThread(PushClientConfigUpdate::handle)
.add();
}
public static <MSG> void sendToServer(MSG message){
channel.sendToServer(message);
}
public static <MSG> void sendToPlayer(MSG message, ServerPlayer player)
{
channel.send(PacketDistributor.PLAYER.with(()->player), message);
}
public static <MSG> void sendToAll(MSG message)
{
channel.send(PacketDistributor.ALL.noArg(), message);
}
}

View file

@ -0,0 +1,130 @@
package dev.zontreck.wmd.networking.packets.c2s;
import dev.zontreck.libzontreck.chat.ChatColor;
import dev.zontreck.libzontreck.chestgui.ChestGUI;
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
import dev.zontreck.libzontreck.items.ModItems;
import dev.zontreck.libzontreck.lore.LoreContainer;
import dev.zontreck.libzontreck.lore.LoreEntry;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.libzontreck.vectors.Vector2i;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.configs.WMDClientConfig;
import dev.zontreck.wmd.networking.ModMessages;
import dev.zontreck.wmd.networking.packets.s2c.PushClientConfigUpdate;
import dev.zontreck.wmd.networking.packets.s2c.RequestClientConfig;
import dev.zontreck.wmd.networking.packets.s2c.S2CResetConfig;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraftforge.network.NetworkEvent;
import java.util.UUID;
import java.util.function.Supplier;
public class ClientConfigResponse {
public CompoundTag tag;
public UUID id;
public ClientConfigResponse(FriendlyByteBuf buf) {
tag = buf.readAnySizeNbt();
id = buf.readUUID();
}
public ClientConfigResponse(UUID playerID) {
tag = WMDClientConfig.serialize();
id = playerID;
}
public void toBytes(FriendlyByteBuf buf) {
buf.writeNbt(tag);
buf.writeUUID(id);
}
public void handle(Supplier<NetworkEvent.Context> supplier) {
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(() -> {
// Open config editor for player
boolean enableHealth = tag.getBoolean("watchMyHealth");
boolean enableHunger = tag.getBoolean("watchMyHunger");
boolean enableDurability = tag.getBoolean("watchDurability");
ServerPlayer player = ServerUtilities.getPlayerByID(id.toString());
try {
ChestGUI prompt = ChestGUI.builder().withGUIId(new ChestGUIIdentifier("wmdsettings")).withPlayer(player.getUUID()).withTitle("WMD Settings");
ItemStack wtd = new ItemStack(Items.DIAMOND_PICKAXE, 1);
wtd.setHoverName(Component.literal("Watch Tool Durability"));
prompt.withButton(new ChestGUIButton(wtd, (stack, container, lore) -> {
var wd = !tag.getBoolean("watchDurability");
tag.putBoolean("watchDurability", wd);
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (wd ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
lore.commitLore();
}, new Vector2i(0, 0))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableDurability ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build())
);
ItemStack wmhunger = new ItemStack(Items.APPLE, 1);
wmhunger.setHoverName(Component.literal("Watch My Hunger"));
prompt.withButton(new ChestGUIButton(wmhunger, (stack, container, lore) -> {
var eh = !tag.getBoolean("watchMyHunger");
tag.putBoolean("watchMyHunger", eh);
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (eh ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
lore.commitLore();
}, new Vector2i(0, 1))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHunger ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build())
);
ItemStack wmhealth = new ItemStack(Items.PUFFERFISH, 1);
wmhealth.setHoverName(Component.literal("Watch My Health"));
prompt.withButton(new ChestGUIButton(wmhealth, (stack, container, lore) -> {
var eh = !tag.getBoolean("watchMyHealth");
tag.putBoolean("watchMyHealth", eh);
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (eh ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
lore.commitLore();
}, new Vector2i(0, 2))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHealth ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build())
);
prompt.withButton(new ChestGUIButton(ModItems.CHESTGUI_RESET.get(), "Reset", (stack, container, lore) -> {
ModMessages.sendToPlayer(new S2CResetConfig(), ServerUtilities.getPlayerByID(id.toString()));
prompt.close();
ModMessages.sendToPlayer(new RequestClientConfig(), player);
}, new Vector2i(2, 4)));
prompt.hasReset = false;
prompt.open();
} catch (Exception e) {
WatchMyDurability.LOGGER.error(e.getMessage());
e.printStackTrace();
}
});
}
}

View file

@ -0,0 +1,36 @@
package dev.zontreck.wmd.networking.packets.s2c;
import dev.zontreck.wmd.configs.WMDClientConfig;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class PushClientConfigUpdate
{
public CompoundTag tag;
public PushClientConfigUpdate(FriendlyByteBuf buf)
{
tag = buf.readAnySizeNbt();
}
public PushClientConfigUpdate(CompoundTag tag)
{
this.tag=tag;
}
public void toBytes(FriendlyByteBuf buf)
{
buf.writeNbt(tag);
}
public void handle(Supplier<NetworkEvent.Context> supplier)
{
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(()->{
WMDClientConfig.deserialize(tag);
});
}
}

View file

@ -0,0 +1,35 @@
package dev.zontreck.wmd.networking.packets.s2c;
import dev.zontreck.wmd.networking.ModMessages;
import dev.zontreck.wmd.networking.packets.c2s.ClientConfigResponse;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class RequestClientConfig
{
public RequestClientConfig(FriendlyByteBuf buf)
{
}
public RequestClientConfig(){
}
public void toBytes(FriendlyByteBuf buf){
}
public void handle(Supplier<NetworkEvent.Context> supplier)
{
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(()->{
ClientConfigResponse reply = new ClientConfigResponse(Minecraft.getInstance().player.getUUID());
ModMessages.sendToServer(reply);
});
}
}

View file

@ -0,0 +1,45 @@
package dev.zontreck.wmd.networking.packets.s2c;
import dev.zontreck.wmd.configs.WMDClientConfig;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class S2CResetConfig
{
public S2CResetConfig(FriendlyByteBuf buf)
{
}
public S2CResetConfig()
{
}
public void toBytes(FriendlyByteBuf buf)
{
}
public void handle(Supplier<NetworkEvent.Context> supplier)
{
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(()->
{
WMDClientConfig.WMD_PREFIX.set(WMDClientConfig.WMD_PREFIX.getDefault());
WMDClientConfig.WMD_PREFIX.save();
WMDClientConfig.EnableHealthAlert.set(WMDClientConfig.EnableHealthAlert.getDefault());
WMDClientConfig.EnableHealthAlert.save();
WMDClientConfig.EnableHungerAlert.set(WMDClientConfig.EnableHungerAlert.getDefault());
WMDClientConfig.EnableHealthAlert.save();
WMDClientConfig.EnableToolWatcher.set(WMDClientConfig.EnableToolWatcher.getDefault());
WMDClientConfig.EnableToolWatcher.save();
});
}
}

View file

@ -0,0 +1,42 @@
package dev.zontreck.wmd.networking.packets.s2c;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.wmd.WatchMyDurability;
import dev.zontreck.wmd.networking.ModMessages;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.network.NetworkEvent;
import java.util.UUID;
import java.util.function.Supplier;
public class WMDServerAvailable
{
public WMDServerAvailable(FriendlyByteBuf buf)
{
}
public WMDServerAvailable()
{
}
public void toBytes(FriendlyByteBuf buf)
{
}
public void handle(Supplier<NetworkEvent.Context> supplier)
{
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(()->{
WatchMyDurability.WMD_SERVER_AVAILABLE =true;
});
}
public void send(UUID ID)
{
ModMessages.sendToPlayer(this, ServerUtilities.getPlayerByID(ID.toString()));
}
}

View file

@ -0,0 +1,36 @@
package dev.zontreck.wmd.types;
import net.minecraft.world.entity.player.Player;
public class Health {
public float maximum;
public float current;
public int asPercent()
{
return (int)Math.round(Math.abs((current * 100 / maximum)));
}
public Health lastHealthState;
public static Health of(Player player){
Health obj = new Health();
obj.current = player.getHealth();
obj.maximum = player.getMaxHealth();
return obj;
}
public boolean shouldGiveAlert()
{
if(asPercent()<=50){
return true;
}else return false;
}
public boolean identical(Health other)
{
if(other.current == current && other.maximum == maximum)return true;
else return false;
}
}

View file

@ -0,0 +1,28 @@
package dev.zontreck.wmd.types;
import dev.zontreck.wmd.WatchMyDurability;
import net.minecraft.world.entity.player.Player;
public class Hunger
{
public boolean needsToEat;
public static Hunger of(Player player)
{
Hunger hunger = new Hunger();
hunger.needsToEat = player.getFoodData().needsFood();
return hunger;
}
public boolean shouldGiveAlert()
{
if(needsToEat && !WatchMyDurability.LastHunger.needsToEat) return true;
else return false;
}
public boolean identical()
{
if(needsToEat == WatchMyDurability.LastHunger.needsToEat) return true;
return false;
}
}

View file

@ -1,8 +1,9 @@
package dev.zontreck.mcmods;
package dev.zontreck.wmd.types;
import java.util.HashMap;
import java.util.Map;
import dev.zontreck.wmd.WatchMyDurability;
import net.minecraft.world.item.ItemStack;
public class ItemRegistry {
@ -21,6 +22,9 @@ public class ItemRegistry {
}
}
public class Health {
}
public Map<String,Map<Integer, Item>> CachedItems;
public ItemRegistry()

View file

@ -0,0 +1,14 @@
package dev.zontreck.wmd.utils.client;
import net.minecraft.client.Minecraft;
import net.minecraft.sounds.SoundEvent;
public class Helpers
{
public static void Soundify(SoundEvent sound)
{
//WatchMyDurability.LOGGER.info("PLAY ALERT SOUND");
Minecraft.getInstance().player.playSound(sound, 1.0f, 1.0f);
}
}

View file

@ -6,32 +6,30 @@
# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml
modLoader="javafml" #mandatory
# A version range to match for said mod loader - for regular FML @Mod it will be the forge version
loaderVersion="[43,)" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
loaderVersion="${loader_version_range}" #mandatory This is typically bumped every Minecraft version by Forge. See our download page for lists of versions.
# The license for you mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
# Review your options at https://choosealicense.com/. All rights reserved is the default copyright stance, and is thus the default here.
license="GPL-v2"
license="${mod_license}"
# A URL to refer people to when problems occur with this mod
#issueTrackerURL="https://change.me.to.your.issue.tracker.example.invalid/" #optional
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
modId="watchmydurability" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build
version="${file.jarVersion}" #mandatory
# A display name for the mod
displayName="Watch My Durability" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
modId="${mod_id}" #mandatory
# The version number of the mod
version="${mod_version}" #mandatory
# A display name for the mod
displayName="${mod_name}" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://docs.minecraftforge.net/en/latest/misc/updatechecker/
#updateJSONURL="https://change.me.example.invalid/updates.json" #optional
# A URL for the "homepage" for this mod, displayed in the mod UI
#displayURL="https://change.me.to.your.mods.homepage.example.invalid/" #optional
# A file name (in the root of the mod JAR) containing a logo for display
# logoFile="examplemod.png" #optional
#logoFile="examplemod.png" #optional
# A text field displayed in the mod UI
credits="zontreck @ ZNI Creations" #optional
#credits="" #optional
# A text field displayed in the mod UI
authors="zontreck" #optional
authors="${mod_authors}" #optional
# Display Test controls the display for your mod in the server connection screen
# MATCH_VERSION means that your mod will cause a red X if the versions on client and server differ. This is the default behaviour and should be what you choose if you have server and client elements to your mod.
# IGNORE_SERVER_VERSION means that your mod will not cause a red X if it's present on the server but not on the client. This is what you should use if you're a server only mod.
@ -41,30 +39,38 @@ authors="zontreck" #optional
#displayTest="MATCH_VERSION" # MATCH_VERSION is the default if nothing is specified (#optional)
# The description text for the mod (multi line!) (#mandatory)
description='''
This mod watches durability of an item.
This is most useful for armor or weapons to alert you to the fact that your armor or weapon might break soon.
Edit the config file to customize the alerts
'''
description='''${mod_description}'''
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.watchmydurability]] #optional
[[dependencies.${mod_id}]] #optional
# the modid of the dependency
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
versionRange="[43,)" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
versionRange="${forge_version_range}" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the dependency is not mandatory
# BEFORE - This mod is loaded BEFORE the dependency
# AFTER - This mod is loaded AFTER the dependency
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
side="CLIENT"
# Side this dependency is applied on - BOTH, CLIENT, or SERVER
side="BOTH"
# Here's another dependency
[[dependencies.watchmydurability]]
[[dependencies.${mod_id}]]
modId="minecraft"
mandatory=true
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="[1.19.2,1.20)"
# This version range declares a minimum of the current minecraft version up to but not including the next major version
versionRange="${minecraft_version_range}"
ordering="NONE"
side="CLIENT"
side="BOTH"
[[dependencies.${mod_id}]]
modId="libzontreck"
mandatory=true
versionRange="[1.10,1.11)"
ordering="NONE"
side="BOTH"
# Features are specific properties of the game environment, that you may want to declare you require. This example declares
# that your mod requires GL version 3.2 or higher. Other features will be added. They are side aware so declaring this won't
# stop your mod loading on the server for example.
#[features.${mod_id}]
#openGLVersion="[3.2,)"

View file

@ -1,8 +1,8 @@
{
"pack": {
"description": "Watch My Durability Resources",
"pack_format": 9,
"forge:resource_pack_format": 9,
"forge:data_pack_format": 10
"description": {
"text": "${mod_id} resources"
},
"pack_format": 15
}
}