Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
#685: Implement support for PersistentDataContainer arrays
Dieser Commit ist enthalten in:
Ursprung
b900513035
Commit
c49b67ac91
@ -14,6 +14,7 @@ import net.minecraft.server.NBTTagDouble;
|
||||
import net.minecraft.server.NBTTagFloat;
|
||||
import net.minecraft.server.NBTTagInt;
|
||||
import net.minecraft.server.NBTTagIntArray;
|
||||
import net.minecraft.server.NBTTagList;
|
||||
import net.minecraft.server.NBTTagLong;
|
||||
import net.minecraft.server.NBTTagLongArray;
|
||||
import net.minecraft.server.NBTTagShort;
|
||||
@ -148,6 +149,32 @@ public final class CraftPersistentDataTypeRegistry {
|
||||
return createAdapter(long[].class, NBTTagLongArray.class, array -> new NBTTagLongArray(Arrays.copyOf(array, array.length)), n -> Arrays.copyOf(n.getLongs(), n.size()));
|
||||
}
|
||||
|
||||
/*
|
||||
Complex Arrays
|
||||
*/
|
||||
if (Objects.equals(PersistentDataContainer[].class, type)) {
|
||||
return createAdapter(PersistentDataContainer[].class, NBTTagList.class,
|
||||
(containerArray) -> {
|
||||
NBTTagList list = new NBTTagList();
|
||||
for (int i = 0; i < containerArray.length; i++) {
|
||||
list.add(((CraftPersistentDataContainer) containerArray[i]).toTagCompound());
|
||||
}
|
||||
return list;
|
||||
},
|
||||
(tag) -> {
|
||||
PersistentDataContainer[] containerArray = new CraftPersistentDataContainer[tag.size()];
|
||||
for (int i = 0; i < tag.size(); i++) {
|
||||
CraftPersistentDataContainer container = new CraftPersistentDataContainer(this);
|
||||
NBTTagCompound compound = tag.getCompound(i);
|
||||
for (String key : compound.getKeys()) {
|
||||
container.put(key, compound.get(key));
|
||||
}
|
||||
containerArray[i] = container;
|
||||
}
|
||||
return containerArray;
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Note that this will map the interface PersistentMetadataContainer directly to the CraftBukkit implementation
|
||||
Passing any other instance of this form to the tag type registry will throw a ClassCastException as defined in TagAdapter#build
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren