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());
}
public static void writeNBTToFile(String fileName, NBTTagCompound nbttagcompound) {
WarpDrive.logger.info("writeNBTToFile " + fileName);
public static void writeNBTToFile(final String fileName, final NBTTagCompound tagCompound) {
if (WarpDrive.isDev) {
WarpDrive.logger.info("writeNBTToFile " + fileName);
}
try {
File file = new File(fileName);
final File file = new File(fileName);
if (!file.exists()) {
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
}
FileOutputStream fileoutputstream = new FileOutputStream(file);
final FileOutputStream fileoutputstream = new FileOutputStream(file);
CompressedStreamTools.writeCompressed(nbttagcompound, fileoutputstream);
CompressedStreamTools.writeCompressed(tagCompound, fileoutputstream);
fileoutputstream.close();
} 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 {
File file = new File(fileName);
final File file = new File(fileName);
if (!file.exists()) {
return null;
}
FileInputStream fileinputstream = new FileInputStream(file);
NBTTagCompound nbttagcompound = CompressedStreamTools.readCompressed(fileinputstream);
final FileInputStream fileinputstream = new FileInputStream(file);
final NBTTagCompound tagCompound = CompressedStreamTools.readCompressed(fileinputstream);
fileinputstream.close();
return nbttagcompound;
return tagCompound;
} catch (Exception exception) {
exception.printStackTrace();
}

View file

@ -67,13 +67,13 @@ public abstract class AbstractStructureInstance extends WorldGenerator {
/**/
}
public void WriteToNBT(NBTTagCompound tag) {
tag.setString("wd_structureGroup", structure.group);
tag.setString("wd_structureName", structure.name);
NBTTagCompound tagVariables = new NBTTagCompound();
public void WriteToNBT(final NBTTagCompound tagCompound) {
tagCompound.setString("wd_structureGroup", structure.group);
tagCompound.setString("wd_structureName", structure.name);
final NBTTagCompound tagVariables = new NBTTagCompound();
for (Entry<String, Double> entry : variables.entrySet()) {
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
public void WriteToNBT(final NBTTagCompound tag) {
super.WriteToNBT(tag);
public void WriteToNBT(final NBTTagCompound tagCompound) {
super.WriteToNBT(tagCompound);
// TODO not implemented
}

View file

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

View file

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

View file

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

View file

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