# Building
Simply invoke `./gradlew build` in the mod directory and after some time the
-finished jar will be saved at "build/libs/TurnBasedMinecraft-1.18.5.jar"
+finished jar will be saved at "build/libs/TurnBasedMinecraft-1.18.6.jar"
# Other notes
//apply plugin: 'eclipse'
//apply plugin: 'maven-publish'
-version = "1.18.5"
+version = "1.18.6"
group = "com.burnedkirby.TurnBasedMinecraft"
archivesBaseName = "TurnBasedMinecraft"
public class BattleGui extends Screen {
private AtomicInteger timeRemaining;
+ private boolean turnTimerEnabled;
private long lastInstant;
private long elapsedTime;
private MenuState state;
String timeRemainingString = "Time remaining: ";
int timeRemainingInt = timeRemaining.get();
- if (timeRemainingInt > 8) {
+ if (timeRemainingInt > 8 || !turnTimerEnabled) {
timeRemainingString += "\u00A7a";
} else if (timeRemainingInt > 4) {
timeRemainingString += "\u00A7e";
} else {
timeRemainingString += "\u00A7c";
}
- timeRemainingString += Integer.toString(timeRemainingInt);
+
+ if (!turnTimerEnabled) {
+ timeRemainingString += "Infinity";
+ } else {
+ timeRemainingString += Integer.toString(timeRemainingInt);
+ }
int stringWidth = font.width(timeRemainingString);
fill(poseStack, width / 2 - stringWidth / 2, 5, width / 2 + stringWidth / 2, 15, 0x70000000);
drawString(poseStack, timeRemainingString, width / 2 - stringWidth / 2, 5, 0xFFFFFFFF);
private void drawString(PoseStack poseStack, String string, int x, int y, int color) {
font.draw(poseStack, string, x, y, color);
}
+
+ public void setTurnTimerEnabled(boolean enabled) {
+ turnTimerEnabled = enabled;
+ }
}
}
}
+ @Override
+ public void setBattleGuiTurnTimerEnabled(boolean enabled) {
+ battleGui.setTurnTimerEnabled(enabled);
+ }
+
@Override
public void battleGuiTurnBegin() {
battleGui.turnBegin();
parent.append(sub);
}
+ sub = new TextComponent("battle_turn_wait_forever ");
+ sub.setStyle(sub.getStyle()
+ .withColor(ChatFormatting.YELLOW)
+ .withBold(true)
+ .withHoverEvent(new HoverEvent(
+ HoverEvent.Action.SHOW_TEXT,
+ new TextComponent("Disables the turn timer (recommended to leave this to false)"))
+ ));
+ parent.append(sub);
+
+ sub = new TextComponent("true ");
+ sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit battle_turn_wait_forever true")));
+ parent.append(sub);
+
+ sub = new TextComponent("false ");
+ sub.setStyle(sub.getStyle().withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND,
+ "/tbm-server-edit battle_turn_wait_forever false")));
+ parent.append(sub);
+
sub = new TextComponent("battle_turn_time_seconds ");
sub.setStyle(sub.getStyle()
.withColor(ChatFormatting.YELLOW)
private long lastInstant;
private long timer;
+ private boolean timerForever;
+
private boolean isServer;
private boolean battleEnded;
state = State.DECISION;
undecidedCount.set(playerCount.get());
timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
+ timerForever = TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever();
battleEnded = false;
notifyPlayersBattleInfo();
}
public long getTimerSeconds() {
- return timer / 1000000000;
+ return timer / 1000000000L;
+ }
+
+ public long getTimerNanos() {
+ return timer;
}
public int getSize() {
if (!isServer) {
return;
}
- PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer);
+ PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
for (Combatant p : players.values()) {
TurnBasedMinecraftMod.getHandler().send(PacketDistributor.PLAYER.with(() -> (ServerPlayer) p.entity), infoPacket);
}
switch (state) {
case DECISION:
timer -= dt;
- if (timer <= 0 || undecidedCount.get() <= 0) {
+ if ((!timerForever && timer <= 0) || undecidedCount.get() <= 0) {
for (Combatant c : sideA.values()) {
// picking decision for sideA non-players
if (!(c.entity instanceof Player) && c.decision == Decision.UNDECIDED && c.entityInfo != null) {
}
state = State.ACTION;
timer = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
+ timerForever = TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever();
sendMessageToAllPlayers(PacketBattleMessage.MessageType.TURN_BEGIN, 0, 0, 0);
turnOrderQueue.clear();
for (Combatant c : sideA.values()) {
public void setBattleGuiBattleChanged() {}
public void setBattleGuiAsGui() {}
+
+ public void setBattleGuiTurnTimerEnabled(boolean enabled) {}
public void battleGuiTurnBegin() {}
public static final long BATTLE_DECISION_DURATION_NANO_MAX = BATTLE_DECISION_DURATION_SEC_MAX * 1000000000L;
public static final long BATTLE_DECISION_DURATION_NANO_DEFAULT = BATTLE_DECISION_DURATION_SEC_DEFAULT * 1000000000L;
private long battleDecisionDurationNanos = BATTLE_DECISION_DURATION_NANO_DEFAULT;
+ private boolean battleDecisionDurationForever = false;
private Map<String, EntityInfo> entityInfoMap;
private Map<String, EntityInfo> customEntityInfoMap;
private Set<String> ignoreBattleTypes;
logTOMLInvalidValue("server_config.battle_turn_time_seconds", "15");
}
+ try {
+ Boolean battle_turn_wait_forever = conf.get("server_config.battle_turn_wait_forever");
+ if (battle_turn_wait_forever != null) {
+ this.battleDecisionDurationForever = battle_turn_wait_forever;
+ } else {
+ this.battleDecisionDurationForever = false;
+ logNotFound("server_config.battle_turn_wait_forever", "false");
+ }
+ } catch (ClassCastException e) {
+ this.battleDecisionDurationForever = false;
+ logTOMLInvalidValue("server_config.battle_turn_wait_forever", "false");
+ }
+
Collection<com.electronwill.nightconfig.core.Config> entities = null;
try {
entities = conf.get("server_config.entity");
public void setCreeperAlwaysAllowDamage(boolean allow_damage) {
creeperAlwaysAllowDamage = allow_damage;
}
+
+ public boolean isBattleDecisionDurationForever() {
+ return battleDecisionDurationForever;
+ }
+
+ public void setBattleDecisionDurationForever(boolean battleDecisionDurationForever) {
+ this.battleDecisionDurationForever = battleDecisionDurationForever;
+ }
}
public class TurnBasedMinecraftMod {
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod";
- public static final String VERSION = "1.18.5";
+ public static final String VERSION = "1.18.6";
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/";
}
return 1;
})))
+ .then(Commands.literal("battle_turn_wait_forever").executes(c -> {
+ TextComponent parent = new TextComponent("Use ");
+ TextComponent sub = new TextComponent("/tbm-server-edit battle_turn_wait_forever <true/false>");
+ sub.setStyle(sub.getStyle().withColor(ChatFormatting.YELLOW));
+ parent.append(sub);
+
+ c.getSource().sendSuccess(parent, false);
+ return 1;
+ })
+ .then(Commands.argument("enabled", BoolArgumentType.bool()).executes(c -> {
+ boolean enabled = BoolArgumentType.getBool(c, "enabled");
+ TurnBasedMinecraftMod.proxy.getConfig().setBattleDecisionDurationForever(enabled);
+ if (!TurnBasedMinecraftMod.proxy.getConfig().updateConfig("server_config.battle_turn_wait_forever", enabled)) {
+ TurnBasedMinecraftMod.logger.warn(
+ "Failed to set \"server_config.battle_turn_wait_forever\" in config file!"
+ );
+ c.getSource().sendFailure(new TextComponent("Failed to set battle_turn_wait_forever to \"" + (enabled ? "true" : "false") + "\" in config file!"));
+ } else {
+ TextComponent response = new TextComponent("Successfully set battle_turn_wait_forever to: ");
+ TextComponent subResponse = new TextComponent((enabled ? "true" : "false"));
+ subResponse.setStyle(subResponse.getStyle().withColor(ChatFormatting.GREEN));
+ response.append(subResponse);
+ c.getSource().sendSuccess(response, true);
+ }
+ return 1;
+ })))
.then(Commands.literal("battle_turn_time_seconds").executes(c -> {
TextComponent parent = new TextComponent("Use ");
TextComponent sub = new TextComponent("/tbm-server-edit battle_turn_time_seconds <5-60>");
private Collection<Integer> sideA;
private Collection<Integer> sideB;
private long decisionNanos;
+ private boolean turnTimerEnabled;
public PacketBattleInfo()
{
sideA = new ArrayList<Integer>();
sideB = new ArrayList<Integer>();
decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
+ turnTimerEnabled = false;
}
- public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos)
+ public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, boolean turnTimerEnabled)
{
this.sideA = sideA;
this.sideB = sideB;
this.decisionNanos = decisionNanos;
+ this.turnTimerEnabled = turnTimerEnabled;
}
public static void encode(PacketBattleInfo msg, FriendlyByteBuf buf) {
buf.writeInt(id);
}
buf.writeLong(msg.decisionNanos);
+ buf.writeBoolean(msg.turnTimerEnabled);
}
public static PacketBattleInfo decode(FriendlyByteBuf buf) {
sideB.add(buf.readInt());
}
long decisionNanos = buf.readLong();
- return new PacketBattleInfo(sideA, sideB, decisionNanos);
+ boolean turnTimerEnabled = buf.readBoolean();
+ return new PacketBattleInfo(sideA, sideB, decisionNanos, turnTimerEnabled);
}
public static void handle(final PacketBattleInfo pkt, Supplier<NetworkEvent.Context> ctx) {
}
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
+ TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
});
ctx.get().setPacketHandled(true);
}
if(b == null) {
return;
}
- TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerSeconds()), ctx.get());
+ TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx.get());
});
ctx.get().setPacketHandled(true);
}
# 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.18.5" #mandatory
+version="1.18.6" #mandatory
# A display name for the mod
displayName="TurnBasedMinecraftMod" #mandatory
# A URL to query for updates for this mod. See the JSON update specification <here>
# will be added to battle until there are less than max entities.
max_in_battle = 8
-# If true, all entities in battle will be frozen in place
+# If true, all entities in battle will be frozen in place.
freeze_battle_combatants = false
# Entity categories that will not initiate battle.
ignore_battle_types = ["passive", "boss"]
-# speed stat of all players in battle
+# Speed stat of all players in battle.
player_speed = 50
-# speed stat of all players under the effects of haste
+# Speed stat of all players under the effects of haste.
player_haste_speed = 80
-# speed stat of all players under the effects of slow
+# Speed stat of all players under the effects of slow.
player_slow_speed = 20
-# attack probability stat for all players
+# Attack probability stat for all players.
player_attack_probability = 90
-# evasion stat for all players
+# Evasion stat for all players.
player_evasion = 10
-# Number of attacks that a "defend" move will block
+# Number of attacks that a "defend" move will block.
defense_duration = 1
-# probability of fleeing from battle when speed is greater than fastest enemy's speed
+# Probability of fleeing from battle when speed is greater than fastest enemy's speed.
flee_good_probability = 90
-# probability of fleeing from battle when speed is less than fastest enemy's speed
+# Probability of fleeing from battle when speed is less than fastest enemy's speed.
flee_bad_probability = 40
# Minimum hit percentage for everyone. If option is set to less than 1,
# Minimum 5, maximum 60.
battle_turn_time_seconds = 15
-# On what turn a Creeper will explode in battle
+# If set to true, battle_turn_time_seconds will be ignored and there will be no turn timer.
+# WARNING: If this is set to true, a player can halt a battle forever by never deciding on their turn.
+battle_turn_wait_forever = false
+
+# On what turn a Creeper will explode in battle.
creeper_explode_turn = 5
-# Keep creepers from exploding when they leave a battle (for leave_battle_cooldown duration)
+# Keep creepers from exploding when they leave a battle (for leave_battle_cooldown duration).
creeper_stop_explode_on_leave_battle = true
-# If false, creepers may not damage others outside of turn-based battle
+# If false, creepers may not damage others outside of turn-based battle.
creeper_always_allow_damage = true
"modid": "com_burnedkirby_turnbasedminecraft",
"name": "Turn Based Minecraft",
"description": "Changes battles to be turn-based.",
- "version": "1.18.5",
+ "version": "1.18.6",
"mcversion": "1.18.2",
"url": "",
"updateUrl": "",