Code cleanup

This commit is contained in:
LemADEC 2017-05-23 23:47:49 +02:00
parent 2cfcad4258
commit 2934f8b493
7 changed files with 92 additions and 82 deletions

View file

@ -373,19 +373,21 @@ public class Commons {
WarpDrive.logger.error(stringBuilder.toString()); WarpDrive.logger.error(stringBuilder.toString());
} }
public static void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) { public static void writeNBTToFile(final String fileName, final NBTTagCompound tagCompound) {
WarpDrive.logger.info("writeNBTToFile " + fileName); if (WarpDrive.isDev) {
WarpDrive.logger.info("writeNBTToFile " + fileName);
}
try { try {
File file = new File(fileName); final File file = new File(fileName);
if (!file.exists()) { if (!file.exists()) {
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
file.createNewFile(); file.createNewFile();
} }
FileOutputStream fileoutputstream = new FileOutputStream(file); final FileOutputStream fileoutputstream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(nbttagcompound, fileoutputstream); CompressedStreamTools.writeCompressed(tagCompound, fileoutputstream);
fileoutputstream.close(); fileoutputstream.close();
} catch (Exception exception) { } catch (Exception exception) {
@ -393,19 +395,23 @@ public class Commons {
} }
} }
public static NBTTagCompound readNBTFromFile(String fileName) { public static NBTTagCompound readNBTFromFile(final String fileName) {
if (WarpDrive.isDev) {
WarpDrive.logger.info("readNBTFromFile " + fileName);
}
try { try {
File file = new File(fileName); final File file = new File(fileName);
if (!file.exists()) { if (!file.exists()) {
return null; return null;
} }
FileInputStream fileinputstream = new FileInputStream(file); final FileInputStream fileinputstream = new FileInputStream(file);
NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream); final NBTTagCompound tagCompound = CompressedStreamTools.readCompressed(fileinputstream);
fileinputstream.close(); fileinputstream.close();
return nbttagcompound; return tagCompound;
} catch (Exception exception) { } catch (Exception exception) {
exception.printStackTrace(); exception.printStackTrace();
} }

View file

@ -67,13 +67,13 @@ public abstract class AbstractStructureInstance extends WorldGenerator {
/**/ /**/
} }
public void WriteToNBT(NBTTagCompound tag) { public void WriteToNBT(final NBTTagCompound tagCompound) {
tag.setString("wd_structureGroup", structure.group); tagCompound.setString("wd_structureGroup", structure.group);
tag.setString("wd_structureName", structure.name); tagCompound.setString("wd_structureName", structure.name);
NBTTagCompound tagVariables = new NBTTagCompound(); final NBTTagCompound tagVariables = new NBTTagCompound();
for (Entry<String, Double> entry : variables.entrySet()) { for (Entry<String, Double> entry : variables.entrySet()) {
tagVariables.setDouble(entry.getKey(), entry.getValue()); tagVariables.setDouble(entry.getKey(), entry.getValue());
} }
tag.setTag("wd_variables", tagVariables); tagCompound.setTag("wd_variables", tagVariables);
} }
} }

View file

@ -23,8 +23,8 @@ public class AsteroidFieldInstance extends AbstractStructureInstance {
} }
@Override @Override
public void WriteToNBT(final NBTTagCompound tag) { public void WriteToNBT(final NBTTagCompound tagCompound) {
super.WriteToNBT(tag); super.WriteToNBT(tagCompound);
// TODO not implemented // TODO not implemented
} }

View file

@ -62,8 +62,8 @@ public class OrbInstance extends AbstractStructureInstance {
} }
@Override @Override
public void WriteToNBT(NBTTagCompound tag) { public void WriteToNBT(NBTTagCompound tagCompound) {
super.WriteToNBT(tag); super.WriteToNBT(tagCompound);
// TODO not implemented // TODO not implemented
} }

View file

@ -78,8 +78,8 @@ public class CelestialObject implements Cloneable, IStringSerializable {
parentCenterZ = parParentCenterZ; parentCenterZ = parParentCenterZ;
} }
public CelestialObject(NBTTagCompound nbt) { public CelestialObject(final NBTTagCompound tagCompound) {
readFromNBT(nbt); readFromNBT(tagCompound);
} }
@Override @Override

View file

@ -479,32 +479,32 @@ public class JumpBlock {
removeUniqueIDs(blockNBT); removeUniqueIDs(blockNBT);
} }
public static void removeUniqueIDs(NBTTagCompound nbtTagCompound) { public static void removeUniqueIDs(final NBTTagCompound tagCompound) {
if (nbtTagCompound == null) { if (tagCompound == null) {
return; return;
} }
// ComputerCraft computer // ComputerCraft computer
if (nbtTagCompound.hasKey("computerID")) { if (tagCompound.hasKey("computerID")) {
nbtTagCompound.removeTag("computerID"); tagCompound.removeTag("computerID");
nbtTagCompound.removeTag("label"); tagCompound.removeTag("label");
} }
// WarpDrive any OC connected tile // WarpDrive any OC connected tile
if (nbtTagCompound.hasKey("oc:node")) { if (tagCompound.hasKey("oc:node")) {
nbtTagCompound.removeTag("oc:node"); tagCompound.removeTag("oc:node");
} }
// OpenComputers case // OpenComputers case
if (nbtTagCompound.hasKey("oc:computer")) { if (tagCompound.hasKey("oc:computer")) {
NBTTagCompound tagComputer = nbtTagCompound.getCompoundTag("oc:computer"); NBTTagCompound tagComputer = tagCompound.getCompoundTag("oc:computer");
tagComputer.removeTag("chunkX"); tagComputer.removeTag("chunkX");
tagComputer.removeTag("chunkZ"); tagComputer.removeTag("chunkZ");
tagComputer.removeTag("components"); tagComputer.removeTag("components");
tagComputer.removeTag("dimension"); tagComputer.removeTag("dimension");
tagComputer.removeTag("node"); tagComputer.removeTag("node");
nbtTagCompound.setTag("oc:computer", tagComputer); tagCompound.setTag("oc:computer", tagComputer);
} }
// OpenComputers case // OpenComputers case
if (nbtTagCompound.hasKey("oc:items")) { if (tagCompound.hasKey("oc:items")) {
NBTTagList tagListItems = nbtTagCompound.getTagList("oc:items", Constants.NBT.TAG_COMPOUND); NBTTagList tagListItems = tagCompound.getTagList("oc:items", Constants.NBT.TAG_COMPOUND);
for (int indexItemSlot = 0; indexItemSlot < tagListItems.tagCount(); indexItemSlot++) { for (int indexItemSlot = 0; indexItemSlot < tagListItems.tagCount(); indexItemSlot++) {
NBTTagCompound tagCompoundItemSlot = tagListItems.getCompoundTagAt(indexItemSlot); NBTTagCompound tagCompoundItemSlot = tagListItems.getCompoundTagAt(indexItemSlot);
NBTTagCompound tagCompoundItem = tagCompoundItemSlot.getCompoundTag("item"); NBTTagCompound tagCompoundItem = tagCompoundItemSlot.getCompoundTag("item");
@ -518,41 +518,45 @@ public class JumpBlock {
} }
// OpenComputers keyboard // OpenComputers keyboard
if (nbtTagCompound.hasKey("oc:keyboard")) { if (tagCompound.hasKey("oc:keyboard")) {
NBTTagCompound tagCompoundKeyboard = nbtTagCompound.getCompoundTag("oc:keyboard"); NBTTagCompound tagCompoundKeyboard = tagCompound.getCompoundTag("oc:keyboard");
tagCompoundKeyboard.removeTag("node"); tagCompoundKeyboard.removeTag("node");
} }
// OpenComputers screen // OpenComputers screen
if (nbtTagCompound.hasKey("oc:hasPower")) { if (tagCompound.hasKey("oc:hasPower")) {
nbtTagCompound.removeTag("node"); tagCompound.removeTag("node");
}
// Immersive Engineering & Thermal Expansion
if (tagCompound.hasKey("Owner")) {
tagCompound.setString("Owner", "None");
}
// Mekanism
if (tagCompound.hasKey("owner")) {
tagCompound.setString("owner", "None");
} }
} }
public void emptyEnergyStorage() { public static void emptyEnergyStorage(final NBTTagCompound tagCompound) {
// IC2 // IC2
if (blockNBT.hasKey("energy")) { if (tagCompound.hasKey("energy")) {
// energy_consume((int)Math.round(blockNBT.getDouble("energy")), true); // energy_consume((int)Math.round(blockNBT.getDouble("energy")), true);
blockNBT.setDouble("energy", 0); tagCompound.setDouble("energy", 0);
} }
// Gregtech // Gregtech
if (blockNBT.hasKey("mStoredEnergy")) { if (tagCompound.hasKey("mStoredEnergy")) {
blockNBT.setInteger("mStoredEnergy", 0); tagCompound.setInteger("mStoredEnergy", 0);
} }
// Immersive Engineering & Thermal Expansion // Immersive Engineering & Thermal Expansion
if (blockNBT.hasKey("Energy")) { if (tagCompound.hasKey("Energy")) {
// energy_consume(blockNBT.getInteger("Energy"), true); // energy_consume(blockNBT.getInteger("Energy"), true);
blockNBT.setInteger("Energy", 0); tagCompound.setInteger("Energy", 0);
}
if (blockNBT.hasKey("Owner")) {
blockNBT.setString("Owner", "None");
} }
// Mekanism // Mekanism
if (blockNBT.hasKey("electricityStored")) { if (tagCompound.hasKey("electricityStored")) {
blockNBT.setDouble("electricityStored", 0); tagCompound.setDouble("electricityStored", 0);
}
if (blockNBT.hasKey("owner")) {
blockNBT.setString("owner", "None");
} }
} }

View file

@ -371,20 +371,20 @@ public class JumpShip {
return true; return true;
} }
public void readFromNBT(NBTTagCompound tag) { public void readFromNBT(NBTTagCompound tagCompound) {
coreX = tag.getInteger("coreX"); coreX = tagCompound.getInteger("coreX");
coreY = tag.getInteger("coreY"); coreY = tagCompound.getInteger("coreY");
coreZ = tag.getInteger("coreZ"); coreZ = tagCompound.getInteger("coreZ");
dx = tag.getInteger("dx"); dx = tagCompound.getInteger("dx");
dz = tag.getInteger("dz"); dz = tagCompound.getInteger("dz");
maxX = tag.getInteger("maxX"); maxX = tagCompound.getInteger("maxX");
maxZ = tag.getInteger("maxZ"); maxZ = tagCompound.getInteger("maxZ");
maxY = tag.getInteger("maxY"); maxY = tagCompound.getInteger("maxY");
minX = tag.getInteger("minX"); minX = tagCompound.getInteger("minX");
minZ = tag.getInteger("minZ"); minZ = tagCompound.getInteger("minZ");
minY = tag.getInteger("minY"); minY = tagCompound.getInteger("minY");
actualMass = tag.getInteger("actualMass"); actualMass = tagCompound.getInteger("actualMass");
NBTTagList tagList = tag.getTagList("jumpBlocks", Constants.NBT.TAG_COMPOUND); final NBTTagList tagList = tagCompound.getTagList("jumpBlocks", Constants.NBT.TAG_COMPOUND);
jumpBlocks = new JumpBlock[tagList.tagCount()]; jumpBlocks = new JumpBlock[tagList.tagCount()];
for(int index = 0; index < tagList.tagCount(); index++) { for(int index = 0; index < tagList.tagCount(); index++) {
jumpBlocks[index] = new JumpBlock(); jumpBlocks[index] = new JumpBlock();
@ -392,25 +392,25 @@ public class JumpShip {
} }
} }
public void writeToNBT(NBTTagCompound tag) { public void writeToNBT(final NBTTagCompound tagCompound) {
tag.setInteger("coreX", coreX); tagCompound.setInteger("coreX", coreX);
tag.setInteger("coreY", coreY); tagCompound.setInteger("coreY", coreY);
tag.setInteger("coreZ", coreZ); tagCompound.setInteger("coreZ", coreZ);
tag.setInteger("dx", dx); tagCompound.setInteger("dx", dx);
tag.setInteger("dz", dz); tagCompound.setInteger("dz", dz);
tag.setInteger("maxX", maxX); tagCompound.setInteger("maxX", maxX);
tag.setInteger("maxZ", maxZ); tagCompound.setInteger("maxZ", maxZ);
tag.setInteger("maxY", maxY); tagCompound.setInteger("maxY", maxY);
tag.setInteger("minX", minX); tagCompound.setInteger("minX", minX);
tag.setInteger("minZ", minZ); tagCompound.setInteger("minZ", minZ);
tag.setInteger("minY", minY); tagCompound.setInteger("minY", minY);
tag.setInteger("actualMass", actualMass); tagCompound.setInteger("actualMass", actualMass);
NBTTagList tagListJumpBlocks = new NBTTagList(); final NBTTagList tagListJumpBlocks = new NBTTagList();
for (JumpBlock jumpBlock : jumpBlocks) { for (JumpBlock jumpBlock : jumpBlocks) {
NBTTagCompound tagCompoundBlock = new NBTTagCompound(); final NBTTagCompound tagCompoundBlock = new NBTTagCompound();
jumpBlock.writeToNBT(tagCompoundBlock); jumpBlock.writeToNBT(tagCompoundBlock);
tagListJumpBlocks.appendTag(tagCompoundBlock); tagListJumpBlocks.appendTag(tagCompoundBlock);
} }
tag.setTag("jumpBlocks", tagListJumpBlocks); tagCompound.setTag("jumpBlocks", tagListJumpBlocks);
} }
} }