Revert "Merge pull request #750 from WinDanesz/patch-1226-2"

This commit is contained in:
WinDanesz
2022-04-17 15:53:48 +02:00
parent 4d078f9597
commit ea27b1a081
2 changed files with 9 additions and 32 deletions
@@ -20,9 +20,7 @@ public class PacketSpellProperties implements IMessageHandler<PacketSpellPropert
if(ctx.side.isClient()){
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(() -> {
int first = message.firstId;
for(int i = first; i <message.propertiesArray.length; i++){
for(int i=0; i<message.propertiesArray.length; i++){
Spell.byNetworkID(i).setPropertiesClient(message.propertiesArray[i]);
}
});
@@ -34,24 +32,21 @@ public class PacketSpellProperties implements IMessageHandler<PacketSpellPropert
public static class Message implements IMessage {
private SpellProperties[] propertiesArray;
private int firstId;
private int count;
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
public Message(){}
public Message(int firstId, int count, SpellProperties... properties){
this.firstId = firstId;
this.count = count;
public Message(SpellProperties... properties){
this.propertiesArray = properties;
}
@Override
public void fromBytes(ByteBuf buf){
List<SpellProperties> propertiesList = new ArrayList<>();
int i = buf.readInt();
count = buf.readInt();
firstId = i;
while(buf.isReadable() && i < count){
int i = 0;
while(buf.isReadable()){
propertiesList.add(new SpellProperties(Spell.byNetworkID(i++), buf));
}
@@ -60,8 +55,6 @@ public class PacketSpellProperties implements IMessageHandler<PacketSpellPropert
@Override
public void toBytes(ByteBuf buf){
buf.writeInt(firstId);
buf.writeInt(count);
for(SpellProperties properties : propertiesArray) properties.write(buf);
}
}
@@ -319,24 +319,8 @@ public abstract class Spell extends IForgeRegistryEntry.Impl<Spell> implements C
// To avoid sending extra data unnecessarily, the spell properties are sent in order of spell ID
List<Spell> spells = new ArrayList<>(registry.getValuesCollection());
spells.sort(Comparator.comparingInt(Spell::networkID));
SpellProperties[] propertiesArray = spells.stream().map(s -> s.properties).toArray(SpellProperties[]::new);
// splitting the packet into batches of 100 spells
int i = 0;
while (i < propertiesArray.length) {
List<SpellProperties> propertiesList = new ArrayList<>();
int first = i;
int batchCounter = 0;
for (int currentIndex = i; currentIndex < propertiesArray.length && batchCounter < 100; currentIndex++) {
propertiesList.add(propertiesArray[currentIndex]);
batchCounter++;
i++;
}
SpellProperties[] currentArray = propertiesList.toArray(new SpellProperties[0]);
PacketSpellProperties.Message currentPacket = new PacketSpellProperties.Message(first, currentArray.length, currentArray);
WizardryPacketHandler.net.sendTo(currentPacket, player);
}
WizardryPacketHandler.net.sendTo(new PacketSpellProperties.Message(spells.stream()
.map(s -> s.properties).toArray(SpellProperties[]::new)), player);
}
private static void clearProperties(){