Compare commits

..

No commits in common. "b00f500e3622691c4ceadb17ff1570fd06a6577a" and "adb3a652f68c50dfaff9793e5ca21d5f910e7fb3" have entirely different histories.

27 changed files with 549 additions and 585 deletions

View file

@ -1,21 +1,5 @@
# Upcoming changes # Upcoming changes
# Version NeoForge-1.24.0
Update to NeoForge 1.20.2-20.2.88.
Allow use of Crossbows in battle (it should behave identically to Bows).
# Version Forge-1.24.0
Update to Forge 1.20.2-48.1.0.
The `master` branch of this repository will track the build for Minecraft Forge.
The `neoforge` branch of this repo. will track the build for NeoForge.
Allow use of Crossbows in battle (it should behave identically to Bows).
# Version 1.23.1 # Version 1.23.1
More robust handling of disallowed Damage Sources in battle (via config). More robust handling of disallowed Damage Sources in battle (via config).

View file

@ -2,88 +2,168 @@ plugins {
id 'eclipse' id 'eclipse'
id 'idea' id 'idea'
id 'maven-publish' id 'maven-publish'
id 'net.neoforged.gradle.userdev' version '7.0.57' id 'net.minecraftforge.gradle' version '[6.0,6.2)'
id 'com.github.johnrengelman.shadow' version '8.1.1'
} }
version = "1.24.0" version = "1.23.1"
group = "com.burnedkirby.TurnBasedMinecraft" group = "com.burnedkirby.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft-NeoForge" archivesBaseName = "TurnBasedMinecraft"
java.toolchain.languageVersion = JavaLanguageVersion.of(17) java.toolchain.languageVersion = JavaLanguageVersion.of(17)
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch')) println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
jarJar.enable() 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.
// Default run configurations. // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
// 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 // This property allows configuring Gradle's ProcessResources task(s) to run on IDE output locations before launching the game.
// You can set various levels here. // It is REQUIRED to be set to true for this template to function.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels // See https://docs.gradle.org/current/dsl/org.gradle.language.jvm.tasks.ProcessResources.html
systemProperty 'forge.logging.console.level', 'debug' copyIdeResources = true
modSource project.sourceSets.main // Default run configurations.
} // These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
client { // Recommended logging data for a userdev environment
// Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.logging.markers', 'REGISTRIES'
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
server { // Recommended logging level for the console
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id property 'forge.logging.console.level', 'debug'
programArgument '--nogui'
}
// This run config launches GameTestServer and runs all registered gametests, then exits. // Comma-separated list of namespaces to load gametests from. Empty = all namespaces.
// By default, the server will crash when no gametests are provided. property 'forge.enabledGameTestNamespaces', 'TurnBasedMinecraftMod'
// The gametest system is also enabled by default for other run configs under the /test command.
gameTestServer {
systemProperty 'forge.enabledGameTestNamespaces', project.mod_id
}
data { mods {
// example of overriding the workingDirectory set in configureEach above, uncomment if you want to use it TurnBasedMinecraftMod {
// workingDirectory project.file('run-data') source sourceSets.main
}
}
}
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources. server {
programArguments.addAll '--mod', project.mod_id, '--all', '--output', file('src/generated/resources/').getAbsolutePath(), '--existing', file('src/main/resources/').getAbsolutePath() 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
}
}
}
} }
} }
// Include resources generated by data generators. // Include resources generated by data generators.
sourceSets.main.resources { srcDir 'src/generated/resources' } sourceSets.main.resources { srcDir 'src/generated/resources' }
repositories { //repositories {
flatDir { // // Put repositories for dependencies here
dir 'libs' // // 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'
// }
//}
apply plugin: 'com.github.johnrengelman.shadow'
configurations {
shade
impelmentation.extendsFrom shade
} }
dependencies { dependencies {
// Specify the version of Minecraft to use. // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed
// Depending on the plugin applied there are several options. We will assume you applied the userdev plugin as shown above. // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied.
// The group for userdev is net.neoforged, the module name is neoforge, and the version is the same as the neoforge version. // The userdev artifact is a special name and will get all sorts of transformations applied to it.
// You can however also use the vanilla plugin (net.neoforged.gradle.vanilla) to use a version of Minecraft without the neoforge loader. minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
// 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') // Real mod deobf dependency examples - these get remapped to your current mappings
implementation 'fr.delthas:javamp3:1.0.3' // 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
jarJar(group: 'fr.delthas', name: 'javamp3', version: '[1.0.0,2.0.0)') { // Examples using mod jars from ./libs
jarJar.pin(it, '1.0.3') // implementation fg.deobf("blank:coolmod-${mc_version}:${coolmod_version}")
}
// 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')
shade files('libs/javamp3-1.0.3.jar')
} }
// This block of code expands all declared replace properties in the specified resource targets. // This block of code expands all declared replace properties in the specified resource targets.
@ -93,7 +173,7 @@ dependencies {
tasks.named('processResources', ProcessResources).configure { tasks.named('processResources', ProcessResources).configure {
var replaceProperties = [ var replaceProperties = [
minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range, minecraft_version: minecraft_version, minecraft_version_range: minecraft_version_range,
neo_version : neo_version, neo_version_range: neo_version_range, forge_version: forge_version, forge_version_range: forge_version_range,
loader_version_range: loader_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_id: mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
mod_authors: mod_authors, mod_description: mod_description, mod_authors: mod_authors, mod_description: mod_description,
@ -123,16 +203,26 @@ jar {
} }
} }
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 // Reproducible Builds
tasks.withType(AbstractArchiveTask).configureEach { tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false preserveFileTimestamps = false
reproducibleFileOrder = true 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 // Example configuration to allow publishing using the maven-publish task
// we define a custom artifact that is sourced from the reobfJar output task // we define a custom artifact that is sourced from the reobfJar output task
// and then declare that to be published // and then declare that to be published

View file

@ -4,17 +4,35 @@ org.gradle.daemon=false
## Environment Properties ## Environment Properties
# The Minecraft version must agree with the Forge version to get a valid artifact # The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.20.2 minecraft_version=1.20.1
# The Minecraft version range can use any release version of Minecraft as bounds. # 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 # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions. # as they do not follow standard versioning conventions.
minecraft_version_range=[1.20.2,1.21) minecraft_version_range=[1.20.1,1.21)
# The Neo version must agree with the Minecraft version to get a valid artifact # The Forge version must agree with the Minecraft version to get a valid artifact
neo_version=20.2.86 forge_version=47.1.0
# The Neo version range can use any version of Neo as bounds or match the loader version range # The Forge version range can use any version of Forge as bounds or match the loader version range
neo_version_range=[20.2,) forge_version_range=[47,)
# The loader version range can only use the major version of Neo/FML as bounds # The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[1,) 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
## Mod Properties ## Mod Properties
@ -26,7 +44,7 @@ mod_name=TurnBasedMinecraftMod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=MIT mod_license=MIT
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=1.24.0 mod_version=1.23.1
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # 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. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html
@ -35,5 +53,3 @@ mod_version=1.24.0
mod_authors=BurnedKirby a.k.a. Stephen Seo 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. # 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. mod_description=Implements turn-based-battle in Minecraft.
# Pack version - this changes each minecraft release, in general.
pack_format_number=18

Binary file not shown.

7
gradlew vendored
View file

@ -85,9 +85,6 @@ done
APP_BASE_NAME=${0##*/} APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 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. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum MAX_FD=maximum
@ -197,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done done
fi 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; # Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in # shell script including quotes and variable substitutions, so put them in

View file

@ -2,7 +2,8 @@ pluginManagement {
repositories { repositories {
gradlePluginPortal() gradlePluginPortal()
maven { maven {
url = 'https://maven.neoforged.net/releases' name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
} }
jcenter() jcenter()
mavenCentral() mavenCentral()

View file

@ -368,9 +368,4 @@ public class BattleGui extends Screen {
public void setTurnTimerMax(int timerMax) { public void setTurnTimerMax(int timerMax) {
this.timerMax = 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,9 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import java.util.function.Supplier;
public class ClientProxy extends CommonProxy { public class ClientProxy extends CommonProxy {
private BattleGui battleGui = null; private BattleGui battleGui = null;
@ -222,7 +224,7 @@ public class ClientProxy extends CommonProxy {
} }
@Override @Override
public <MSG> void handlePacket(MSG msg, NetworkEvent.Context ctx) { public <MSG> void handlePacket(MSG msg, Supplier<NetworkEvent.Context> ctx) {
if (msg.getClass() == PacketBattleMessage.class) { if (msg.getClass() == PacketBattleMessage.class) {
PacketBattleMessage pkt = (PacketBattleMessage) msg; PacketBattleMessage pkt = (PacketBattleMessage) msg;
Entity fromEntity = getEntity(pkt.getEntityIDFrom(), pkt.getDimension()); Entity fromEntity = getEntity(pkt.getEntityIDFrom(), pkt.getDimension());
@ -433,11 +435,6 @@ public class ClientProxy extends CommonProxy {
parentComponent.getSiblings().add(message); parentComponent.getSiblings().add(message);
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent); 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; break;
} }
} else if (msg.getClass() == PacketGeneralMessage.class) { } else if (msg.getClass() == PacketGeneralMessage.class) {

View file

@ -9,10 +9,10 @@ import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.monster.Creeper; import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.neoforged.neoforge.event.entity.living.LivingChangeTargetEvent; import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
import net.neoforged.neoforge.network.PacketDistributor; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.neoforged.bus.api.SubscribeEvent; import net.minecraftforge.network.PacketDistributor;
public class AttackEventHandler public class AttackEventHandler
{ {

View file

@ -4,7 +4,6 @@ import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleInfo;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -14,8 +13,8 @@ import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.*; import net.minecraft.world.item.*;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.CreativeModeTabRegistry; import net.minecraftforge.common.CreativeModeTabRegistry;
import net.neoforged.neoforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -794,28 +793,6 @@ public class Battle {
sendMessageToAllPlayers(PacketBattleMessage.MessageType.BOW_NO_AMMO, next.entity.getId(), 0, 0); sendMessageToAllPlayers(PacketBattleMessage.MessageType.BOW_NO_AMMO, next.entity.getId(), 0, 0);
} }
continue; 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"; debugLog += " without bow";
int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability(); int hitChance = TurnBasedMinecraftMod.proxy.getConfig().getPlayerAttackProbability();

View file

@ -7,10 +7,10 @@ import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.monster.Creeper; import net.minecraft.world.entity.monster.Creeper;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.NeoForge; import net.minecraftforge.common.MinecraftForge;
import net.neoforged.neoforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.neoforged.neoforge.event.entity.living.LivingChangeTargetEvent; import net.minecraftforge.event.entity.living.LivingChangeTargetEvent;
import net.neoforged.neoforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.*; import java.util.*;
@ -32,7 +32,7 @@ public class BattleManager
recentlyLeftBattle = new HashMap<Integer, Combatant>(); recentlyLeftBattle = new HashMap<Integer, Combatant>();
battleUpdater = new BattleUpdater(this); battleUpdater = new BattleUpdater(this);
entityToBattleMap = new HashMap<EntityIDDimPair, Integer>(); entityToBattleMap = new HashMap<EntityIDDimPair, Integer>();
NeoForge.EVENT_BUS.register(battleUpdater); MinecraftForge.EVENT_BUS.register(battleUpdater);
tempIDPair = new EntityIDDimPair(); tempIDPair = new EntityIDDimPair();
} }
@ -307,7 +307,7 @@ public class BattleManager
public void cleanup() public void cleanup()
{ {
battleUpdater.setRunning(false); battleUpdater.setRunning(false);
NeoForge.EVENT_BUS.unregister(battleUpdater); MinecraftForge.EVENT_BUS.unregister(battleUpdater);
battleMap.clear(); battleMap.clear();
battleUpdater = null; battleUpdater = null;
} }

View file

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

View file

@ -5,14 +5,15 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import net.neoforged.neoforge.server.ServerLifecycleHooks; import net.minecraftforge.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import java.util.HashSet; import java.util.HashSet;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Supplier;
public class CommonProxy public class CommonProxy
{ {
@ -172,5 +173,5 @@ public class CommonProxy
return ServerLifecycleHooks.getCurrentServer().getLevel(dim).getEntity(id); return ServerLifecycleHooks.getCurrentServer().getLevel(dim).getEntity(id);
} }
public <MSG> void handlePacket(MSG msg, NetworkEvent.Context ctx) {} public <MSG> void handlePacket(MSG msg, Supplier<NetworkEvent.Context> ctx) {}
} }

View file

@ -1521,7 +1521,7 @@ public class Config
possibleIgnoreHurtDamageSources.clear(); possibleIgnoreHurtDamageSources.clear();
try { 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) { } catch (Exception e) {
logger.warn("Config failed to load possible DamageSources! Undesired things may happen, like Zombies dying from Fire during battle!"); logger.warn("Config failed to load possible DamageSources! Undesired things may happen, like Zombies dying from Fire during battle!");
logger.warn(e); logger.warn(e);

View file

@ -2,9 +2,9 @@ package com.burnedkirby.TurnBasedMinecraft.common;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketGeneralMessage;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.neoforged.neoforge.event.entity.EntityTravelToDimensionEvent; import net.minecraftforge.event.entity.EntityTravelToDimensionEvent;
import net.neoforged.bus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.neoforged.neoforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
public class DimensionChangedHandler { public class DimensionChangedHandler {
@SubscribeEvent @SubscribeEvent

View file

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

View file

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

View file

@ -1,6 +1,5 @@
package com.burnedkirby.TurnBasedMinecraft.common; package com.burnedkirby.TurnBasedMinecraft.common;
import ca.weblite.objc.Client;
import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy; import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy;
import com.burnedkirby.TurnBasedMinecraft.common.networking.*; import com.burnedkirby.TurnBasedMinecraft.common.networking.*;
import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.LiteralMessage;
@ -19,20 +18,20 @@ import net.minecraft.network.chat.HoverEvent;
import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.neoforged.bus.api.SubscribeEvent; import net.minecraftforge.common.MinecraftForge;
import net.neoforged.fml.loading.FMLEnvironment; import net.minecraftforge.event.RegisterCommandsEvent;
import net.neoforged.neoforge.common.NeoForge; import net.minecraftforge.event.server.ServerStartingEvent;
import net.neoforged.neoforge.event.RegisterCommandsEvent; import net.minecraftforge.event.server.ServerStoppingEvent;
import net.neoforged.neoforge.event.server.ServerStartingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.neoforged.neoforge.event.server.ServerStoppingEvent; import net.minecraftforge.fml.DistExecutor;
import net.neoforged.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.event.lifecycle.FMLDedicatedServerSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.neoforged.neoforge.network.NetworkRegistry; import net.minecraftforge.network.NetworkRegistry;
import net.neoforged.neoforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.neoforged.neoforge.network.simple.SimpleChannel; import net.minecraftforge.network.simple.SimpleChannel;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -40,7 +39,7 @@ import org.apache.logging.log4j.Logger;
public class TurnBasedMinecraftMod { public class TurnBasedMinecraftMod {
public static final String MODID = "com_burnedkirby_turnbasedminecraft"; public static final String MODID = "com_burnedkirby_turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod"; public static final String NAME = "Turn Based Minecraft Mod";
public static final String VERSION = "1.24.0"; public static final String VERSION = "1.23.1";
public static final String CONFIG_FILENAME = "TBM_Config.toml"; public static final String CONFIG_FILENAME = "TBM_Config.toml";
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml"; public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
@ -51,7 +50,7 @@ public class TurnBasedMinecraftMod {
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/"; public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/"; public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
private static final String PROTOCOL_VERSION = Integer.toString(3); private static final String PROTOCOL_VERSION = Integer.toString(2);
private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel"); private static final ResourceLocation HANDLER_ID = new ResourceLocation(MODID, "main_channel");
private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder private static final SimpleChannel HANDLER = NetworkRegistry.ChannelBuilder
.named(HANDLER_ID) .named(HANDLER_ID)
@ -76,15 +75,11 @@ public class TurnBasedMinecraftMod {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitClient); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitClient);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitServer); FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitServer);
NeoForge.EVENT_BUS.register(this); MinecraftForge.EVENT_BUS.register(this);
} }
private void firstInit(final FMLCommonSetupEvent event) { private void firstInit(final FMLCommonSetupEvent event) {
if (FMLEnvironment.dist.isClient()) { proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> CommonProxy::new);
proxy = new ClientProxy();
} else {
proxy = new CommonProxy();
}
proxy.setLogger(logger); proxy.setLogger(logger);
proxy.initialize(); proxy.initialize();
@ -93,45 +88,45 @@ public class TurnBasedMinecraftMod {
HANDLER.registerMessage( HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
PacketBattleInfo.class, PacketBattleInfo.class,
new PacketBattleInfo.Encoder(), PacketBattleInfo::encode,
new PacketBattleInfo.Decoder(), PacketBattleInfo::decode,
new PacketBattleInfo.Consumer()); PacketBattleInfo::handle);
HANDLER.registerMessage( HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
PacketBattleRequestInfo.class, PacketBattleRequestInfo.class,
new PacketBattleRequestInfo.Encoder(), PacketBattleRequestInfo::encode,
new PacketBattleRequestInfo.Decoder(), PacketBattleRequestInfo::decode,
new PacketBattleRequestInfo.Consumer()); PacketBattleRequestInfo::handle);
HANDLER.registerMessage( HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
PacketBattleDecision.class, PacketBattleDecision.class,
new PacketBattleDecision.Encoder(), PacketBattleDecision::encode,
new PacketBattleDecision.Decoder(), PacketBattleDecision::decode,
new PacketBattleDecision.Consumer()); PacketBattleDecision::handle);
HANDLER.registerMessage( HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
PacketBattleMessage.class, PacketBattleMessage.class,
new PacketBattleMessage.Encoder(), PacketBattleMessage::encode,
new PacketBattleMessage.Decoder(), PacketBattleMessage::decode,
new PacketBattleMessage.Consumer()); PacketBattleMessage::handle);
HANDLER.registerMessage( HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
PacketGeneralMessage.class, PacketGeneralMessage.class,
new PacketGeneralMessage.Encoder(), PacketGeneralMessage::encode,
new PacketGeneralMessage.Decoder(), PacketGeneralMessage::decode,
new PacketGeneralMessage.Consumer()); PacketGeneralMessage::handle);
HANDLER.registerMessage( HANDLER.registerMessage(
packetHandlerID++, packetHandlerID++,
PacketEditingMessage.class, PacketEditingMessage.class,
new PacketEditingMessage.Encoder(), PacketEditingMessage::encode,
new PacketEditingMessage.Decoder(), PacketEditingMessage::decode,
new PacketEditingMessage.Consumer()); PacketEditingMessage::handle);
// register event handler(s) // register event handler(s)
NeoForge.EVENT_BUS.register(new AttackEventHandler()); MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
NeoForge.EVENT_BUS.register(new PlayerJoinEventHandler()); MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler());
NeoForge.EVENT_BUS.register(new DimensionChangedHandler()); MinecraftForge.EVENT_BUS.register(new DimensionChangedHandler());
NeoForge.EVENT_BUS.register(new HurtEventHandler()); MinecraftForge.EVENT_BUS.register(new HurtEventHandler());
logger.debug("Init com_burnedkirby_turnbasedminecraft"); logger.debug("Init com_burnedkirby_turnbasedminecraft");
} }

View file

@ -1,13 +1,14 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.Battle; import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.Battle.Decision; import com.burnedkirby.TurnBasedMinecraft.common.Battle.Decision;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleDecision public class PacketBattleDecision
{ {
@ -24,40 +25,25 @@ public class PacketBattleDecision
this.targetIDOrItemID = targetIDOrItemID; this.targetIDOrItemID = targetIDOrItemID;
} }
public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleDecision> { public static void encode(PacketBattleDecision pkt, FriendlyByteBuf buf) {
public Encoder() {} buf.writeInt(pkt.battleID);
buf.writeInt(pkt.decision.getValue());
@Override buf.writeInt(pkt.targetIDOrItemID);
public void encode(PacketBattleDecision pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.battleID);
buf.writeInt(pkt.decision.getValue());
buf.writeInt(pkt.targetIDOrItemID);
}
} }
public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleDecision> { public static PacketBattleDecision decode(FriendlyByteBuf buf) {
public Decoder() {} return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
@Override
public PacketBattleDecision decode(FriendlyByteBuf buf) {
return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
}
} }
public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleDecision> { public static void handle(final PacketBattleDecision pkt, Supplier<NetworkEvent.Context> ctx) {
public Consumer() {} ctx.get().enqueueWork(() -> {
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
@Override if(b != null)
public void handle(PacketBattleDecision pkt, NetworkEvent.Context ctx) { {
ctx.enqueueWork(() -> { ServerPlayer player = ctx.get().getSender();
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID); b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID);
if(b != null) }
{ });
ServerPlayer player = ctx.getSender(); ctx.get().setPacketHandled(true);
b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID);
}
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -2,14 +2,14 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleInfo public class PacketBattleInfo
{ {
@ -38,80 +38,65 @@ public class PacketBattleInfo
this.turnTimerEnabled = turnTimerEnabled; this.turnTimerEnabled = turnTimerEnabled;
} }
public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleInfo> { public static void encode(PacketBattleInfo msg, FriendlyByteBuf buf) {
public Encoder() {} buf.writeInt(msg.sideA.size());
buf.writeInt(msg.sideB.size());
@Override for(Integer id : msg.sideA) {
public void encode(PacketBattleInfo msg, FriendlyByteBuf buf) { buf.writeInt(id);
buf.writeInt(msg.sideA.size()); }
buf.writeInt(msg.sideB.size()); for(Integer id : msg.sideB) {
for(Integer id : msg.sideA) { buf.writeInt(id);
buf.writeInt(id); }
} buf.writeLong(msg.decisionNanos);
for(Integer id : msg.sideB) { buf.writeLong(msg.maxDecisionNanos);
buf.writeInt(id); buf.writeBoolean(msg.turnTimerEnabled);
}
buf.writeLong(msg.decisionNanos);
buf.writeLong(msg.maxDecisionNanos);
buf.writeBoolean(msg.turnTimerEnabled);
}
} }
public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleInfo> { public static PacketBattleInfo decode(FriendlyByteBuf buf) {
public Decoder() {} int sideACount = buf.readInt();
int sideBCount = buf.readInt();
@Override Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
public PacketBattleInfo decode(FriendlyByteBuf buf) { Collection<Integer> sideB = new ArrayList<Integer>(sideBCount);
int sideACount = buf.readInt(); for(int i = 0; i < sideACount; ++i) {
int sideBCount = buf.readInt(); sideA.add(buf.readInt());
Collection<Integer> sideA = new ArrayList<Integer>(sideACount); }
Collection<Integer> sideB = new ArrayList<Integer>(sideBCount); for(int i = 0; i < sideBCount; ++i) {
for(int i = 0; i < sideACount; ++i) { sideB.add(buf.readInt());
sideA.add(buf.readInt()); }
} long decisionNanos = buf.readLong();
for(int i = 0; i < sideBCount; ++i) { long maxDecisionNanos = buf.readLong();
sideB.add(buf.readInt()); boolean turnTimerEnabled = buf.readBoolean();
} return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
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 static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
public Consumer() {} ctx.get().enqueueWork(() -> {
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
@Override {
public void handle(PacketBattleInfo pkt, NetworkEvent.Context ctx) { return;
ctx.enqueueWork(() -> { }
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null) TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : pkt.sideA)
{
Entity e = Minecraft.getInstance().level.getEntity(id);
if(e != null)
{ {
return; TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
} }
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants(); }
for(Integer id : pkt.sideA) for(Integer id : pkt.sideB)
{
Entity e = Minecraft.getInstance().level.getEntity(id);
if(e != null)
{ {
Entity e = Minecraft.getInstance().level.getEntity(id); TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
if(e != null)
{
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
}
} }
for(Integer id : pkt.sideB) }
{ TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
Entity e = Minecraft.getInstance().level.getEntity(id); TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
if(e != null) TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
{ TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerMax((int)(pkt.maxDecisionNanos / 1000000000L));
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e); });
} ctx.get().setPacketHandled(true);
}
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);
}
} }
} }

View file

@ -2,6 +2,7 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
@ -9,9 +10,9 @@ import com.burnedkirby.TurnBasedMinecraft.common.Utility;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.neoforged.fml.loading.FMLEnvironment; import net.minecraftforge.api.distmarker.Dist;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.fml.DistExecutor;
import net.neoforged.neoforge.network.simple.MessageFunctions; import net.minecraftforge.network.NetworkEvent;
public class PacketBattleMessage public class PacketBattleMessage
{ {
@ -38,8 +39,7 @@ public class PacketBattleMessage
BOW_NO_AMMO(18), BOW_NO_AMMO(18),
CREEPER_WAIT(19), CREEPER_WAIT(19),
CREEPER_WAIT_FINAL(20), CREEPER_WAIT_FINAL(20),
CREEPER_EXPLODE(21), CREEPER_EXPLODE(21);
CROSSBOW_NO_AMMO(22);
private int value; private int value;
private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>(); private static Map<Integer, MessageType> map = new HashMap<Integer, MessageType>();
@ -154,47 +154,30 @@ public class PacketBattleMessage
this.custom = custom; this.custom = custom;
} }
public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleMessage> { public static void encode(PacketBattleMessage pkt, FriendlyByteBuf buf) {
public Encoder() {} buf.writeInt(pkt.messageType.getValue());
buf.writeInt(pkt.entityIDFrom);
@Override buf.writeInt(pkt.entityIDTo);
public void encode(PacketBattleMessage pkt, FriendlyByteBuf buf) { buf.writeUtf(Utility.serializeDimension(pkt.dimension));
buf.writeInt(pkt.messageType.getValue()); buf.writeInt(pkt.amount);
buf.writeInt(pkt.entityIDFrom); buf.writeUtf(pkt.custom);
buf.writeInt(pkt.entityIDTo);
buf.writeUtf(Utility.serializeDimension(pkt.dimension));
buf.writeInt(pkt.amount);
buf.writeUtf(pkt.custom);
}
} }
public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleMessage> { public static PacketBattleMessage decode(FriendlyByteBuf buf) {
public Decoder() {} return new PacketBattleMessage(
MessageType.valueOf(
@Override buf.readInt()),
public PacketBattleMessage decode(FriendlyByteBuf buf) { buf.readInt(),
return new PacketBattleMessage( buf.readInt(),
MessageType.valueOf( Utility.deserializeDimension(buf.readUtf()),
buf.readInt()), buf.readInt(),
buf.readInt(), buf.readUtf());
buf.readInt(),
Utility.deserializeDimension(buf.readUtf()),
buf.readInt(),
buf.readUtf());
}
} }
public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleMessage> { public static void handle(final PacketBattleMessage pkt, Supplier<NetworkEvent.Context> ctx) {
public Consumer() {} ctx.get().enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
@Override });
public void handle(PacketBattleMessage pkt, NetworkEvent.Context ctx) { ctx.get().setPacketHandled(true);
ctx.enqueueWork(() -> {
if (FMLEnvironment.dist.isClient()) {
TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
}
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -1,11 +1,12 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.Battle; import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.network.NetworkEvent;
import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketBattleRequestInfo public class PacketBattleRequestInfo
{ {
@ -18,37 +19,22 @@ public class PacketBattleRequestInfo
this.battleID = battleID; this.battleID = battleID;
} }
public static class Encoder implements MessageFunctions.MessageEncoder<PacketBattleRequestInfo> { public static void encode(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) {
public Encoder() {} buf.writeInt(pkt.battleID);
@Override
public void encode(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.battleID);
}
} }
public static class Decoder implements MessageFunctions.MessageDecoder<PacketBattleRequestInfo> { public static PacketBattleRequestInfo decode(FriendlyByteBuf buf) {
public Decoder() {} return new PacketBattleRequestInfo(buf.readInt());
@Override
public PacketBattleRequestInfo decode(FriendlyByteBuf buf) {
return new PacketBattleRequestInfo(buf.readInt());
}
} }
public static class Consumer implements MessageFunctions.MessageConsumer<PacketBattleRequestInfo> { public static void handle(final PacketBattleRequestInfo pkt, Supplier<NetworkEvent.Context> ctx) {
public Consumer() {} ctx.get().enqueueWork(() -> {
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
@Override if(b == null) {
public void handle(PacketBattleRequestInfo pkt, NetworkEvent.Context ctx) { return;
ctx.enqueueWork(() -> { }
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID); TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get());
if(b == null) { });
return; ctx.get().setPacketHandled(true);
}
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,12 +3,13 @@ package com.burnedkirby.TurnBasedMinecraft.common.networking;
import com.burnedkirby.TurnBasedMinecraft.common.EntityInfo; import com.burnedkirby.TurnBasedMinecraft.common.EntityInfo;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.neoforged.fml.loading.FMLEnvironment; import net.minecraftforge.api.distmarker.Dist;
import net.neoforged.neoforge.network.NetworkEvent; import net.minecraftforge.fml.DistExecutor;
import net.neoforged.neoforge.network.simple.MessageFunctions; import net.minecraftforge.network.NetworkEvent;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
public class PacketEditingMessage public class PacketEditingMessage
{ {
@ -87,75 +88,58 @@ public class PacketEditingMessage
} }
} }
public static class Encoder implements MessageFunctions.MessageEncoder<PacketEditingMessage> { public static void encode(PacketEditingMessage pkt, FriendlyByteBuf buf) {
public Encoder() {} buf.writeInt(pkt.type.getValue());
if(pkt.entityInfo.classType != null) {
@Override buf.writeUtf(pkt.entityInfo.classType.getName());
public void encode(PacketEditingMessage pkt, FriendlyByteBuf buf) { } else {
buf.writeInt(pkt.type.getValue()); buf.writeUtf("unknown");
if(pkt.entityInfo.classType != null) { }
buf.writeUtf(pkt.entityInfo.classType.getName()); buf.writeBoolean(pkt.entityInfo.ignoreBattle);
} else { buf.writeInt(pkt.entityInfo.attackPower);
buf.writeUtf("unknown"); buf.writeInt(pkt.entityInfo.attackProbability);
} buf.writeInt(pkt.entityInfo.attackVariance);
buf.writeBoolean(pkt.entityInfo.ignoreBattle); buf.writeUtf(pkt.entityInfo.attackEffect.toString());
buf.writeInt(pkt.entityInfo.attackPower); buf.writeInt(pkt.entityInfo.attackEffectProbability);
buf.writeInt(pkt.entityInfo.attackProbability); buf.writeInt(pkt.entityInfo.defenseDamage);
buf.writeInt(pkt.entityInfo.attackVariance); buf.writeInt(pkt.entityInfo.defenseDamageProbability);
buf.writeUtf(pkt.entityInfo.attackEffect.toString()); buf.writeInt(pkt.entityInfo.evasion);
buf.writeInt(pkt.entityInfo.attackEffectProbability); buf.writeInt(pkt.entityInfo.speed);
buf.writeInt(pkt.entityInfo.defenseDamage); buf.writeUtf(pkt.entityInfo.category);
buf.writeInt(pkt.entityInfo.defenseDamageProbability); buf.writeInt(pkt.entityInfo.decisionAttack);
buf.writeInt(pkt.entityInfo.evasion); buf.writeInt(pkt.entityInfo.decisionDefend);
buf.writeInt(pkt.entityInfo.speed); buf.writeInt(pkt.entityInfo.decisionFlee);
buf.writeUtf(pkt.entityInfo.category); buf.writeUtf(pkt.entityInfo.customName);
buf.writeInt(pkt.entityInfo.decisionAttack);
buf.writeInt(pkt.entityInfo.decisionDefend);
buf.writeInt(pkt.entityInfo.decisionFlee);
buf.writeUtf(pkt.entityInfo.customName);
}
} }
public static class Decoder implements MessageFunctions.MessageDecoder<PacketEditingMessage> { public static PacketEditingMessage decode(FriendlyByteBuf buf) {
public Decoder() {} Type type = Type.valueOf(buf.readInt());
EntityInfo einfo = new EntityInfo();
@Override try {
public PacketEditingMessage decode(FriendlyByteBuf buf) { einfo.classType = einfo.getClass().getClassLoader().loadClass(buf.readUtf());
Type type = Type.valueOf(buf.readInt()); } catch (ClassNotFoundException e) { /* ignored */ }
EntityInfo einfo = new EntityInfo(); einfo.ignoreBattle = buf.readBoolean();
try { einfo.attackPower = buf.readInt();
einfo.classType = einfo.getClass().getClassLoader().loadClass(buf.readUtf()); einfo.attackProbability = buf.readInt();
} catch (ClassNotFoundException e) { /* ignored */ } einfo.attackVariance = buf.readInt();
einfo.ignoreBattle = buf.readBoolean(); einfo.attackEffect = EntityInfo.Effect.fromString(buf.readUtf());
einfo.attackPower = buf.readInt(); einfo.attackEffectProbability = buf.readInt();
einfo.attackProbability = buf.readInt(); einfo.defenseDamage = buf.readInt();
einfo.attackVariance = buf.readInt(); einfo.defenseDamageProbability = buf.readInt();
einfo.attackEffect = EntityInfo.Effect.fromString(buf.readUtf()); einfo.evasion = buf.readInt();
einfo.attackEffectProbability = buf.readInt(); einfo.speed = buf.readInt();
einfo.defenseDamage = buf.readInt(); einfo.category = buf.readUtf();
einfo.defenseDamageProbability = buf.readInt(); einfo.decisionAttack = buf.readInt();
einfo.evasion = buf.readInt(); einfo.decisionDefend = buf.readInt();
einfo.speed = buf.readInt(); einfo.decisionFlee = buf.readInt();
einfo.category = buf.readUtf(); einfo.customName = buf.readUtf();
einfo.decisionAttack = buf.readInt(); return new PacketEditingMessage(type, einfo);
einfo.decisionDefend = buf.readInt();
einfo.decisionFlee = buf.readInt();
einfo.customName = buf.readUtf();
return new PacketEditingMessage(type, einfo);
}
} }
public static class Consumer implements MessageFunctions.MessageConsumer<PacketEditingMessage> { public static void handle(final PacketEditingMessage pkt, Supplier<NetworkEvent.Context> ctx) {
public Consumer() {} ctx.get().enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
@Override });
public void handle(PacketEditingMessage pkt, NetworkEvent.Context ctx) { ctx.get().setPacketHandled(true);
ctx.enqueueWork(() -> {
if (FMLEnvironment.dist.isClient()) {
TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
}
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -1,13 +1,13 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.neoforged.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.neoforged.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.neoforged.fml.loading.FMLEnvironment; import net.minecraftforge.network.NetworkEvent;
import net.neoforged.neoforge.network.NetworkEvent;
import net.neoforged.neoforge.network.simple.MessageFunctions;
public class PacketGeneralMessage public class PacketGeneralMessage
{ {
@ -27,35 +27,18 @@ public class PacketGeneralMessage
this.message = message; this.message = message;
} }
public static class Encoder implements MessageFunctions.MessageEncoder<PacketGeneralMessage> { public static void encode(PacketGeneralMessage pkt, FriendlyByteBuf buf) {
public Encoder() {} buf.writeUtf(pkt.message);
@Override
public void encode(PacketGeneralMessage pkt, FriendlyByteBuf buf) {
buf.writeUtf(pkt.message);
}
} }
public static class Decoder implements MessageFunctions.MessageDecoder<PacketGeneralMessage> { public static PacketGeneralMessage decode(FriendlyByteBuf buf) {
public Decoder() {} return new PacketGeneralMessage(buf.readUtf());
@Override
public PacketGeneralMessage decode(FriendlyByteBuf buf) {
return new PacketGeneralMessage(buf.readUtf());
}
} }
public static class Consumer implements MessageFunctions.MessageConsumer<PacketGeneralMessage> { public static void handle(final PacketGeneralMessage pkt, Supplier<NetworkEvent.Context> ctx) {
public Consumer() {} ctx.get().enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
@Override });
public void handle(PacketGeneralMessage pkt, NetworkEvent.Context ctx) { ctx.get().setPacketHandled(true);
ctx.enqueueWork(() -> {
if (FMLEnvironment.dist.isClient()) {
TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx);
}
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -35,11 +35,11 @@ Implements turn-based-battle in Minecraft.
# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. # A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional.
[[dependencies.com_burnedkirby_turnbasedminecraft]] #optional [[dependencies.com_burnedkirby_turnbasedminecraft]] #optional
# the modid of the dependency # the modid of the dependency
modId="neoforge" #mandatory modId="forge" #mandatory
# Does this dependency have to exist - if not, ordering below must be specified # Does this dependency have to exist - if not, ordering below must be specified
mandatory=true #mandatory mandatory=true #mandatory
# The version range of the dependency # 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 # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory
ordering="NONE" ordering="NONE"
# Side this dependency is applied on - BOTH, CLIENT or SERVER # Side this dependency is applied on - BOTH, CLIENT or SERVER

View file

@ -3,7 +3,7 @@
"modid": "com_burnedkirby_turnbasedminecraft", "modid": "com_burnedkirby_turnbasedminecraft",
"name": "Turn Based Minecraft", "name": "Turn Based Minecraft",
"description": "Changes battles to be turn-based.", "description": "Changes battles to be turn-based.",
"version": "1.24.0", "version": "1.23.1",
"mcversion": "1.20.1", "mcversion": "1.20.1",
"url": "", "url": "",
"updateUrl": "", "updateUrl": "",