Update mod for 1.20.2 Forge

Also add support for Crossbows in battle.
This commit is contained in:
Stephen Seo 2023-12-29 11:59:23 +09:00
parent adb3a652f6
commit 62576a06c6
21 changed files with 487 additions and 355 deletions

View file

@ -1,5 +1,15 @@
# Upcoming changes # Upcoming changes
# 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

@ -61,7 +61,7 @@ configured for them.)
# Building # Building
Simply invoke `./gradlew build` in the mod directory and after some time the Simply invoke `./gradlew build` in the mod directory and after some time the
finished jar will be saved at "build/libs/TurnBasedMinecraft-1.23.1.jar" finished jar will be saved at "build/libs/TurnBasedMinecraft-Forge-1.24.0.jar"
# Other notes # Other notes

View file

@ -2,13 +2,13 @@ plugins {
id 'eclipse' id 'eclipse'
id 'idea' id 'idea'
id 'maven-publish' id 'maven-publish'
id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'net.minecraftforge.gradle' version '[6.0.16,6.2)'
id 'com.github.johnrengelman.shadow' version '8.1.1' id 'com.github.johnrengelman.shadow' version '8.1.1'
} }
version = "1.23.1" version = "1.24.0"
group = "com.burnedkirby.TurnBasedMinecraft" group = "com.burnedkirby.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft" archivesBaseName = "TurnBasedMinecraft-Forge"
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'))

View file

@ -4,17 +4,17 @@ 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.1 minecraft_version=1.20.2
# 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.1,1.21) minecraft_version_range=[1.20.2,1.21)
# The Forge 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
forge_version=47.1.0 forge_version=48.1.0
# The Forge version range can use any version of Forge 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
forge_version_range=[47,) forge_version_range=[48,)
# The loader version range can only use the major version of Forge/FML as bounds # The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[47,) loader_version_range=[48,)
# The mapping channel to use for mappings. # The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"]. # 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. # Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
@ -32,7 +32,7 @@ loader_version_range=[47,)
mapping_channel=official mapping_channel=official
# The mapping version to query from the mapping channel. # The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel. # This must match the format required by the mapping channel.
mapping_version=1.20.1 mapping_version=1.20.2
## Mod Properties ## Mod Properties
@ -44,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.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. # 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

View file

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

View file

@ -11,5 +11,5 @@ pluginManagement {
} }
plugins { plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' id 'org.gradle.toolchains.foojay-resolver-convention' version '0.7.0'
} }

View file

@ -5,13 +5,13 @@ import com.burnedkirby.TurnBasedMinecraft.common.Combatant;
import com.burnedkirby.TurnBasedMinecraft.common.Config; import com.burnedkirby.TurnBasedMinecraft.common.Config;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleDecision; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleDecision;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractButton; import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraftforge.network.PacketDistributor;
import java.util.ConcurrentModificationException; import java.util.ConcurrentModificationException;
import java.util.HashMap; import java.util.HashMap;
@ -269,29 +269,35 @@ public class BattleGui extends Screen {
drawString(guiGraphics, info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF); drawString(guiGraphics, info, width / 2 - stringWidth / 2, 20, 0xFFFFFFFF);
} }
@Override
public void renderBackground(GuiGraphics p_283688_, int p_299421_, int p_298679_, float p_297268_) {
}
protected void buttonActionEvent(AbstractButton button, ButtonAction action) { protected void buttonActionEvent(AbstractButton button, ButtonAction action) {
switch (action) { switch (action) {
case ATTACK: case ATTACK:
setState(MenuState.ATTACK_TARGET); setState(MenuState.ATTACK_TARGET);
break; break;
case DEFEND: case DEFEND:
TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision( TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0)); TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.DEFEND, 0),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ITEM: case ITEM:
setState(MenuState.ITEM_ACTION); setState(MenuState.ITEM_ACTION);
break; break;
case FLEE: case FLEE:
TurnBasedMinecraftMod.getHandler().sendToServer(new PacketBattleDecision( TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0)); TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.FLEE, 0),
PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING); setState(MenuState.WAITING);
break; break;
case ATTACK_TARGET: case ATTACK_TARGET:
if (button instanceof EntitySelectionButton) { if (button instanceof EntitySelectionButton) {
TurnBasedMinecraftMod.getHandler() TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID()),
Battle.Decision.ATTACK, ((EntitySelectionButton) button).getID())); PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING); setState(MenuState.WAITING);
} else { } else {
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);
@ -308,9 +314,9 @@ public class BattleGui extends Screen {
break; break;
case DO_ITEM_SWITCH: case DO_ITEM_SWITCH:
if (button instanceof ItemSelectionButton) { if (button instanceof ItemSelectionButton) {
TurnBasedMinecraftMod.getHandler() TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton) button).getID()),
Battle.Decision.SWITCH_ITEM, ((ItemSelectionButton) button).getID())); PacketDistributor.SERVER.noArg());
if (((ItemSelectionButton) button).getID() >= 0 && ((ItemSelectionButton) button).getID() < 9) { if (((ItemSelectionButton) button).getID() >= 0 && ((ItemSelectionButton) button).getID() < 9) {
Minecraft.getInstance().player.getInventory().selected = ((ItemSelectionButton) button).getID(); Minecraft.getInstance().player.getInventory().selected = ((ItemSelectionButton) button).getID();
} }
@ -321,9 +327,9 @@ public class BattleGui extends Screen {
break; break;
case DO_USE_ITEM: case DO_USE_ITEM:
if (button instanceof ItemSelectionButton) { if (button instanceof ItemSelectionButton) {
TurnBasedMinecraftMod.getHandler() TurnBasedMinecraftMod.getHandler().send(new PacketBattleDecision(
.sendToServer(new PacketBattleDecision(TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), TurnBasedMinecraftMod.proxy.getLocalBattle().getId(), Battle.Decision.USE_ITEM, ((ItemSelectionButton) button).getID()),
Battle.Decision.USE_ITEM, ((ItemSelectionButton) button).getID())); PacketDistributor.SERVER.noArg());
setState(MenuState.WAITING); setState(MenuState.WAITING);
} else { } else {
setState(MenuState.MAIN_MENU); setState(MenuState.MAIN_MENU);

View file

@ -15,9 +15,7 @@ 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.minecraftforge.network.NetworkEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import java.util.function.Supplier;
public class ClientProxy extends CommonProxy { public class ClientProxy extends CommonProxy {
private BattleGui battleGui = null; private BattleGui battleGui = null;
@ -224,7 +222,7 @@ public class ClientProxy extends CommonProxy {
} }
@Override @Override
public <MSG> void handlePacket(MSG msg, Supplier<NetworkEvent.Context> ctx) { public <MSG> void handlePacket(MSG msg, CustomPayloadEvent.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());
@ -436,6 +434,12 @@ public class ClientProxy extends CommonProxy {
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent); TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
} }
break; break;
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) { } else if (msg.getClass() == PacketGeneralMessage.class) {
PacketGeneralMessage pkt = (PacketGeneralMessage) msg; PacketGeneralMessage pkt = (PacketGeneralMessage) msg;

View file

@ -82,7 +82,7 @@ public class AttackEventHandler
if(!event.getEntity().hasCustomName()) if(!event.getEntity().hasCustomName())
{ {
TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name"); TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name");
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)editingInfo.editor), new PacketGeneralMessage("Cannot edit custom name from entity without custom name")); TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
return; return;
} }
editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomName().getString()); editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomName().getString());
@ -91,9 +91,9 @@ public class AttackEventHandler
editingInfo.entityInfo = new EntityInfo(); editingInfo.entityInfo = new EntityInfo();
editingInfo.entityInfo.customName = event.getEntity().getCustomName().getString(); editingInfo.entityInfo.customName = event.getEntity().getCustomName().getString();
} }
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)editingInfo.editor), new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\"")); TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\""), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomName().getString() + "\""); TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomName().getString() + "\"");
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)editingInfo.editor), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); TurnBasedMinecraftMod.getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
} }
else else
{ {
@ -107,9 +107,9 @@ public class AttackEventHandler
{ {
editingInfo.entityInfo = editingInfo.entityInfo.clone(); editingInfo.entityInfo = editingInfo.entityInfo.clone();
} }
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)editingInfo.editor), new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\"")); TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\""); TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\"");
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer)editingInfo.editor), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); TurnBasedMinecraftMod.getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with((ServerPlayer)editingInfo.editor));
} }
return; return;
} }

View file

@ -4,6 +4,7 @@ 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;
@ -448,7 +449,7 @@ public class Battle {
} }
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()); PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
for (Combatant p : players.values()) { for (Combatant p : players.values()) {
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), infoPacket); TurnBasedMinecraftMod.getHandler().send(infoPacket, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
} }
} }
@ -463,7 +464,7 @@ public class Battle {
PacketBattleMessage packet = new PacketBattleMessage(type, from, to, dimension, amount, custom); PacketBattleMessage packet = new PacketBattleMessage(type, from, to, dimension, amount, custom);
for (Combatant p : players.values()) { for (Combatant p : players.values()) {
if (p.entity.isAlive()) { if (p.entity.isAlive()) {
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), packet); TurnBasedMinecraftMod.getHandler().send(packet, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
} }
} }
} }
@ -573,7 +574,7 @@ public class Battle {
private void removeCombatantPostRemove(Combatant c) { private void removeCombatantPostRemove(Combatant c) {
if (c.entity instanceof Player) { if (c.entity instanceof Player) {
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) c.entity), new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, dimension, 0)); TurnBasedMinecraftMod.getHandler().send(new PacketBattleMessage(PacketBattleMessage.MessageType.ENDED, 0, 0, dimension, 0), PacketDistributor.PLAYER.with((ServerPlayer)c.entity));
} }
battleManager.addRecentlyLeftBattle(c); battleManager.addRecentlyLeftBattle(c);
} }
@ -793,6 +794,29 @@ 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)) {
// Similar to attack with bow.
final Entity nextEntity = next.entity;
final Entity targetEntity = target.entity;
final float yawDirection = Utility.yawDirection(next.entity.getX(), next.entity.getZ(), target.entity.getX(), target.entity.getZ());
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(((Player) nextEntity).getMainHandItem(), nextEntity.level(), (LivingEntity) nextEntity, -100);
itemCrossbow.use(nextEntity.level(), (Player)nextEntity, InteractionHand.MAIN_HAND);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.FIRED_ARROW, nextEntity.getId(), targetEntity.getId(), 0);
} else {
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

@ -317,7 +317,7 @@ public class BattleManager
c.time = System.nanoTime(); c.time = System.nanoTime();
Config config = TurnBasedMinecraftMod.proxy.getConfig(); Config config = TurnBasedMinecraftMod.proxy.getConfig();
if(c.entity instanceof ServerPlayer) { if(c.entity instanceof ServerPlayer) {
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(()->(ServerPlayer) c.entity), new PacketGeneralMessage("You just left battle! " + config.getLeaveBattleCooldownSeconds() + " seconds until you can attack/be-attacked again!")); TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("You just left battle! " + config.getLeaveBattleCooldownSeconds() + " seconds until you can attack/be-attacked again!"), PacketDistributor.PLAYER.with((ServerPlayer)c.entity));
} }
recentlyLeftBattle.put(c.entity.getId(), c); recentlyLeftBattle.put(c.entity.getId(), c);
entityToBattleMap.remove(new EntityIDDimPair(c.entity)); entityToBattleMap.remove(new EntityIDDimPair(c.entity));
@ -337,7 +337,7 @@ public class BattleManager
iter.remove(); iter.remove();
if(entry.getValue().entity instanceof ServerPlayer) if(entry.getValue().entity instanceof ServerPlayer)
{ {
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(()->(ServerPlayer)entry.getValue().entity), new PacketGeneralMessage("Timer ended, you can now attack/be-attacked again.")); TurnBasedMinecraftMod.getHandler().send(new PacketGeneralMessage("Timer ended, you can now attack/be-attacked again."), PacketDistributor.PLAYER.with((ServerPlayer)entry.getValue().entity));
} }
} }
} }

View file

@ -5,7 +5,7 @@ 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.minecraftforge.network.NetworkEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.server.ServerLifecycleHooks; import net.minecraftforge.server.ServerLifecycleHooks;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -13,7 +13,6 @@ 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
{ {
@ -173,5 +172,5 @@ public class CommonProxy
return ServerLifecycleHooks.getCurrentServer().getLevel(dim).getEntity(id); return ServerLifecycleHooks.getCurrentServer().getLevel(dim).getEntity(id);
} }
public <MSG> void handlePacket(MSG msg, Supplier<NetworkEvent.Context> ctx) {} public <MSG> void handlePacket(MSG msg,CustomPayloadEvent.Context ctx) {}
} }

View file

@ -15,8 +15,8 @@ public class DimensionChangedHandler {
if(TurnBasedMinecraftMod.proxy.getBattleManager().forceLeaveBattle(new EntityIDDimPair(event.getEntity())) if(TurnBasedMinecraftMod.proxy.getBattleManager().forceLeaveBattle(new EntityIDDimPair(event.getEntity()))
&& event.getEntity() instanceof ServerPlayer) { && event.getEntity() instanceof ServerPlayer) {
TurnBasedMinecraftMod.getHandler().send( TurnBasedMinecraftMod.getHandler().send(
PacketDistributor.PLAYER.with(() -> (ServerPlayer)event.getEntity()), new PacketGeneralMessage("Left battle due to moving to a different dimension"),
new PacketGeneralMessage("Left battle due to moving to a different dimension")); PacketDistributor.PLAYER.with((ServerPlayer)event.getEntity()));
} }
} }
} }

View file

@ -29,9 +29,7 @@ import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.*;
import net.minecraftforge.network.PacketDistributor;
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;
@ -39,7 +37,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.23.1"; public static final String VERSION = "1.24.0";
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/";
@ -50,13 +48,14 @@ 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(2); private static final Integer PROTOCOL_VERSION = 3;
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 = ChannelBuilder
.named(HANDLER_ID) .named(HANDLER_ID)
.clientAcceptedVersions(PROTOCOL_VERSION::equals) .clientAcceptedVersions(Channel.VersionTest.exact(PROTOCOL_VERSION))
.serverAcceptedVersions(PROTOCOL_VERSION::equals) .serverAcceptedVersions(Channel.VersionTest.exact(PROTOCOL_VERSION))
.networkProtocolVersion(() -> PROTOCOL_VERSION) .networkProtocolVersion(PROTOCOL_VERSION)
.simpleChannel(); .simpleChannel();
protected static Logger logger = LogManager.getLogger(); protected static Logger logger = LogManager.getLogger();
@ -84,43 +83,36 @@ public class TurnBasedMinecraftMod {
proxy.initialize(); proxy.initialize();
// register packets // register packets
int packetHandlerID = 0; HANDLER.messageBuilder(PacketBattleInfo.class, NetworkDirection.PLAY_TO_CLIENT)
HANDLER.registerMessage( .encoder(new PacketBattleInfo.Encoder())
packetHandlerID++, .decoder(new PacketBattleInfo.Decoder())
PacketBattleInfo.class, .consumerNetworkThread(new PacketBattleInfo.Consumer())
PacketBattleInfo::encode, .add();
PacketBattleInfo::decode, HANDLER.messageBuilder(PacketBattleRequestInfo.class, NetworkDirection.PLAY_TO_SERVER)
PacketBattleInfo::handle); .encoder(new PacketBattleRequestInfo.Encoder())
HANDLER.registerMessage( .decoder(new PacketBattleRequestInfo.Decoder())
packetHandlerID++, .consumerNetworkThread(new PacketBattleRequestInfo.Consumer())
PacketBattleRequestInfo.class, .add();
PacketBattleRequestInfo::encode, HANDLER.messageBuilder(PacketBattleDecision.class, NetworkDirection.PLAY_TO_SERVER)
PacketBattleRequestInfo::decode, .encoder(new PacketBattleDecision.Encoder())
PacketBattleRequestInfo::handle); .decoder(new PacketBattleDecision.Decoder())
HANDLER.registerMessage( .consumerNetworkThread(new PacketBattleDecision.Consumer())
packetHandlerID++, .add();
PacketBattleDecision.class, HANDLER.messageBuilder(PacketBattleMessage.class, NetworkDirection.PLAY_TO_CLIENT)
PacketBattleDecision::encode, .encoder(new PacketBattleMessage.Encoder())
PacketBattleDecision::decode, .decoder(new PacketBattleMessage.Decoder())
PacketBattleDecision::handle); .consumerNetworkThread(new PacketBattleMessage.Consumer())
HANDLER.registerMessage( .add();
packetHandlerID++, HANDLER.messageBuilder(PacketGeneralMessage.class, NetworkDirection.PLAY_TO_CLIENT)
PacketBattleMessage.class, .encoder(new PacketGeneralMessage.Encoder())
PacketBattleMessage::encode, .decoder(new PacketGeneralMessage.Decoder())
PacketBattleMessage::decode, .consumerNetworkThread(new PacketGeneralMessage.Consumer())
PacketBattleMessage::handle); .add();
HANDLER.registerMessage( HANDLER.messageBuilder(PacketEditingMessage.class, NetworkDirection.PLAY_TO_CLIENT)
packetHandlerID++, .encoder(new PacketEditingMessage.Encoder())
PacketGeneralMessage.class, .decoder(new PacketEditingMessage.Decoder())
PacketGeneralMessage::encode, .consumerNetworkThread(new PacketEditingMessage.Consumer())
PacketGeneralMessage::decode, .add();
PacketGeneralMessage::handle);
HANDLER.registerMessage(
packetHandlerID++,
PacketEditingMessage.class,
PacketEditingMessage::encode,
PacketEditingMessage::decode,
PacketEditingMessage::handle);
// register event handler(s) // register event handler(s)
MinecraftForge.EVENT_BUS.register(new AttackEventHandler()); MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
@ -172,7 +164,7 @@ public class TurnBasedMinecraftMod {
proxy.getConfig().setBattleDisabledForAll(true); proxy.getConfig().setBattleDisabledForAll(true);
for (ServerPlayer player : c.getSource().getServer().getPlayerList().getPlayers()) { for (ServerPlayer player : c.getSource().getServer().getPlayerList().getPlayers()) {
proxy.getConfig().addBattleIgnoringPlayer(player.getId()); proxy.getConfig().addBattleIgnoringPlayer(player.getId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("OP disabled turn-based-combat for everyone")); getHandler().send(new PacketGeneralMessage("OP disabled turn-based-combat for everyone"), PacketDistributor.PLAYER.with(player));
} }
return 1; return 1;
})); }));
@ -193,7 +185,7 @@ public class TurnBasedMinecraftMod {
proxy.getConfig().setBattleDisabledForAll(false); proxy.getConfig().setBattleDisabledForAll(false);
proxy.getConfig().clearBattleIgnoringPlayers(); proxy.getConfig().clearBattleIgnoringPlayers();
for (ServerPlayer player : c.getSource().getServer().getPlayerList().getPlayers()) { for (ServerPlayer player : c.getSource().getServer().getPlayerList().getPlayers()) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("OP enabled turn-based-combat for everyone")); getHandler().send(new PacketGeneralMessage("OP enabled turn-based-combat for everyone"), PacketDistributor.PLAYER.with(player));
} }
return 1; return 1;
})); }));
@ -204,7 +196,7 @@ public class TurnBasedMinecraftMod {
.then(Commands.argument("targets", EntityArgument.players()).executes(c -> { .then(Commands.argument("targets", EntityArgument.players()).executes(c -> {
for (ServerPlayer player : EntityArgument.getPlayers(c, "targets")) { for (ServerPlayer player : EntityArgument.getPlayers(c, "targets")) {
proxy.getConfig().addBattleIgnoringPlayer(player.getId()); proxy.getConfig().addBattleIgnoringPlayer(player.getId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("OP enabled turn-based-combat for you")); getHandler().send(new PacketGeneralMessage("OP enabled turn-based-combat for you"), PacketDistributor.PLAYER.with(player));
c.getSource().sendSuccess(() -> Component.literal("Enabled turn-based-combat for " + player.getDisplayName().getString()), true); c.getSource().sendSuccess(() -> Component.literal("Enabled turn-based-combat for " + player.getDisplayName().getString()), true);
} }
return 1; return 1;
@ -216,7 +208,7 @@ public class TurnBasedMinecraftMod {
.then(Commands.argument("targets", EntityArgument.players()).executes(c -> { .then(Commands.argument("targets", EntityArgument.players()).executes(c -> {
for (ServerPlayer player : EntityArgument.getPlayers(c, "targets")) { for (ServerPlayer player : EntityArgument.getPlayers(c, "targets")) {
proxy.getConfig().removeBattleIgnoringPlayer(player.getId()); proxy.getConfig().removeBattleIgnoringPlayer(player.getId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("OP disabled turn-based-combat for you")); getHandler().send(new PacketGeneralMessage("OP disabled turn-based-combat for you"), PacketDistributor.PLAYER.with(player));
c.getSource().sendSuccess(() -> Component.literal("Disabled turn-based-combat for " + player.getDisplayName().getString()), true); c.getSource().sendSuccess(() -> Component.literal("Disabled turn-based-combat for " + player.getDisplayName().getString()), true);
} }
return 1; return 1;
@ -229,12 +221,12 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
proxy.setEditingPlayer(player); proxy.setEditingPlayer(player);
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
logger.info("Begin editing TBM Entity for player \"" + player.getDisplayName().getString() + "\" (\"" + c.getSource().getDisplayName() + "\")"); logger.info("Begin editing TBM Entity for player \"" + player.getDisplayName().getString() + "\" (\"" + c.getSource().getDisplayName() + "\")");
} }
return 1; return 1;
@ -245,14 +237,14 @@ public class TurnBasedMinecraftMod {
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
if (!proxy.getConfig().editEntityEntry(editingInfo.entityInfo)) { if (!proxy.getConfig().editEntityEntry(editingInfo.entityInfo)) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("An error occurred while attempting to save an entry to the config")); getHandler().send(new PacketGeneralMessage("An error occurred while attempting to save an entry to the config"), PacketDistributor.PLAYER.with(player));
proxy.removeEditingInfo(player.getId()); proxy.removeEditingInfo(player.getId());
} else { } else {
proxy.removeEditingInfo(player.getId()); proxy.removeEditingInfo(player.getId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Entity info saved in config and loaded.")); getHandler().send(new PacketGeneralMessage("Entity info saved in config and loaded."), PacketDistributor.PLAYER.with(player));
} }
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -265,7 +257,7 @@ public class TurnBasedMinecraftMod {
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null) { if (editingInfo != null) {
proxy.removeEditingInfo(player.getId()); proxy.removeEditingInfo(player.getId());
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Cancelled editing entry.")); getHandler().send(new PacketGeneralMessage("Cancelled editing entry."), PacketDistributor.PLAYER.with(player));
} }
return 1; return 1;
})) }))
@ -277,11 +269,11 @@ public class TurnBasedMinecraftMod {
Message exceptionMessage = new LiteralMessage("Invalid action for tbm-edit"); Message exceptionMessage = new LiteralMessage("Invalid action for tbm-edit");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
proxy.setEditingPlayer(player); proxy.setEditingPlayer(player);
proxy.getEditingInfo(player.getId()).isEditingCustomName = true; proxy.getEditingInfo(player.getId()).isEditingCustomName = true;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
logger.info("Begin editing custom TBM Entity for player \"" + player.getDisplayName().getString() + "\" (\"" + c.getSource().getDisplayName() + "\")"); logger.info("Begin editing custom TBM Entity for player \"" + player.getDisplayName().getString() + "\" (\"" + c.getSource().getDisplayName() + "\")");
} }
return 1; return 1;
@ -291,9 +283,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -305,9 +297,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -321,9 +313,9 @@ public class TurnBasedMinecraftMod {
boolean ignoreBattle = BoolArgumentType.getBool(c, "ignoreBattle"); boolean ignoreBattle = BoolArgumentType.getBool(c, "ignoreBattle");
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.ignoreBattle = ignoreBattle; editingInfo.entityInfo.ignoreBattle = ignoreBattle;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -336,9 +328,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -355,9 +347,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackPower = attackPower; editingInfo.entityInfo.attackPower = attackPower;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -370,9 +362,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -391,9 +383,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackProbability = attackProbability; editingInfo.entityInfo.attackProbability = attackProbability;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -406,9 +398,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -425,9 +417,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackVariance = attackVariance; editingInfo.entityInfo.attackVariance = attackVariance;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -440,9 +432,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -456,9 +448,9 @@ public class TurnBasedMinecraftMod {
EntityInfo.Effect effect = EntityInfo.Effect.fromString(StringArgumentType.getString(c, "attackEffect")); EntityInfo.Effect effect = EntityInfo.Effect.fromString(StringArgumentType.getString(c, "attackEffect"));
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackEffect = effect; editingInfo.entityInfo.attackEffect = effect;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -471,9 +463,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -492,9 +484,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.attackEffectProbability = attackEffectProbability; editingInfo.entityInfo.attackEffectProbability = attackEffectProbability;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -507,9 +499,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -526,9 +518,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.defenseDamage = defenseDamage; editingInfo.entityInfo.defenseDamage = defenseDamage;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -541,9 +533,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -562,9 +554,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.defenseDamageProbability = defenseDamageProbability; editingInfo.entityInfo.defenseDamageProbability = defenseDamageProbability;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -577,9 +569,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -598,9 +590,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.evasion = evasion; editingInfo.entityInfo.evasion = evasion;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -613,9 +605,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -632,9 +624,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.speed = speed; editingInfo.entityInfo.speed = speed;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -647,9 +639,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -663,9 +655,9 @@ public class TurnBasedMinecraftMod {
String category = StringArgumentType.getString(c, "category"); String category = StringArgumentType.getString(c, "category");
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.category = category; editingInfo.entityInfo.category = category;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -678,9 +670,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -699,9 +691,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.decisionAttack = decisionAttack; editingInfo.entityInfo.decisionAttack = decisionAttack;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -714,9 +706,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -735,9 +727,9 @@ public class TurnBasedMinecraftMod {
} }
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.decisionDefend = decisionDefend; editingInfo.entityInfo.decisionDefend = decisionDefend;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -750,9 +742,9 @@ public class TurnBasedMinecraftMod {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId()); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -766,9 +758,9 @@ public class TurnBasedMinecraftMod {
int decisionFlee = IntegerArgumentType.getInteger(c, "decisionFlee"); int decisionFlee = IntegerArgumentType.getInteger(c, "decisionFlee");
if (editingInfo != null && !editingInfo.isPendingEntitySelection) { if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.decisionFlee = decisionFlee; editingInfo.entityInfo.decisionFlee = decisionFlee;
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) { } else if (editingInfo != null) {
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else { } else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
@ -784,7 +776,7 @@ public class TurnBasedMinecraftMod {
.requires(c -> c.hasPermission(2)) .requires(c -> c.hasPermission(2))
.executes(c -> { .executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException(); ServerPlayer player = c.getSource().getPlayerOrException();
getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.SERVER_EDIT)); getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.SERVER_EDIT), PacketDistributor.PLAYER.with(player));
return 1; return 1;
}) })
.then(Commands.literal("leave_battle_cooldown").executes(c -> { .then(Commands.literal("leave_battle_cooldown").executes(c -> {

View file

@ -1,6 +1,7 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier; import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.Battle; import com.burnedkirby.TurnBasedMinecraft.common.Battle;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
@ -8,7 +9,7 @@ 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.minecraftforge.network.NetworkEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleDecision public class PacketBattleDecision
{ {
@ -24,26 +25,41 @@ public class PacketBattleDecision
this.decision = decision; this.decision = decision;
this.targetIDOrItemID = targetIDOrItemID; this.targetIDOrItemID = targetIDOrItemID;
} }
public static void encode(PacketBattleDecision pkt, FriendlyByteBuf buf) { public static class Encoder implements BiConsumer<PacketBattleDecision, FriendlyByteBuf> {
buf.writeInt(pkt.battleID); public Encoder() {}
buf.writeInt(pkt.decision.getValue());
buf.writeInt(pkt.targetIDOrItemID); @Override
public void accept(PacketBattleDecision pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.battleID);
buf.writeInt(pkt.decision.getValue());
buf.writeInt(pkt.targetIDOrItemID);
}
} }
public static PacketBattleDecision decode(FriendlyByteBuf buf) { public static class Decoder implements Function<FriendlyByteBuf, PacketBattleDecision> {
return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt()); public Decoder() {}
@Override
public PacketBattleDecision apply(FriendlyByteBuf buf) {
return new PacketBattleDecision(buf.readInt(), Decision.valueOf(buf.readInt()), buf.readInt());
}
} }
public static void handle(final PacketBattleDecision pkt, Supplier<NetworkEvent.Context> ctx) { public static class Consumer implements BiConsumer<PacketBattleDecision, CustomPayloadEvent.Context> {
ctx.get().enqueueWork(() -> { public Consumer() {}
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
if(b != null) @Override
{ public void accept(PacketBattleDecision pkt, CustomPayloadEvent.Context ctx) {
ServerPlayer player = ctx.get().getSender(); ctx.enqueueWork(() -> {
b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID); Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
} if(b != null)
}); {
ctx.get().setPacketHandled(true); ServerPlayer player = ctx.getSender();
b.setDecision(player.getId(), pkt.decision, pkt.targetIDOrItemID);
}
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -2,14 +2,15 @@ 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 java.util.function.BiConsumer;
import java.util.function.Function;
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.minecraftforge.network.NetworkEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleInfo public class PacketBattleInfo
{ {
@ -38,65 +39,80 @@ public class PacketBattleInfo
this.turnTimerEnabled = turnTimerEnabled; this.turnTimerEnabled = turnTimerEnabled;
} }
public static void encode(PacketBattleInfo msg, FriendlyByteBuf buf) { public static class Encoder implements BiConsumer<PacketBattleInfo, FriendlyByteBuf> {
buf.writeInt(msg.sideA.size()); public Encoder() {}
buf.writeInt(msg.sideB.size());
for(Integer id : msg.sideA) { @Override
buf.writeInt(id); public void accept(PacketBattleInfo msg, FriendlyByteBuf buf) {
} buf.writeInt(msg.sideA.size());
for(Integer id : msg.sideB) { buf.writeInt(msg.sideB.size());
buf.writeInt(id); for(Integer id : msg.sideA) {
} buf.writeInt(id);
buf.writeLong(msg.decisionNanos); }
buf.writeLong(msg.maxDecisionNanos); for(Integer id : msg.sideB) {
buf.writeBoolean(msg.turnTimerEnabled); buf.writeInt(id);
}
buf.writeLong(msg.decisionNanos);
buf.writeLong(msg.maxDecisionNanos);
buf.writeBoolean(msg.turnTimerEnabled);
}
} }
public static PacketBattleInfo decode(FriendlyByteBuf buf) { public static class Decoder implements Function<FriendlyByteBuf, PacketBattleInfo> {
int sideACount = buf.readInt(); public Decoder() {}
int sideBCount = buf.readInt();
Collection<Integer> sideA = new ArrayList<Integer>(sideACount); @Override
Collection<Integer> sideB = new ArrayList<Integer>(sideBCount); public PacketBattleInfo apply(FriendlyByteBuf buf) {
for(int i = 0; i < sideACount; ++i) { int sideACount = buf.readInt();
sideA.add(buf.readInt()); int sideBCount = buf.readInt();
} Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
for(int i = 0; i < sideBCount; ++i) { Collection<Integer> sideB = new ArrayList<Integer>(sideBCount);
sideB.add(buf.readInt()); for(int i = 0; i < sideACount; ++i) {
} sideA.add(buf.readInt());
long decisionNanos = buf.readLong(); }
long maxDecisionNanos = buf.readLong(); for(int i = 0; i < sideBCount; ++i) {
boolean turnTimerEnabled = buf.readBoolean(); sideB.add(buf.readInt());
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 void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) { public static class Consumer implements BiConsumer<PacketBattleInfo, CustomPayloadEvent.Context> {
ctx.get().enqueueWork(() -> { public Consumer() {}
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
{ @Override
return; public void accept(PacketBattleInfo pkt, CustomPayloadEvent.Context ctx) {
} ctx.enqueueWork(() -> {
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants(); if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
for(Integer id : pkt.sideA)
{
Entity e = Minecraft.getInstance().level.getEntity(id);
if(e != null)
{ {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e); return;
} }
} TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
for(Integer id : pkt.sideB) for(Integer id : pkt.sideA)
{
Entity e = Minecraft.getInstance().level.getEntity(id);
if(e != null)
{ {
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e); Entity e = Minecraft.getInstance().level.getEntity(id);
if(e != null)
{
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideA(e);
}
} }
} for(Integer id : pkt.sideB)
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L)); {
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged(); Entity e = Minecraft.getInstance().level.getEntity(id);
TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled); if(e != null)
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,7 +2,8 @@ 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 java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
@ -11,8 +12,8 @@ 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.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.NetworkEvent;
public class PacketBattleMessage public class PacketBattleMessage
{ {
@ -39,7 +40,8 @@ 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>();
@ -153,31 +155,46 @@ public class PacketBattleMessage
this.amount = amount; this.amount = amount;
this.custom = custom; this.custom = custom;
} }
public static void encode(PacketBattleMessage pkt, FriendlyByteBuf buf) { public static class Encoder implements BiConsumer<PacketBattleMessage, FriendlyByteBuf> {
buf.writeInt(pkt.messageType.getValue()); public Encoder() {}
buf.writeInt(pkt.entityIDFrom);
buf.writeInt(pkt.entityIDTo); @Override
buf.writeUtf(Utility.serializeDimension(pkt.dimension)); public void accept(PacketBattleMessage pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.amount); buf.writeInt(pkt.messageType.getValue());
buf.writeUtf(pkt.custom); 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) { public static class Decoder implements Function<FriendlyByteBuf, PacketBattleMessage> {
return new PacketBattleMessage( public Decoder() {}
MessageType.valueOf(
buf.readInt()), @Override
buf.readInt(), public PacketBattleMessage apply(FriendlyByteBuf buf) {
buf.readInt(), return new PacketBattleMessage(
Utility.deserializeDimension(buf.readUtf()), MessageType.valueOf(
buf.readInt(), buf.readInt()),
buf.readUtf()); buf.readInt(),
buf.readInt(),
Utility.deserializeDimension(buf.readUtf()),
buf.readInt(),
buf.readUtf());
}
} }
public static void handle(final PacketBattleMessage pkt, Supplier<NetworkEvent.Context> ctx) { public static class Consumer implements BiConsumer<PacketBattleMessage, CustomPayloadEvent.Context> {
ctx.get().enqueueWork(() -> { public Consumer() {}
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
}); @Override
ctx.get().setPacketHandled(true); public void accept(PacketBattleMessage pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -1,12 +1,13 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier; import java.util.function.BiConsumer;
import java.util.function.Function;
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.minecraftforge.network.NetworkEvent; import net.minecraftforge.event.network.CustomPayloadEvent;
public class PacketBattleRequestInfo public class PacketBattleRequestInfo
{ {
@ -18,23 +19,38 @@ public class PacketBattleRequestInfo
{ {
this.battleID = battleID; this.battleID = battleID;
} }
public static void encode(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) { public static class Encoder implements BiConsumer<PacketBattleRequestInfo, FriendlyByteBuf> {
buf.writeInt(pkt.battleID); public Encoder() {}
@Override
public void accept(PacketBattleRequestInfo pkt, FriendlyByteBuf buf) {
buf.writeInt(pkt.battleID);
}
} }
public static PacketBattleRequestInfo decode(FriendlyByteBuf buf) { public static class Decoder implements Function<FriendlyByteBuf, PacketBattleRequestInfo> {
return new PacketBattleRequestInfo(buf.readInt()); public Decoder() {}
@Override
public PacketBattleRequestInfo apply(FriendlyByteBuf buf) {
return new PacketBattleRequestInfo(buf.readInt());
}
} }
public static void handle(final PacketBattleRequestInfo pkt, Supplier<NetworkEvent.Context> ctx) { public static class Consumer implements BiConsumer<PacketBattleRequestInfo, CustomPayloadEvent.Context> {
ctx.get().enqueueWork(() -> { public Consumer() {}
Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
if(b == null) { @Override
return; public void accept(PacketBattleRequestInfo pkt, CustomPayloadEvent.Context ctx) {
} ctx.enqueueWork(() -> {
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get()); Battle b = TurnBasedMinecraftMod.proxy.getBattleManager().getBattleByID(pkt.battleID);
}); if(b == null) {
ctx.get().setPacketHandled(true); return;
}
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

@ -4,12 +4,13 @@ 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.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
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; import java.util.function.BiConsumer;
import java.util.function.Function;
public class PacketEditingMessage public class PacketEditingMessage
{ {
@ -87,59 +88,74 @@ public class PacketEditingMessage
this.entityInfo = entityInfo; this.entityInfo = entityInfo;
} }
} }
public static void encode(PacketEditingMessage pkt, FriendlyByteBuf buf) { public static class Encoder implements BiConsumer<PacketEditingMessage, FriendlyByteBuf> {
buf.writeInt(pkt.type.getValue()); public Encoder() {}
if(pkt.entityInfo.classType != null) {
buf.writeUtf(pkt.entityInfo.classType.getName()); @Override
} else { public void accept(PacketEditingMessage pkt, FriendlyByteBuf buf) {
buf.writeUtf("unknown"); buf.writeInt(pkt.type.getValue());
} if(pkt.entityInfo.classType != null) {
buf.writeBoolean(pkt.entityInfo.ignoreBattle); buf.writeUtf(pkt.entityInfo.classType.getName());
buf.writeInt(pkt.entityInfo.attackPower); } else {
buf.writeInt(pkt.entityInfo.attackProbability); buf.writeUtf("unknown");
buf.writeInt(pkt.entityInfo.attackVariance); }
buf.writeUtf(pkt.entityInfo.attackEffect.toString()); buf.writeBoolean(pkt.entityInfo.ignoreBattle);
buf.writeInt(pkt.entityInfo.attackEffectProbability); buf.writeInt(pkt.entityInfo.attackPower);
buf.writeInt(pkt.entityInfo.defenseDamage); buf.writeInt(pkt.entityInfo.attackProbability);
buf.writeInt(pkt.entityInfo.defenseDamageProbability); buf.writeInt(pkt.entityInfo.attackVariance);
buf.writeInt(pkt.entityInfo.evasion); buf.writeUtf(pkt.entityInfo.attackEffect.toString());
buf.writeInt(pkt.entityInfo.speed); buf.writeInt(pkt.entityInfo.attackEffectProbability);
buf.writeUtf(pkt.entityInfo.category); buf.writeInt(pkt.entityInfo.defenseDamage);
buf.writeInt(pkt.entityInfo.decisionAttack); buf.writeInt(pkt.entityInfo.defenseDamageProbability);
buf.writeInt(pkt.entityInfo.decisionDefend); buf.writeInt(pkt.entityInfo.evasion);
buf.writeInt(pkt.entityInfo.decisionFlee); buf.writeInt(pkt.entityInfo.speed);
buf.writeUtf(pkt.entityInfo.customName); buf.writeUtf(pkt.entityInfo.category);
} buf.writeInt(pkt.entityInfo.decisionAttack);
buf.writeInt(pkt.entityInfo.decisionDefend);
public static PacketEditingMessage decode(FriendlyByteBuf buf) { buf.writeInt(pkt.entityInfo.decisionFlee);
Type type = Type.valueOf(buf.readInt()); buf.writeUtf(pkt.entityInfo.customName);
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) { public static class Decoder implements Function<FriendlyByteBuf, PacketEditingMessage> {
ctx.get().enqueueWork(() -> { public Decoder() {}
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
}); @Override
ctx.get().setPacketHandled(true); public PacketEditingMessage apply(FriendlyByteBuf buf) {
Type type = Type.valueOf(buf.readInt());
EntityInfo einfo = new EntityInfo();
try {
einfo.classType = einfo.getClass().getClassLoader().loadClass(buf.readUtf());
} catch (ClassNotFoundException e) { /* ignored */ }
einfo.ignoreBattle = buf.readBoolean();
einfo.attackPower = buf.readInt();
einfo.attackProbability = buf.readInt();
einfo.attackVariance = buf.readInt();
einfo.attackEffect = EntityInfo.Effect.fromString(buf.readUtf());
einfo.attackEffectProbability = buf.readInt();
einfo.defenseDamage = buf.readInt();
einfo.defenseDamageProbability = buf.readInt();
einfo.evasion = buf.readInt();
einfo.speed = buf.readInt();
einfo.category = buf.readUtf();
einfo.decisionAttack = buf.readInt();
einfo.decisionDefend = buf.readInt();
einfo.decisionFlee = buf.readInt();
einfo.customName = buf.readUtf();
return new PacketEditingMessage(type, einfo);
}
}
public static class Consumer implements BiConsumer<PacketEditingMessage, CustomPayloadEvent.Context> {
public Consumer() {}
@Override
public void accept(PacketEditingMessage pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -1,13 +1,14 @@
package com.burnedkirby.TurnBasedMinecraft.common.networking; package com.burnedkirby.TurnBasedMinecraft.common.networking;
import java.util.function.Supplier; import java.util.function.BiConsumer;
import java.util.function.Function;
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod; import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.network.NetworkEvent;
public class PacketGeneralMessage public class PacketGeneralMessage
{ {
@ -26,19 +27,34 @@ public class PacketGeneralMessage
{ {
this.message = message; this.message = message;
} }
public static void encode(PacketGeneralMessage pkt, FriendlyByteBuf buf) { public static class Encoder implements BiConsumer<PacketGeneralMessage, FriendlyByteBuf> {
buf.writeUtf(pkt.message); public Encoder() {}
@Override
public void accept(PacketGeneralMessage pkt, FriendlyByteBuf buf) {
buf.writeUtf(pkt.message);
}
} }
public static PacketGeneralMessage decode(FriendlyByteBuf buf) { public static class Decoder implements Function<FriendlyByteBuf, PacketGeneralMessage> {
return new PacketGeneralMessage(buf.readUtf()); public Decoder() {}
@Override
public PacketGeneralMessage apply(FriendlyByteBuf buf) {
return new PacketGeneralMessage(buf.readUtf());
}
} }
public static void handle(final PacketGeneralMessage pkt, Supplier<NetworkEvent.Context> ctx) { public static class Consumer implements BiConsumer<PacketGeneralMessage, CustomPayloadEvent.Context> {
ctx.get().enqueueWork(() -> { public Consumer() {}
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
}); @Override
ctx.get().setPacketHandled(true); public void accept(PacketGeneralMessage pkt, CustomPayloadEvent.Context ctx) {
ctx.enqueueWork(() -> {
DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> TurnBasedMinecraftMod.proxy.handlePacket(pkt, ctx));
});
ctx.setPacketHandled(true);
}
} }
} }

View file

@ -3,8 +3,8 @@
"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.23.1", "version": "1.24.0",
"mcversion": "1.20.1", "mcversion": "1.20.2",
"url": "", "url": "",
"updateUrl": "", "updateUrl": "",
"authorList": ["Stephen Seo"], "authorList": ["Stephen Seo"],