Compare commits
11 commits
4652ecf20e
...
ecf981fb0c
Author | SHA1 | Date | |
---|---|---|---|
ecf981fb0c | |||
cf8df83b49 | |||
1b585b4377 | |||
b676a00c1c | |||
252b3a5272 | |||
8e469f1a8a | |||
02f7b179a5 | |||
c65f9bde1c | |||
504329fa88 | |||
8e646cb814 | |||
e6501e4fe3 |
14 changed files with 174 additions and 19 deletions
24
Changelog.md
24
Changelog.md
|
@ -1,5 +1,29 @@
|
|||
# Upcoming changes
|
||||
|
||||
# Version Forge-1.26.1
|
||||
|
||||
Minor fixes/refactorings that should make the mod more robust.
|
||||
|
||||
Port to Forge 52.0.22 (Minecraft 1.21.1).
|
||||
|
||||
Allow leaving battle GUI with Escape key (temporarily), and some refactorings
|
||||
to (hopefully) fix that pesky transient client-freeze-bug.
|
||||
|
||||
Minecraft's music should be paused during battle, even if it starts mid-battle.
|
||||
(Minecraft's music may play up to 4 seconds before it is paused by TBMM.)
|
||||
|
||||
# Version NeoForge-1.26.1
|
||||
|
||||
Minor fixes/refactorings that should make the mod more robust.
|
||||
|
||||
Port to NeoForge-21.1.72 (Minecraft 1.21.1).
|
||||
|
||||
Allow leaving battle GUI with Escape key (temporarily), and some refactorings
|
||||
to (hopefully) fix that pesky transient client-freeze-bug.
|
||||
|
||||
Minecraft's music should be paused during battle, even if it starts mid-battle.
|
||||
(Minecraft's music may play up to 4 seconds before it is paused by TBMM.)
|
||||
|
||||
# Version Forge-1.26.0
|
||||
|
||||
Port to Forge 52.0.21 (Minecraft 1.21.1).
|
||||
|
|
|
@ -73,7 +73,7 @@ configured for them.)
|
|||
|
||||
Simply invoke `./gradlew build` in the mod directory and after some time the
|
||||
finished jar will be saved at
|
||||
`build/libs/TurnBasedMinecraft-Forge-1.26.0-all.jar`
|
||||
`build/libs/TurnBasedMinecraft-Forge-1.26.1-all.jar`
|
||||
|
||||
# Reproducibility
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ minecraft_version=1.21.1
|
|||
# as they do not follow standard versioning conventions.
|
||||
minecraft_version_range=[1.21.1,1.22)
|
||||
# The Forge version must agree with the Minecraft version to get a valid artifact
|
||||
forge_version=52.0.21
|
||||
forge_version=52.0.22
|
||||
# The Forge version range can use any version of Forge as bounds or match the loader version range
|
||||
forge_version_range=[0,)
|
||||
# The loader version range can only use the major version of Forge/FML as bounds
|
||||
|
@ -48,7 +48,7 @@ mod_name=TurnBasedMinecraftMod
|
|||
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
|
||||
mod_license=MIT
|
||||
# The mod version. See https://semver.org/
|
||||
mod_version=1.26.0
|
||||
mod_version=1.26.1
|
||||
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
@ -28,6 +28,7 @@ public class BattleGui extends Screen {
|
|||
private MenuState state;
|
||||
private boolean stateChanged;
|
||||
private String info;
|
||||
private Long waitMissingBattleTicks;
|
||||
|
||||
private enum MenuState {
|
||||
MAIN_MENU(0), ATTACK_TARGET(1), ITEM_ACTION(2), WAITING(3), SWITCH_ITEM(4), USE_ITEM(5);
|
||||
|
@ -91,6 +92,7 @@ public class BattleGui extends Screen {
|
|||
elapsedTime = 0;
|
||||
state = MenuState.MAIN_MENU;
|
||||
stateChanged = true;
|
||||
waitMissingBattleTicks = null;
|
||||
}
|
||||
|
||||
private void setState(MenuState state) {
|
||||
|
@ -224,12 +226,29 @@ public class BattleGui extends Screen {
|
|||
}
|
||||
}
|
||||
|
||||
private int colorFromTicks(final Long ticks) {
|
||||
if (ticks < 20 * 10) {
|
||||
double value = (20 * 10 - ticks.intValue()) / (20.0 * 10.0);
|
||||
return 0xFF0000FF | (((int)(value * 255.0)) << 8) | (((int)(value * 255.0)) << 16);
|
||||
} else {
|
||||
return 0xFF0000FF;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() == null) {
|
||||
if (waitMissingBattleTicks == null) {
|
||||
waitMissingBattleTicks = 0L;
|
||||
} else {
|
||||
waitMissingBattleTicks += 1L;
|
||||
}
|
||||
// drawHoveringText("Waiting...", width / 2 - 50, height / 2);
|
||||
drawString(guiGraphics, "Waiting...", width / 2 - 50, height / 2, 0xFFFFFFFF);
|
||||
drawString(guiGraphics, "Waiting...", width / 2 - 50, height / 2, colorFromTicks(waitMissingBattleTicks));
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
return;
|
||||
} else {
|
||||
waitMissingBattleTicks = null;
|
||||
}
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION
|
||||
&& timeRemaining.get() > 0) {
|
||||
|
@ -353,9 +372,13 @@ public class BattleGui extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int a, int b, int c) {
|
||||
public boolean keyPressed(int keyCode, int b, int c) {
|
||||
if (getMinecraft().player.isCreative()) {
|
||||
return super.keyPressed(a, b, c);
|
||||
return super.keyPressed(keyCode, b, c);
|
||||
} else if (keyCode == 256) {
|
||||
TurnBasedMinecraftMod.proxy.displayString("Leaving GUI, but the battle continues!");
|
||||
getMinecraft().setScreen(null);
|
||||
return true;
|
||||
}
|
||||
return false; // TODO verify return value
|
||||
}
|
||||
|
|
|
@ -180,7 +180,7 @@ public class BattleMusic
|
|||
if(initialized && next != null)
|
||||
{
|
||||
logger.debug("play called with file " + next.getName() + " and vol " + volume);
|
||||
Minecraft.getInstance().getSoundManager().pause();
|
||||
TurnBasedMinecraftMod.proxy.pauseMCMusic();
|
||||
String suffix = next.getName().substring(next.getName().length() - 3).toLowerCase();
|
||||
if(suffix.equals("mid") && sequencer != null)
|
||||
{
|
||||
|
@ -362,7 +362,7 @@ public class BattleMusic
|
|||
}
|
||||
if(resumeMCSounds)
|
||||
{
|
||||
Minecraft.getInstance().getSoundManager().resume();
|
||||
TurnBasedMinecraftMod.proxy.resumeMCMusic();
|
||||
}
|
||||
isPlaying = false;
|
||||
}
|
||||
|
|
|
@ -370,6 +370,10 @@ public class ClientProxy extends CommonProxy {
|
|||
break;
|
||||
case TURN_BEGIN:
|
||||
TurnBasedMinecraftMod.proxy.displayString("The turn begins!");
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() == null || TurnBasedMinecraftMod.proxy.getLocalBattle().getId() != pkt.getAmount()) {
|
||||
TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.getAmount());
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.battleStarted();
|
||||
TurnBasedMinecraftMod.proxy.battleGuiTurnBegin();
|
||||
break;
|
||||
case TURN_END:
|
||||
|
@ -1479,4 +1483,14 @@ public class ClientProxy extends CommonProxy {
|
|||
public void showClientConfigGui() {
|
||||
Minecraft.getInstance().setScreen(new ClientConfigGui());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pauseMCMusic() {
|
||||
Minecraft.getInstance().getSoundManager().pause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeMCMusic() {
|
||||
Minecraft.getInstance().getSoundManager().resume();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ package com.burnedkirby.TurnBasedMinecraft.common;
|
|||
|
||||
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleInfo;
|
||||
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage;
|
||||
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattlePing;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -49,6 +50,8 @@ public class Battle {
|
|||
|
||||
private ResourceKey<Level> dimension;
|
||||
|
||||
private long pingTimerNanos;
|
||||
|
||||
public enum State {
|
||||
DECISION(0),
|
||||
ACTION(1),
|
||||
|
@ -122,6 +125,7 @@ public class Battle {
|
|||
undecidedCount = new AtomicInteger(0);
|
||||
random = new Random();
|
||||
this.dimension = dimension;
|
||||
pingTimerNanos = 0;
|
||||
if (sideA != null) {
|
||||
for (Entity e : sideA) {
|
||||
EntityInfo entityInfo;
|
||||
|
@ -447,12 +451,22 @@ public class Battle {
|
|||
if (!isServer) {
|
||||
return;
|
||||
}
|
||||
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
|
||||
PacketBattleInfo infoPacket = new PacketBattleInfo(getId(), getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
|
||||
for (Combatant p : players.values()) {
|
||||
TurnBasedMinecraftMod.getHandler().send(infoPacket, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
|
||||
}
|
||||
}
|
||||
|
||||
protected void notifyPlayersBattlePing() {
|
||||
if (!isServer) {
|
||||
return;
|
||||
}
|
||||
PacketBattlePing pingPacket = new PacketBattlePing(getId(), (int)(timer / 1000000000L));
|
||||
for (Combatant p : players.values()) {
|
||||
TurnBasedMinecraftMod.getHandler().send(pingPacket, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount) {
|
||||
sendMessageToAllPlayers(type, from, to, amount, new String());
|
||||
}
|
||||
|
@ -651,6 +665,11 @@ public class Battle {
|
|||
}
|
||||
|
||||
private boolean update(final long dt) {
|
||||
pingTimerNanos += dt;
|
||||
if (pingTimerNanos >= 4000000000L) {
|
||||
pingTimerNanos = 0;
|
||||
notifyPlayersBattlePing();
|
||||
}
|
||||
if (battleEnded) {
|
||||
Collection<Combatant> combatants = new ArrayList<Combatant>();
|
||||
combatants.addAll(sideA.values());
|
||||
|
|
|
@ -26,7 +26,7 @@ public class BattleUpdater
|
|||
|
||||
@SubscribeEvent
|
||||
public void update(TickEvent.ServerTickEvent tickEvent) {
|
||||
if(tickEvent.phase != TickEvent.Phase.START && isRunning.get() && ++tick > tickLimit) {
|
||||
if(tickEvent.phase != TickEvent.Phase.START && isRunning.get() && ++tick > tickLimit && tickEvent.haveTime()) {
|
||||
tick = 0;
|
||||
manager.battleMap.entrySet().removeIf(entry -> entry.getValue().update());
|
||||
manager.updateRecentlyLeftBattle();
|
||||
|
|
|
@ -175,4 +175,7 @@ public class CommonProxy
|
|||
public <MSG> void handlePacket(MSG msg,CustomPayloadEvent.Context ctx) {}
|
||||
|
||||
public void showClientConfigGui() {}
|
||||
|
||||
public void pauseMCMusic() {}
|
||||
public void resumeMCMusic() {}
|
||||
}
|
|
@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger;
|
|||
public class TurnBasedMinecraftMod {
|
||||
public static final String MODID = "com_burnedkirby_turnbasedminecraft";
|
||||
public static final String NAME = "Turn Based Minecraft Mod";
|
||||
public static final String VERSION = "1.26.0";
|
||||
public static final String VERSION = "1.26.1";
|
||||
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/";
|
||||
|
@ -50,7 +50,7 @@ public class TurnBasedMinecraftMod {
|
|||
public static final String MUSIC_SILLY = MUSIC_ROOT + "silly/";
|
||||
public static final String MUSIC_BATTLE = MUSIC_ROOT + "battle/";
|
||||
|
||||
private static final Integer PROTOCOL_VERSION = 4;
|
||||
private static final Integer PROTOCOL_VERSION = 5;
|
||||
private static final ResourceLocation HANDLER_ID = ResourceLocation.fromNamespaceAndPath(MODID, "main_channel");
|
||||
|
||||
private static final SimpleChannel HANDLER = ChannelBuilder
|
||||
|
@ -122,6 +122,11 @@ public class TurnBasedMinecraftMod {
|
|||
.decoder(new PacketClientGui.Decoder())
|
||||
.consumerNetworkThread(new PacketClientGui.Consumer())
|
||||
.add();
|
||||
HANDLER.messageBuilder(PacketBattlePing.class, NetworkDirection.PLAY_TO_CLIENT)
|
||||
.encoder(new PacketBattlePing.Encoder())
|
||||
.decoder(new PacketBattlePing.Decoder())
|
||||
.consumerNetworkThread(new PacketBattlePing.Consumer())
|
||||
.add();
|
||||
|
||||
// register event handler(s)
|
||||
MinecraftForge.EVENT_BUS.register(new AttackEventHandler());
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.function.Function;
|
|||
|
||||
public class PacketBattleInfo
|
||||
{
|
||||
private int battleID;
|
||||
private Collection<Integer> sideA;
|
||||
private Collection<Integer> sideB;
|
||||
private long decisionNanos;
|
||||
|
@ -22,6 +23,7 @@ public class PacketBattleInfo
|
|||
|
||||
public PacketBattleInfo()
|
||||
{
|
||||
battleID = 0;
|
||||
sideA = new ArrayList<Integer>();
|
||||
sideB = new ArrayList<Integer>();
|
||||
decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
|
||||
|
@ -29,8 +31,9 @@ public class PacketBattleInfo
|
|||
turnTimerEnabled = false;
|
||||
}
|
||||
|
||||
public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, long maxDecisionNanos, boolean turnTimerEnabled)
|
||||
public PacketBattleInfo(int battleID, Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, long maxDecisionNanos, boolean turnTimerEnabled)
|
||||
{
|
||||
this.battleID = battleID;
|
||||
this.sideA = sideA;
|
||||
this.sideB = sideB;
|
||||
this.decisionNanos = decisionNanos;
|
||||
|
@ -43,6 +46,7 @@ public class PacketBattleInfo
|
|||
|
||||
@Override
|
||||
public void accept(PacketBattleInfo msg, RegistryFriendlyByteBuf buf) {
|
||||
buf.writeInt(msg.battleID);
|
||||
buf.writeInt(msg.sideA.size());
|
||||
buf.writeInt(msg.sideB.size());
|
||||
for(Integer id : msg.sideA) {
|
||||
|
@ -62,6 +66,7 @@ public class PacketBattleInfo
|
|||
|
||||
@Override
|
||||
public PacketBattleInfo apply(RegistryFriendlyByteBuf buf) {
|
||||
int battleID = buf.readInt();
|
||||
int sideACount = buf.readInt();
|
||||
int sideBCount = buf.readInt();
|
||||
Collection<Integer> sideA = new ArrayList<Integer>(sideACount);
|
||||
|
@ -75,7 +80,7 @@ public class PacketBattleInfo
|
|||
long decisionNanos = buf.readLong();
|
||||
long maxDecisionNanos = buf.readLong();
|
||||
boolean turnTimerEnabled = buf.readBoolean();
|
||||
return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
|
||||
return new PacketBattleInfo(battleID, sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +92,7 @@ public class PacketBattleInfo
|
|||
ctx.enqueueWork(() -> {
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
|
||||
{
|
||||
return;
|
||||
TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.battleID);
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
|
||||
for(Integer id : pkt.sideA)
|
||||
|
@ -106,6 +111,7 @@ public class PacketBattleInfo
|
|||
TurnBasedMinecraftMod.proxy.getLocalBattle().addCombatantToSideB(e);
|
||||
}
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiAsGui();
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTime((int)(pkt.decisionNanos / 1000000000L));
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTurnTimerEnabled(pkt.turnTimerEnabled);
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package com.burnedkirby.TurnBasedMinecraft.common.networking;
|
||||
|
||||
import com.burnedkirby.TurnBasedMinecraft.common.TurnBasedMinecraftMod;
|
||||
import net.minecraft.network.RegistryFriendlyByteBuf;
|
||||
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class PacketBattlePing {
|
||||
private int battleID;
|
||||
private int decisionSeconds;
|
||||
|
||||
public PacketBattlePing() {
|
||||
battleID = 0;
|
||||
decisionSeconds = 1;
|
||||
}
|
||||
|
||||
public PacketBattlePing(int battleID, int decisionSeconds) {
|
||||
this.battleID = battleID;
|
||||
this.decisionSeconds = decisionSeconds;
|
||||
}
|
||||
|
||||
public static class Encoder implements BiConsumer<PacketBattlePing, RegistryFriendlyByteBuf> {
|
||||
public Encoder() {}
|
||||
|
||||
@Override
|
||||
public void accept(PacketBattlePing pkt, RegistryFriendlyByteBuf buf) {
|
||||
buf.writeInt(pkt.battleID);
|
||||
buf.writeInt(pkt.decisionSeconds);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Decoder implements Function<RegistryFriendlyByteBuf, PacketBattlePing> {
|
||||
public Decoder() {}
|
||||
|
||||
@Override
|
||||
public PacketBattlePing apply(RegistryFriendlyByteBuf buf) {
|
||||
return new PacketBattlePing(buf.readInt(), buf.readInt());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Consumer implements BiConsumer<PacketBattlePing, CustomPayloadEvent.Context> {
|
||||
public Consumer() {}
|
||||
|
||||
@Override
|
||||
public void accept(PacketBattlePing pkt, CustomPayloadEvent.Context ctx) {
|
||||
ctx.enqueueWork(() -> {
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle() == null) {
|
||||
TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.battleID);
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiAsGui();
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiBattleChanged();
|
||||
TurnBasedMinecraftMod.proxy.setBattleGuiTime(pkt.decisionSeconds);
|
||||
TurnBasedMinecraftMod.proxy.pauseMCMusic();
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,7 +47,7 @@ public class PacketBattleRequestInfo
|
|||
if(b == null) {
|
||||
return;
|
||||
}
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx);
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getId(), b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ version="${mod_version}" #mandatory
|
|||
displayName="${mod_name}" #mandatory
|
||||
# A URL to query for updates for this mod. See the JSON update specification <here>
|
||||
#updateJSONURL="" #optional
|
||||
updateJSONURL="https://github.com/Stephen-Seo/TurnBasedMinecraftMod/raw/refs/heads/forge/update.json"
|
||||
# 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
|
||||
|
|
Loading…
Reference in a new issue