From a0208915280f30b878fdc4a2bd01b275450fc514 Mon Sep 17 00:00:00 2001 From: Francesco Macagno Date: Sat, 29 Aug 2015 01:55:48 -0700 Subject: [PATCH] Fixed obo --- .../config/filler/FillerFactory.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main/java/cr0s/warpdrive/config/filler/FillerFactory.java b/src/main/java/cr0s/warpdrive/config/filler/FillerFactory.java index 02087010..265301fe 100644 --- a/src/main/java/cr0s/warpdrive/config/filler/FillerFactory.java +++ b/src/main/java/cr0s/warpdrive/config/filler/FillerFactory.java @@ -3,9 +3,9 @@ package cr0s.warpdrive.config.filler; import java.util.Map.Entry; import java.util.TreeMap; -import net.minecraft.block.Block; import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.config.MetaBlock; +import net.minecraft.block.Block; /** * Used for constructing FillerSets from a combination of Weights and Ratios @@ -18,12 +18,12 @@ public class FillerFactory { private int totalWeightNeeded; private int totalWeightWeightedBlocks; - + private Object lock; //Used to keep track of added ratio blocks in case this factory is imported into another. private TreeMap addedRatioMetaBlocks; - + /** * Initializes new FillerFactory */ @@ -42,7 +42,7 @@ public class FillerFactory { totalWeightNeeded = 0; totalWeightWeightedBlocks = 0; - + addedRatioMetaBlocks = new TreeMap(); } @@ -98,16 +98,16 @@ public class FillerFactory { } /** - * Add a MetaBlock weith the given ratio. Ratio should be convertible to a double. + * Add a MetaBlock with the given ratio. Ratio should be convertible to a double. * * @param mb * @param ratio */ public void addRatioMetaBlock(MetaBlock mb, String ratio) { - + //In case of an import addedRatioMetaBlocks.put(mb, ratio); - + //Prevent this from being run twice at once synchronized (lock) { @@ -117,21 +117,21 @@ public class FillerFactory { //Make sure it is an actual number if (Double.parseDouble(ratio) > 1) throw new IllegalArgumentException("Ratio must be less than one"); - + //Get the position of the period, so that we can find the number of significant digits. - + //This will probably be at 1 int lastDot = ratio.lastIndexOf('.'); - + int sigFig; //Go through and check to find the actual last significant digit. - for (sigFig = ratio.length(); sigFig > lastDot; sigFig--) { - + for (sigFig = ratio.length() - 1; sigFig > lastDot; sigFig--) { + if (ratio.charAt(sigFig) != '0') break; - + } - + //Check to make sure there was an actual number. if (sigFig <= lastDot) throw new IllegalArgumentException("Ratio must be greater than zero"); @@ -169,12 +169,12 @@ public class FillerFactory { convertedRatioMetaBlocks.put(mb, ratioInt); } - + } /** * Construct the actual array that should be used to generate random blocks - * + * * @return A MetaBlock array */ public MetaBlock[] constructWeightedMetaBlockList() { @@ -189,10 +189,10 @@ public class FillerFactory { int index = 0; for (Entry entry : metaBlocksWeight.entrySet()) { - + for (int i = 0; i < entry.getValue(); i++) list[index++] = entry.getKey(); - + } return list; @@ -200,16 +200,16 @@ public class FillerFactory { } //Add up ratio weights - + MetaBlock[] list = new MetaBlock[totalWeightNeeded]; - + int ratioTotalWeightUsed = 0; int index = 0; for (Entry entry : convertedRatioMetaBlocks.entrySet()) { - + for (int i = 0; i < entry.getValue(); i++) list[index++] = entry.getKey(); - + ratioTotalWeightUsed += entry.getValue(); } @@ -217,29 +217,29 @@ public class FillerFactory { if(remainingWeight < 0) throw new IllegalArgumentException("Ratios add up to more than 100%"); - + if(remainingWeight == 0) { WarpDrive.logger.info("Ratios add up perfectly to 100%, skipping weights"); } else { - + //Add //Add in weights //There are two ways to do this. //Option 1: Convert weighted Blocks to ratios compared to each other, and then get that ratio of the remaining //Option 2: Treat the largest weight as a filler for unfilled places - + //For now using option 1 //TODO: Make adjustable - + for (Entry entry : metaBlocksWeight.entrySet()) { - + int converted = entry.getValue() * remainingWeight / totalWeightWeightedBlocks; - + for (int i = 0; i < converted; i++) list[index++] = entry.getKey(); - + } } @@ -249,7 +249,7 @@ public class FillerFactory { } } - + /** * Add all the blocks previously added to the given factory to this factory * @@ -257,13 +257,13 @@ public class FillerFactory { * Factory to get MetaBlocks from */ public void addFromFactory(FillerFactory factory) { - + for (Entry addedBlock : factory.addedRatioMetaBlocks.entrySet()) addRatioMetaBlock(addedBlock.getKey(), addedBlock.getValue()); for (Entry addedBlock : factory.metaBlocksWeight.entrySet()) addWeightedMetaBlock(addedBlock.getKey(), addedBlock.getValue()); - + }