aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/Java/gtPlusPlus/core')
-rw-r--r--src/Java/gtPlusPlus/core/item/base/BaseEuItem.java6
-rw-r--r--src/Java/gtPlusPlus/core/item/tool/misc/GregtechPump.java16
-rw-r--r--src/Java/gtPlusPlus/core/util/data/FileUtils.java95
3 files changed, 109 insertions, 8 deletions
diff --git a/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java b/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java
index 57e183f998..b4988136c0 100644
--- a/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java
+++ b/src/Java/gtPlusPlus/core/item/base/BaseEuItem.java
@@ -572,7 +572,11 @@ public class BaseEuItem extends Item implements ISpecialElectricItem, IElectricI
@Override
public String getItemStackDisplayName(final ItemStack par1ItemStack) {
- return this.itemName.get(par1ItemStack.getItemDamage()-this.mOffset).getValue();
+ int keyValue = (par1ItemStack.getItemDamage() - this.mOffset);
+ if (keyValue < 0 || keyValue > 3) {
+ keyValue = 0;
+ }
+ return this.itemName.get(keyValue).getValue();
}
}
diff --git a/src/Java/gtPlusPlus/core/item/tool/misc/GregtechPump.java b/src/Java/gtPlusPlus/core/item/tool/misc/GregtechPump.java
index bdddd26255..2943951734 100644
--- a/src/Java/gtPlusPlus/core/item/tool/misc/GregtechPump.java
+++ b/src/Java/gtPlusPlus/core/item/tool/misc/GregtechPump.java
@@ -686,7 +686,11 @@ public class GregtechPump extends Item implements ISpecialElectricItem, IElectri
@Override
public String getItemStackDisplayName(final ItemStack par1ItemStack) {
- return this.itemName.get(par1ItemStack.getItemDamage() - this.mOffset).getValue();
+ int keyValue = (par1ItemStack.getItemDamage() - this.mOffset);
+ if (keyValue < 0 || keyValue > 3) {
+ keyValue = 0;
+ }
+ return this.itemName.get(keyValue).getValue();
}
/**
@@ -938,12 +942,10 @@ public class GregtechPump extends Item implements ISpecialElectricItem, IElectri
return false;
} else {
double aCharge = this.getCharge(aStack);
- boolean didDrain;
+ boolean didDrain = false;
if (aTier > 0 && aCharge > 0) {
if (discharge(aStack, removal, aTier, true, true, false) > 0) {
didDrain = true;
- } else {
- didDrain = false;
}
} else if (aTier == 0) {
didDrain = true;
@@ -954,9 +956,10 @@ public class GregtechPump extends Item implements ISpecialElectricItem, IElectri
if (didDrain) {
if ((tTileEntity instanceof IGregTechTileEntity)) {
return this.drainTankGT(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ);
- } else if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) {
+ }
+ /*else if ((tTileEntity instanceof IFluidTank || tTileEntity instanceof IFluidHandler)) {
return this.drainIFluidTank(tTileEntity, aStack, aWorld, aPlayer, aX, aY, aZ);
- }
+ }*/
}
}
}
@@ -1211,7 +1214,6 @@ public class GregtechPump extends Item implements ISpecialElectricItem, IElectri
return false;
}
final IMetaTileEntity aMetaTileEntity = aTileEntity.getMetaTileEntity();
- ;
if (aMetaTileEntity == null) {
return false;
}
diff --git a/src/Java/gtPlusPlus/core/util/data/FileUtils.java b/src/Java/gtPlusPlus/core/util/data/FileUtils.java
new file mode 100644
index 0000000000..d7d6b9e36e
--- /dev/null
+++ b/src/Java/gtPlusPlus/core/util/data/FileUtils.java
@@ -0,0 +1,95 @@
+package gtPlusPlus.core.util.data;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.List;
+
+import gtPlusPlus.api.objects.Logger;
+import gtPlusPlus.core.util.Utils;
+
+public class FileUtils {
+
+ private static final Charset utf8 = StandardCharsets.UTF_8;
+
+ public static boolean doesFileExist(File f) {
+ if (f != null && f.exists() && !f.isDirectory()) {
+ return true;
+ }
+ return false;
+ }
+
+ public static File createFile(String path, String filename, String extension) {
+ File file = new File(Utils.getMcDir(), path + filename + extension);
+ boolean blnCreated = false;
+ Logger.INFO("Trying to use path "+file.getPath());
+ try {
+ Logger.INFO("Trying to use path "+file.getCanonicalPath());
+ Logger.INFO("Trying to use absolute path "+file.getAbsolutePath());
+ blnCreated = file.createNewFile();
+ } catch (IOException ioe) {
+ Logger.INFO("Error while creating a new empty file :" + ioe);
+ return null;
+ }
+ return blnCreated ? file : null;
+ }
+
+ public static File getFile(String filename, String extension) {
+ return getFile("", filename, extension);
+ }
+
+ public static File getFile(String path, String filename, String extension) {
+ if (path == null || path.length() <= 0) {
+ path = "";
+ }
+ else {
+ path = path + "/";
+ }
+ if (filename == null || filename.length() <= 0) {
+ return null;
+ }
+ if (extension == null || extension.length() <= 0) {
+ extension = ".txt";
+ }
+ else {
+ extension = "." + extension;
+ }
+ File file = new File(Utils.getMcDir(), path + filename + extension);
+ boolean doesExist = doesFileExist(file);
+
+ if (doesExist) {
+ Logger.INFO("Found File: " + file.getAbsolutePath());
+ return file;
+ } else {
+ Logger.INFO("Creating file, as it was not found.");
+ return createFile(path, filename, extension);
+ }
+ }
+
+ public static boolean appendListToFile(File file, List<String> content) {
+ try {
+ long oldSize;
+ long newSize;
+ if (doesFileExist(file)) {
+ Path p = Paths.get(file.getPath());
+ if (p != null && Files.isWritable(p)) {
+ oldSize = Files.size(p);
+ try {
+ Files.write(p, content, utf8, StandardOpenOption.APPEND);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ newSize = Files.size(p);
+ return newSize > oldSize;
+ }
+ }
+ } catch (IOException e) {
+ }
+ return false;
+ }
+}