Fixed obo
This commit is contained in:
parent
fb322b4787
commit
a020891528
1 changed files with 32 additions and 32 deletions
|
@ -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<MetaBlock, String> addedRatioMetaBlocks;
|
||||
|
||||
|
||||
/**
|
||||
* Initializes new FillerFactory
|
||||
*/
|
||||
|
@ -42,7 +42,7 @@ public class FillerFactory {
|
|||
|
||||
totalWeightNeeded = 0;
|
||||
totalWeightWeightedBlocks = 0;
|
||||
|
||||
|
||||
addedRatioMetaBlocks = new TreeMap<MetaBlock, String>();
|
||||
|
||||
}
|
||||
|
@ -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<MetaBlock, Integer> 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<MetaBlock, Integer> 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<MetaBlock, Integer> 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<MetaBlock, String> addedBlock : factory.addedRatioMetaBlocks.entrySet())
|
||||
addRatioMetaBlock(addedBlock.getKey(), addedBlock.getValue());
|
||||
|
||||
for (Entry<MetaBlock, Integer> addedBlock : factory.metaBlocksWeight.entrySet())
|
||||
addWeightedMetaBlock(addedBlock.getKey(), addedBlock.getValue());
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue