Compare commits
No commits in common. "c38f19840a394ffcda43787f6a3415bd39c1859f" and "eb8e56142655668c97cd5a77fe9846fa3a0cd536" have entirely different histories.
c38f19840a
...
eb8e561426
7 changed files with 9 additions and 52 deletions
|
@ -4,9 +4,6 @@ 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 fix that pesky transient client-freeze-bug.
|
||||
|
||||
# Version Forge-1.26.0
|
||||
|
||||
Port to Forge 52.0.21 (Minecraft 1.21.1).
|
||||
|
|
|
@ -28,7 +28,6 @@ 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);
|
||||
|
@ -92,7 +91,6 @@ public class BattleGui extends Screen {
|
|||
elapsedTime = 0;
|
||||
state = MenuState.MAIN_MENU;
|
||||
stateChanged = true;
|
||||
waitMissingBattleTicks = null;
|
||||
}
|
||||
|
||||
private void setState(MenuState state) {
|
||||
|
@ -226,29 +224,13 @@ 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, colorFromTicks(waitMissingBattleTicks));
|
||||
drawString(guiGraphics, "Waiting...", width / 2 - 50, height / 2, 0xFFFFFFFF);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
return;
|
||||
} else {
|
||||
waitMissingBattleTicks = null;
|
||||
}
|
||||
if (TurnBasedMinecraftMod.proxy.getLocalBattle().getState() == Battle.State.DECISION
|
||||
&& timeRemaining.get() > 0) {
|
||||
|
@ -372,13 +354,9 @@ public class BattleGui extends Screen {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int b, int c) {
|
||||
public boolean keyPressed(int a, int b, int c) {
|
||||
if (getMinecraft().player.isCreative()) {
|
||||
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 super.keyPressed(a, b, c);
|
||||
}
|
||||
return false; // TODO verify return value
|
||||
}
|
||||
|
|
|
@ -370,10 +370,6 @@ 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:
|
||||
|
|
|
@ -49,8 +49,6 @@ public class Battle {
|
|||
|
||||
private ResourceKey<Level> dimension;
|
||||
|
||||
private long infoNanos;
|
||||
|
||||
public enum State {
|
||||
DECISION(0),
|
||||
ACTION(1),
|
||||
|
@ -124,7 +122,6 @@ public class Battle {
|
|||
undecidedCount = new AtomicInteger(0);
|
||||
random = new Random();
|
||||
this.dimension = dimension;
|
||||
infoNanos = 0;
|
||||
if (sideA != null) {
|
||||
for (Entity e : sideA) {
|
||||
EntityInfo entityInfo;
|
||||
|
@ -450,7 +447,7 @@ public class Battle {
|
|||
if (!isServer) {
|
||||
return;
|
||||
}
|
||||
PacketBattleInfo infoPacket = new PacketBattleInfo(getId(), getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
|
||||
PacketBattleInfo infoPacket = new PacketBattleInfo(getSideAIDs(), getSideBIDs(), timer, TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever());
|
||||
for (Combatant p : players.values()) {
|
||||
TurnBasedMinecraftMod.getHandler().send(infoPacket, PacketDistributor.PLAYER.with((ServerPlayer)p.entity));
|
||||
}
|
||||
|
@ -654,11 +651,6 @@ public class Battle {
|
|||
}
|
||||
|
||||
private boolean update(final long dt) {
|
||||
infoNanos += dt;
|
||||
if (infoNanos >= 4000000000L) {
|
||||
infoNanos = 0;
|
||||
notifyPlayersBattleInfo();
|
||||
}
|
||||
if (battleEnded) {
|
||||
Collection<Combatant> combatants = new ArrayList<Combatant>();
|
||||
combatants.addAll(sideA.values());
|
||||
|
|
|
@ -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 = 5;
|
||||
private static final Integer PROTOCOL_VERSION = 4;
|
||||
private static final ResourceLocation HANDLER_ID = ResourceLocation.fromNamespaceAndPath(MODID, "main_channel");
|
||||
|
||||
private static final SimpleChannel HANDLER = ChannelBuilder
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.function.Function;
|
|||
|
||||
public class PacketBattleInfo
|
||||
{
|
||||
private int battleID;
|
||||
private Collection<Integer> sideA;
|
||||
private Collection<Integer> sideB;
|
||||
private long decisionNanos;
|
||||
|
@ -23,7 +22,6 @@ public class PacketBattleInfo
|
|||
|
||||
public PacketBattleInfo()
|
||||
{
|
||||
battleID = 0;
|
||||
sideA = new ArrayList<Integer>();
|
||||
sideB = new ArrayList<Integer>();
|
||||
decisionNanos = TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos();
|
||||
|
@ -31,9 +29,8 @@ public class PacketBattleInfo
|
|||
turnTimerEnabled = false;
|
||||
}
|
||||
|
||||
public PacketBattleInfo(int battleID, Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, long maxDecisionNanos, boolean turnTimerEnabled)
|
||||
public PacketBattleInfo(Collection<Integer> sideA, Collection<Integer> sideB, long decisionNanos, long maxDecisionNanos, boolean turnTimerEnabled)
|
||||
{
|
||||
this.battleID = battleID;
|
||||
this.sideA = sideA;
|
||||
this.sideB = sideB;
|
||||
this.decisionNanos = decisionNanos;
|
||||
|
@ -46,7 +43,6 @@ 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) {
|
||||
|
@ -66,7 +62,6 @@ 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);
|
||||
|
@ -80,7 +75,7 @@ public class PacketBattleInfo
|
|||
long decisionNanos = buf.readLong();
|
||||
long maxDecisionNanos = buf.readLong();
|
||||
boolean turnTimerEnabled = buf.readBoolean();
|
||||
return new PacketBattleInfo(battleID, sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
|
||||
return new PacketBattleInfo(sideA, sideB, decisionNanos, maxDecisionNanos, turnTimerEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,7 +87,7 @@ public class PacketBattleInfo
|
|||
ctx.enqueueWork(() -> {
|
||||
if(TurnBasedMinecraftMod.proxy.getLocalBattle() == null)
|
||||
{
|
||||
TurnBasedMinecraftMod.proxy.createLocalBattle(pkt.battleID);
|
||||
return;
|
||||
}
|
||||
TurnBasedMinecraftMod.proxy.getLocalBattle().clearCombatants();
|
||||
for(Integer id : pkt.sideA)
|
||||
|
@ -111,7 +106,6 @@ 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);
|
||||
|
|
|
@ -47,7 +47,7 @@ public class PacketBattleRequestInfo
|
|||
if(b == null) {
|
||||
return;
|
||||
}
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getId(), b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx);
|
||||
TurnBasedMinecraftMod.getHandler().reply(new PacketBattleInfo(b.getSideAIDs(), b.getSideBIDs(), b.getTimerNanos(), TurnBasedMinecraftMod.proxy.getConfig().getDecisionDurationNanos(), !TurnBasedMinecraftMod.proxy.getConfig().isBattleDecisionDurationForever()), ctx);
|
||||
});
|
||||
ctx.setPacketHandled(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue