From ac2a012bd3af13b6ed522658bb9b91c11cc30a7a Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 28 Nov 2019 16:32:34 +0900 Subject: [PATCH] Fixes, mod now works (still WIP) TODO: Battles currently don't work in dimensions other than the overworld. --- build.gradle | 4 +- .../common/AttackEventHandler.java | 41 +- .../TurnBasedMinecraft/common/Battle.java | 28 +- .../common/BattleManager.java | 10 +- .../TurnBasedMinecraft/common/Combatant.java | 28 +- .../common/CommonProxy.java | 10 +- .../TurnBasedMinecraft/common/Config.java | 25 + .../common/TurnBasedMinecraftMod.java | 804 ++++++++++++------ src/main/resources/META-INF/mods.toml | 52 ++ .../TBM_Config.toml | 274 ++++-- src/main/resources/mcmod.info | 4 +- 11 files changed, 877 insertions(+), 403 deletions(-) create mode 100644 src/main/resources/META-INF/mods.toml rename src/main/resources/assets/{TurnBasedMinecraft => com_burnedkirby_turnbasedminecraft}/TBM_Config.toml (70%) diff --git a/build.gradle b/build.gradle index f3ef80a..4eb15c9 100644 --- a/build.gradle +++ b/build.gradle @@ -116,11 +116,11 @@ jar { manifest { attributes([ "Specification-Title": "TurnBasedMinecraftMod", - "Specification-Vendor": "TurnBasedMinecraftMod_SS", + "Specification-Vendor": "TurnBasedMinecraftMod_BK", "Specification-Version": "1", // We are version 1 of ourselves "Implementation-Title": project.name, "Implementation-Version": "${version}", - "Implementation-Vendor" :"TurnBasedMinecraftMod_SS", + "Implementation-Vendor" :"TurnBasedMinecraftMod_BK", "Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "ContainedDeps": "javamp3-1.0.3.jar" ]) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java index a6fd700..4ae9fed 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/AttackEventHandler.java @@ -10,7 +10,7 @@ import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraftforge.event.entity.living.LivingAttackEvent; import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.network.NetworkDirection; +import net.minecraftforge.fml.network.PacketDistributor; public class AttackEventHandler { @@ -68,10 +68,9 @@ public class AttackEventHandler BattleManager battleManager = proxy.getBattleManager(); // handle edit entity, pick entity via attack { - EditingInfo editingInfo = null; if(event.getSource().getTrueSource() != null && event.getEntity() != null) { - editingInfo = proxy.getEditingInfo(event.getSource().getTrueSource().getEntityId()); + final EditingInfo editingInfo = proxy.getEditingInfo(event.getSource().getTrueSource().getEntityId()); if(editingInfo != null && editingInfo.isPendingEntitySelection) { editingInfo.isPendingEntitySelection = false; @@ -81,28 +80,18 @@ public class AttackEventHandler if(!event.getEntity().hasCustomName()) { TurnBasedMinecraftMod.logger.error("Cannot edit custom name from entity without custom name"); - TurnBasedMinecraftMod.getHandler().sendTo( - new PacketGeneralMessage("Cannot edit custom name from entity without custom name"), - ((ServerPlayerEntity)editingInfo.editor).connection.netManager, - NetworkDirection.PLAY_TO_CLIENT); + TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity)editingInfo.editor), new PacketGeneralMessage("Cannot edit custom name from entity without custom name")); return; } - //editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomNameTag()); - editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomName().getString()); + editingInfo.entityInfo = config.getCustomEntityInfo(event.getEntity().getCustomName().getUnformattedComponentText()); if(editingInfo.entityInfo == null) { editingInfo.entityInfo = new EntityInfo(); editingInfo.entityInfo.customName = event.getEntity().getCustomName().getString(); } - TurnBasedMinecraftMod.getHandler().sendTo( - new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getString() + "\""), - ((ServerPlayerEntity)editingInfo.editor).connection.netManager, - NetworkDirection.PLAY_TO_CLIENT); + TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity)editingInfo.editor), new PacketGeneralMessage("Editing custom name \"" + event.getEntity().getCustomName().getUnformattedComponentText() + "\"")); TurnBasedMinecraftMod.logger.info("Begin editing custom \"" + event.getEntity().getCustomName().getString() + "\""); - TurnBasedMinecraftMod.getHandler().sendTo( - new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), - ((ServerPlayerEntity)editingInfo.editor).connection.netManager, - NetworkDirection.PLAY_TO_CLIENT); + TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity)editingInfo.editor), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); } else { @@ -116,15 +105,9 @@ public class AttackEventHandler { editingInfo.entityInfo = editingInfo.entityInfo.clone(); } - TurnBasedMinecraftMod.getHandler().sendTo( - new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\""), - ((ServerPlayerEntity)editingInfo.editor).connection.netManager, - NetworkDirection.PLAY_TO_CLIENT); + TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity)editingInfo.editor), new PacketGeneralMessage("Editing entity \"" + editingInfo.entityInfo.classType.getName() + "\"")); TurnBasedMinecraftMod.logger.info("Begin editing \"" + editingInfo.entityInfo.classType.getName() + "\""); - TurnBasedMinecraftMod.getHandler().sendTo( - new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), - ((ServerPlayerEntity)editingInfo.editor).connection.netManager, - NetworkDirection.PLAY_TO_CLIENT); + TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity)editingInfo.editor), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); } return; } @@ -132,6 +115,7 @@ public class AttackEventHandler } if(event.getEntity() != null && event.getSource().getTrueSource() != null && (battleManager.isRecentlyLeftBattle(event.getEntity().getEntityId()) || battleManager.isRecentlyLeftBattle(event.getSource().getTrueSource().getEntityId()))) { +// TurnBasedMinecraftMod.logger.debug("Canceled attack"); event.setCanceled(true); return; } @@ -143,13 +127,12 @@ public class AttackEventHandler && !config.getBattleIgnoringPlayers().contains(event.getEntity().getEntityId()) && battleManager.checkAttack(event)) { -// TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.commonProxy.getAttackingEntity() + " and " + event.getEntity()); +// TurnBasedMinecraftMod.logger.debug("Canceled LivingAttackEvent between " + TurnBasedMinecraftMod.proxy.getAttackingEntity() + " and " + event.getEntity()); event.setCanceled(true); - } - else - { + } else { // TurnBasedMinecraftMod.logger.debug("Did not cancel attack"); } + if(TurnBasedMinecraftMod.proxy.getAttackingDamage() < (int) event.getAmount()) { TurnBasedMinecraftMod.proxy.setAttackingDamage((int) event.getAmount()); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 4eb287a..9801157 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java @@ -128,7 +128,12 @@ public class Battle { for(Entity e : sideA) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + EntityInfo entityInfo; + try { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + } catch(NullPointerException exception) { + entityInfo = null; + } if(entityInfo == null) { entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); @@ -161,7 +166,12 @@ public class Battle { for(Entity e : sideB) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + EntityInfo entityInfo; + try { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + } catch(NullPointerException exception) { + entityInfo = null; + } if(entityInfo == null) { entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); @@ -296,7 +306,12 @@ public class Battle public void addCombatantToSideA(Entity e) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + EntityInfo entityInfo; + try { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + } catch(NullPointerException exception) { + entityInfo = null; + } if(entityInfo == null) { entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); @@ -357,7 +372,12 @@ public class Battle public void addCombatantToSideB(Entity e) { - EntityInfo entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + EntityInfo entityInfo; + try { + entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getCustomEntityInfoReference(e.getCustomName().getUnformattedComponentText()); + } catch(NullPointerException exception) { + entityInfo = null; + } if(entityInfo == null) { entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getMatchingEntityInfo(e); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java index cbaf34b..28f77c8 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/BattleManager.java @@ -46,9 +46,9 @@ public class BattleManager public boolean checkAttack(final LivingAttackEvent event) { Config config = TurnBasedMinecraftMod.proxy.getConfig(); - // verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo String receiverClassName = event.getEntity().getClass().getName(); String receiverCustomName; + try { receiverCustomName = event.getEntity().getCustomName().getUnformattedComponentText(); } catch (NullPointerException e) { @@ -67,9 +67,13 @@ public class BattleManager attackerCustomName = null; } - if(!((event.getEntity() instanceof PlayerEntity && !((PlayerEntity)event.getEntity()).isCreative()) || (config.getEntityInfoReference(receiverClassName) != null || config.getCustomEntityInfoReference(receiverCustomName) != null)) - || !((event.getSource().getTrueSource() instanceof PlayerEntity && !((PlayerEntity)event.getSource().getTrueSource()).isCreative()) || (config.getEntityInfoReference(attackerClassName) != null || config.getCustomEntityInfoReference(attackerCustomName) != null))) + // verify that both entities are EntityPlayer and not in creative or has a corresponding EntityInfo + if(!((event.getEntity() instanceof PlayerEntity && !((PlayerEntity)event.getEntity()).isCreative()) + || (config.getEntityInfoReference(receiverClassName) != null || config.getCustomEntityInfoReference(receiverCustomName) != null)) + || !((event.getSource().getTrueSource() instanceof PlayerEntity && !((PlayerEntity)event.getSource().getTrueSource()).isCreative()) + || (config.getEntityInfoReference(attackerClassName) != null || config.getCustomEntityInfoReference(attackerCustomName) != null))) { + logger.debug("BattleManager: Failed first check, attacker is \"" + attackerClassName + "\", defender is \"" + receiverClassName + "\""); return false; } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java index 78f72b7..3ca2b10 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Combatant.java @@ -3,10 +3,10 @@ package com.burnedkirby.TurnBasedMinecraft.common; import java.util.Comparator; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.MobEffects; -import net.minecraft.potion.PotionEffect; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.potion.EffectInstance; +import net.minecraft.potion.Effects; public class Combatant { @@ -50,18 +50,18 @@ public class Combatant @Override public int compare(Combatant c0, Combatant c1) { - if(c0.entity instanceof EntityPlayer && c0.recalcSpeedOnCompare) + if(c0.entity instanceof PlayerEntity && c0.recalcSpeedOnCompare) { - EntityLivingBase c0Entity = (EntityLivingBase)c0.entity; + LivingEntity c0Entity = (LivingEntity)c0.entity; boolean isHaste = false; boolean isSlow = false; - for(PotionEffect e : c0Entity.getActivePotionEffects()) + for(EffectInstance e : c0Entity.getActivePotionEffects()) { - if(e.getEffectName().equals(MobEffects.HASTE.getName()) || e.getEffectName().equals(MobEffects.SPEED.getName())) + if(e.getEffectName().equals(Effects.HASTE.getName()) || e.getEffectName().equals(Effects.SPEED.getName())) { isHaste = true; } - else if(e.getEffectName().equals(MobEffects.SLOWNESS.getName())) + else if(e.getEffectName().equals(Effects.SLOWNESS.getName())) { isSlow = true; } @@ -84,18 +84,18 @@ public class Combatant } } - if(c1.entity instanceof EntityPlayer && c1.recalcSpeedOnCompare) + if(c1.entity instanceof PlayerEntity && c1.recalcSpeedOnCompare) { - EntityLivingBase c1Entity = (EntityLivingBase)c1.entity; + LivingEntity c1Entity = (LivingEntity)c1.entity; boolean isHaste = false; boolean isSlow = false; - for(PotionEffect e : c1Entity.getActivePotionEffects()) + for(EffectInstance e : c1Entity.getActivePotionEffects()) { - if(e.getEffectName().equals(MobEffects.HASTE.getName())) + if(e.getEffectName().equals(Effects.HASTE.getName())) { isHaste = true; } - else if(e.getEffectName().equals(MobEffects.SLOWNESS.getName())) + else if(e.getEffectName().equals(Effects.SLOWNESS.getName())) { isSlow = true; } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java index 7ef5559..15de04a 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/CommonProxy.java @@ -4,12 +4,11 @@ import java.util.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.text.ITextComponent; -import net.minecraftforge.common.MinecraftForge; +import net.minecraft.world.dimension.DimensionType; +import net.minecraftforge.fml.server.ServerLifecycleHooks; import org.apache.logging.log4j.Logger; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; -import net.minecraftforge.fml.common.FMLCommonHandler; public class CommonProxy { @@ -26,6 +25,7 @@ public class CommonProxy attackerViaBow = new HashSet(); editingPlayers = new Hashtable(); initializeClient(); + logger.debug("Init proxy for com_burnedkirby_turnbasedminecraft"); } protected void initializeClient() {} @@ -69,6 +69,7 @@ public class CommonProxy { config = new Config(logger); postInitClient(); + logger.debug("postInit proxy for com_burnedkirby_turnbasedminecraft"); } protected void postInitClient() {} @@ -94,7 +95,8 @@ public class CommonProxy public Entity getEntityByID(int id) { - return FMLCommonHandler.instance().getMinecraftServerInstance().getEntityWorld().getEntityByID(id); + // TODO validate dimension of entity + return ServerLifecycleHooks.getCurrentServer().getWorld(DimensionType.OVERWORLD).getEntityByID(id); } public final boolean isServerRunning() diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java index 3a99926..64519e5 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java @@ -57,6 +57,16 @@ public class Config musicSillyTypes = new HashSet(); battleIgnoringPlayers = new HashSet(); + { + File confPath = new File(TurnBasedMinecraftMod.CONFIG_DIRECTORY); + if(!confPath.exists()) { + if(!confPath.mkdirs()) { + logger.error("Failed to create config dir \"" + TurnBasedMinecraftMod.CONFIG_DIRECTORY + "\""); + return; + } + } + } + writeDefaultConfig(getClass().getResourceAsStream(TurnBasedMinecraftMod.CONFIG_INTERNAL_PATH)); int internalVersion = getConfigFileVersion(new File(TurnBasedMinecraftMod.DEFAULT_CONFIG_FILE_PATH)); @@ -776,6 +786,7 @@ public class Config return false; } + boolean saved = false; try { if (eInfo.classType != null || !eInfo.customName.isEmpty()) { for (com.electronwill.nightconfig.core.Config entity : entities) { @@ -795,6 +806,7 @@ public class Config entity.set("decision_attack_probability", eInfo.decisionAttack); entity.set("decision_defend_probability", eInfo.decisionDefend); entity.set("decision_flee_probability", eInfo.decisionFlee); + saved = true; break; } } @@ -812,6 +824,19 @@ public class Config conf.save(); conf.close(); + if(!saved) { + logger.warn("Failed to save \"" + eInfo.classType.getName() + "\""); + return false; + } + + if(eInfo.classType != null) { + entityInfoMap.put(eInfo.classType.getName(), eInfo); + } else if(!eInfo.customName.isEmpty()){ + customEntityInfoMap.put(eInfo.customName, eInfo); + } else { + logger.warn("Failed to update entity info in memory"); + } + return true; } diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java index a027c75..a06e745 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/TurnBasedMinecraftMod.java @@ -4,6 +4,8 @@ import com.burnedkirby.TurnBasedMinecraft.client.ClientProxy; import com.burnedkirby.TurnBasedMinecraft.common.networking.*; import com.mojang.brigadier.LiteralMessage; import com.mojang.brigadier.Message; +import com.mojang.brigadier.arguments.BoolArgumentType; +import com.mojang.brigadier.arguments.IntegerArgumentType; import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; @@ -21,24 +23,25 @@ import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLDedicatedServerSetupEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.network.NetworkRegistry; import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.simple.SimpleChannel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -@Mod(value = TurnBasedMinecraftMod.MODID) +@Mod(TurnBasedMinecraftMod.MODID) 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 VERSION = "1.8"; + public static final String VERSION = "1.9"; public static final String CONFIG_FILENAME = "TBM_Config.toml"; public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_FILE_PATH = CONFIG_DIRECTORY + CONFIG_FILENAME; public static final String DEFAULT_CONFIG_FILE_PATH = CONFIG_DIRECTORY + DEFAULT_CONFIG_FILENAME; - public static final String CONFIG_INTERNAL_PATH = "/assets/TurnBasedMinecraft/" + CONFIG_FILENAME; + public static final String CONFIG_INTERNAL_PATH = "/assets/com_burnedkirby_turnbasedminecraft/" + CONFIG_FILENAME; public static final String MUSIC_ROOT = CONFIG_DIRECTORY + "Music/"; public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/"; public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/"; @@ -63,13 +66,20 @@ public class TurnBasedMinecraftMod public static CommonProxy proxy; - @SubscribeEvent - public void firstInit(FMLCommonSetupEvent event) + public TurnBasedMinecraftMod() { + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::firstInit); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitClient); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::secondInitServer); + + MinecraftForge.EVENT_BUS.register(this); + } + + private void firstInit(final FMLCommonSetupEvent event) { proxy = DistExecutor.runForDist(()->()->new ClientProxy(), ()->()->new CommonProxy()); - proxy.initialize(); proxy.setLogger(logger); - + proxy.initialize(); + // register packets int packetHandlerID = 0; HANDLER.registerMessage( @@ -112,16 +122,16 @@ public class TurnBasedMinecraftMod // register event handler(s) MinecraftForge.EVENT_BUS.register(new AttackEventHandler()); MinecraftForge.EVENT_BUS.register(new PlayerJoinEventHandler()); + + logger.debug("Init com_burnedkirby_turnbasedminecraft"); } - @SubscribeEvent - public void secondInitClient(FMLClientSetupEvent event) + private void secondInitClient(final FMLClientSetupEvent event) { proxy.postInit(); } - @SubscribeEvent - public void secondInitServer(FMLDedicatedServerSetupEvent event) + private void secondInitServer(final FMLDedicatedServerSetupEvent event) { proxy.postInit(); } @@ -220,110 +230,80 @@ public class TurnBasedMinecraftMod } else if(editingInfo != null) { getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); } else { - proxy.setEditingPlayer(c.getSource().asPlayer()); + proxy.setEditingPlayer(player); getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); - logger.info("Begin editing TBM Entity for player \"" + player.getDisplayName().getUnformattedComponentText() + "\""); + logger.info("Begin editing TBM Entity for player \"" + player.getDisplayName().getUnformattedComponentText() + "\" (\"" + c.getSource().getName() + "\")"); } return 1; }) - .then(Commands.argument("action", StringArgumentType.word()) + .then(Commands.literal("finish") .executes(c -> { - String action = StringArgumentType.getString(c, "action").toLowerCase(); ServerPlayerEntity player = c.getSource().asPlayer(); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); if(editingInfo != null && !editingInfo.isPendingEntitySelection) { - if (action.equals("finish")) { - 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")); - proxy.removeEditingInfo(player.getEntityId()); - } else { - proxy.removeEditingInfo(player.getEntityId()); - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Entity info saved in config and loaded.")); - } - } else if (action.equals("cancel")) { + 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")); proxy.removeEditingInfo(player.getEntityId()); - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Cancelled editing entry.")); - } else if (action.equals("edit")) { - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); } else { - Message exceptionMessage = new LiteralMessage("Invalid action for tbm-edit"); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + proxy.removeEditingInfo(player.getEntityId()); + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Entity info saved in config and loaded.")); } } else if(editingInfo != null) { getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); } else { - if(action.equals("custom")) { - proxy.setEditingPlayer(player); - proxy.getEditingInfo(player.getEntityId()).isEditingCustomName = true; - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); - logger.info("Begin editing custom TBM Entity for player \"" + player.getDisplayName().getUnformattedComponentText() + "\'"); - } else { - Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + .then(Commands.literal("cancel") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null) { + proxy.removeEditingInfo(player.getEntityId()); + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketGeneralMessage("Cancelled editing entry.")); + } + return 1; + })) + .then(Commands.literal("custom") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + Message exceptionMessage = new LiteralMessage("Invalid action for tbm-edit"); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + proxy.setEditingPlayer(player); + proxy.getEditingInfo(player.getEntityId()).isEditingCustomName = true; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + logger.info("Begin editing custom TBM Entity for player \"" + player.getDisplayName().getUnformattedComponentText() + "\" (\"" + c.getSource().getName() + "\")"); + } + return 1; + })) + .then(Commands.literal("edit") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null){ + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); } return 1; }) - .then(Commands.argument("category", StringArgumentType.word()) + .then(Commands.literal("ignoreBattle") .executes(c -> { - String action = StringArgumentType.getString(c, "action").toLowerCase(); - String category = StringArgumentType.getString(c, "category"); ServerPlayerEntity player = c.getSource().asPlayer(); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); if(editingInfo != null && !editingInfo.isPendingEntitySelection) { - if (action.equals("edit")) { - switch (category) { - case "ignoreBattle": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE)); - break; - case "attackPower": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER)); - break; - case "attackProbability": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY)); - break; - case "attackVariance": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE)); - break; - case "attackEffect": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT)); - break; - case "attackEffectProbability": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY)); - break; - case "defenseDamage": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE)); - break; - case "defenseDamageProbability": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY)); - break; - case "evasion": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION)); - break; - case "speed": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED)); - break; - case "category": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY)); - break; - case "decisionAttack": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK)); - break; - case "decisionDefend": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND)); - break; - case "decisionFlee": - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE)); - break; - default: - Message exceptionMessage = new LiteralMessage("Invalid argument for \"/tbm-edit edit \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - } else { - Message exceptionMessage = new LiteralMessage("Invalid argument"); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - } else if(editingInfo != null){ + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_IGNORE_BATTLE)); + } else if(editingInfo != null) { getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); } else { Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); @@ -331,190 +311,14 @@ public class TurnBasedMinecraftMod } return 1; }) - .then(Commands.argument("value", StringArgumentType.greedyString())) + .then(Commands.argument("ignoreBattle", BoolArgumentType.bool()) .executes(c -> { - String action = StringArgumentType.getString(c, "action").toLowerCase(); - String category = StringArgumentType.getString(c, "category"); - String value = StringArgumentType.getString(c, "value").toLowerCase(); ServerPlayerEntity player = c.getSource().asPlayer(); EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + boolean ignoreBattle = BoolArgumentType.getBool(c, "ignoreBattle"); if(editingInfo != null && !editingInfo.isPendingEntitySelection) { - if (action.equals("edit")) { - switch (category) { - case "ignoreBattle": - if (value.equals("true")) { - editingInfo.entityInfo.ignoreBattle = true; - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } else if (value.equals("false")) { - editingInfo.entityInfo.ignoreBattle = false; - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } else { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit ignoreBattle \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "attackPower": - try { - editingInfo.entityInfo.attackPower = Integer.parseInt(value); - if (editingInfo.entityInfo.attackPower < 0) { - editingInfo.entityInfo.attackPower = 0; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackPower \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "attackProbability": - try { - editingInfo.entityInfo.attackProbability = Integer.parseInt(value); - if (editingInfo.entityInfo.attackProbability < 0) { - editingInfo.entityInfo.attackProbability = 0; - } else if (editingInfo.entityInfo.attackProbability > 100) { - editingInfo.entityInfo.attackProbability = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackProbability \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "attackVariance": - try { - editingInfo.entityInfo.attackVariance = Integer.parseInt(value); - if (editingInfo.entityInfo.attackVariance < 0) { - editingInfo.entityInfo.attackVariance = 0; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackVariance \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "attackEffect": - editingInfo.entityInfo.attackEffect = EntityInfo.Effect.fromString(value); - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - break; - case "attackEffectProbability": - try { - editingInfo.entityInfo.attackEffectProbability = Integer.parseInt(value); - if (editingInfo.entityInfo.attackEffectProbability < 0) { - editingInfo.entityInfo.attackEffectProbability = 0; - } else if (editingInfo.entityInfo.attackEffectProbability > 100) { - editingInfo.entityInfo.attackEffectProbability = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit attackEffectProbability \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "defenseDamage": - try { - editingInfo.entityInfo.defenseDamage = Integer.parseInt(value); - if (editingInfo.entityInfo.defenseDamage < 0) { - editingInfo.entityInfo.defenseDamage = 0; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit defenseDamage \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "defenseDamageProbability": - try { - editingInfo.entityInfo.defenseDamageProbability = Integer.parseInt(value); - if (editingInfo.entityInfo.defenseDamageProbability < 0) { - editingInfo.entityInfo.defenseDamageProbability = 0; - } else if (editingInfo.entityInfo.defenseDamageProbability > 100) { - editingInfo.entityInfo.defenseDamageProbability = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit defenseDamageProbability \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "evasion": - try { - editingInfo.entityInfo.evasion = Integer.parseInt(value); - if (editingInfo.entityInfo.evasion < 0) { - editingInfo.entityInfo.evasion = 0; - } else if (editingInfo.entityInfo.evasion > 100) { - editingInfo.entityInfo.evasion = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit evasion \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "speed": - try { - editingInfo.entityInfo.speed = Integer.parseInt(value); - if (editingInfo.entityInfo.speed < 0) { - editingInfo.entityInfo.speed = 0; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit speed \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "category": - editingInfo.entityInfo.category = value; - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - break; - case "decisionAttack": - try { - editingInfo.entityInfo.decisionAttack = Integer.parseInt(value); - if (editingInfo.entityInfo.decisionAttack < 0) { - editingInfo.entityInfo.decisionAttack = 0; - } else if (editingInfo.entityInfo.decisionAttack > 100) { - editingInfo.entityInfo.decisionAttack = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit decisionAttack \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "decisionDefend": - try { - editingInfo.entityInfo.decisionDefend = Integer.parseInt(value); - if (editingInfo.entityInfo.decisionDefend < 0) { - editingInfo.entityInfo.decisionDefend = 0; - } else if (editingInfo.entityInfo.decisionDefend > 100) { - editingInfo.entityInfo.decisionDefend = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit decisionDefend \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - case "decisionFlee": - try { - editingInfo.entityInfo.decisionFlee = Integer.parseInt(value); - if (editingInfo.entityInfo.decisionFlee < 0) { - editingInfo.entityInfo.decisionFlee = 0; - } else if (editingInfo.entityInfo.decisionFlee > 100) { - editingInfo.entityInfo.decisionFlee = 100; - } - getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); - } catch (NumberFormatException e) { - Message exceptionMessage = new LiteralMessage("Invalid value for \"/tbm-edit edit decisionFlee \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - break; - default: - Message exceptionMessage = new LiteralMessage("Invalid category for \"/tbm-edit edit \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } - } else { - Message exceptionMessage = new LiteralMessage("Invalid args for \"/tbm-edit \""); - throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); - } + editingInfo.entityInfo.ignoreBattle = ignoreBattle; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); } else if(editingInfo != null) { getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); } else { @@ -522,8 +326,454 @@ public class TurnBasedMinecraftMod throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); } return 1; - }) - )) + })) + ) + .then(Commands.literal("attackPower") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_POWER)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("attackPower", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int attackPower = IntegerArgumentType.getInteger(c, "attackPower"); + if(attackPower < 0) { + attackPower = 0; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.attackPower = attackPower; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("attackProbability") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_PROBABILITY)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("attackProbability", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int attackProbability = IntegerArgumentType.getInteger(c, "attackProbability"); + if(attackProbability < 0) { + attackProbability = 0; + } else if(attackProbability > 100) { + attackProbability = 100; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.attackProbability = attackProbability; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("attackVariance") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_VARIANCE)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("attackVariance", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int attackVariance = IntegerArgumentType.getInteger(c, "attackVariance"); + if(attackVariance < 0) { + attackVariance = 0; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.attackVariance = attackVariance; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("attackEffect") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("attackEffect", StringArgumentType.word()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + EntityInfo.Effect effect = EntityInfo.Effect.fromString(StringArgumentType.getString(c, "attackEffect")); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.attackEffect = effect; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("attackEffectProbability") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_ATTACK_EFFECT_PROBABILITY)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("attackEffectProbability", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int attackEffectProbability = IntegerArgumentType.getInteger(c, "attackEffectProbability"); + if(attackEffectProbability < 0) { + attackEffectProbability = 0; + } else if(attackEffectProbability > 100) { + attackEffectProbability = 100; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.attackEffectProbability = attackEffectProbability; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("defenseDamage") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("defenseDamage", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int defenseDamage = IntegerArgumentType.getInteger(c, "defenseDamage"); + if(defenseDamage < 0) { + defenseDamage = 0; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.defenseDamage = defenseDamage; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("defenseDamageProbability") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DEFENSE_DAMAGE_PROBABILITY)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("defenseDamageProbability", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int defenseDamageProbability = IntegerArgumentType.getInteger(c, "defenseDamageProbability"); + if(defenseDamageProbability < 0) { + defenseDamageProbability = 0; + } else if(defenseDamageProbability > 100) { + defenseDamageProbability = 100; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.defenseDamageProbability = defenseDamageProbability; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("evasion") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_EVASION)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("evasion", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int evasion = IntegerArgumentType.getInteger(c, "evasion"); + if(evasion < 0) { + evasion = 0; + } else if(evasion > 100) { + evasion = 100; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.evasion = evasion; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("speed") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SPEED)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("speed", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int speed = IntegerArgumentType.getInteger(c, "speed"); + if(speed < 0) { + speed = 0; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.speed = speed; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("category") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_CATEGORY)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("category", StringArgumentType.word()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + String category = StringArgumentType.getString(c, "category"); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.category = category; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("decisionAttack") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_ATTACK)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("decisionAttack", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int decisionAttack = IntegerArgumentType.getInteger(c, "decisionAttack"); + if(decisionAttack < 0) { + decisionAttack = 0; + } else if(decisionAttack > 100) { + decisionAttack = 100; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.decisionAttack = decisionAttack; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("decisionDefend") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_DEFEND)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("decisionDefend", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int decisionDefend = IntegerArgumentType.getInteger(c, "decisionDefend"); + if(decisionDefend < 0) { + decisionDefend = 0; + } else if(decisionDefend > 100) { + decisionDefend = 100; + } + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.decisionDefend = decisionDefend; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + .then(Commands.literal("decisionFlee") + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.EDIT_DECISION_FLEE)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + }) + .then(Commands.argument("decisionFlee", IntegerArgumentType.integer()) + .executes(c -> { + ServerPlayerEntity player = c.getSource().asPlayer(); + EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getEntityId()); + int decisionFlee = IntegerArgumentType.getInteger(c, "decisionFlee"); + if(editingInfo != null && !editingInfo.isPendingEntitySelection) { + editingInfo.entityInfo.decisionFlee = decisionFlee; + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo)); + } else if(editingInfo != null) { + getHandler().send(PacketDistributor.PLAYER.with(() -> player), new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY)); + } else { + Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\")."); + throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage); + } + return 1; + })) + ) + ) ); } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml new file mode 100644 index 0000000..6c3bacf --- /dev/null +++ b/src/main/resources/META-INF/mods.toml @@ -0,0 +1,52 @@ +# This is an example mods.toml file. It contains the data relating to the loading mods. +# There are several mandatory fields (#mandatory), and many more that are optional (#optional). +# The overall format is standard TOML format, v0.5.0. +# Note that there are a couple of TOML lists in this file. +# Find more information on toml format here: https://github.com/toml-lang/toml +# The name of the mod loader type to load - for regular FML @Mod mods it should be javafml +modLoader="javafml" #mandatory +# A version range to match for said mod loader - for regular FML @Mod it will be the forge version +loaderVersion="[28,)" #mandatory (28 is current forge version) +# A URL to refer people to when problems occur with this mod +issueTrackerURL="https://github.com/Stephen-Seo/TurnBasedMinecraftMod/issues" #optional +# A list of mods - how many allowed here is determined by the individual mod loader +[[mods]] #mandatory +# The modid of the mod +modId="com_burnedkirby_turnbasedminecraft" #mandatory +# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it +version="1.9" #mandatory + # A display name for the mod +displayName="TurnBasedMinecraftMod" #mandatory +# A URL to query for updates for this mod. See the JSON update specification +#updateJSONURL="" #optional +# A URL for the "homepage" for this mod, displayed in the mod UI +displayURL="https://github.com/Stephen-Seo/TurnBasedMinecraftMod" #optional +# A file name (in the root of the mod JAR) containing a logo for display +#logoFile="" #optional +# A text field displayed in the mod UI +credits="Thanks for this mod goes to Java" #optional +# A text field displayed in the mod UI +authors="BurnedKirby" #optional +# The description text for the mod (multi line!) (#mandatory) +description=''' +Implements turn-based-battle in Minecraft. +''' +# A dependency - use the . to indicate dependency for a specific modid. Dependencies are optional. +[[dependencies.com_burnedkirby_turnbasedminecraft]] #optional + # the modid of the dependency + modId="forge" #mandatory + # Does this dependency have to exist - if not, ordering below must be specified + mandatory=true #mandatory + # The version range of the dependency + versionRange="[28,)" #mandatory + # An ordering relationship for the dependency - BEFORE or AFTER required if the relationship is not mandatory + ordering="NONE" + # Side this dependency is applied on - BOTH, CLIENT or SERVER + side="BOTH" +# Here's another dependency +[[dependencies.com_burnedkirby_turnbasedminecraft]] + modId="minecraft" + mandatory=true + versionRange="[1.14.4]" + ordering="NONE" + side="BOTH" diff --git a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml b/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml similarity index 70% rename from src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml rename to src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml index b890aef..85347d0 100644 --- a/src/main/resources/assets/TurnBasedMinecraft/TBM_Config.toml +++ b/src/main/resources/assets/com_burnedkirby_turnbasedminecraft/TBM_Config.toml @@ -88,7 +88,7 @@ battle_turn_time_seconds = 15 # decision_flee_probability: Percentage of entity choosing to flee on turn. [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityBlaze" +name = "net.minecraft.entity.monster.BlazeEntity" attack_power = 5 attack_probability = 50 attack_effect = "fire" @@ -101,7 +101,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityCaveSpider" +name = "net.minecraft.entity.monster.CaveSpiderEntity" attack_power = 2 attack_probability = 75 attack_effect = "poison" @@ -114,7 +114,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityCreeper" +name = "net.minecraft.entity.monster.CreeperEntity" ignore_battle = true attack_power = 15 attack_probability = 17 @@ -127,7 +127,19 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityElderGuardian" +name = "net.minecraft.entity.monster.DrownedEntity" +attack_power = 3 +attack_probability = 70 +attack_variance = 2 +evasion = 5 +category = "monster" +speed = 25 +decision_attack_probability = 100 +decision_defend_probability = 0 +decision_flee_probability = 0 + +[[server_config.entity]] +name = "net.minecraft.entity.monster.ElderGuardianEntity" attack_power = 8 attack_probability = 65 defense_damage = 2 @@ -140,7 +152,7 @@ decision_defend_probability = 20 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityEnderman" +name = "net.minecraft.entity.monster.EndermanEntity" attack_power = 7 attack_probability = 80 evasion = 40 @@ -151,7 +163,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityEndermite" +name = "net.minecraft.entity.monster.EndermiteEntity" attack_power = 2 attack_probability = 80 evasion = 40 @@ -162,7 +174,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityEvoker" +name = "net.minecraft.entity.monster.EvokerEntity" attack_power = 6 attack_probability = 60 evasion = 35 @@ -173,7 +185,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityGhast" +name = "net.minecraft.entity.monster.GhastEntity" ignore_battle = true attack_power = 13 attack_probability = 20 @@ -185,7 +197,7 @@ decision_defend_probability = 0 decision_flee_probability = 25 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityGiantZombie" +name = "net.minecraft.entity.monster.GiantEntity" attack_power = 11 attack_probability = 35 evasion = 2 @@ -196,7 +208,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityGuardian" +name = "net.minecraft.entity.monster.GuardianEntity" attack_power = 6 attack_probability = 55 defense_damage = 2 @@ -209,7 +221,7 @@ decision_defend_probability = 20 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityHusk" +name = "net.minecraft.entity.monster.HuskEntity" attack_power = 3 attack_probability = 70 attack_effect = "hunger" @@ -222,7 +234,19 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityIronGolem" +name = "net.minecraft.entity.monster.IllusionerEntity" +attack_power = 2 +attack_probability = 70 +attack_variance = 2 +evasion = 5 +category = "monster" +speed = 35 +decision_attack_probability = 100 +decision_defend_probability = 0 +decision_flee_probability = 0 + +[[server_config.entity]] +name = "net.minecraft.entity.monster.IronGolemEntity" attack_power = 14 attack_probability = 85 attack_variance = 7 @@ -234,7 +258,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityMagmaCube" +name = "net.minecraft.entity.monster.MagmaCubeEntity" attack_power = 3 attack_probability = 35 evasion = 12 @@ -245,29 +269,43 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityPigZombie" -attack_power = 8 -attack_probability = 70 +name = "net.minecraft.entity.monster.PhantomEntity" +attack_power = 2 +attack_probability = 90 +attack_variance = 1 +evasion = 35 +category = "monster" +speed = 65 +decision_attack_probability = 100 +decision_defend_probability = 0 +decision_flee_probability = 0 + +[[server_config.entity]] +name = "net.minecraft.entity.monster.PillagerEntity" +attack_power = 3 +attack_probability = 60 +attack_variance = 1 evasion = 10 category = "monster" -speed = 50 +speed = 30 decision_attack_probability = 100 decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityPolarBear" -attack_power = 6 -attack_probability = 67 -evasion = 5 -category = "animal" +name = "net.minecraft.entity.monster.RavagerEntity" +attack_power = 12 +attack_probability = 70 +attack_variance = 4 +evasion = 4 +category = "monster" speed = 35 -decision_attack_probability = 100 +decision_attack_probability = 90 decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityShulker" +name = "net.minecraft.entity.monster.ShulkerEntity" attack_power = 4 attack_probability = 80 evasion = 15 @@ -278,7 +316,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntitySilverfish" +name = "net.minecraft.entity.monster.SilverfishEntity" attack_power = 1 attack_probability = 85 evasion = 37 @@ -289,7 +327,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntitySkeleton" +name = "net.minecraft.entity.monster.SkeletonEntity" attack_power = 3 attack_probability = 75 attack_variance = 1 @@ -301,7 +339,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntitySlime" +name = "net.minecraft.entity.monster.SlimeEntity" attack_power = 2 attack_probability = 35 evasion = 10 @@ -312,18 +350,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntitySnowman" -attack_power = 0 -attack_probability = 80 -evasion = 5 -category = "passive" -speed = 60 -decision_attack_probability = 100 -decision_defend_probability = 0 -decision_flee_probability = 0 - -[[server_config.entity]] -name = "net.minecraft.entity.monster.EntitySpider" +name = "net.minecraft.entity.monster.SpiderEntity" attack_power = 2 attack_probability = 70 evasion = 25 @@ -334,7 +361,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityStray" +name = "net.minecraft.entity.monster.StrayEntity" attack_power = 3 attack_probability = 75 attack_variance = 1 @@ -348,7 +375,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityVex" +name = "net.minecraft.entity.monster.VexEntity" attack_power = 9 attack_probability = 65 evasion = 30 @@ -359,7 +386,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityVindicator" +name = "net.minecraft.entity.monster.VindicatorEntity" attack_power = 13 attack_probability = 70 evasion = 10 @@ -370,7 +397,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityWitch" +name = "net.minecraft.entity.monster.WitchEntity" attack_power = 5 attack_probability = 75 attack_variance = 1 @@ -382,7 +409,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityWitherSkeleton" +name = "net.minecraft.entity.monster.WitherSkeletonEntity" attack_power = 8 attack_probability = 70 attack_effect = "wither" @@ -395,7 +422,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityZombie" +name = "net.minecraft.entity.monster.ZombieEntity" attack_power = 3 attack_probability = 70 evasion = 5 @@ -406,7 +433,18 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.monster.EntityZombieVillager" +name = "net.minecraft.entity.monster.ZombiePigmanEntity" +attack_power = 8 +attack_probability = 70 +evasion = 10 +category = "monster" +speed = 50 +decision_attack_probability = 100 +decision_defend_probability = 0 +decision_flee_probability = 0 + +[[server_config.entity]] +name = "net.minecraft.entity.monster.ZombieVillagerEntity" attack_power = 3 attack_probability = 70 evasion = 5 @@ -417,7 +455,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityBat" +name = "net.minecraft.entity.passive.BatEntity" attack_power = 0 attack_probability = 70 evasion = 35 @@ -428,7 +466,7 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityChicken" +name = "net.minecraft.entity.passive.ChickenEntity" attack_power = 0 attack_probability = 70 evasion = 10 @@ -439,7 +477,7 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityCow" +name = "net.minecraft.entity.passive.CowEntity" attack_power = 0 attack_probability = 50 evasion = 1 @@ -450,7 +488,19 @@ decision_defend_probability = 10 decision_flee_probability = 80 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityDonkey" +name = "net.minecraft.entity.passive.DolphinEntity" +attack_power = 3 +attack_probability = 80 +attack_variance = 1 +evasion = 45 +category = "passive" +speed = 75 +decision_attack_probability = 70 +decision_defend_probability = 0 +decision_flee_probability = 30 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.horse.DonkeyEntity" attack_power = 0 attack_probability = 70 evasion = 10 @@ -461,7 +511,7 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityHorse" +name = "net.minecraft.entity.passive.horse.HorseEntity" attack_power = 0 attack_probability = 70 evasion = 10 @@ -472,7 +522,7 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityLlama" +name = "net.minecraft.entity.passive.horse.LlamaEntity" attack_power = 1 attack_probability = 70 evasion = 10 @@ -483,7 +533,7 @@ decision_defend_probability = 0 decision_flee_probability = 25 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityMooshroom" +name = "net.minecraft.entity.passive.MooshroomEntity" attack_power = 0 attack_probability = 70 evasion = 1 @@ -494,7 +544,7 @@ decision_defend_probability = 10 decision_flee_probability = 80 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityMule" +name = "net.minecraft.entity.passive.horse.MuleEntity" attack_power = 0 attack_probability = 70 evasion = 10 @@ -505,11 +555,11 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityOcelot" +name = "net.minecraft.entity.passive.OcelotEntity" attack_power = 1 attack_probability = 70 attack_variance = 1 -evasion = 10 +evasion = 30 category = "passive" speed = 75 decision_attack_probability = 0 @@ -517,7 +567,18 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityParrot" +name = "net.minecraft.entity.passive.PandaEntity" +attack_power = 6 +attack_probability = 60 +evasion = 10 +category = "passive" +speed = 30 +decision_attack_probability = 45 +decision_defend_probability = 25 +decision_flee_probability = 30 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.ParrotEntity" attack_power = 0 attack_probability = 70 evasion = 35 @@ -528,7 +589,7 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityPig" +name = "net.minecraft.entity.passive.PigEntity" attack_power = 0 attack_probability = 70 evasion = 10 @@ -539,7 +600,18 @@ decision_defend_probability = 5 decision_flee_probability = 85 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityRabbit" +name = "net.minecraft.entity.passive.PolarBearEntity" +attack_power = 6 +attack_probability = 67 +evasion = 5 +category = "animal" +speed = 35 +decision_attack_probability = 100 +decision_defend_probability = 0 +decision_flee_probability = 0 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.RabbitEntity" attack_power = 0 attack_probability = 70 evasion = 40 @@ -550,7 +622,7 @@ decision_defend_probability = 0 decision_flee_probability = 100 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntitySheep" +name = "net.minecraft.entity.passive.SheepEntity" attack_power = 0 attack_probability = 70 evasion = 5 @@ -561,7 +633,7 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntitySkeletonHorse" +name = "net.minecraft.entity.passive.horse.SkeletonHorseEntity" attack_power = 0 attack_probability = 70 evasion = 5 @@ -572,7 +644,18 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntitySquid" +name = "net.minecraft.entity.passive.SnowGolemEntity" +attack_power = 0 +attack_probability = 80 +evasion = 5 +category = "passive" +speed = 60 +decision_attack_probability = 100 +decision_defend_probability = 0 +decision_flee_probability = 0 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.SquidEntity" attack_power = 0 attack_probability = 70 evasion = 15 @@ -583,7 +666,18 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityVillager" +name = "net.minecraft.entity.passive.horse.TraderLlamaEntity" +attack_power = 1 +attack_probability = 70 +evasion = 10 +category = "passive" +speed = 50 +decision_attack_probability = 65 +decision_defend_probability = 0 +decision_flee_probability = 25 + +[[server_config.entity]] +name = "net.minecraft.entity.merchant.villager.VillagerEntity" attack_power = 0 attack_probability = 70 evasion = 5 @@ -594,7 +688,7 @@ decision_defend_probability = 10 decision_flee_probability = 80 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityWolf" +name = "net.minecraft.entity.passive.WolfEntity" attack_power = 4 attack_probability = 70 evasion = 20 @@ -605,7 +699,7 @@ decision_defend_probability = 15 decision_flee_probability = 5 [[server_config.entity]] -name = "net.minecraft.entity.passive.EntityZombieHorse" +name = "net.minecraft.entity.passive.horse.ZombieHorseEntity" attack_power = 0 attack_probability = 70 evasion = 8 @@ -616,7 +710,53 @@ decision_defend_probability = 0 decision_flee_probability = 90 [[server_config.entity]] -name = "net.minecraft.entity.boss.EntityDragon" +name = "net.minecraft.entity.passive.fish.CodEntity" +attack_power = 0 +attack_probability = 50 +evasion = 50 +category = "passive" +speed = 75 +decision_attack_probability = 25 +decision_defend_probability = 0 +decision_flee_probability = 75 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.fish.PufferfishEntity" +attack_power = 0 +attack_probability = 50 +defense_damage = 3 +defense_damage_probability = 75 +evasion = 25 +category = "passive" +speed = 45 +decision_attack_probability = 35 +decision_defend_probability = 0 +decision_flee_probability = 65 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.fish.SalmonEntity" +attack_power = 0 +attack_probability = 50 +evasion = 50 +category = "passive" +speed = 75 +decision_attack_probability = 25 +decision_defend_probability = 0 +decision_flee_probability = 75 + +[[server_config.entity]] +name = "net.minecraft.entity.passive.fish.TropicalFishEntity" +attack_power = 0 +attack_probability = 50 +evasion = 50 +category = "passive" +speed = 75 +decision_attack_probability = 25 +decision_defend_probability = 0 +decision_flee_probability = 75 + +[[server_config.entity]] +name = "net.minecraft.entity.boss.dragon.EnderDragonEntity" attack_power = 10 attack_probability = 70 attack_variance = 2 @@ -628,7 +768,7 @@ decision_defend_probability = 0 decision_flee_probability = 0 [[server_config.entity]] -name = "net.minecraft.entity.boss.EntityWither" +name = "net.minecraft.entity.boss.WitherEntity" attack_power = 8 attack_probability = 70 attack_effect = "wither" diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index c6fb5d1..af95c02 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,6 +1,6 @@ [ { - "modid": "com.burnedkirby.turnbasedminecraft", + "modid": "com_burnedkirby_turnbasedminecraft", "name": "Turn Based Minecraft", "description": "Changes battles to be turn-based.", "version": "${version}", @@ -10,8 +10,6 @@ "authorList": ["Stephen Seo"], "credits": "The Forge and FML guys, for making this possible. Dependencies: - shadow by John Rengelman (Apache License 2.0) - Cava-Toml by ConenSys team (Apache License 2.0) JavaMP3 by delthas, josephx86, GlaDOSik, and kevinstadler (MIT License)", "logoFile": "", "screenshots": [],