Compare commits

..

64 commits

Author SHA1 Message Date
Stephen Seo cbfd354919 Change action runner for tags/releases 2024-03-21 16:16:48 +09:00
Stephen Seo 524df98c22 Change action runner for tags/releases 2024-03-21 13:23:06 +09:00
Stephen Seo 20fe64ed61 Update README.md 2024-01-30 11:13:39 +09:00
Stephen Seo 5372e7a25a Action: Check if release exists before releasing
All checks were successful
Build TurnBasedMC and create Release / check-release-exists (push) Successful in 0s
Build TurnBasedMC and create Release / build-and-create-release (push) Has been skipped
2024-01-22 18:26:21 +09:00
Stephen Seo c07828f411 Enable "any_archLinux" act runner for building jar 2024-01-20 20:02:41 +09:00
Stephen Seo eef8433df4 Fix Reproducibility.md 2024-01-17 15:00:19 +09:00
Stephen Seo b763720989 Update Reproducibility.md 2024-01-17 14:45:01 +09:00
Stephen Seo 5c59c73332 Update Changelog.md 2024-01-17 14:44:53 +09:00
Stephen Seo f18cd91560 Update Reproducibility.md
All checks were successful
Build TurnBasedMC and create Release / build-and-create-release (push) Successful in 27s
2024-01-17 14:18:20 +09:00
Stephen Seo d57a75d3b2 Bump version to 1.25.2 2024-01-17 14:17:03 +09:00
Stephen Seo fb7d4e39de Fix usage of throwable potions in battle
Add (experimental) "right-click" support for items when "Use" is invoked
on an item in battle.
2024-01-17 14:11:11 +09:00
Stephen Seo 71e3796694 Update FAQ.md 2024-01-17 13:43:10 +09:00
Stephen Seo c066e10762 Update README.md 2024-01-17 13:38:39 +09:00
Stephen Seo 971c56c69b Update README.md 2024-01-17 13:35:35 +09:00
Stephen Seo b20f8314d0 Update Changelog.md, Reproducibility.md
All checks were successful
Build TurnBasedMC and create Release / build-and-create-release (push) Successful in 1m41s
2024-01-16 22:19:13 +09:00
Stephen Seo e1e462cb6d Bump version to 1.25.1, update to forge 49.0.19
MC Version 1.20.4
2024-01-16 22:17:06 +09:00
Stephen Seo 84006554e8 Update Reproducibility.md 2024-01-16 17:31:46 +09:00
Stephen Seo a20d0e0ccb Update Changelog.md 2024-01-16 17:31:35 +09:00
Stephen Seo 6815276eef Update .gitignore 2024-01-16 17:30:41 +09:00
Stephen Seo 8476b9b19c Remove unused mcmod.info file 2024-01-14 20:28:35 +09:00
Stephen Seo 458aeaaf07 Update Changelog.md 2024-01-14 20:23:35 +09:00
Stephen Seo 530fdadc07 Add "icon" for mod 2024-01-14 20:20:10 +09:00
Stephen Seo be99607226 "Pin" j-ogg-vorbis version 2024-01-11 16:29:51 +09:00
Stephen Seo 00c6ec12a4 Tweak to forgejo action/workflow 2024-01-10 11:56:36 +09:00
Stephen Seo 5dda78f3a5 Minor tweak to FAQ.md 2024-01-09 11:15:48 +09:00
Stephen Seo ae18f2686e Minor fix to build-jar action/workflow 2024-01-08 18:33:25 +09:00
Stephen Seo 6c3aa48923 Update README.md 2024-01-08 18:24:26 +09:00
Stephen Seo 05ab18b572 Update LICENSE year 2024-01-08 18:20:43 +09:00
Stephen Seo 768844b05f Update FAQ.md 2024-01-08 17:30:52 +09:00
Stephen Seo c0879e120c Update README.md 2024-01-08 17:27:54 +09:00
Stephen Seo 039f27cbc1 Add FAQ.md 2024-01-08 17:24:42 +09:00
Stephen Seo ad78063a16 Update Reproducibility.md 2024-01-08 15:41:51 +09:00
Stephen Seo 4c2bc47007 Update Changelog.md 2024-01-08 15:34:53 +09:00
Stephen Seo be19ce8748 Fix build-jar workflow
All checks were successful
Build TurnBasedMC and create Release / build-and-store-artifact (push) Successful in 24s
2024-01-08 15:06:47 +09:00
Stephen Seo 3a6d800745 Minor fix to build-jar action
Some checks failed
Build TurnBasedMC and create Release / build-and-store-artifact (push) Failing after 33s
2024-01-08 15:03:58 +09:00
Stephen Seo 56a9db15ad Update Reproducibility.md 2024-01-08 15:02:44 +09:00
Stephen Seo 18076715e0 Update Changelog.md 2024-01-08 15:01:11 +09:00
Stephen Seo 8551aae80b Update README.md 2024-01-08 15:00:03 +09:00
Stephen Seo cc7ef71384 Minor tweak to build-jar action 2024-01-08 14:58:35 +09:00
Stephen Seo 6d8384ce04 Update README.md 2024-01-08 14:58:21 +09:00
Stephen Seo 0d0c0ca08c Add support for ogg-vorbis audio files 2024-01-08 12:29:09 +09:00
Stephen Seo 74291dde8f Bump version, use jarJar instead of shadow jar
Also add "j-ogg-vorbis" dependency.
2024-01-08 12:18:32 +09:00
Stephen Seo f687dfdaf3 Minor tweak/fix to release summary on tag action
All checks were successful
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Successful in 28s
2024-01-06 14:52:46 +09:00
Stephen Seo 6e8d3a8d5a Fix build-jar action for master branch
All checks were successful
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Successful in 33s
2024-01-06 14:33:54 +09:00
Stephen Seo 47a2eb9c74 Change action to create release on tag with jar 2024-01-06 14:30:57 +09:00
Stephen Seo 9680fdb24b Name build artifact based on tag name 2024-01-05 20:28:59 +09:00
Stephen Seo 398e8a9218 Fix builds changing MANIFEST based on project dir 2024-01-05 18:51:55 +09:00
Stephen Seo c4a8664297 Fix tag wildcard in action .yaml 2024-01-05 17:06:04 +09:00
Stephen Seo 9daf5c139f Use action when tag is pushed 2024-01-05 16:37:24 +09:00
Stephen Seo 5168f8b346 Output sha256sum of jars in action
All checks were successful
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Successful in 3m45s
2024-01-05 16:29:02 +09:00
Stephen Seo 304c739a25 Change repo clone dir name in action 2024-01-05 16:27:27 +09:00
Stephen Seo 0d8699c420 Rename artifact name for buidl action
All checks were successful
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Successful in 4m24s
2024-01-05 15:45:39 +09:00
Stephen Seo 8ee3c99846 Update action to use less ram
All checks were successful
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Successful in 54s
2024-01-05 15:35:12 +09:00
Stephen Seo e5beef7c98 Fix forgejo action (missing ';' for find cmd)
Some checks failed
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Failing after 14m30s
2024-01-05 13:22:02 +09:00
Stephen Seo 56353462f7 Add workflow to build jar and store as artifact
Some checks failed
Build TurnBasedMC and store Artifact / build-and-store-artifact (push) Has been cancelled
2024-01-05 13:19:44 +09:00
Stephen Seo da17601477 Fix newline for download links list 2024-01-01 12:38:03 +09:00
Stephen Seo 5d905ac55e Add modrinth.com link to README.md 2024-01-01 12:35:37 +09:00
Stephen Seo d7e35cbf5a Update Reproducibility.md 2023-12-30 14:01:14 +09:00
Stephen Seo 132d16b2bd Update README.md
Reorder `Reproducibility` to be under `Building`.
2023-12-30 13:50:55 +09:00
Stephen Seo 24247eab7b Update Reproducibility.md 2023-12-30 12:35:47 +09:00
Stephen Seo dc7d621d5c Update README.md, add Reproducibility.md 2023-12-30 12:25:14 +09:00
Stephen Seo fc34310cbe Update README.md 2023-12-30 11:55:10 +09:00
Stephen Seo 601d5bc15d Update Changelog.md 2023-12-29 17:26:53 +09:00
Stephen Seo 62576a06c6 Update mod for 1.20.2 Forge
Also add support for Crossbows in battle.
2023-12-29 11:59:23 +09:00
28 changed files with 684 additions and 650 deletions

View file

@ -6,7 +6,7 @@ on:
jobs:
check-release-exists:
runs-on: any_archLinux
runs-on: highmem_self
outputs:
status: ${{ steps.release_exists_check.outputs.http_code }}
steps:
@ -19,13 +19,13 @@ jobs:
build-and-create-release:
needs: check-release-exists
if: ${{ needs.check-release-exists.outputs.status == '404' }}
runs-on: any_archLinux
runs-on: highmem_self
steps:
- run: git clone --depth=1 --no-single-branch https://git.seodisparate.com/stephenseo/TurnBasedMinecraftMod.git TurnBasedMinecraftMod
- run: cd TurnBasedMinecraftMod && git checkout ${GITHUB_REF_NAME}
- run: cd TurnBasedMinecraftMod && sed -i '/org.gradle.jvmargs/s/Xmx[0-9]\+m/Xmx1024m/' gradle.properties && echo 'neogradle.subsystems.decompiler.maxThreads=1' >> gradle.properties
- run: cd TurnBasedMinecraftMod && sed -i '/org.gradle.jvmargs/s/Xmx[0-9]\+m/Xmx1024m/' gradle.properties
- run: cd TurnBasedMinecraftMod && ./gradlew --console=plain build
- run: cd TurnBasedMinecraftMod/build/libs && find . -type f -regex '.*all.jar$' -exec sha256sum '{}' ';' -exec bash -c 'sha256sum {} >> sha256sums.txt' ';' && java --version >> javaVersion.txt && javac --version >> javaVersion.txt
- run: cd TurnBasedMinecraftMod/build/libs && find . -type f -exec sha256sum '{}' ';' -exec bash -c 'sha256sum {} >> sha256sums.txt' ';' && java --version >> javaVersion.txt && javac --version >> javaVersion.txt
- name: Create release and attach jar
run: |
curl --fail-with-body -X 'POST' \
@ -35,7 +35,7 @@ jobs:
-H 'Content-Type: application/json' \
-d "{
\"name\": \"TurnBasedMinecraftMod version ${GITHUB_REF_NAME}\",
\"body\": \"See the [Changelog](https://git.seodisparate.com/stephenseo/TurnBasedMinecraftMod/src/branch/neoforge/Changelog.md)
\"body\": \"See the [Changelog](https://git.seodisparate.com/stephenseo/TurnBasedMinecraftMod/src/branch/master/Changelog.md)
$(java --version | sed -n '1p;2,$s/^/ /p')
$(javac --version)

View file

@ -72,7 +72,7 @@ configured for them.)
Simply invoke `./gradlew build` in the mod directory and after some time the
finished jar will be saved at
`build/libs/TurnBasedMinecraft-NeoForge-1.25.2-all.jar`
`build/libs/TurnBasedMinecraft-Forge-1.25.2-all.jar`
# Reproducibility
@ -81,9 +81,9 @@ more details.
# Other notes
This mod uses [j-ogg-vorbis](https://github.com/stephengold/j-ogg-all)
available from [http://www.j-ogg.de](http://www.j-ogg.de) and copyrighted by
Tor-Einar Jarnbjo.
This mod uses [j-ogg-vorbis](https://github.com/stephengold/j-ogg-all) available
from [http://www.j-ogg.de](http://www.j-ogg.de) and copyrighted by Tor-Einar
Jarnbjo.
This mod also uses [JavaMP3](https://github.com/kevinstadler/JavaMP3)
which is licensed under the [MIT License](https://github.com/kevinstadler/JavaMP3/blob/master/LICENSE).

View file

@ -2,61 +2,78 @@ plugins {
id 'eclipse'
id 'idea'
id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.80'
id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
}
version = mod_version
group = mod_group_id
archivesBaseName = "TurnBasedMinecraft-NeoForge"
archivesBaseName = "TurnBasedMinecraft-Forge"
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'))
jarJar.enable()
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
// applies to all the run configs below
configureEach {
// 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.
systemProperty 'forge.logging.markers', 'REGISTRIES'
minecraft {
// The mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD Snapshot are built nightly.
// stable_# Stables are built at the discretion of the MCP team.
// 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: mapping_channel, version: mapping_version
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable.
// 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
systemProperty 'forge.logging.console.level', 'debug'
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
modSource project.sourceSets.main
}
// 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
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
// applies to all the run configs below
configureEach {
workingDirectory project.file('run')
server {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
programArgument '--nogui'
}
// 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'
// 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 {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
// 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'
}
data {
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
// workingDirectory project.file('run-data')
client {
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
property 'forge.enabledGameTestNamespaces', mod_id
}
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath()
server {
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 {
property 'forge.enabledGameTestNamespaces', mod_id
}
data {
// 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', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
}
}
}
@ -71,14 +88,12 @@ repositories {
dependencies {
// Specify the version of Minecraft to use.
// Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above.
// The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version.
// You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader.
// And its provides the option to then use net.minecraft as the group, and one of; client, server or joined as the module name, plus the game version as version.
// For all intends and purposes: You can treat this dependency as if it is a normal library you would use.
implementation "net.neoforged:neoforge:${neo_version}"
// 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}"
// implementation files('libs/javamp3-1.0.3.jar')
implementation 'fr.delthas:javamp3:1.0.3'
implementation 'com.github.stephengold:j-ogg-vorbis:1.0.4'
@ -96,36 +111,36 @@ dependencies {
// 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.withType(ProcessResources).configureEach {
tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [
minecraft_version : minecraft_version, minecraft_version_range: minecraft_version_range,
neo_version : neo_version, neo_version_range: neo_version_range,
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,
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']) {
filesMatching(['META-INF/mods.toml', 'pack.mcmeta']) {
expand replaceProperties + [project: project]
}
}
// Example for how to get properties into the manifest for reading by the runtime..
jar {
archiveClassifier = 'slim'
// Example for how to get properties into the manifest for reading at runtime.
tasks.named('jar', Jar).configure {
manifest {
attributes([
"Specification-Title": "TurnBasedMinecraftMod",
"Specification-Vendor": "TurnBasedMinecraftMod_BK",
"Specification-Version": "1", // We are version 1 of ourselves
"Implementation-Title": "TurnBasedMinecraftMod",
"Implementation-Version": "${version}",
"Implementation-Vendor" :"TurnBasedMinecraftMod_BK",
// Do not place timestamp for the sake of reproducible builds
// "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
'Specification-Title' : mod_id,
'Specification-Vendor' : mod_authors,
'Specification-Version' : '1', // We are version 1 of ourselves
'Implementation-Title' : "TurnBasedMinecraftMod",
'Implementation-Version' : project.jar.archiveVersion,
'Implementation-Vendor' : mod_authors
])
}
// This is the preferred method to reobfuscate your jar file
finalizedBy 'reobfJar'
}
// Reproducible Builds
@ -137,3 +152,13 @@ tasks.withType(AbstractArchiveTask).configureEach {
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
}
// Merge the resources and classes into the same directory.
// This is done because java expects modules to be in a single directory.
// And if we have it in multiple we have to do performance intensive hacks like having the UnionFileSystem
// This will eventually be migrated to ForgeGradle so modders don't need to manually do it. But that is later.
sourceSets.each {
def dir = layout.buildDirectory.dir("sourcesSets/$it.name")
it.output.resourcesDir = dir
it.java.destinationDirectory = dir
}

View file

@ -1,25 +1,38 @@
org.gradle.jvmargs=-Xmx4096m
org.gradle.daemon=false
org.gradle.debug=false
#read more on this at https://github.com/neoforged/NeoGradle/blob/NG_7.0/README.md#apply-parchment-mappings
# you can also find the latest versions at: https://parchmentmc.org/docs/getting-started
neogradle.subsystems.parchment.minecraftVersion=1.20.3
neogradle.subsystems.parchment.mappingsVersion=2023.12.31
# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
## Environment Properties
# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.4
# 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.4,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=20.4.109-beta
# The Neo version range can use any version of Neo as bounds
neo_version_range=[20.4,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[2,)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=49.0.19
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[0,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[0,)
# 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=official
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=1.20.4
## Mod Properties

Binary file not shown.

View file

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

11
gradlew vendored
View file

@ -85,9 +85,6 @@ done
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"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@ -144,7 +141,7 @@ 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
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@ -152,7 +149,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi
# 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"'
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in

184
gradlew.bat vendored
View file

@ -1,92 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
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%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
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%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View file

@ -2,7 +2,8 @@ pluginManagement {
repositories {
gradlePluginPortal()
maven {
url = 'https://maven.neoforged.net/releases'
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
jcenter()
mavenCentral()
@ -10,5 +11,5 @@ pluginManagement {
}
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
}

View file

@ -11,7 +11,7 @@ import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.neoforged.neoforge.network.PacketDistributor;
import net.minecraftforge.network.PacketDistributor;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
@ -275,20 +275,22 @@ public class BattleGui extends Screen {
setState(MenuState.ATTACK_TARGET);
break;
case DEFEND:
PacketDistributor.SERVER.noArg().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0));
TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING);
break;
case ITEM:
setState(MenuState.ITEM_ACTION);
break;
case FLEE:
PacketDistributor.SERVER.noArg().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0));
TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING);
break;
case ATTACK_TARGET:
// Invalid, but set menu to main menu anyways.
// Invalid but set to main menu anyways.
setState(MenuState.MAIN_MENU);
break;
case SWITCH_HELD_ITEM:
@ -301,7 +303,7 @@ public class BattleGui extends Screen {
setState(MenuState.MAIN_MENU);
break;
case DO_ITEM_SWITCH:
// Invalid, but set menu to main menu anyways.
// Invalid but set to main menu anyways.
setState(MenuState.MAIN_MENU);
break;
case DO_USE_ITEM:
@ -313,9 +315,9 @@ public class BattleGui extends Screen {
protected void entityButtonActionEvent(EntitySelectionButton button, ButtonAction action) {
if (action.equals(ButtonAction.ATTACK_TARGET)) {
PacketDistributor.SERVER.noArg().send(
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID()));
TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, button.getID()),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING);
} else {
setState(MenuState.MAIN_MENU);
@ -325,18 +327,18 @@ public class BattleGui extends Screen {
protected void itemButtonActionEvent(ItemSelectionButton button, ButtonAction action) {
switch (action) {
case DO_ITEM_SWITCH:
PacketDistributor.SERVER.noArg().send(
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
Battle.Decision.SWITCH_ITEM, button.getID()));
TurnBasedMinecraftMod.getHandler().send(
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, button.getID()),
PacketDistributor.SERVER.noArg());
if (button.getID() >= 0 && button.getID() < 9) {
Minecraft.getInstance().player.getInventory().selected = button.getID();
}
setState(MenuState.WAITING);
break;
case DO_USE_ITEM:
PacketDistributor.SERVER.noArg().send(
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(),
Battle.Decision.USE_ITEM, button.getID()));
TurnBasedMinecraftMod.getHandler().send(
new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, button.getID()),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING);
break;
default:
@ -358,6 +360,11 @@ public class BattleGui extends Screen {
return false; // TODO verify return value
}
@Override
public void renderBackground(GuiGraphics p_283688_, int p_299421_, int p_298679_, float p_297268_) {
// Left blank to not render background.
}
@Override
public boolean keyReleased(int a, int b, int c) {
if (getMinecraft().player.isCreative()) {
@ -381,9 +388,4 @@ public class BattleGui extends Screen {
public void setTurnTimerMax(int timerMax) {
this.timerMax = timerMax;
}
@Override
public void renderBackground(GuiGraphics p_283688_, int p_296369_, int p_296477_, float p_294317_) {
// Prevent graying of background.
}
}

View file

@ -15,7 +15,7 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.event.network.CustomPayloadEvent;
public class ClientProxy extends CommonProxy {
private BattleGui battleGui = null;
@ -222,7 +222,7 @@ public class ClientProxy extends CommonProxy {
}
@Override
public <MSG> void handlePacket(final MSG msg, final PlayPayloadContext ctx) {
public <MSG> void handlePacket(MSG msg, CustomPayloadEvent.Context ctx) {
if (msg.getClass() == PacketBattleMessage.class) {
PacketBattleMessage pkt = (PacketBattleMessage) msg;
Entity fromEntity = getEntity(pkt.getEntityIDFrom(), pkt.getDimension());
@ -433,6 +433,7 @@ public class ClientProxy extends CommonProxy {
parentComponent.getSiblings().add(message);
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
}
break;
case CROSSBOW_NO_AMMO: {
parentComponent.getSiblings().add(from);
parentComponent.getSiblings().add(Component.literal(" tried to use their crossbow but ran out of ammo!"));

View file

@ -9,10 +9,10 @@ import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
import net.neoforged.neoforge.event.entity.living.LivingChangeTargetEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import net.neoforged.bus.api.SubscribeEvent;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.network.PacketDistributor;
public class AttackEventHandler
{
@ -82,7 +82,7 @@ public class AttackEventHandler
if(!event.getEntity().hasCustomName())
{
TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name");
PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor).send(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"));
TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
return;
}
editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomName().getString());
@ -91,9 +91,9 @@ public class AttackEventHandler
editingInfo.entityInfo = new EntityInfo();
editingInfo.entityInfo.customName = event.getEntity().getCustomName().getString();
}
PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor).send(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\""));
TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\""), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomName().getString() + "\"");
PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
TurnBasedMinecraftMod.getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
}
else
{
@ -107,9 +107,9 @@ public class AttackEventHandler
{
editingInfo.entityInfo = editingInfo.entityInfo.clone();
}
PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor).send(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""));
TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\"");
PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
TurnBasedMinecraftMod.getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
}
return;
}

View file

@ -14,8 +14,8 @@ import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.CreativeModeTabRegistry;
import net.neoforged.neoforge.network.PacketDistributor;
import net.minecraftforge.common.CreativeModeTabRegistry;
import net.minecraftforge.network.PacketDistributor;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -449,7 +449,7 @@ public class Battle {
}
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
for (Combatant p : players.values()) {
PacketDistributor.PLAYER.with((ServerPlayer)p.entity).send(infoPacket);
TurnBasedMinecraftMod.getHandler().send(infoPacket, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
}
}
@ -464,7 +464,7 @@ public class Battle {
PacketBattleMessage packet = new PacketBattleMessage(type, from, to, dimension, amount, custom);
for (Combatant p : players.values()) {
if (p.entity.isAlive()) {
PacketDistributor.PLAYER.with((ServerPlayer)p.entity).send(packet);
TurnBasedMinecraftMod.getHandler().send(packet, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
}
}
}
@ -574,7 +574,7 @@ public class Battle {
private void removeCombatantPostRemove(Combatant c) {
if (c.entity instanceof Player) {
PacketDistributor.PLAYER.with((ServerPlayer)c.entity).send(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, dimension, 0));
TurnBasedMinecraftMod.getHandler().send(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, dimension, 0), PacketDistributor.PLAYER.with((ServerPlayer)c.entity));
}
battleManager.addRecentlyLeftBattle(c);
}
@ -796,7 +796,8 @@ public class Battle {
continue;
} else if (heldItemStack.getItem() instanceof CrossbowItem) {
debugLog += " with crossbow";
if (Utility.doesPlayerHaveArrows((Player) next.entity)) {
if (Utility.doesPlayerHaveArrows((Player)next.entity)) {
// Similar to attack with bow.
final Entity nextEntity = next.entity;
final Entity targetEntity = target.entity;
final float yawDirection = Utility.yawDirection(next.entity.getX(), next.entity.getZ(), target.entity.getX(), target.entity.getZ());
@ -809,7 +810,7 @@ public class Battle {
((ServerPlayer) nextEntity).connection.teleport(nextEntity.getX(), nextEntity.getY(), nextEntity.getZ(), yawDirection, pitchDirection);
CrossbowItem itemCrossbow = (CrossbowItem) heldItemStack.getItem();
TurnBasedMinecraftMod.proxy.getAttackerViaBowSet().add(new AttackerViaBow(nextEntity, getId()));
itemCrossbow.releaseUsing(heldItemStack, nextEntity.level(), (LivingEntity)nextEntity, -100);
itemCrossbow.releaseUsing(((Player) nextEntity).getMainHandItem(), nextEntity.level(), (LivingEntity) nextEntity, -100);
itemCrossbow.use(nextEntity.level(), (Player)nextEntity, InteractionHand.MAIN_HAND);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FIRED_ARROW, nextEntity.getId(), targetEntity.getId(), 0);
} else {

View file

@ -7,10 +7,10 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent;
import net.neoforged.neoforge.event.entity.living.LivingChangeTargetEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
import net.minecraftforge.network.PacketDistributor;
import org.apache.logging.log4j.Logger;
import java.util.*;
@ -32,7 +32,7 @@ public class BattleManager
recentlyLeftBattle = new HashMap<Integer, Combatant>();
battleUpdater = new BattleUpdater(this);
entityToBattleMap = new HashMap<EntityIDDimPair, Integer>();
NeoForge.EVENT_BUS.register(battleUpdater);
MinecraftForge.EVENT_BUS.register(battleUpdater);
tempIDPair = new EntityIDDimPair();
}
@ -307,7 +307,7 @@ public class BattleManager
public void cleanup()
{
battleUpdater.setRunning(false);
NeoForge.EVENT_BUS.unregister(battleUpdater);
MinecraftForge.EVENT_BUS.unregister(battleUpdater);
battleMap.clear();
battleUpdater = null;
}
@ -317,7 +317,7 @@ public class BattleManager
c.time = System.nanoTime();
Config config = TurnBasedMinecraftMod.proxy.getConfig();
if(c.entity instanceof ServerPlayer) {
PacketDistributor.PLAYER.with((ServerPlayer)c.entity).send(new PacketGeneralMessage("You just left battle! " + config.getLeaveBattleCooldownSeconds() + " seconds until you can attack/be-attacked again!"));
TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("You just left battle! " + config.getLeaveBattleCooldownSeconds() + " seconds until you can attack/be-attacked again!"), PacketDistributor.PLAYER.with((ServerPlayer)c.entity));
}
recentlyLeftBattle.put(c.entity.getId(), c);
entityToBattleMap.remove(new EntityIDDimPair(c.entity));
@ -337,7 +337,7 @@ public class BattleManager
iter.remove();
if(entry.getValue().entity instanceof ServerPlayer)
{
PacketDistributor.PLAYER.with((ServerPlayer)entry.getValue().entity).send(new PacketGeneralMessage("Timer ended, you can now attack/be-attacked again."));
TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Timer ended, you can now attack/be-attacked again."), PacketDistributor.PLAYER.with((ServerPlayer)entry.getValue().entity));
}
}
}

View file

@ -1,8 +1,8 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.TickEvent;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import java.util.concurrent.atomic.AtomicBoolean;

View file

@ -5,8 +5,8 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.neoforged.neoforge.server.ServerLifecycleHooks;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger;
import java.util.HashSet;
@ -172,5 +172,5 @@ public class CommonProxy
return ServerLifecycleHooks.getCurrentServer().getLevel(dim).getEntity(id);
}
public <MSG> void handlePacket(final MSG msg, final PlayPayloadContext ctx) {}
public <MSG> void handlePacket(MSG msg,CustomPayloadEvent.Context ctx) {}
}

View file

@ -1521,7 +1521,7 @@ public class Config
possibleIgnoreHurtDamageSources.clear();
try {
VanillaRegistries.createLookup().lookupOrThrow(Registries.DAMAGE_TYPE).listElements().forEach(dt -> possibleIgnoreHurtDamageSources.add(dt.value().msgId()));
VanillaRegistries.createLookup().lookupOrThrow(Registries.DAMAGE_TYPE).listElements().forEach(dt -> possibleIgnoreHurtDamageSources.add(dt.get().msgId()));
} catch (Exception e) {
logger.warn("Config failed to load possible DamageSources! Undesired things may happen, like Zombies dying from Fire during battle!");
logger.warn(e);

View file

@ -2,9 +2,9 @@ package com.burnedkirby.TurnBasedMinecraft.common;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.event.entity.EntityTravelToDimensionEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.network.PacketDistributor;
import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.network.PacketDistributor;
public class DimensionChangedHandler {
@SubscribeEvent
@ -14,7 +14,9 @@ public class DimensionChangedHandler {
}
if(TurnBasedMinecraftMod.proxy.getBattleManager().forceLeaveBattle(new EntityIDDimPair(event.getEntity()))
&& event.getEntity() instanceof ServerPlayer) {
PacketDistributor.PLAYER.with((ServerPlayer)event.getEntity()).send(new PacketGeneralMessage("Left battle due to moving to a different dimension"));
TurnBasedMinecraftMod.getHandler().send(
new PacketGeneralMessage("Left battle due to moving to a different dimension"),
PacketDistributor.PLAYER.with((ServerPlayer)event.getEntity()));
}
}
}

View file

@ -1,7 +1,7 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class HurtEventHandler {
@SubscribeEvent

View file

@ -1,8 +1,8 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import net.minecraft.world.entity.player.Player;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
public class PlayerJoinEventHandler
{

View file

@ -1,6 +1,5 @@
package com.burnedkirby.TurnBasedMinecraft.common;
import ca.weblite.objc.Client;
import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy;
import com.burnedkirby.TurnBasedMinecraft.common.networking.*;
import com.mojang.brigadier.LiteralMessage;
@ -19,20 +18,18 @@ import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.common.NeoForge;
import net.neoforged.neoforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlerEvent;
import net.neoforged.neoforge.network.registration.IPayloadRegistrar;
import net.neoforged.neoforge.network.PacketDistributor;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.network.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -51,62 +48,77 @@ public class TurnBasedMinecraftMod {
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
private static final String PROTOCOL_VERSION = Integer.toString(3);
private static final Integer PROTOCOL_VERSION = 3;
private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel");
private static final SimpleChannel HANDLER = ChannelBuilder
.named(HANDLER_ID)
.clientAcceptedVersions(Channel.VersionTest.exact(PROTOCOL_VERSION))
.serverAcceptedVersions(Channel.VersionTest.exact(PROTOCOL_VERSION))
.networkProtocolVersion(PROTOCOL_VERSION)
.simpleChannel();
protected static Logger logger = LogManager.getLogger();
public static ResourceLocation getNetResourceLocation() {
return HANDLER_ID;
}
public static CommonProxy proxy;
public TurnBasedMinecraftMod(IEventBus eventBus) {
eventBus.addListener(this::firstInit);
eventBus.addListener(this::secondInitClient);
eventBus.addListener(this::secondInitServer);
eventBus.addListener(this::registerNetwork);
NeoForge.EVENT_BUS.register(this);
public static SimpleChannel getHandler() {
return HANDLER;
}
private void registerNetwork(final RegisterPayloadHandlerEvent event) {
final IPayloadRegistrar registrar = event.registrar(MODID);
public static CommonProxy proxy;
registrar.play(PacketBattleDecision.ID, PacketBattleDecision::new, handler -> handler
.server(PacketBattleDecision.PayloadHandler.getInstance()::handleData));
public TurnBasedMinecraftMod() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::firstInit);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitClient);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitServer);
registrar.play(PacketBattleInfo.ID, PacketBattleInfo::new, handler -> handler
.client(PacketBattleInfo.PayloadHandler.getInstance()::handleData));
registrar.play(PacketBattleMessage.ID, PacketBattleMessage::new, handler -> handler
.client(PacketBattleMessage.PayloadHandler.getInstance()::handleData));
registrar.play(PacketBattleRequestInfo.ID, PacketBattleRequestInfo::new, handler -> handler
.server(PacketBattleRequestInfo.PayloadHandler.getInstance()::handleData));
registrar.play(PacketEditingMessage.ID, PacketEditingMessage::new, handler -> handler
.client(PacketEditingMessage.PayloadHandler.getInstance()::handleData));
registrar.play(PacketGeneralMessage.ID, PacketGeneralMessage::new, handler -> handler
.client(PacketGeneralMessage.PayloadHandler.getInstance()::handleData));
logger.debug("Register packets com_burnedkirby_turnbasedminecraft");
MinecraftForge.EVENT_BUS.register(this);
}
private void firstInit(final FMLCommonSetupEvent event) {
if (FMLEnvironment.dist.isClient()) {
proxy = new ClientProxy();
} else {
proxy = new CommonProxy();
}
proxy = DistExecutor.unsafeRunForDist(() -> () -> new ClientProxy(), () -> () -> new CommonProxy());
proxy.setLogger(logger);
proxy.initialize();
// register packets
HANDLER.messageBuilder(PacketBattleInfo.class, NetworkDirection.PLAY_TO_CLIENT)
.encoder(new PacketBattleInfo.Encoder())
.decoder(new PacketBattleInfo.Decoder())
.consumerNetworkThread(new PacketBattleInfo.Consumer())
.add();
HANDLER.messageBuilder(PacketBattleRequestInfo.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(new PacketBattleRequestInfo.Encoder())
.decoder(new PacketBattleRequestInfo.Decoder())
.consumerNetworkThread(new PacketBattleRequestInfo.Consumer())
.add();
HANDLER.messageBuilder(PacketBattleDecision.class, NetworkDirection.PLAY_TO_SERVER)
.encoder(new PacketBattleDecision.Encoder())
.decoder(new PacketBattleDecision.Decoder())
.consumerNetworkThread(new PacketBattleDecision.Consumer())
.add();
HANDLER.messageBuilder(PacketBattleMessage.class, NetworkDirection.PLAY_TO_CLIENT)
.encoder(new PacketBattleMessage.Encoder())
.decoder(new PacketBattleMessage.Decoder())
.consumerNetworkThread(new PacketBattleMessage.Consumer())
.add();
HANDLER.messageBuilder(PacketGeneralMessage.class, NetworkDirection.PLAY_TO_CLIENT)
.encoder(new PacketGeneralMessage.Encoder())
.decoder(new PacketGeneralMessage.Decoder())
.consumerNetworkThread(new PacketGeneralMessage.Consumer())
.add();
HANDLER.messageBuilder(PacketEditingMessage.class, NetworkDirection.PLAY_TO_CLIENT)
.encoder(new PacketEditingMessage.Encoder())
.decoder(new PacketEditingMessage.Decoder())
.consumerNetworkThread(new PacketEditingMessage.Consumer())
.add();
// register event handler(s)
NeoForge.EVENT_BUS.register(new AttackEventHandler());
NeoForge.EVENT_BUS.register(new PlayerJoinEventHandler());
NeoForge.EVENT_BUS.register(new DimensionChangedHandler());
NeoForge.EVENT_BUS.register(new HurtEventHandler());
MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
MinecraftForge.EVENT_BUS.register(new DimensionChangedHandler());
MinecraftForge.EVENT_BUS.register(new HurtEventHandler());
logger.debug("Init com_burnedkirby_turnbasedminecraft");
}
@ -152,7 +164,7 @@ public class TurnBasedMinecraftMod {
proxy.getConfig().setBattleDisabledForAll(true);
for (ServerPlayer player : c.getSource().getServer().getPlayerList().getPlayers()) {
proxy.getConfig().addBattleIgnoringPlayer(player.getId());
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("OP disabled turn-based-combat for everyone"));
getHandler().send(new PacketGeneralMessage("OP disabled turn-based-combat for everyone"), PacketDistributor.PLAYER.with(player));
}
return 1;
}));
@ -173,7 +185,7 @@ public class TurnBasedMinecraftMod {
proxy.getConfig().setBattleDisabledForAll(false);
proxy.getConfig().clearBattleIgnoringPlayers();
for (ServerPlayer player : c.getSource().getServer().getPlayerList().getPlayers()) {
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("OP enabled turn-based-combat for everyone"));
getHandler().send(new PacketGeneralMessage("OP enabled turn-based-combat for everyone"), PacketDistributor.PLAYER.with(player));
}
return 1;
}));
@ -184,7 +196,7 @@ public class TurnBasedMinecraftMod {
.then(Commands.argument("targets", EntityArgument.players()).executes(c -> {
for (ServerPlayer player : EntityArgument.getPlayers(c, "targets")) {
proxy.getConfig().addBattleIgnoringPlayer(player.getId());
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("OP enabled turn-based-combat for you"));
getHandler().send(new PacketGeneralMessage("OP enabled turn-based-combat for you"), PacketDistributor.PLAYER.with(player));
c.getSource().sendSuccess(() -> Component.literal("Enabled turn-based-combat for " + player.getDisplayName().getString()), true);
}
return 1;
@ -196,7 +208,7 @@ public class TurnBasedMinecraftMod {
.then(Commands.argument("targets", EntityArgument.players()).executes(c -> {
for (ServerPlayer player : EntityArgument.getPlayers(c, "targets")) {
proxy.getConfig().removeBattleIgnoringPlayer(player.getId());
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("OP disabled turn-based-combat for you"));
getHandler().send(new PacketGeneralMessage("OP disabled turn-based-combat for you"), PacketDistributor.PLAYER.with(player));
c.getSource().sendSuccess(() -> Component.literal("Disabled turn-based-combat for " + player.getDisplayName().getString()), true);
}
return 1;
@ -209,12 +221,12 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
proxy.setEditingPlayer(player);
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
logger.info("Begin editing TBM Entity for player \"" + player.getDisplayName().getString() + "\" (\"" + c.getSource().getDisplayName() + "\")");
}
return 1;
@ -225,14 +237,14 @@ public class TurnBasedMinecraftMod {
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
if (!proxy.getConfig().editEntityEntry(editingInfo.entityInfo)) {
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("An error occurred while attempting to save an entry to the config"));
getHandler().send(new PacketGeneralMessage("An error occurred while attempting to save an entry to the config"), PacketDistributor.PLAYER.with(player));
proxy.removeEditingInfo(player.getId());
} else {
proxy.removeEditingInfo(player.getId());
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("Entity info saved in config and loaded."));
getHandler().send(new PacketGeneralMessage("Entity info saved in config and loaded."), PacketDistributor.PLAYER.with(player));
}
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -245,7 +257,7 @@ public class TurnBasedMinecraftMod {
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null) {
proxy.removeEditingInfo(player.getId());
PacketDistributor.PLAYER.with(player).send(new PacketGeneralMessage("Cancelled editing entry."));
getHandler().send(new PacketGeneralMessage("Cancelled editing entry."), PacketDistributor.PLAYER.with(player));
}
return 1;
}))
@ -257,11 +269,11 @@ public class TurnBasedMinecraftMod {
Message exceptionMessage = new LiteralMessage("Invalid action for tbm-edit");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
proxy.setEditingPlayer(player);
proxy.getEditingInfo(player.getId()).isEditingCustomName = true;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
logger.info("Begin editing custom TBM Entity for player \"" + player.getDisplayName().getString() + "\" (\"" + c.getSource().getDisplayName() + "\")");
}
return 1;
@ -271,9 +283,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -285,9 +297,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -301,9 +313,9 @@ public class TurnBasedMinecraftMod {
boolean ignoreBattle = BoolArgumentType.getBool(c, "ignoreBattle");
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.ignoreBattle = ignoreBattle;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -316,9 +328,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -335,9 +347,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackPower = attackPower;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -350,9 +362,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -371,9 +383,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackProbability = attackProbability;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -386,9 +398,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -405,9 +417,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackVariance = attackVariance;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -420,9 +432,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -436,9 +448,9 @@ public class TurnBasedMinecraftMod {
EntityInfo.Effect effect = EntityInfo.Effect.fromString(StringArgumentType.getString(c, "attackEffect"));
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackEffect = effect;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -451,9 +463,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -472,9 +484,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackEffectProbability = attackEffectProbability;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -487,9 +499,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -506,9 +518,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.defenseDamage = defenseDamage;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -521,9 +533,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -542,9 +554,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.defenseDamageProbability = defenseDamageProbability;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -557,9 +569,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -578,9 +590,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.evasion = evasion;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -593,9 +605,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -612,9 +624,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.speed = speed;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -627,9 +639,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -643,9 +655,9 @@ public class TurnBasedMinecraftMod {
String category = StringArgumentType.getString(c, "category");
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.category = category;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -658,9 +670,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -679,9 +691,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.decisionAttack = decisionAttack;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -694,9 +706,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -715,9 +727,9 @@ public class TurnBasedMinecraftMod {
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.decisionDefend = decisionDefend;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -730,9 +742,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -746,9 +758,9 @@ public class TurnBasedMinecraftMod {
int decisionFlee = IntegerArgumentType.getInteger(c, "decisionFlee");
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.decisionFlee = decisionFlee;
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -764,7 +776,7 @@ public class TurnBasedMinecraftMod {
.requires(c -> c.hasPermission(2))
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
PacketDistributor.PLAYER.with(player).send(new PacketEditingMessage(PacketEditingMessage.Type.SERVER_EDIT));
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.SERVER_EDIT), PacketDistributor.PLAYER.with(player));
return 1;
})
.then(Commands.literal("leave_battle_cooldown").executes(c -> {

View file

@ -1,20 +1,18 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.Battle.Decision;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.player.Player;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleDecision implements CustomPacketPayload
public class PacketBattleDecision
{
public static final ResourceLocation ID = new ResourceLocation(TurnBasedMinecraftMod.MODID, "network_packetbattledecision");
private int battleID;
private Battle.Decision decision;
private int targetIDOrItemID;
@ -28,43 +26,40 @@ public class PacketBattleDecision implements CustomPacketPayload
this.targetIDOrItemID = targetIDOrItemID;
}
public PacketBattleDecision(final FriendlyByteBuf buf) {
this.battleID = buf.readInt();
this.decision = Decision.valueOf(buf.readInt());
this.targetIDOrItemID = buf.readInt();
}
public static class Encoder implements BiConsumer<PacketBattleDecision, FriendlyByteBuf> {
public Encoder() {}
@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(battleID);
buf.writeInt(decision.getValue());
buf.writeInt(targetIDOrItemID);
}
@Override
public ResourceLocation id() {
return ID;
}
public static class PayloadHandler {
private static final PayloadHandler INSTANCE = new PayloadHandler();
public static PayloadHandler getInstance() {
return INSTANCE;
@Override
public void accept(PacketBattleDecision pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.battleID);
buf.writeInt(pkt.decision.getValue());
buf.writeInt(pkt.targetIDOrItemID);
}
}
public void handleData(final PacketBattleDecision pkt, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
if(b != null)
{
Player player = ctx.player().get();
b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID);
}
}).exceptionally(e -> {
ctx.packetHandler().disconnect(Component.literal("Exception handling PacketBattleDecision! " + e.getMessage()));
return null;
});
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleDecision> {
public Decoder() {}
@Override
public PacketBattleDecision apply(FriendlyByteBuf buf) {
return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
}
}
public static class Consumer implements BiConsumer<PacketBattleDecision, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketBattleDecision pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
if(b != null)
{
ServerPlayer player = ctx.getSender();
b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID);
}
});
ctx.setPacketHandled(true);
}
}
}

View file

@ -2,20 +2,18 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.FriendlyByteBuf;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleInfo implements CustomPacketPayload
public class PacketBattleInfo
{
public static final ResourceLocation ID = new ResourceLocation(TurnBasedMinecraftMod.MODID, "network_packetbattleinfo");
private Collection<Integer> sideA;
private Collection<Integer> sideB;
private long decisionNanos;
@ -41,51 +39,53 @@ public class PacketBattleInfo implements CustomPacketPayload
this.turnTimerEnabled = turnTimerEnabled;
}
public PacketBattleInfo(final FriendlyByteBuf buf) {
int sideACount = buf.readInt();
int sideBCount = buf.readInt();
this.sideA = new ArrayList<>(sideACount);
this.sideB = new ArrayList<>(sideBCount);
for (int i = 0; i < sideACount; ++i) {
this.sideA.add(buf.readInt());
public static class Encoder implements BiConsumer<PacketBattleInfo, FriendlyByteBuf> {
public Encoder() {}
@Override
public void accept(PacketBattleInfo msg, FriendlyByteBuf buf) {
buf.writeInt(msg.sideA.size());
buf.writeInt(msg.sideB.size());
for(Integer id : msg.sideA) {
buf.writeInt(id);
}
for(Integer id : msg.sideB) {
buf.writeInt(id);
}
buf.writeLong(msg.decisionNanos);
buf.writeLong(msg.maxDecisionNanos);
buf.writeBoolean(msg.turnTimerEnabled);
}
for (int i = 0; i < sideBCount; ++i) {
this.sideB.add(buf.readInt());
}
this.decisionNanos = buf.readLong();
this.maxDecisionNanos = buf.readLong();
this.turnTimerEnabled = buf.readBoolean();
}
@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(sideA.size());
buf.writeInt(sideB.size());
for(Integer id : sideA) {
buf.writeInt(id);
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleInfo> {
public Decoder() {}
@Override
public PacketBattleInfo apply(FriendlyByteBuf buf) {
int sideACount = buf.readInt();
int sideBCount = buf.readInt();
Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
Collection<Integer> sideB = new ArrayList<Integer>(sideBCount);
for(int i = 0; i < sideACount; ++i) {
sideA.add(buf.readInt());
}
for(int i = 0; i < sideBCount; ++i) {
sideB.add(buf.readInt());
}
long decisionNanos = buf.readLong();
long maxDecisionNanos = buf.readLong();
boolean turnTimerEnabled = buf.readBoolean();
return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
}
for(Integer id : sideB) {
buf.writeInt(id);
}
buf.writeLong(decisionNanos);
buf.writeLong(maxDecisionNanos);
buf.writeBoolean(turnTimerEnabled);
}
@Override
public ResourceLocation id() {
return ID;
}
public static class Consumer implements BiConsumer<PacketBattleInfo, CustomPayloadEvent.Context> {
public Consumer() {}
public static class PayloadHandler {
private static final PayloadHandler INSTANCE = new PayloadHandler();
public static PayloadHandler getInstance() {
return INSTANCE;
}
public void handleData(final PacketBattleInfo pkt, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
@Override
public void accept(PacketBattleInfo pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{
return;
@ -111,10 +111,8 @@ public class PacketBattleInfo implements CustomPacketPayload
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerMax((int)(pkt.maxDecisionNanos / 1000000000L));
}).exceptionally(e -> {
ctx.packetHandler().disconnect(Component.literal("Exception handling PacketBattleInfo! " + e.getMessage()));
return null;
});
ctx.setPacketHandled(true);
}
}
}

View file

@ -2,38 +2,21 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.Utility;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.Level;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor;
public class PacketBattleMessage implements CustomPacketPayload
public class PacketBattleMessage
{
public static final ResourceLocation ID = new ResourceLocation(TurnBasedMinecraftMod.MODID, "network_packetbattlemessage");
@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(messageType.getValue());
buf.writeInt(entityIDFrom);
buf.writeInt(entityIDTo);
buf.writeUtf(Utility.serializeDimension(dimension));
buf.writeInt(amount);
buf.writeUtf(custom);
}
@Override
public ResourceLocation id() {
return ID;
}
public enum MessageType
{
ENTERED(0),
@ -173,31 +156,45 @@ public class PacketBattleMessage implements CustomPacketPayload
this.custom = custom;
}
public PacketBattleMessage(final FriendlyByteBuf buf) {
this.messageType = MessageType.valueOf(buf.readInt());
this.entityIDFrom = buf.readInt();
this.entityIDTo = buf.readInt();
this.dimension = Utility.deserializeDimension(buf.readUtf());
this.amount = buf.readInt();
this.custom = buf.readUtf();
public static class Encoder implements BiConsumer<PacketBattleMessage, FriendlyByteBuf> {
public Encoder() {}
@Override
public void accept(PacketBattleMessage pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.messageType.getValue());
buf.writeInt(pkt.entityIDFrom);
buf.writeInt(pkt.entityIDTo);
buf.writeUtf(Utility.serializeDimension(pkt.dimension));
buf.writeInt(pkt.amount);
buf.writeUtf(pkt.custom);
}
}
public static class PayloadHandler {
private static final PayloadHandler INSTANCE = new PayloadHandler();
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleMessage> {
public Decoder() {}
public static PayloadHandler getInstance() {
return INSTANCE;
@Override
public PacketBattleMessage apply(FriendlyByteBuf buf) {
return new PacketBattleMessage(
MessageType.valueOf(
buf.readInt()),
buf.readInt(),
buf.readInt(),
Utility.deserializeDimension(buf.readUtf()),
buf.readInt(),
buf.readUtf());
}
}
public void handleData(final PacketBattleMessage pkt, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
if (FMLEnvironment.dist.isClient()) {
TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
}
}).exceptionally(e -> {
ctx.packetHandler().disconnect(Component.literal("Exception handling PacketBattleMessage! " + e.getMessage()));
return null;
public static class Consumer implements BiConsumer<PacketBattleMessage, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketBattleMessage pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
});
ctx.setPacketHandled(true);
}
}
}

View file

@ -1,18 +1,16 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleRequestInfo implements CustomPacketPayload
public class PacketBattleRequestInfo
{
public static final ResourceLocation ID = new ResourceLocation(TurnBasedMinecraftMod.MODID, "network_packetbattlerequestinfo");
private int battleID;
public PacketBattleRequestInfo() {}
@ -22,43 +20,37 @@ public class PacketBattleRequestInfo implements CustomPacketPayload
this.battleID = battleID;
}
public PacketBattleRequestInfo(final FriendlyByteBuf buf) {
battleID = buf.readInt();
}
public static class Encoder implements BiConsumer<PacketBattleRequestInfo, FriendlyByteBuf> {
public Encoder() {}
@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(battleID);
}
@Override
public ResourceLocation id() {
return ID;
}
public static class PayloadHandler {
private static final PayloadHandler INSTANCE = new PayloadHandler();
public static PayloadHandler getInstance() {
return INSTANCE;
@Override
public void accept(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.battleID);
}
}
public void handleData(final PacketBattleRequestInfo pkt, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
public static class Decoder implements Function<FriendlyByteBuf, PacketBattleRequestInfo> {
public Decoder() {}
@Override
public PacketBattleRequestInfo apply(FriendlyByteBuf buf) {
return new PacketBattleRequestInfo(buf.readInt());
}
}
public static class Consumer implements BiConsumer<PacketBattleRequestInfo, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketBattleRequestInfo pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
if(b == null) {
return;
}
ctx.replyHandler().send(new PacketBattleInfo(
b.getSideAIDs(),
b.getSideBIDs(),
b.getTimerNanos(),
TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(),
!TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()));
}).exceptionally(e -> {
ctx.packetHandler().disconnect(Component.literal("Exception handling PacketBattleRequestInfo! " + e.getMessage()));
return null;
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx);
});
ctx.setPacketHandled(true);
}
}
}

View file

@ -3,49 +3,17 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import com.burnedkirby.TurnBasedMinecraft.common.EntityInfo;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class PacketEditingMessage implements CustomPacketPayload
public class PacketEditingMessage
{
public static final ResourceLocation ID = new ResourceLocation(TurnBasedMinecraftMod.MODID, "network_packeteditingmessage");
@Override
public void write(FriendlyByteBuf buf) {
buf.writeInt(type.getValue());
if(entityInfo.classType != null) {
buf.writeUtf(entityInfo.classType.getName());
} else {
buf.writeUtf("unknown");
}
buf.writeBoolean(entityInfo.ignoreBattle);
buf.writeInt(entityInfo.attackPower);
buf.writeInt(entityInfo.attackProbability);
buf.writeInt(entityInfo.attackVariance);
buf.writeUtf(entityInfo.attackEffect.toString());
buf.writeInt(entityInfo.attackEffectProbability);
buf.writeInt(entityInfo.defenseDamage);
buf.writeInt(entityInfo.defenseDamageProbability);
buf.writeInt(entityInfo.evasion);
buf.writeInt(entityInfo.speed);
buf.writeUtf(entityInfo.category);
buf.writeInt(entityInfo.decisionAttack);
buf.writeInt(entityInfo.decisionDefend);
buf.writeInt(entityInfo.decisionFlee);
buf.writeUtf(entityInfo.customName);
}
@Override
public ResourceLocation id() {
return ID;
}
public enum Type
{
ATTACK_ENTITY(0),
@ -121,45 +89,73 @@ public class PacketEditingMessage implements CustomPacketPayload
}
}
public PacketEditingMessage(final FriendlyByteBuf buf) {
this.type = Type.valueOf(buf.readInt());
this.entityInfo = new EntityInfo();
try {
this.entityInfo.classType = this.entityInfo.getClass().getClassLoader().loadClass(buf.readUtf());
} catch (ClassNotFoundException e) { /* ignored */ }
this.entityInfo.ignoreBattle = buf.readBoolean();
this.entityInfo.attackPower = buf.readInt();
this.entityInfo.attackProbability = buf.readInt();
this.entityInfo.attackVariance = buf.readInt();
this.entityInfo.attackEffect = EntityInfo.Effect.fromString(buf.readUtf());
this.entityInfo.attackEffectProbability = buf.readInt();
this.entityInfo.defenseDamage = buf.readInt();
this.entityInfo.defenseDamageProbability = buf.readInt();
this.entityInfo.evasion = buf.readInt();
this.entityInfo.speed = buf.readInt();
this.entityInfo.category = buf.readUtf();
this.entityInfo.decisionAttack = buf.readInt();
this.entityInfo.decisionDefend = buf.readInt();
this.entityInfo.decisionFlee = buf.readInt();
this.entityInfo.customName = buf.readUtf();
public static class Encoder implements BiConsumer<PacketEditingMessage, FriendlyByteBuf> {
public Encoder() {}
@Override
public void accept(PacketEditingMessage pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.type.getValue());
if(pkt.entityInfo.classType != null) {
buf.writeUtf(pkt.entityInfo.classType.getName());
} else {
buf.writeUtf("unknown");
}
buf.writeBoolean(pkt.entityInfo.ignoreBattle);
buf.writeInt(pkt.entityInfo.attackPower);
buf.writeInt(pkt.entityInfo.attackProbability);
buf.writeInt(pkt.entityInfo.attackVariance);
buf.writeUtf(pkt.entityInfo.attackEffect.toString());
buf.writeInt(pkt.entityInfo.attackEffectProbability);
buf.writeInt(pkt.entityInfo.defenseDamage);
buf.writeInt(pkt.entityInfo.defenseDamageProbability);
buf.writeInt(pkt.entityInfo.evasion);
buf.writeInt(pkt.entityInfo.speed);
buf.writeUtf(pkt.entityInfo.category);
buf.writeInt(pkt.entityInfo.decisionAttack);
buf.writeInt(pkt.entityInfo.decisionDefend);
buf.writeInt(pkt.entityInfo.decisionFlee);
buf.writeUtf(pkt.entityInfo.customName);
}
}
public static class PayloadHandler {
private static final PayloadHandler INSTANCE = new PayloadHandler();
public static class Decoder implements Function<FriendlyByteBuf, PacketEditingMessage> {
public Decoder() {}
public static PayloadHandler getInstance() {
return INSTANCE;
@Override
public PacketEditingMessage apply(FriendlyByteBuf buf) {
Type type = Type.valueOf(buf.readInt());
EntityInfo einfo = new EntityInfo();
try {
einfo.classType = einfo.getClass().getClassLoader().loadClass(buf.readUtf());
} catch (ClassNotFoundException e) { /* ignored */ }
einfo.ignoreBattle = buf.readBoolean();
einfo.attackPower = buf.readInt();
einfo.attackProbability = buf.readInt();
einfo.attackVariance = buf.readInt();
einfo.attackEffect = EntityInfo.Effect.fromString(buf.readUtf());
einfo.attackEffectProbability = buf.readInt();
einfo.defenseDamage = buf.readInt();
einfo.defenseDamageProbability = buf.readInt();
einfo.evasion = buf.readInt();
einfo.speed = buf.readInt();
einfo.category = buf.readUtf();
einfo.decisionAttack = buf.readInt();
einfo.decisionDefend = buf.readInt();
einfo.decisionFlee = buf.readInt();
einfo.customName = buf.readUtf();
return new PacketEditingMessage(type, einfo);
}
}
public void handleData(final PacketEditingMessage pkt, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
if (FMLEnvironment.dist.isClient()) {
TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
}
}).exceptionally(e -> {
ctx.packetHandler().disconnect(Component.literal("Exception handling PacketEditingMessage! " + e.getMessage()));
return null;
public static class Consumer implements BiConsumer<PacketEditingMessage, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketEditingMessage pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
});
ctx.setPacketHandled(true);
}
}
}
}

View file

@ -1,18 +1,17 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.fml.loading.FMLEnvironment;
import net.neoforged.neoforge.network.handling.PlayPayloadContext;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor;
public class PacketGeneralMessage implements CustomPacketPayload
public class PacketGeneralMessage
{
public static final ResourceLocation ID = new ResourceLocation(TurnBasedMinecraftMod.MODID, "network_packetgeneralmessage");
String message;
public String getMessage() {
@ -29,36 +28,33 @@ public class PacketGeneralMessage implements CustomPacketPayload
this.message = message;
}
public PacketGeneralMessage(final FriendlyByteBuf buf) {
this.message = buf.readUtf();
}
public static class Encoder implements BiConsumer<PacketGeneralMessage, FriendlyByteBuf> {
public Encoder() {}
@Override
public void write(FriendlyByteBuf buf) {
buf.writeUtf(message);
}
@Override
public ResourceLocation id() {
return ID;
}
public static class PayloadHandler {
private static final PayloadHandler INSTANCE = new PayloadHandler();
public static PayloadHandler getInstance() {
return INSTANCE;
@Override
public void accept(PacketGeneralMessage pkt, FriendlyByteBuf buf) {
buf.writeUtf(pkt.message);
}
}
public void handleData(final PacketGeneralMessage pkt, final PlayPayloadContext ctx) {
ctx.workHandler().submitAsync(() -> {
if (FMLEnvironment.dist.isClient()) {
TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
}
}).exceptionally(e -> {
ctx.packetHandler().disconnect(Component.literal("Exception handling PacketGeneralMessage! " + e.getMessage()));
return null;
public static class Decoder implements Function<FriendlyByteBuf, PacketGeneralMessage> {
public Decoder() {}
@Override
public PacketGeneralMessage apply(FriendlyByteBuf buf) {
return new PacketGeneralMessage(buf.readUtf());
}
}
public static class Consumer implements BiConsumer<PacketGeneralMessage, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketGeneralMessage pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
});
ctx.setPacketHandled(true);
}
}
}

View file

@ -9,7 +9,7 @@ modLoader="javafml" #mandatory
loaderVersion="${loader_version_range}" #mandatory (34 is current forge version)
# A URL to refer people to when problems occur with this mod
issueTrackerURL="https://github.com/Stephen-Seo/TurnBasedMinecraftMod/issues" #optional
license="${mod_license}"
license="MIT"
# A list of mods - how many allowed here is determined by the individual mod loader
[[mods]] #mandatory
# The modid of the mod
@ -29,18 +29,20 @@ credits="Thanks for this mod goes to Java" #optional
# A text field displayed in the mod UI
authors="${mod_authors}" #optional
# The description text for the mod (multi line!) (#mandatory)
description='''${mod_description}'''
description='''
Implements turn-based-battle in Minecraft.
'''
logoFile="assets/com_burnedkirby_turnbasedminecraft/tbmm_icon.png"
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.com_burnedkirby_turnbasedminecraft]] #optional
# the modid of the dependency
modId="neoforge" #mandatory
modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
type="required" #mandatory
mandatory=true #mandatory
# The version range of the dependency
versionRange="${neo_version_range}" #mandatory
versionRange="${forge_version_range}" #mandatory
# An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER
@ -48,7 +50,7 @@ logoFile="assets/com_burnedkirby_turnbasedminecraft/tbmm_icon.png"
# Here's another dependency
[[dependencies.com_burnedkirby_turnbasedminecraft]]
modId="minecraft"
type="required"
mandatory=true
versionRange="${minecraft_version_range}"
ordering="NONE"
side="BOTH"