id 'eclipse'
id 'idea'
id 'maven-publish'
- id 'net.minecraftforge.gradle' version '[6.0,6.2)'
- id 'com.github.johnrengelman.shadow' version '8.1.1'
+ id 'net.neoforged.gradle.userdev' version '7.0.57'
}
-version = "1.23.1"
+version = "1.24.0"
group = "com.burnedkirby.TurnBasedMinecraft"
-archivesBaseName = "TurnBasedMinecraft"
+archivesBaseName = "TurnBasedMinecraft-NeoForge"
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'))
-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.
-
- // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
-
- // 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
-
- // Default run configurations.
- // These can be tweaked, removed, or duplicated as needed.
- runs {
- client {
- workingDirectory project.file('run')
-
- // Recommended logging data for a userdev environment
- property 'forge.logging.markers', 'REGISTRIES'
-
- // Recommended logging level for the console
- property 'forge.logging.console.level', 'debug'
-
- // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
- property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
-
- mods {
- TurnBasedMinecraftMod {
- source sourceSets.main
- }
- }
- }
-
- server {
- workingDirectory project.file('run')
-
- // Recommended logging data for a userdev environment
- property 'forge.logging.markers', 'REGISTRIES'
-
- // Recommended logging level for the console
- property 'forge.logging.console.level', 'debug'
-
- // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
- property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
-
- mods {
- TurnBasedMinecraftMod {
- source sourceSets.main
- }
- }
- }
-
- // This run config launches GameTestServer and runs all registered gametests, then exits.
- // By default, the server will crash when no gametests are provided.
- // The gametest system is also enabled by default for other run configs under the /test command.
- gameTestServer {
- workingDirectory project.file('run')
-
- // Recommended logging data for a userdev environment
- // The markers can be added/remove as needed separated by commas.
- // "SCAN": For mods scan.
- // "REGISTRIES": For firing of registry events.
- // "REGISTRYDUMP": For getting the contents of all registries.
- property 'forge.logging.markers', 'REGISTRIES'
-
- // Recommended logging level for the console
- // You can set various levels here.
- // Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
- property 'forge.logging.console.level', 'debug'
-
- // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
- property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
-
- mods {
- TurnBasedMinecraftMod {
- source sourceSets.main
- }
- }
- }
-
- data {
- workingDirectory project.file('run')
-
- // Recommended logging data for a userdev environment
- property 'forge.logging.markers', 'REGISTRIES'
-
- // Recommended logging level for the console
- property 'forge.logging.console.level', 'debug'
-
- args '--mod', 'TurnBasedMinecraftMod', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources')
-
- mods {
- TurnBasedMinecraftMod {
- source sourceSets.main
- }
- }
- }
+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'
+
+ // 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'
+
+ modSource project.sourceSets.main
}
-}
-
-// Include resources generated by data generators.
-sourceSets.main.resources { srcDir 'src/generated/resources' }
-//repositories {
-// // Put repositories for dependencies here
-// // ForgeGradle automatically adds the Forge maven and Maven Central for you
-//
-// // If you have mod jar dependencies in ./libs, you can declare them as a repository like so:
-// // flatDir {
-// // dir 'libs'
-// // }
-// mavenCentral()
-// jcenter()
-//
-// dependencies {
-// classpath 'com.github.jengelman.gradle.plugins:shadow:4.0.4'
-// }
-//}
+ client {
+ // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
+ systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
+ }
-apply plugin: 'com.github.johnrengelman.shadow'
+ server {
+ systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
+ programArgument '--nogui'
+ }
-configurations {
- shade
- impelmentation.extendsFrom shade
-}
+ // 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
+ }
-dependencies {
- // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
- // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
- // The userdev artifact is a special name and will get all sorts of transformations applied to it.
- minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
+ data {
+ // example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it
+ // workingDirectory project.file('run-data')
- // Real mod deobf dependency examples - these get remapped to your current mappings
- // compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
- // runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
- // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency
+ // 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()
+ }
+}
- // Examples using mod jars from ./libs
- // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
+// Include resources generated by data generators.
+sourceSets.main.resources { srcDir 'src/generated/resources' }
- // For more info...
- // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
- // http://www.gradle.org/docs/current/userguide/dependency_management.html
- implementation files('libs/javamp3-1.0.3.jar')
+repositories {
+ flatDir {
+ dir 'libs'
+ }
+}
- shade files('libs/javamp3-1.0.3.jar')
+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}"
+
+// implementation files('libs/javamp3-1.0.3.jar')
+ implementation 'fr.delthas:javamp3:1.0.3'
+
+ jarJar(group: 'fr.delthas', name: 'javamp3', version: '[1.0.0,2.0.0)') {
+ jarJar.pin(it, '1.0.3')
+ }
}
// This block of code expands all declared replace properties in the specified resource targets.
tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
- forge_version: forge_version, forge_version_range: forge_version_range,
+ neo_version : neo_version, neo_version_range: neo_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,
}
}
-shadowJar {
- archiveClassifier = ''
- //project.configurations.shadow.setTransitive(true);
- configurations = [project.configurations.shade]
- relocate 'fr.delthas', 'com.burnedkirby.tbm_repack.fr.delthas'
- finalizedBy 'reobfShadowJar'
-}
-
-assemble.dependsOn shadowJar
-
-reobf {
- shadowJar {} // reobfuscate the shadowed jar
-}
-
// Reproducible Builds
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
+tasks.withType(JavaCompile).configureEach {
+ options.encoding = 'UTF-8' // Use the UTF-8 charset for Java compilation
+}
+
// Example configuration to allow publishing using the maven-publish task
// we define a custom artifact that is sourced from the reobfJar output task
// and then declare that to be published
## Environment Properties
# The Minecraft version must agree with the Forge version to get a valid artifact
-minecraft_version=1.20.1
+minecraft_version=1.20.2
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
-minecraft_version_range=[1.20.1,1.21)
-# The Forge version must agree with the Minecraft version to get a valid artifact
-forge_version=47.1.0
-# The Forge version range can use any version of Forge as bounds or match the loader version range
-forge_version_range=[47,)
-# The loader version range can only use the major version of Forge/FML as bounds
-loader_version_range=[47,)
-# The mapping channel to use for mappings.
-# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
-# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
-#
-# | Channel | Version | |
-# |-----------|----------------------|--------------------------------------------------------------------------------|
-# | official | MCVersion | Official field/method names from Mojang mapping files |
-# | parchment | YYYY.MM.DD-MCVersion | Open community-sourced parameter names and javadocs layered on top of official |
-#
-# You must be aware of the Mojang license when using the 'official' or 'parchment' mappings.
-# See more information here: https://github.com/MinecraftForge/MCPConfig/blob/master/Mojang.md
-#
-# Parchment is an unofficial project maintained by ParchmentMC, separate from Minecraft Forge.
-# Additional setup is needed to use their mappings, see https://parchmentmc.org/docs/getting-started
-mapping_channel=official
-# The mapping version to query from the mapping channel.
-# This must match the format required by the mapping channel.
-mapping_version=1.20.1
+minecraft_version_range=[1.20.2,1.21)
+# The Neo version must agree with the Minecraft version to get a valid artifact
+neo_version=20.2.86
+# The Neo version range can use any version of Neo as bounds or match the loader version range
+neo_version_range=[20.2,)
+# The loader version range can only use the major version of Neo/FML as bounds
+loader_version_range=[1,)
## Mod Properties
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT
# The mod version. See https://semver.org/
-mod_version=1.23.1
+mod_version=1.24.0
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
mod_authors=BurnedKirby a.k.a. Stephen Seo
# The description of the mod. This is a simple multiline text string that is used for display purposes in the mod list.
mod_description=Implements turn-based-battle in Minecraft.
+# Pack version - this changes each minecraft release, in general.
+pack_format_number=18
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
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
'' | 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
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
-@rem\r
-@rem Copyright 2015 the original author or authors.\r
-@rem\r
-@rem Licensed under the Apache License, Version 2.0 (the "License");\r
-@rem you may not use this file except in compliance with the License.\r
-@rem You may obtain a copy of the License at\r
-@rem\r
-@rem https://www.apache.org/licenses/LICENSE-2.0\r
-@rem\r
-@rem Unless required by applicable law or agreed to in writing, software\r
-@rem distributed under the License is distributed on an "AS IS" BASIS,\r
-@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-@rem See the License for the specific language governing permissions and\r
-@rem limitations under the License.\r
-@rem\r
-\r
-@if "%DEBUG%"=="" @echo off\r
-@rem ##########################################################################\r
-@rem\r
-@rem Gradle startup script for Windows\r
-@rem\r
-@rem ##########################################################################\r
-\r
-@rem Set local scope for the variables with windows NT shell\r
-if "%OS%"=="Windows_NT" setlocal\r
-\r
-set DIRNAME=%~dp0\r
-if "%DIRNAME%"=="" set DIRNAME=.\r
-@rem This is normally unused\r
-set APP_BASE_NAME=%~n0\r
-set APP_HOME=%DIRNAME%\r
-\r
-@rem Resolve any "." and ".." in APP_HOME to make it shorter.\r
-for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi\r
-\r
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\r
-set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"\r
-\r
-@rem Find java.exe\r
-if defined JAVA_HOME goto findJavaFromJavaHome\r
-\r
-set JAVA_EXE=java.exe\r
-%JAVA_EXE% -version >NUL 2>&1\r
-if %ERRORLEVEL% equ 0 goto execute\r
-\r
-echo.\r
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\r
-echo.\r
-echo Please set the JAVA_HOME variable in your environment to match the\r
-echo location of your Java installation.\r
-\r
-goto fail\r
-\r
-:findJavaFromJavaHome\r
-set JAVA_HOME=%JAVA_HOME:"=%\r
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe\r
-\r
-if exist "%JAVA_EXE%" goto execute\r
-\r
-echo.\r
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\r
-echo.\r
-echo Please set the JAVA_HOME variable in your environment to match the\r
-echo location of your Java installation.\r
-\r
-goto fail\r
-\r
-:execute\r
-@rem Setup the command line\r
-\r
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar\r
-\r
-\r
-@rem Execute Gradle\r
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*\r
-\r
-:end\r
-@rem End local scope for the variables with windows NT shell\r
-if %ERRORLEVEL% equ 0 goto mainEnd\r
-\r
-:fail\r
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\r
-rem the _cmd.exe /c_ return code!\r
-set EXIT_CODE=%ERRORLEVEL%\r
-if %EXIT_CODE% equ 0 set EXIT_CODE=1\r
-if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%\r
-exit /b %EXIT_CODE%\r
-\r
-:mainEnd\r
-if "%OS%"=="Windows_NT" endlocal\r
-\r
-:omega\r
+@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
repositories {\r
gradlePluginPortal()\r
maven {\r
- name = 'MinecraftForge'\r
- url = 'https://maven.minecraftforge.net/'\r
+ url = 'https://maven.neoforged.net/releases'\r
}\r
jcenter()\r
mavenCentral()\r
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.
+ }
}
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level;
-import net.minecraftforge.network.NetworkEvent;
-
-import java.util.function.Supplier;
+import net.neoforged.neoforge.network.NetworkEvent;
public class ClientProxy extends CommonProxy {
private BattleGui battleGui = null;
}
@Override
- public <MSG> void handlePacket(MSG msg, Supplier<NetworkEvent.Context> ctx) {
+ public <MSG> void handlePacket(MSG msg, NetworkEvent.Context ctx) {
if (msg.getClass() == PacketBattleMessage.class) {
PacketBattleMessage pkt = (PacketBattleMessage) msg;
Entity fromEntity = getEntity(pkt.getEntityIDFrom(), pkt.getDimension());
parentComponent.getSiblings().add(message);
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
}
+ case CROSSBOW_NO_AMMO: {
+ parentComponent.getSiblings().add(from);
+ parentComponent.getSiblings().add(Component.literal(" tried to use their crossbow but ran out of ammo!"));
+ TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
+ }
break;
}
} else if (msg.getClass() == PacketGeneralMessage.class) {
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.server.level.ServerPlayer;
-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;
+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;
public class AttackEventHandler
{
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*;
import net.minecraft.world.level.Level;
-import net.minecraftforge.common.CreativeModeTabRegistry;
-import net.minecraftforge.network.PacketDistributor;
+import net.neoforged.neoforge.common.CreativeModeTabRegistry;
+import net.neoforged.neoforge.network.PacketDistributor;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
sendMessageToAllPlayers(PacketBattleMessage.MessageType.BOW_NO_AMMO, next.entity.getId(), 0, 0);
}
continue;
+ } else if (heldItemStack.getItem() instanceof CrossbowItem) {
+ debugLog += " with crossbow";
+ if (Utility.doesPlayerHaveArrows((Player) next.entity)) {
+ 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());
+ final float pitchDirection = Utility.pitchDirection(next.entity.getX(), next.entity.getY(), next.entity.getZ(), target.entity.getX(), target.entity.getY(), target.entity.getZ());
+ if (TurnBasedMinecraftMod.proxy.getConfig().isFreezeCombatantsEnabled()) {
+ next.yaw = yawDirection;
+ next.pitch = pitchDirection;
+ }
+ // have player look at attack target
+ ((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.use(nextEntity.level(), (Player)nextEntity, InteractionHand.MAIN_HAND);
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.FIRED_ARROW, nextEntity.getId(), targetEntity.getId(), 0);
+ } else {
+ sendMessageToAllPlayers(PacketBattleMessage.MessageType.CROSSBOW_NO_AMMO, next.entity.getId(), 0, 0);
+ }
+ continue;
}
debugLog += " without bow";
int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability();
import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
-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 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 org.apache.logging.log4j.Logger;
import java.util.*;
recentlyLeftBattle = new HashMap<Integer, Combatant>();
battleUpdater = new BattleUpdater(this);
entityToBattleMap = new HashMap<EntityIDDimPair, Integer>();
- MinecraftForge.EVENT_BUS.register(battleUpdater);
+ NeoForge.EVENT_BUS.register(battleUpdater);
tempIDPair = new EntityIDDimPair();
}
public void cleanup()
{
battleUpdater.setRunning(false);
- MinecraftForge.EVENT_BUS.unregister(battleUpdater);
+ NeoForge.EVENT_BUS.unregister(battleUpdater);
battleMap.clear();
battleUpdater = null;
}
package com.burnedkirby.TurnBasedMinecraft.common;
-import net.minecraftforge.event.TickEvent;
-import net.minecraftforge.eventbus.api.SubscribeEvent;
+import net.neoforged.bus.api.SubscribeEvent;
+import net.neoforged.neoforge.event.TickEvent;
import java.util.concurrent.atomic.AtomicBoolean;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
-import net.minecraftforge.network.NetworkEvent;
-import net.minecraftforge.server.ServerLifecycleHooks;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Map;
import java.util.Set;
-import java.util.function.Supplier;
public class CommonProxy
{
return ServerLifecycleHooks.getCurrentServer().getLevel(dim).getEntity(id);
}
- public <MSG> void handlePacket(MSG msg, Supplier<NetworkEvent.Context> ctx) {}
+ public <MSG> void handlePacket(MSG msg, NetworkEvent.Context ctx) {}
}
possibleIgnoreHurtDamageSources.clear();
try {
- VanillaRegistries.createLookup().lookupOrThrow(Registries.DAMAGE_TYPE).listElements().forEach(dt -> possibleIgnoreHurtDamageSources.add(dt.get().msgId()));
+ VanillaRegistries.createLookup().lookupOrThrow(Registries.DAMAGE_TYPE).listElements().forEach(dt -> possibleIgnoreHurtDamageSources.add(dt.value().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);
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
import net.minecraft.server.level.ServerPlayer;
-import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
-import net.minecraftforge.eventbus.api.SubscribeEvent;
-import net.minecraftforge.network.PacketDistributor;
+import net.neoforged.neoforge.event.entity.EntityTravelToDimensionEvent;
+import net.neoforged.bus.api.SubscribeEvent;
+import net.neoforged.neoforge.network.PacketDistributor;
public class DimensionChangedHandler {
@SubscribeEvent
package com.burnedkirby.TurnBasedMinecraft.common;
-import net.minecraftforge.event.entity.living.LivingHurtEvent;
-import net.minecraftforge.eventbus.api.SubscribeEvent;
+import net.neoforged.bus.api.SubscribeEvent;
+import net.neoforged.neoforge.event.entity.living.LivingHurtEvent;
public class HurtEventHandler {
@SubscribeEvent
package com.burnedkirby.TurnBasedMinecraft.common;
import net.minecraft.world.entity.player.Player;
-import net.minecraftforge.event.entity.EntityJoinLevelEvent;
-import net.minecraftforge.eventbus.api.SubscribeEvent;
+import net.neoforged.bus.api.SubscribeEvent;
+import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
public class PlayerJoinEventHandler
{
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;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
-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.NetworkRegistry;
-import net.minecraftforge.network.PacketDistributor;
-import net.minecraftforge.network.simple.SimpleChannel;
+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.fml.javafmlmod.FMLJavaModLoadingContext;
+import net.neoforged.neoforge.network.NetworkRegistry;
+import net.neoforged.neoforge.network.PacketDistributor;
+import net.neoforged.neoforge.network.simple.SimpleChannel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TurnBasedMinecraftMod {
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod";
- public static final String VERSION = "1.23.1";
+ public static final String VERSION = "1.24.0";
public static final String CONFIG_FILENAME = "TBM_Config.toml";
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
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(2);
+ private static final String PROTOCOL_VERSION = Integer.toString(3);
private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel");
private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
.named(HANDLER_ID)
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitClient);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitServer);
- MinecraftForge.EVENT_BUS.register(this);
+ NeoForge.EVENT_BUS.register(this);
}
private void firstInit(final FMLCommonSetupEvent event) {
- proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
+ if (FMLEnvironment.dist.isClient()) {
+ proxy = new ClientProxy();
+ } else {
+ proxy = new CommonProxy();
+ }
proxy.setLogger(logger);
proxy.initialize();
HANDLER.registerMessage(
packetHandlerID++,
PacketBattleInfo.class,
- PacketBattleInfo::encode,
- PacketBattleInfo::decode,
- PacketBattleInfo::handle);
+ new PacketBattleInfo.Encoder(),
+ new PacketBattleInfo.Decoder(),
+ new PacketBattleInfo.Consumer());
HANDLER.registerMessage(
packetHandlerID++,
PacketBattleRequestInfo.class,
- PacketBattleRequestInfo::encode,
- PacketBattleRequestInfo::decode,
- PacketBattleRequestInfo::handle);
+ new PacketBattleRequestInfo.Encoder(),
+ new PacketBattleRequestInfo.Decoder(),
+ new PacketBattleRequestInfo.Consumer());
HANDLER.registerMessage(
packetHandlerID++,
PacketBattleDecision.class,
- PacketBattleDecision::encode,
- PacketBattleDecision::decode,
- PacketBattleDecision::handle);
+ new PacketBattleDecision.Encoder(),
+ new PacketBattleDecision.Decoder(),
+ new PacketBattleDecision.Consumer());
HANDLER.registerMessage(
packetHandlerID++,
PacketBattleMessage.class,
- PacketBattleMessage::encode,
- PacketBattleMessage::decode,
- PacketBattleMessage::handle);
+ new PacketBattleMessage.Encoder(),
+ new PacketBattleMessage.Decoder(),
+ new PacketBattleMessage.Consumer());
HANDLER.registerMessage(
packetHandlerID++,
PacketGeneralMessage.class,
- PacketGeneralMessage::encode,
- PacketGeneralMessage::decode,
- PacketGeneralMessage::handle);
+ new PacketGeneralMessage.Encoder(),
+ new PacketGeneralMessage.Decoder(),
+ new PacketGeneralMessage.Consumer());
HANDLER.registerMessage(
packetHandlerID++,
PacketEditingMessage.class,
- PacketEditingMessage::encode,
- PacketEditingMessage::decode,
- PacketEditingMessage::handle);
+ new PacketEditingMessage.Encoder(),
+ new PacketEditingMessage.Decoder(),
+ new PacketEditingMessage.Consumer());
// register event handler(s)
- MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
- MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
- MinecraftForge.EVENT_BUS.register(new DimensionChangedHandler());
- MinecraftForge.EVENT_BUS.register(new HurtEventHandler());
+ NeoForge.EVENT_BUS.register(new AttackEventHandler());
+ NeoForge.EVENT_BUS.register(new PlayerJoinEventHandler());
+ NeoForge.EVENT_BUS.register(new DimensionChangedHandler());
+ NeoForge.EVENT_BUS.register(new HurtEventHandler());
logger.debug("Init com_burnedkirby_turnbasedminecraft");
}
package com.burnedkirby.TurnBasedMinecraft.common.networking;
-import java.util.function.Supplier;
-
import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.Battle.Decision;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraftforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleDecision
{
this.decision = decision;
this.targetIDOrItemID = targetIDOrItemID;
}
-
- public static void encode(PacketBattleDecision pkt, FriendlyByteBuf buf) {
- buf.writeInt(pkt.battleID);
- buf.writeInt(pkt.decision.getValue());
- buf.writeInt(pkt.targetIDOrItemID);
+
+ public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleDecision> {
+ public Encoder() {}
+
+ @Override
+ public void encode(PacketBattleDecision pkt, FriendlyByteBuf buf) {
+ buf.writeInt(pkt.battleID);
+ buf.writeInt(pkt.decision.getValue());
+ buf.writeInt(pkt.targetIDOrItemID);
+ }
}
-
- public static PacketBattleDecision decode(FriendlyByteBuf buf) {
- return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
+
+ public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleDecision> {
+ public Decoder() {}
+
+ @Override
+ public PacketBattleDecision decode(FriendlyByteBuf buf) {
+ return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
+ }
}
-
- public static void handle(final PacketBattleDecision pkt, Supplier<NetworkEvent.Context> ctx) {
- ctx.get().enqueueWork(() -> {
- Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
- if(b != null)
- {
- ServerPlayer player = ctx.get().getSender();
- b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID);
- }
- });
- ctx.get().setPacketHandled(true);
+
+ public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleDecision> {
+ public Consumer() {}
+
+ @Override
+ public void handle(PacketBattleDecision pkt, NetworkEvent.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);
+ }
}
}
import java.util.ArrayList;
import java.util.Collection;
-import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.Entity;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraftforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleInfo
{
this.turnTimerEnabled = turnTimerEnabled;
}
- public static void encode(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);
- }
+ public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleInfo> {
+ public Encoder() {}
- public static PacketBattleInfo decode(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);
+ @Override
+ public void encode(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);
+ }
}
-
- public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
- ctx.get().enqueueWork(() -> {
- if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
- {
- return;
+
+ public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleInfo> {
+ public Decoder() {}
+
+ @Override
+ public PacketBattleInfo decode(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());
}
- TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
- for(Integer id : pkt.sideA)
- {
- Entity e = Minecraft.getInstance().level.getEntity(id);
- if(e != null)
+ long decisionNanos = buf.readLong();
+ long maxDecisionNanos = buf.readLong();
+ boolean turnTimerEnabled = buf.readBoolean();
+ return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
+ }
+ }
+
+ public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleInfo> {
+ public Consumer() {}
+
+ @Override
+ public void handle(PacketBattleInfo pkt, NetworkEvent.Context ctx) {
+ ctx.enqueueWork(() -> {
+ if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{
- TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
+ return;
}
- }
- for(Integer id : pkt.sideB)
- {
- Entity e = Minecraft.getInstance().level.getEntity(id);
- if(e != null)
+ TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
+ for(Integer id : pkt.sideA)
{
- TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
+ Entity e = Minecraft.getInstance().level.getEntity(id);
+ if(e != null)
+ {
+ TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
+ }
}
- }
- TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
- TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
- TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
- TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerMax((int)(pkt.maxDecisionNanos / 1000000000L));
- });
- ctx.get().setPacketHandled(true);
+ for(Integer id : pkt.sideB)
+ {
+ Entity e = Minecraft.getInstance().level.getEntity(id);
+ if(e != null)
+ {
+ TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
+ }
+ }
+ TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
+ TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
+ TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
+ TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerMax((int)(pkt.maxDecisionNanos / 1000000000L));
+ });
+ ctx.setPacketHandled(true);
+ }
}
}
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
-import net.minecraftforge.api.distmarker.Dist;
-import net.minecraftforge.fml.DistExecutor;
-import net.minecraftforge.network.NetworkEvent;
+import net.neoforged.fml.loading.FMLEnvironment;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleMessage
{
BOW_NO_AMMO(18),
CREEPER_WAIT(19),
CREEPER_WAIT_FINAL(20),
- CREEPER_EXPLODE(21);
+ CREEPER_EXPLODE(21),
+ CROSSBOW_NO_AMMO(22);
private int value;
private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>();
this.amount = amount;
this.custom = custom;
}
-
- public static void encode(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 Encoder implements MessageFunctions.MessageEncoder<PacketBattleMessage> {
+ public Encoder() {}
+
+ @Override
+ public void encode(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 PacketBattleMessage decode(FriendlyByteBuf buf) {
- return new PacketBattleMessage(
- MessageType.valueOf(
- buf.readInt()),
- buf.readInt(),
- buf.readInt(),
- Utility.deserializeDimension(buf.readUtf()),
- buf.readInt(),
- buf.readUtf());
+
+ public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleMessage> {
+ public Decoder() {}
+
+ @Override
+ public PacketBattleMessage decode(FriendlyByteBuf buf) {
+ return new PacketBattleMessage(
+ MessageType.valueOf(
+ buf.readInt()),
+ buf.readInt(),
+ buf.readInt(),
+ Utility.deserializeDimension(buf.readUtf()),
+ buf.readInt(),
+ buf.readUtf());
+ }
}
-
- public static void handle(final PacketBattleMessage pkt, Supplier<NetworkEvent.Context> ctx) {
- ctx.get().enqueueWork(() -> {
- DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
- });
- ctx.get().setPacketHandled(true);
+
+ public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleMessage> {
+ public Consumer() {}
+
+ @Override
+ public void handle(PacketBattleMessage pkt, NetworkEvent.Context ctx) {
+ ctx.enqueueWork(() -> {
+ if (FMLEnvironment.dist.isClient()) {
+ TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
+ }
+ });
+ ctx.setPacketHandled(true);
+ }
}
}
package com.burnedkirby.TurnBasedMinecraft.common.networking;
-import java.util.function.Supplier;
-
import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraftforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleRequestInfo
{
{
this.battleID = battleID;
}
-
- public static void encode(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) {
- buf.writeInt(pkt.battleID);
+
+ public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleRequestInfo> {
+ public Encoder() {}
+
+ @Override
+ public void encode(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) {
+ buf.writeInt(pkt.battleID);
+ }
}
-
- public static PacketBattleRequestInfo decode(FriendlyByteBuf buf) {
- return new PacketBattleRequestInfo(buf.readInt());
+
+ public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleRequestInfo> {
+ public Decoder() {}
+
+ @Override
+ public PacketBattleRequestInfo decode(FriendlyByteBuf buf) {
+ return new PacketBattleRequestInfo(buf.readInt());
+ }
}
-
- public static void handle(final PacketBattleRequestInfo pkt, Supplier<NetworkEvent.Context> ctx) {
- ctx.get().enqueueWork(() -> {
- Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
- if(b == null) {
- return;
- }
- TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get());
- });
- ctx.get().setPacketHandled(true);
+
+ public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleRequestInfo> {
+ public Consumer() {}
+
+ @Override
+ public void handle(PacketBattleRequestInfo pkt, NetworkEvent.Context ctx) {
+ ctx.enqueueWork(() -> {
+ Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
+ if(b == null) {
+ return;
+ }
+ TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx);
+ });
+ ctx.setPacketHandled(true);
+ }
}
}
import com.burnedkirby.TurnBasedMinecraft.common.EntityInfo;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraftforge.api.distmarker.Dist;
-import net.minecraftforge.fml.DistExecutor;
-import net.minecraftforge.network.NetworkEvent;
+import net.neoforged.fml.loading.FMLEnvironment;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.simple.MessageFunctions;
import java.util.HashMap;
import java.util.Map;
-import java.util.function.Supplier;
public class PacketEditingMessage
{
this.entityInfo = entityInfo;
}
}
-
- public static void encode(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 Encoder implements MessageFunctions.MessageEncoder<PacketEditingMessage> {
+ public Encoder() {}
+
+ @Override
+ public void encode(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 PacketEditingMessage decode(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 static class Decoder implements MessageFunctions.MessageDecoder<PacketEditingMessage> {
+ public Decoder() {}
+
+ @Override
+ public PacketEditingMessage decode(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 static void handle(final PacketEditingMessage pkt, Supplier<NetworkEvent.Context> ctx) {
- ctx.get().enqueueWork(() -> {
- DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
- });
- ctx.get().setPacketHandled(true);
+ public static class Consumer implements MessageFunctions.MessageConsumer<PacketEditingMessage> {
+ public Consumer() {}
+
+ @Override
+ public void handle(PacketEditingMessage pkt, NetworkEvent.Context ctx) {
+ ctx.enqueueWork(() -> {
+ if (FMLEnvironment.dist.isClient()) {
+ TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
+ }
+ });
+ ctx.setPacketHandled(true);
+ }
}
}
package com.burnedkirby.TurnBasedMinecraft.common.networking;
-import java.util.function.Supplier;
-
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf;
-import net.minecraftforge.api.distmarker.Dist;
-import net.minecraftforge.fml.DistExecutor;
-import net.minecraftforge.network.NetworkEvent;
+import net.neoforged.api.distmarker.Dist;
+import net.neoforged.fml.DistExecutor;
+import net.neoforged.fml.loading.FMLEnvironment;
+import net.neoforged.neoforge.network.NetworkEvent;
+import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketGeneralMessage
{
{
this.message = message;
}
-
- public static void encode(PacketGeneralMessage pkt, FriendlyByteBuf buf) {
- buf.writeUtf(pkt.message);
+
+ public static class Encoder implements MessageFunctions.MessageEncoder<PacketGeneralMessage> {
+ public Encoder() {}
+
+ @Override
+ public void encode(PacketGeneralMessage pkt, FriendlyByteBuf buf) {
+ buf.writeUtf(pkt.message);
+ }
}
-
- public static PacketGeneralMessage decode(FriendlyByteBuf buf) {
- return new PacketGeneralMessage(buf.readUtf());
+
+ public static class Decoder implements MessageFunctions.MessageDecoder<PacketGeneralMessage> {
+ public Decoder() {}
+
+ @Override
+ public PacketGeneralMessage decode(FriendlyByteBuf buf) {
+ return new PacketGeneralMessage(buf.readUtf());
+ }
}
-
- public static void handle(final PacketGeneralMessage pkt, Supplier<NetworkEvent.Context> ctx) {
- ctx.get().enqueueWork(() -> {
- DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
- });
- ctx.get().setPacketHandled(true);
+
+ public static class Consumer implements MessageFunctions.MessageConsumer<PacketGeneralMessage> {
+ public Consumer() {}
+
+ @Override
+ public void handle(PacketGeneralMessage pkt, NetworkEvent.Context ctx) {
+ ctx.enqueueWork(() -> {
+ if (FMLEnvironment.dist.isClient()) {
+ TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
+ }
+ });
+ ctx.setPacketHandled(true);
+ }
}
}
# 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="forge" #mandatory
+ modId="neoforge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory
# The version range of the dependency
- versionRange="${forge_version_range}" #mandatory
+ versionRange="${neo_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