Compare commits

..

No commits in common. "2b4909e1f49ee127c50294febdff38d48d588cbe" and "e66eb63b31625fad12cec7c84de066dad6ef0151" have entirely different histories.

3 changed files with 7 additions and 82 deletions

View file

@ -2,7 +2,6 @@ package com.burnedkirby.TurnBasedMinecraft.common;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleInfo; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleInfo;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage; import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattleMessage;
import com.burnedkirby.TurnBasedMinecraft.common.networking.PacketBattlePing;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
@ -50,7 +49,7 @@ public class Battle {
private ResourceKey<Level> dimension; private ResourceKey<Level> dimension;
private long pingTimerNanos; private long infoNanos;
public enum State { public enum State {
DECISION(0), DECISION(0),
@ -125,7 +124,7 @@ public class Battle {
undecidedCount = new AtomicInteger(0); undecidedCount = new AtomicInteger(0);
random = new Random(); random = new Random();
this.dimension = dimension; this.dimension = dimension;
pingTimerNanos = 0; infoNanos = 0;
if (sideA != null) { if (sideA != null) {
for (Entity e : sideA) { for (Entity e : sideA) {
EntityInfo entityInfo; EntityInfo entityInfo;
@ -457,16 +456,6 @@ public class Battle {
} }
} }
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) { protected void sendMessageToAllPlayers(PacketBattleMessage.MessageType type, int from, int to, int amount) {
sendMessageToAllPlayers(type, from, to, amount, new String()); sendMessageToAllPlayers(type, from, to, amount, new String());
} }
@ -665,10 +654,10 @@ public class Battle {
} }
private boolean update(final long dt) { private boolean update(final long dt) {
pingTimerNanos += dt; infoNanos += dt;
if (pingTimerNanos >= 4000000000L) { if (infoNanos >= 4000000000L) {
pingTimerNanos = 0; infoNanos = 0;
notifyPlayersBattlePing(); notifyPlayersBattleInfo();
} }
if (battleEnded) { if (battleEnded) {
Collection<Combatant> combatants = new ArrayList<Combatant>(); Collection<Combatant> combatants = new ArrayList<Combatant>();

View file

@ -39,7 +39,7 @@ import org.apache.logging.log4j.Logger;
public class TurnBasedMinecraftMod { public class TurnBasedMinecraftMod {
public static final String MODID = "com_burnedkirby_turnbasedminecraft"; public static final String MODID = "com_burnedkirby_turnbasedminecraft";
public static final String NAME = "Turn Based Minecraft Mod"; public static final String NAME = "Turn Based Minecraft Mod";
public static final String VERSION = "1.26.1"; public static final String VERSION = "1.26.0";
public static final String CONFIG_FILENAME = "TBM_Config.toml"; public static final String CONFIG_FILENAME = "TBM_Config.toml";
public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml"; public static final String DEFAULT_CONFIG_FILENAME = "TBM_Config_DEFAULT.toml";
public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/"; public static final String CONFIG_DIRECTORY = "config/TurnBasedMinecraft/";
@ -122,11 +122,6 @@ public class TurnBasedMinecraftMod {
.decoder(new PacketClientGui.Decoder()) .decoder(new PacketClientGui.Decoder())
.consumerNetworkThread(new PacketClientGui.Consumer()) .consumerNetworkThread(new PacketClientGui.Consumer())
.add(); .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) // register event handler(s)
MinecraftForge.EVENT_BUS.register(new AttackEventHandler()); MinecraftForge.EVENT_BUS.register(new AttackEventHandler());

View file

@ -1,59 +0,0 @@
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);
});
ctx.setPacketHandled(true);
}
}
}