Fixing Entity Inventory
This commit is contained in:
parent
37b85b4cee
commit
c64c6eca7b
1 changed files with 65 additions and 52 deletions
|
@ -35,63 +35,75 @@ public class DataFixerAPI {
|
||||||
LOGGER.info("Everything up to date");
|
LOGGER.info("Everything up to date");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean[] allOk = {true};
|
||||||
|
|
||||||
List<File> regions = getAllRegions(dir, null);
|
List<File> regions = getAllRegions(dir, null);
|
||||||
boolean[] allOk = {true};
|
regions.parallelStream().forEach((file) -> fixRegion(data, allOk, file));
|
||||||
regions.parallelStream()
|
|
||||||
.forEach((file) -> {
|
|
||||||
try {
|
|
||||||
LOGGER.info("Inspecting " + file);
|
|
||||||
boolean[] changed = new boolean[1];
|
|
||||||
RegionFile region = new RegionFile(file, file.getParentFile(), true);
|
|
||||||
for (int x = 0; x < 32; x++) {
|
|
||||||
for (int z = 0; z < 32; z++) {
|
|
||||||
ChunkPos pos = new ChunkPos(x, z);
|
|
||||||
changed[0] = false;
|
|
||||||
if (region.hasChunk(pos)) {
|
|
||||||
DataInputStream input = region.getChunkDataInputStream(pos);
|
|
||||||
CompoundTag root = NbtIo.read(input);
|
|
||||||
// if ((root.toString().contains("betternether") || root.toString().contains("bclib")) && root.toString().contains("chest")) {
|
|
||||||
// NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + ".nbt"));
|
|
||||||
// }
|
|
||||||
input.close();
|
|
||||||
|
|
||||||
ListTag tileEntities = root.getCompound("Level")
|
|
||||||
.getList("TileEntities", 10);
|
|
||||||
fixItemArrayWithID(tileEntities, changed, data, true);
|
|
||||||
|
|
||||||
ListTag sections = root.getCompound("Level")
|
|
||||||
.getList("Sections", 10);
|
|
||||||
sections.forEach((tag) -> {
|
|
||||||
ListTag palette = ((CompoundTag) tag).getList("Palette", 10);
|
|
||||||
palette.forEach((blockTag) -> {
|
|
||||||
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
|
||||||
changed[0] = data.replaceStringFromIDs(blockTagCompound, "Name");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
if (changed[0]) {
|
|
||||||
LOGGER.warning("Writing '{}': {}/{}", file, x, z);
|
|
||||||
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
|
||||||
NbtIo.write(root, output);
|
|
||||||
output.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
region.close();
|
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
allOk[0] = false;
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (allOk[0]) {
|
if (allOk[0]) {
|
||||||
data.markApplied();
|
data.markApplied();
|
||||||
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
WorldDataAPI.saveFile(BCLib.MOD_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void fixRegion(MigrationProfile data, boolean[] allOk, File file) {
|
||||||
|
try {
|
||||||
|
LOGGER.info("Inspecting " + file);
|
||||||
|
boolean[] changed = new boolean[1];
|
||||||
|
RegionFile region = new RegionFile(file, file.getParentFile(), true);
|
||||||
|
for (int x = 0; x < 32; x++) {
|
||||||
|
for (int z = 0; z < 32; z++) {
|
||||||
|
ChunkPos pos = new ChunkPos(x, z);
|
||||||
|
changed[0] = false;
|
||||||
|
if (region.hasChunk(pos)) {
|
||||||
|
DataInputStream input = region.getChunkDataInputStream(pos);
|
||||||
|
CompoundTag root = NbtIo.read(input);
|
||||||
|
if ((root.toString().contains("betternether:chest") || root.toString().contains("bclib:chest"))) {
|
||||||
|
NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + ".nbt"));
|
||||||
|
}
|
||||||
|
input.close();
|
||||||
|
|
||||||
|
//Checking TileEntities
|
||||||
|
ListTag tileEntities = root.getCompound("Level")
|
||||||
|
.getList("TileEntities", 10);
|
||||||
|
fixItemArrayWithID(tileEntities, changed, data, true);
|
||||||
|
|
||||||
|
//Checking Entities
|
||||||
|
ListTag entities = root.getList("Entities", 10);
|
||||||
|
fixItemArrayWithID(entities, changed, data, true);
|
||||||
|
|
||||||
|
|
||||||
|
//Checking Block Palette
|
||||||
|
ListTag sections = root.getCompound("Level")
|
||||||
|
.getList("Sections", 10);
|
||||||
|
sections.forEach((tag) -> {
|
||||||
|
ListTag palette = ((CompoundTag) tag).getList("Palette", 10);
|
||||||
|
palette.forEach((blockTag) -> {
|
||||||
|
CompoundTag blockTagCompound = ((CompoundTag) blockTag);
|
||||||
|
changed[0] |= data.replaceStringFromIDs(blockTagCompound, "Name");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
if (changed[0]) {
|
||||||
|
LOGGER.warning("Writing '{}': {}/{}", file, x, z);
|
||||||
|
NbtIo.write(root, new File(file.toString() + "-" + x + "-" + z + "-changed.nbt"));
|
||||||
|
DataOutputStream output = region.getChunkDataOutputStream(pos);
|
||||||
|
NbtIo.write(root, output);
|
||||||
|
output.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
region.close();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
allOk[0] = false;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static CompoundTag patchConfTag = null;
|
static CompoundTag patchConfTag = null;
|
||||||
static CompoundTag getPatchData(){
|
static CompoundTag getPatchData(){
|
||||||
if (patchConfTag==null) {
|
if (patchConfTag==null) {
|
||||||
|
@ -109,6 +121,9 @@ public class DataFixerAPI {
|
||||||
if (recursive && tag.contains("Items")) {
|
if (recursive && tag.contains("Items")) {
|
||||||
changed[0] |= fixItemArrayWithID(tag.getList("Items", 10), changed, data, true);
|
changed[0] |= fixItemArrayWithID(tag.getList("Items", 10), changed, data, true);
|
||||||
}
|
}
|
||||||
|
if (recursive && tag.contains("Inventory")) {
|
||||||
|
changed[0] |= fixItemArrayWithID(tag.getList("Inventory", 10), changed, data, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return changed[0];
|
return changed[0];
|
||||||
|
@ -121,9 +136,7 @@ public class DataFixerAPI {
|
||||||
for (File file : dir.listFiles()) {
|
for (File file : dir.listFiles()) {
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
getAllRegions(file, list);
|
getAllRegions(file, list);
|
||||||
}
|
} else if (file.isFile() && file.getName().endsWith(".mca")) {
|
||||||
else if (file.isFile() && file.getName()
|
|
||||||
.endsWith(".mca")) {
|
|
||||||
list.add(file);
|
list.add(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue