diff options
Diffstat (limited to 'src/Java')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/networking/NetworkUtils.java | 55 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_IndustrialSifter.java | 54 |
2 files changed, 73 insertions, 36 deletions
diff --git a/src/Java/gtPlusPlus/core/util/networking/NetworkUtils.java b/src/Java/gtPlusPlus/core/util/networking/NetworkUtils.java index c25c5d05be..77f7d74928 100644 --- a/src/Java/gtPlusPlus/core/util/networking/NetworkUtils.java +++ b/src/Java/gtPlusPlus/core/util/networking/NetworkUtils.java @@ -7,36 +7,32 @@ import java.util.Enumeration; public class NetworkUtils { public static String getContentFromURL(final String args) { - try { - if (hasValidNetworkInterface()){ - if (netIsAvailableGithub() || netIsAvailableOther() || netIsAvailableBaidu() || netIsAvailableGoogle()){ - try { - URL url; - // get URL content - url = new URL(args); - final URLConnection conn = url.openConnection(); - // open the stream and put it into BufferedReader - final BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); - String inputLine; - String tempLine = null; - while ((inputLine = br.readLine()) != null) { - tempLine = inputLine; - } - br.close(); - return tempLine; + if (checkNetworkIsAvailableWithValidInterface()){ + try { + URL url; + // get URL content + url = new URL(args); + final URLConnection conn = url.openConnection(); + // open the stream and put it into BufferedReader + final BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String inputLine; + String tempLine = null; + while ((inputLine = br.readLine()) != null) { + tempLine = inputLine; } - catch (final MalformedURLException e) {} - catch (final IOException e) {} + br.close(); + return tempLine; } - } - } catch (final SocketException e) {} + catch (final MalformedURLException e) {} + catch (final IOException e) {} + } return "offline"; } public static boolean checkNetworkIsAvailableWithValidInterface(){ try { if (hasValidNetworkInterface()){ - if (netIsAvailableGithub() || netIsAvailableOther() || netIsAvailableBaidu() || netIsAvailableGoogle()){ + if (checkAddressWithTimeout("http://www.google.com", 10) || checkAddressWithTimeout("http://www.baidu.com", 10) || checkAddressWithTimeout("https://github.com/draknyte1/GTplusplus", 10) || checkAddressWithTimeout("www.yahoo.com", 10)){ return true; } } @@ -99,6 +95,21 @@ public class NetworkUtils { } return false; } + + private static boolean checkAddressWithTimeout(String URL, int timeout) { + try { + final InetAddress[] addresses = InetAddress.getAllByName(URL); + for (final InetAddress address : addresses) { + if (address.isReachable(timeout)) { + return true; + } + return false; + } + } catch (final Exception e) { + return false; + } + return false; + } private static boolean hasValidNetworkInterface() throws SocketException{ final Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_IndustrialSifter.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_IndustrialSifter.java index 88fb1c5b2f..4e22220f4c 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_IndustrialSifter.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntity_IndustrialSifter.java @@ -107,6 +107,11 @@ extends GregtechMeta_MultiBlockBase { this.sendLoopStart((byte) 1); } + ItemStack[] mInputStacks; + int[] cloneChances; + GT_Recipe baseRecipe; + GT_Recipe cloneRecipe; + @Override public boolean checkRecipe(final ItemStack aStack) { @@ -137,11 +142,31 @@ extends GregtechMeta_MultiBlockBase { return false; } + Utils.LOG_INFO("3"); //Make a recipe instance for the rest of the method. final GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sSifterRecipes.findRecipe(this.getBaseMetaTileEntity(), false, 9223372036854775807L, null, tInputs); - + + baseRecipe = tRecipe; + + if (cloneRecipe != tRecipe || cloneRecipe == null){ + cloneRecipe = tRecipe; + Utils.LOG_INFO("Setting Recipe"); + } + if (mInputStacks != tRecipe.mInputs || mInputStacks == null){ + mInputStacks = tRecipe.mInputs; + Utils.LOG_INFO("Setting Recipe Inputs"); + } + if (cloneChances != tRecipe.mChances || cloneChances == null){ + cloneChances = tRecipe.mChances; + Utils.LOG_INFO("Setting Chances"); + } + + for (int r=0;r<cloneChances.length;r++){ + Utils.LOG_INFO("Original map Output["+r+"] chance = "+cloneChances[r]); + } + Utils.LOG_INFO("3.1"); //Change bonus chances @@ -149,8 +174,8 @@ extends GregtechMeta_MultiBlockBase { Utils.LOG_INFO("3.2"); - if (tRecipe.mChances != null){ - outputChances = tRecipe.mChances; + if (cloneRecipe.mChances != null){ + outputChances = cloneRecipe.mChances; Utils.LOG_INFO("3.3"); @@ -176,7 +201,7 @@ extends GregtechMeta_MultiBlockBase { Utils.LOG_INFO("3.4"); //Rebuff Drop Rates for % output - tRecipe.mChances = outputChances; + cloneRecipe.mChances = outputChances; } @@ -184,28 +209,28 @@ extends GregtechMeta_MultiBlockBase { Utils.LOG_INFO("4"); - final int tValidOutputSlots = this.getValidOutputSlots(this.getBaseMetaTileEntity(), tRecipe, tInputs); + final int tValidOutputSlots = this.getValidOutputSlots(this.getBaseMetaTileEntity(), cloneRecipe, tInputs); Utils.LOG_INFO("Sifter - Valid Output Hatches: "+tValidOutputSlots); //More than or one input if ((tInputList.size() > 0) && (tValidOutputSlots >= 1)) { - if ((tRecipe != null) && (tRecipe.isRecipeInputEqual(true, null, tInputs))) { - Utils.LOG_WARNING("Valid Recipe found - size "+tRecipe.mOutputs.length); + if ((cloneRecipe != null) && (cloneRecipe.isRecipeInputEqual(true, null, tInputs))) { + Utils.LOG_WARNING("Valid Recipe found - size "+cloneRecipe.mOutputs.length); this.mEfficiency = (10000 - ((this.getIdealStatus() - this.getRepairStatus()) * 1000)); this.mEfficiencyIncrease = 10000; - this.mEUt = (-tRecipe.mEUt); - this.mMaxProgresstime = Math.max(1, (tRecipe.mDuration/5)); - final ItemStack[] outputs = new ItemStack[tRecipe.mOutputs.length]; - for (int i = 0; i < tRecipe.mOutputs.length; i++){ + this.mEUt = (-cloneRecipe.mEUt); + this.mMaxProgresstime = Math.max(1, (cloneRecipe.mDuration/5)); + final ItemStack[] outputs = new ItemStack[cloneRecipe.mOutputs.length]; + for (int i = 0; i < cloneRecipe.mOutputs.length; i++){ if (i==0) { Utils.LOG_WARNING("Adding the default output"); - outputs[0] = tRecipe.getOutput(i); + outputs[0] = cloneRecipe.getOutput(i); } - else if (this.getBaseMetaTileEntity().getRandomNumber(7500) < tRecipe.getOutputChance(i)){ + else if (this.getBaseMetaTileEntity().getRandomNumber(7500) < cloneRecipe.getOutputChance(i)){ Utils.LOG_WARNING("Adding a bonus output"); - outputs[i] = tRecipe.getOutput(i); + outputs[i] = cloneRecipe.getOutput(i); } else { Utils.LOG_WARNING("Adding null output"); @@ -216,6 +241,7 @@ extends GregtechMeta_MultiBlockBase { this.mOutputItems = outputs; this.sendLoopStart((byte) 20); this.updateSlots(); + tRecipe.mChances = baseRecipe.mChances; return true; } } |