Apply spotless

This commit is contained in:
glowredman committed 2023-06-15 21:36:37 +02:00
1 parent 908a011cb3
commit dff0c469cd
7 files changed
+279 -209

No files matched your search

@@ -1,5 +1,12 @@
package hellfirepvp.beebetteratbees.client.gui;
import static hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import codechicken.nei.PositionedStack;
import forestry.api.apiculture.IBeeMutation;
import forestry.api.genetics.IAllele;
@@ -7,13 +14,6 @@ import forestry.api.genetics.IAlleleSpecies;
import hellfirepvp.beebetteratbees.client.util.SimpleBinaryTree;
import hellfirepvp.beebetteratbees.common.ModConfig;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import static hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler.*;
/**
* HellFirePvP@Admin
* Date: 28.04.2016 / 23:44
@@ -22,9 +22,9 @@ import static hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler.*;
*/
public class CachedBeeMutationTree extends CachedRecipe {
//RENDERING BB
//X = 15 to 135 (Size: 120)
//Y = 10 to 100 (Size: 90)
// RENDERING BB
// X = 15 to 135 (Size: 120)
// Y = 10 to 100 (Size: 90)
private static final int MIN_X = 15, MAX_X = 135;
private static final int X_SEPERATION_THRESHOLD = 7;
@@ -37,54 +37,71 @@ public class CachedBeeMutationTree extends CachedRecipe {
private PositionedMutationNodeStack rootStack;
public CachedBeeMutationTree(IBeeMutation parentMutation) {
//parentMutation.getTemplate() Gets results primary at array[0], secondary at array[1]
//parentMutation.getAllele0() or getAllele1() Gets bees needed for mutation.
this.mutationTree = new SimpleBinaryTree<IAllele>(4, parentMutation.getTemplate()[0],
new SimpleBinaryTree.RootProvider<IAllele>() {
@Override
public IAllele[] provideSubNodes(IAllele superNode) {
List<IBeeMutation> mutations = BBABGuiRecipeTreeHandler.getMutationsWithResult(superNode);
if(mutations.size() > 0) {
IBeeMutation mutation = mutations.get(0);
// parentMutation.getTemplate() Gets results primary at array[0], secondary at array[1]
// parentMutation.getAllele0() or getAllele1() Gets bees needed for mutation.
this.mutationTree = new SimpleBinaryTree<IAllele>(
4,
parentMutation.getTemplate()[0],
new SimpleBinaryTree.RootProvider<IAllele>() {
return new IAllele[] { mutation.getAllele0(), mutation.getAllele1() };
} else {
return null;
}
@Override
public IAllele[] provideSubNodes(IAllele superNode) {
List<IBeeMutation> mutations = BBABGuiRecipeTreeHandler.getMutationsWithResult(superNode);
if (mutations.size() > 0) {
IBeeMutation mutation = mutations.get(0);
return new IAllele[] { mutation.getAllele0(), mutation.getAllele1() };
} else {
return null;
}
});
}
});
if(!ModConfig.showDuplicateTrees) {
if (!ModConfig.showDuplicateTrees) {
List<IAllele> foundMutationTrees = new ArrayList<IAllele>();
removeAndReplaceDuplicates(this.mutationTree.getRoot(), foundMutationTrees);
}
//Important: We don't need to buffer root, because that's the "result"
// Important: We don't need to buffer root, because that's the "result"
this.evaluatedBeePositions = new LinkedList<PositionedMutationNodeStack>();
int iterationDepth = 3;
int maxTotalDepth = Math.min(iterationDepth, mutationTree.getRoot().getMaxFollowingDepth());
if(maxTotalDepth <= 0) {
int maxTotalDepth = Math.min(
iterationDepth,
mutationTree.getRoot()
.getMaxFollowingDepth());
if (maxTotalDepth <= 0) {
oversized = false;
return; //In case the root is a leaf, there is nothing to display anyway except the root.
return; // In case the root is a leaf, there is nothing to display anyway except the root.
}
int yStep = 110 / maxTotalDepth;
this.oversized = checkSeparationWidth(maxTotalDepth, X_SEPERATION_THRESHOLD);
this.evaluatedMaxX = /*this.oversized ? buildNewMaxX(maxTotalDepth, X_SEPERATION_THRESHOLD) :*/ MAX_X;
this.evaluatedMaxX = /* this.oversized ? buildNewMaxX(maxTotalDepth, X_SEPERATION_THRESHOLD) : */ MAX_X;
int center = (MIN_X + this.evaluatedMaxX) / 2;
PositionedMutationNodeStack leftChild = placeInRenderBuffer(mutationTree.getRoot().getLeftNode(),
Y_OFFSET + yStep, yStep,
MIN_X, center, iterationDepth - 1);
PositionedMutationNodeStack rightChild = placeInRenderBuffer(mutationTree.getRoot().getRightNode(),
Y_OFFSET + yStep, yStep,
center, this.evaluatedMaxX, iterationDepth - 1);
PositionedMutationNodeStack leftChild = placeInRenderBuffer(
mutationTree.getRoot()
.getLeftNode(),
Y_OFFSET + yStep,
yStep,
MIN_X,
center,
iterationDepth - 1);
PositionedMutationNodeStack rightChild = placeInRenderBuffer(
mutationTree.getRoot()
.getRightNode(),
Y_OFFSET + yStep,
yStep,
center,
this.evaluatedMaxX,
iterationDepth - 1);
List<IBeeMutation> mutationsToRoot = getMutationsWithResult(mutationTree.getRoot().getValue());
List<IBeeMutation> mutationsToRoot = getMutationsWithResult(
mutationTree.getRoot()
.getValue());
float ch = -1;
Collection<String> requirements = new LinkedList<String>();
if(mutationsToRoot.size() > 0) {
if (mutationsToRoot.size() > 0) {
IBeeMutation mut = mutationsToRoot.get(0);
ch = mut.getBaseChance();
try {
@@ -93,19 +110,30 @@ public class CachedBeeMutationTree extends CachedRecipe {
}
this.rootStack = new PositionedMutationNodeStack(
createStack((IAlleleSpecies) mutationTree.getRoot().getValue(), BEE_TYPE_PRINCESS),
(MIN_X + this.evaluatedMaxX) / 2, Y_OFFSET,
ch, requirements,
leftChild, rightChild, true);
createStack(
(IAlleleSpecies) mutationTree.getRoot()
.getValue(),
BEE_TYPE_PRINCESS),
(MIN_X + this.evaluatedMaxX) / 2,
Y_OFFSET,
ch,
requirements,
leftChild,
rightChild,
true);
}
private void removeAndReplaceDuplicates(SimpleBinaryTree.Node<IAllele> node, List<IAllele> discoveredMutations) { //Replace with 2 lines.
if(discoveredMutations.contains(node.getValue())) {
private void removeAndReplaceDuplicates(SimpleBinaryTree.Node<IAllele> node, List<IAllele> discoveredMutations) { // Replace
// with
// 2
// lines.
if (discoveredMutations.contains(node.getValue())) {
List<IBeeMutation> mutations = getMutationsWithResult(node.getValue());
if(mutations.size() > 0) node.removeDuplicate(); //Only if it actually has mutations that has this node as result.
if (mutations.size() > 0) node.removeDuplicate(); // Only if it actually has mutations that has this node as
// result.
} else {
discoveredMutations.add(node.getValue());
if(node.getMaxFollowingDepth() > 0) {
if (node.getMaxFollowingDepth() > 0) {
removeAndReplaceDuplicates(node.getLeftNode(), discoveredMutations);
removeAndReplaceDuplicates(node.getRightNode(), discoveredMutations);
}
@@ -113,26 +141,27 @@ public class CachedBeeMutationTree extends CachedRecipe {
}
/*
private int buildNewMaxX(int maxTotalDepth, int xSeparationThreshold) {
int maxDivision = (int) Math.pow(2, maxTotalDepth + 1);
return MIN_X + (maxDivision * xSeparationThreshold);
}
*/
* private int buildNewMaxX(int maxTotalDepth, int xSeparationThreshold) {
* int maxDivision = (int) Math.pow(2, maxTotalDepth + 1);
* return MIN_X + (maxDivision * xSeparationThreshold);
* }
*/
private boolean checkSeparationWidth(int maxTotalDepth, int xSeparationThreshold) {
double maxDivision = Math.pow(2, maxTotalDepth + 1);
int resultingLLWidth = (int) (120 / maxDivision); //LowestLevelWidth
int resultingLLWidth = (int) (120 / maxDivision); // LowestLevelWidth
return resultingLLWidth < xSeparationThreshold;
}
private PositionedMutationNodeStack placeInRenderBuffer(SimpleBinaryTree.Node<IAllele> node, int minY, int yStep, int minX, int maxX, int iterationMaxCount) {
private PositionedMutationNodeStack placeInRenderBuffer(SimpleBinaryTree.Node<IAllele> node, int minY, int yStep,
int minX, int maxX, int iterationMaxCount) {
int center = (minX + maxX) / 2;
iterationMaxCount--;
if(iterationMaxCount < 0 || node.getMaxFollowingDepth() <= 0) {
if (iterationMaxCount < 0 || node.getMaxFollowingDepth() <= 0) {
List<IBeeMutation> mutationsToRoot = getMutationsWithResult(node.getValue());
float ch = -1;
Collection<String> requirements = new LinkedList<String>();
if(mutationsToRoot.size() > 0) {
if (mutationsToRoot.size() > 0) {
IBeeMutation mut = mutationsToRoot.get(0);
ch = mut.getBaseChance();
try {
@@ -141,20 +170,23 @@ public class CachedBeeMutationTree extends CachedRecipe {
requirements = new LinkedList<String>();
}
}
PositionedMutationNodeStack leaf = new PositionedMutationNodeStack( //Leaf
createStack((IAlleleSpecies) node.getValue(), BEE_TYPE_DRONE),
center, minY,
ch, requirements,
null, null, node.getMaxFollowingDepth() > 0);
PositionedMutationNodeStack leaf = new PositionedMutationNodeStack( // Leaf
createStack((IAlleleSpecies) node.getValue(), BEE_TYPE_DRONE),
center,
minY,
ch,
requirements,
null,
null,
node.getMaxFollowingDepth() > 0);
evaluatedBeePositions.add(leaf);
return leaf;
}
List<IBeeMutation> mutations = getMutationsWithResult(node.getValue());
float ch = -1;
Collection<String> requirements = new LinkedList<String>();
if(mutations.size() > 0) {
if (mutations.size() > 0) {
IBeeMutation mut = mutations.get(0);
ch = mut.getBaseChance();
try {
@@ -165,20 +197,18 @@ public class CachedBeeMutationTree extends CachedRecipe {
}
PositionedMutationNodeStack outNode = new PositionedMutationNodeStack(
createStack((IAlleleSpecies) node.getValue(), BEE_TYPE_DRONE),
center, minY,
ch, requirements,
node.getLeftNode() != null ?
placeInRenderBuffer(node.getLeftNode(),
minY + yStep, yStep,
minX, center, iterationMaxCount)
createStack((IAlleleSpecies) node.getValue(), BEE_TYPE_DRONE),
center,
minY,
ch,
requirements,
node.getLeftNode() != null
? placeInRenderBuffer(node.getLeftNode(), minY + yStep, yStep, minX, center, iterationMaxCount)
: null,
node.getRightNode() != null ?
placeInRenderBuffer(node.getRightNode(),
minY + yStep, yStep,
center, maxX, iterationMaxCount)
node.getRightNode() != null
? placeInRenderBuffer(node.getRightNode(), minY + yStep, yStep, center, maxX, iterationMaxCount)
: null,
true);
true);
evaluatedBeePositions.add(outNode);
return outNode;
}
@@ -217,10 +247,9 @@ public class CachedBeeMutationTree extends CachedRecipe {
public final Collection<String> requirements;
public final PositionedMutationNodeStack leftChild, rightChild;
public PositionedMutationNodeStack(Object object, int x, int y, boolean genPerms,
float baseChance, Collection<String> requirementInfo,
PositionedMutationNodeStack leftChild, PositionedMutationNodeStack rightChild,
boolean hasPossibleChildren) {
public PositionedMutationNodeStack(Object object, int x, int y, boolean genPerms, float baseChance,
Collection<String> requirementInfo, PositionedMutationNodeStack leftChild,
PositionedMutationNodeStack rightChild, boolean hasPossibleChildren) {
super(object, x, y, genPerms);
this.leftChild = leftChild;
this.rightChild = rightChild;
@@ -229,10 +258,9 @@ public class CachedBeeMutationTree extends CachedRecipe {
this.requirements = requirementInfo;
}
public PositionedMutationNodeStack(Object object, int x, int y,
float baseChance, Collection<String> requirementInfo,
PositionedMutationNodeStack leftChild, PositionedMutationNodeStack rightChild,
boolean hasPossibleChildren) {
public PositionedMutationNodeStack(Object object, int x, int y, float baseChance,
Collection<String> requirementInfo, PositionedMutationNodeStack leftChild,
PositionedMutationNodeStack rightChild, boolean hasPossibleChildren) {
super(object, x, y);
this.leftChild = leftChild;
this.rightChild = rightChild;