Revert "Merge pull request #750 from WinDanesz/patch-1226-2"
This commit is contained in:
@@ -20,9 +20,7 @@ public class PacketSpellProperties implements IMessageHandler<PacketSpellPropert
|
|||||||
if(ctx.side.isClient()){
|
if(ctx.side.isClient()){
|
||||||
|
|
||||||
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(() -> {
|
net.minecraft.client.Minecraft.getMinecraft().addScheduledTask(() -> {
|
||||||
|
for(int i=0; i<message.propertiesArray.length; i++){
|
||||||
int first = message.firstId;
|
|
||||||
for(int i = first; i <message.propertiesArray.length; i++){
|
|
||||||
Spell.byNetworkID(i).setPropertiesClient(message.propertiesArray[i]);
|
Spell.byNetworkID(i).setPropertiesClient(message.propertiesArray[i]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -34,24 +32,21 @@ public class PacketSpellProperties implements IMessageHandler<PacketSpellPropert
|
|||||||
public static class Message implements IMessage {
|
public static class Message implements IMessage {
|
||||||
|
|
||||||
private SpellProperties[] propertiesArray;
|
private SpellProperties[] propertiesArray;
|
||||||
private int firstId;
|
|
||||||
private int count;
|
|
||||||
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
// This constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
|
||||||
public Message(){}
|
public Message(){}
|
||||||
|
|
||||||
public Message(int firstId, int count, SpellProperties... properties){
|
public Message(SpellProperties... properties){
|
||||||
this.firstId = firstId;
|
|
||||||
this.count = count;
|
|
||||||
this.propertiesArray = properties;
|
this.propertiesArray = properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fromBytes(ByteBuf buf){
|
public void fromBytes(ByteBuf buf){
|
||||||
|
|
||||||
List<SpellProperties> propertiesList = new ArrayList<>();
|
List<SpellProperties> propertiesList = new ArrayList<>();
|
||||||
int i = buf.readInt();
|
int i = 0;
|
||||||
count = buf.readInt();
|
|
||||||
firstId = i;
|
while(buf.isReadable()){
|
||||||
while(buf.isReadable() && i < count){
|
|
||||||
propertiesList.add(new SpellProperties(Spell.byNetworkID(i++), buf));
|
propertiesList.add(new SpellProperties(Spell.byNetworkID(i++), buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +55,6 @@ public class PacketSpellProperties implements IMessageHandler<PacketSpellPropert
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toBytes(ByteBuf buf){
|
public void toBytes(ByteBuf buf){
|
||||||
buf.writeInt(firstId);
|
|
||||||
buf.writeInt(count);
|
|
||||||
for(SpellProperties properties : propertiesArray) properties.write(buf);
|
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
|
// To avoid sending extra data unnecessarily, the spell properties are sent in order of spell ID
|
||||||
List<Spell> spells = new ArrayList<>(registry.getValuesCollection());
|
List<Spell> spells = new ArrayList<>(registry.getValuesCollection());
|
||||||
spells.sort(Comparator.comparingInt(Spell::networkID));
|
spells.sort(Comparator.comparingInt(Spell::networkID));
|
||||||
|
WizardryPacketHandler.net.sendTo(new PacketSpellProperties.Message(spells.stream()
|
||||||
SpellProperties[] propertiesArray = spells.stream().map(s -> s.properties).toArray(SpellProperties[]::new);
|
.map(s -> s.properties).toArray(SpellProperties[]::new)), player);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void clearProperties(){
|
private static void clearProperties(){
|
||||||
|
|||||||
Reference in New Issue
Block a user