That's one heck of a commit you've got there...
I may have got a bit behind with version control. A lot behind, in fact. Maybe I'll go back and split this sometime - then again, I probably won't. But hey, at least it's here!
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
package electroblob.wizardry.packet;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import electroblob.wizardry.Wizardry;
|
||||
import electroblob.wizardry.data.IVariable;
|
||||
import electroblob.wizardry.data.WizardData;
|
||||
import electroblob.wizardry.packet.PacketPlayerSync.Message;
|
||||
import electroblob.wizardry.spell.Spell;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
@@ -11,9 +10,11 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <b>[Server -> Client]</b> This packet is sent to synchronise any fields that need synchronising in
|
||||
* {@link electroblob.wizardry.WizardData WizardData}. This packet is not sent often enough and is too small to warrant
|
||||
* {@link WizardData WizardData}. This packet is not sent often enough and is too small to warrant
|
||||
* having separate packets for each field that needs synchronising.
|
||||
*/
|
||||
public class PacketPlayerSync implements IMessageHandler<Message, IMessage> {
|
||||
@@ -24,12 +25,7 @@ public class PacketPlayerSync implements IMessageHandler<Message, IMessage> {
|
||||
if(ctx.side.isClient()){
|
||||
// Using a fully qualified name is a good course of action here; we don't really want to clutter the proxy
|
||||
// methods any more than necessary.
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(new Runnable(){
|
||||
@Override
|
||||
public void run(){
|
||||
Wizardry.proxy.handlePlayerSyncPacket(message);
|
||||
}
|
||||
});
|
||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(() -> Wizardry.proxy.handlePlayerSyncPacket(message));
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -37,36 +33,51 @@ public class PacketPlayerSync implements IMessageHandler<Message, IMessage> {
|
||||
|
||||
public static class Message implements IMessage {
|
||||
|
||||
public long seed;
|
||||
public Set<Spell> spellsDiscovered;
|
||||
public int selectedMinionID;
|
||||
public Map<IVariable, Object> spellData;
|
||||
|
||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||
public Message(){
|
||||
}
|
||||
|
||||
public Message(Set<Spell> spellsDiscovered2, int selectedMinionID){
|
||||
this.spellsDiscovered = spellsDiscovered2;
|
||||
public Message(long seed, Set<Spell> spellsDiscovered, int selectedMinionID, Map<IVariable, Object> spellData){
|
||||
this.seed = seed;
|
||||
this.spellsDiscovered = spellsDiscovered;
|
||||
this.selectedMinionID = selectedMinionID;
|
||||
this.spellData = spellData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf){
|
||||
|
||||
this.seed = buf.readLong();
|
||||
this.selectedMinionID = buf.readInt();
|
||||
this.spellsDiscovered = new HashSet<Spell>();
|
||||
|
||||
this.spellData = new HashMap<>();
|
||||
WizardData.getSyncedVariables().forEach(v -> spellData.put(v, v.read(buf)));
|
||||
// Have to send empty tags to guarantee correct ByteBuf size/order, but no point keeping the resulting nulls
|
||||
spellData.values().removeIf(Objects::isNull);
|
||||
|
||||
this.spellsDiscovered = new HashSet<>();
|
||||
while(buf.isReadable()){
|
||||
this.spellsDiscovered.add(Spell.get(buf.readInt()));
|
||||
this.spellsDiscovered.add(Spell.byNetworkID(buf.readInt()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked") // We know it's ok
|
||||
public void toBytes(ByteBuf buf){
|
||||
|
||||
buf.writeLong(seed);
|
||||
buf.writeInt(selectedMinionID);
|
||||
|
||||
if(this.spellsDiscovered == null) return;
|
||||
WizardData.getSyncedVariables().forEach(v -> v.write(buf, spellData.get(v)));
|
||||
|
||||
if(this.spellsDiscovered == null) return;
|
||||
for(Spell spell : this.spellsDiscovered){
|
||||
buf.writeInt(spell.id());
|
||||
buf.writeInt(spell.networkID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user