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,19 @@
package hellfirepvp.beebetteratbees.client.gui;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
@@ -17,18 +31,6 @@ import codechicken.nei.recipe.GuiUsageRecipe;
import codechicken.nei.recipe.ICraftingHandler;
import codechicken.nei.recipe.IUsageHandler;
import codechicken.nei.recipe.RecipeInfo;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Container;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
/**
* HellFirePvP@Admin
@@ -47,18 +49,21 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
RecipeTransferRectHandler.registerRectsToGuis(getRecipeTransferRectGuis(), this.transferRects);
}
private static boolean transferRect(GuiContainer gui, Collection<RecipeTransferRect> transferRects, int offsetx, int offsety, boolean usage) {
private static boolean transferRect(GuiContainer gui, Collection<RecipeTransferRect> transferRects, int offsetx,
int offsety, boolean usage) {
Point pos = GuiDraw.getMousePosition();
Point relMouse = new Point(pos.x - gui.width - offsetx, pos.y - gui.height - offsety);
for (RecipeTransferRect rect : transferRects) {
if ((rect.rect.contains(relMouse)) && (usage ? GuiUsageRecipe.openRecipeGui(rect.outputId, rect.results) : GuiCraftingRecipe.openRecipeGui(rect.outputId, rect.results))) {
if ((rect.rect.contains(relMouse)) && (usage ? GuiUsageRecipe.openRecipeGui(rect.outputId, rect.results)
: GuiCraftingRecipe.openRecipeGui(rect.outputId, rect.results))) {
return true;
}
}
return false;
}
private static List<String> transferRectTooltip(GuiContainer gui, Collection<RecipeTransferRect> transferRects, int offsetx, int offsety, List<String> currenttip) {
private static List<String> transferRectTooltip(GuiContainer gui, Collection<RecipeTransferRect> transferRects,
int offsetx, int offsety, List<String> currenttip) {
Point pos = GuiDraw.getMousePosition();
Point relMouse = new Point(pos.x - gui.width - offsetx, pos.y - gui.height - offsety);
for (RecipeTransferRect rect : transferRects) {
@@ -94,7 +99,8 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
public AbstractTreeGUIHandler newInstance() {
try {
return getClass().getConstructor().newInstance();
return getClass().getConstructor()
.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -136,17 +142,20 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
@Override
public List<PositionedStack> getIngredientStacks(int recipe) {
return this.arecipes.get(recipe).getIngredients();
return this.arecipes.get(recipe)
.getIngredients();
}
@Override
public PositionedStack getResultStack(int recipe) {
return this.arecipes.get(recipe).getResult();
return this.arecipes.get(recipe)
.getResult();
}
@Override
public List<PositionedStack> getOtherStacks(int recipe) {
return this.arecipes.get(recipe).getOtherStacks();
return this.arecipes.get(recipe)
.getOtherStacks();
}
@Override
@@ -158,7 +167,8 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
@Override
public boolean hasOverlay(GuiContainer gui, Container container, int recipe) {
return (RecipeInfo.hasDefaultOverlay(gui, getOverlayIdentifier())) || (RecipeInfo.hasOverlayHandler(gui, getOverlayIdentifier()));
return (RecipeInfo.hasDefaultOverlay(gui, getOverlayIdentifier()))
|| (RecipeInfo.hasOverlayHandler(gui, getOverlayIdentifier()));
}
@Override
@@ -257,7 +267,8 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
private static HashMap<Class<? extends GuiContainer>, HashSet<RecipeTransferRect>> guiMap = new HashMap<Class<? extends GuiContainer>, HashSet<RecipeTransferRect>>();
public static void registerRectsToGuis(List<Class<? extends GuiContainer>> classes, List<RecipeTransferRect> rects) {
public static void registerRectsToGuis(List<Class<? extends GuiContainer>> classes,
List<RecipeTransferRect> rects) {
if (classes == null) {
return;
}
@@ -309,16 +320,13 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
}
@Override
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {
}
public void onKeyTyped(GuiContainer gui, char keyChar, int keyID) {}
@Override
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {
}
public void onMouseClicked(GuiContainer gui, int mousex, int mousey, int button) {}
@Override
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {
}
public void onMouseUp(GuiContainer gui, int mousex, int mousey, int button) {}
@Override
public boolean keyTyped(GuiContainer gui, char keyChar, int keyID) {
@@ -331,8 +339,7 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
}
@Override
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {
}
public void onMouseScrolled(GuiContainer gui, int mousex, int mousey, int scrolled) {}
@Override
public List<String> handleTooltip(GuiContainer gui, int mousex, int mousey, List<String> currenttip) {
@@ -341,7 +348,8 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
}
if ((GuiContainerManager.shouldShowTooltip(gui)) && (currenttip.size() == 0)) {
int[] offset = RecipeInfo.getGuiOffset(gui);
currenttip = AbstractTreeGUIHandler.transferRectTooltip(gui, guiMap.get(gui.getClass()), offset[0], offset[1], currenttip);
currenttip = AbstractTreeGUIHandler
.transferRectTooltip(gui, guiMap.get(gui.getClass()), offset[0], offset[1], currenttip);
}
return currenttip;
}
@@ -352,13 +360,13 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
}
@Override
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, List<String> currenttip) {
public List<String> handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey,
List<String> currenttip) {
return currenttip;
}
@Override
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {
}
public void onMouseDragged(GuiContainer gui, int mousex, int mousey, int button, long heldTime) {}
}
@@ -367,4 +375,4 @@ public abstract class AbstractTreeGUIHandler implements ICraftingHandler, IUsage
GuiContainerManager.addTooltipHandler(new RecipeTransferRectHandler());
}
}
}
@@ -1,5 +1,26 @@
package hellfirepvp.beebetteratbees.client.gui;
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.GuiRecipe;
@@ -13,25 +34,6 @@ import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ISpeciesRoot;
import hellfirepvp.beebetteratbees.common.BeeBetterAtBees;
import hellfirepvp.beebetteratbees.common.ModConfig;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* HellFirePvP@Admin
@@ -47,10 +49,10 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
private static IBeeRoot speciesRoot;
public static List<IBeeMutation> getMutationsWithResult(IAllele allele) {
if(speciesRoot == null) return new LinkedList<IBeeMutation>();
if (speciesRoot == null) return new LinkedList<IBeeMutation>();
LinkedList<IBeeMutation> out = new LinkedList<IBeeMutation>();
for (IBeeMutation mutation : speciesRoot.getMutations(false)) {
if(mutation.getTemplate()[0].equals(allele)) out.add(mutation);
if (mutation.getTemplate()[0].equals(allele)) out.add(mutation);
}
return out;
}
@@ -73,7 +75,7 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
@Override
public void loadCraftingRecipes(String outputId, Object... results) {
if(speciesRoot == null) return;
if (speciesRoot == null) return;
if (outputId.equals("item")) {
loadCraftingRecipes((ItemStack) results[0]);
@@ -81,7 +83,7 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
}
public void loadCraftingRecipes(ItemStack result) {
if(speciesRoot == null) return;
if (speciesRoot == null) return;
if (!speciesRoot.isMember(result)) {
return;
@@ -95,14 +97,16 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
BeeBetterAtBees.log.warn("Genome is null when searching recipe for %s", result.toString());
return;
}
if (resultIndividual.getGenome().getPrimary() == null) {
if (resultIndividual.getGenome()
.getPrimary() == null) {
BeeBetterAtBees.log.warn("Species is null when searching recipe for %s", result.toString());
return;
}
IAlleleSpecies species = resultIndividual.getGenome().getPrimary();
IAlleleSpecies species = resultIndividual.getGenome()
.getPrimary();
for (IBeeMutation mutation : speciesRoot.getMutations(false)) {
if(mutation.getTemplate()[0].equals(species)) {
if(!mutation.isSecret() || ModConfig.shouldShowSecretRecipes) {
if (mutation.getTemplate()[0].equals(species)) {
if (!mutation.isSecret() || ModConfig.shouldShowSecretRecipes) {
this.arecipes.add(new CachedBeeMutationTree(mutation));
}
}
@@ -115,7 +119,7 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
@Override
public void drawExtras(int recipe) {
CachedRecipe rec = this.arecipes.get(recipe);
if(rec instanceof CachedBeeMutationTree) {
if (rec instanceof CachedBeeMutationTree) {
Map<Rectangle, Collection<String>> boxes = new HashMap<Rectangle, Collection<String>>(4);
CachedBeeMutationTree.PositionedMutationNodeStack root = ((CachedBeeMutationTree) rec).getRootStack();
drawExtrasFrom(root, boxes);
@@ -123,59 +127,60 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
}
}
private static final Color lineColorBlack = new Color(0, 0, 0),
lineColorRed = new Color(169, 0, 10);
private static final Color lineColorBlack = new Color(0, 0, 0), lineColorRed = new Color(169, 0, 10);
private static final int offsetCorrection = 8;
private static final int possibleChildOffset = 16;
public static void drawExtrasFrom(CachedBeeMutationTree.PositionedMutationNodeStack nodeStack, Map<Rectangle, Collection<String>> infoBoxes) {
public static void drawExtrasFrom(CachedBeeMutationTree.PositionedMutationNodeStack nodeStack,
Map<Rectangle, Collection<String>> infoBoxes) {
int nodeX = nodeStack.relx;
int nodeY = nodeStack.rely;
if(nodeStack.leftChild == null ||
nodeStack.rightChild == null) {
if(nodeStack.hasPossibleChildren) {
if (nodeStack.leftChild == null || nodeStack.rightChild == null) {
if (nodeStack.hasPossibleChildren) {
Color drawColor = lineColorBlack;
if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
if (nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
drawColor = lineColorRed;
}
float chance = nodeStack.baseChance;
if(chance > 0) {
if (chance > 0) {
int length = drawChanceInfo(nodeX, nodeY, chance, Minecraft.getMinecraft().fontRenderer, drawColor);
if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
if (nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
Rectangle rec = new Rectangle(nodeX + 4, nodeY + 17, (int) (length * 0.75F), 5);
infoBoxes.put(rec, nodeStack.requirements);
}
}
drawLine(
nodeX + offsetCorrection, nodeY + offsetCorrection,
nodeX + offsetCorrection - 4,
nodeY + offsetCorrection + possibleChildOffset,
drawColor);
nodeX + offsetCorrection,
nodeY + offsetCorrection,
nodeX + offsetCorrection - 4,
nodeY + offsetCorrection + possibleChildOffset,
drawColor);
drawLine(
nodeX + offsetCorrection, nodeY + offsetCorrection,
nodeX + offsetCorrection + 4,
nodeY + offsetCorrection + possibleChildOffset,
drawColor);
nodeX + offsetCorrection,
nodeY + offsetCorrection,
nodeX + offsetCorrection + 4,
nodeY + offsetCorrection + possibleChildOffset,
drawColor);
}
return; //Has no children anymore.
return; // Has no children anymore.
}
Color drawColor = lineColorBlack;
if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
if (nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
drawColor = lineColorRed;
}
float chance = nodeStack.baseChance;
if(chance > 0) {
if (chance > 0) {
int length = drawChanceInfo(nodeX, nodeY, chance, Minecraft.getMinecraft().fontRenderer, drawColor);
if(nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
if (nodeStack.requirements != null && !nodeStack.requirements.isEmpty()) {
Rectangle rec = new Rectangle(nodeX + 4, nodeY + 17, (int) (length * 0.75F), 5);
infoBoxes.put(rec, nodeStack.requirements);
}
@@ -183,14 +188,18 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
CachedBeeMutationTree.PositionedMutationNodeStack left = nodeStack.leftChild;
drawLine(
nodeX + offsetCorrection, nodeY + offsetCorrection,
left.relx + offsetCorrection, left.rely + offsetCorrection,
drawColor);
nodeX + offsetCorrection,
nodeY + offsetCorrection,
left.relx + offsetCorrection,
left.rely + offsetCorrection,
drawColor);
CachedBeeMutationTree.PositionedMutationNodeStack right = nodeStack.rightChild;
drawLine(
nodeX + offsetCorrection, nodeY + offsetCorrection,
right.relx + offsetCorrection, right.rely + offsetCorrection,
drawColor);
nodeX + offsetCorrection,
nodeY + offsetCorrection,
right.relx + offsetCorrection,
right.rely + offsetCorrection,
drawColor);
drawExtrasFrom(left, infoBoxes);
drawExtrasFrom(right, infoBoxes);
@@ -202,10 +211,11 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
GL11.glScalef(0.65F, 0.65F, 0.65F);
int chAsInt = (int) (chance);
StringBuilder sb = new StringBuilder().append(EnumChatFormatting.BOLD);
if(chAsInt <= 0) {
if (chAsInt <= 0) {
sb.append("<1%");
} else {
sb.append(chAsInt).append("%");
sb.append(chAsInt)
.append("%");
}
int length = fr.drawString(sb.toString(), 0, 0, drawColor.getRGB());
GL11.glPopMatrix();
@@ -214,12 +224,12 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
@Override
public List<String> handleTooltip(GuiRecipe<?> gui, List<String> currenttip, int recipe) {
if(GuiContainerManager.shouldShowTooltip(gui) && currenttip.size() == 0) {
if (GuiContainerManager.shouldShowTooltip(gui) && currenttip.size() == 0) {
Point pos = GuiDraw.getMousePosition();
Point guiOffset = getGuiOffset(gui);
Point relMouse = new Point(pos.x - guiOffset.x - 5, pos.y - guiOffset.y - 16);
for (Rectangle rec : tipBoxes.keySet()) {
if(rec.contains(relMouse)) {
if (rec.contains(relMouse)) {
return new LinkedList<String>(tipBoxes.get(rec));
}
}
@@ -266,7 +276,7 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
@Override
public void loadUsageRecipes(String inputId, Object... ingredients) {
if(speciesRoot == null) return;
if (speciesRoot == null) return;
if (inputId.equals("item")) {
loadUsageRecipes((ItemStack) ingredients[0]);
@@ -274,7 +284,7 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
}
public void loadUsageRecipes(ItemStack ingredient) {
if(speciesRoot == null) return;
if (speciesRoot == null) return;
if (!speciesRoot.isMember(ingredient)) {
return;
@@ -288,14 +298,19 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
BeeBetterAtBees.log.warn("Genome is null when searching recipe for %s", ingredient.toString());
return;
}
if (individual.getGenome().getPrimary() == null) {
if (individual.getGenome()
.getPrimary() == null) {
BeeBetterAtBees.log.warn("Species is null when searching recipe for %s", ingredient.toString());
return;
}
IAlleleSpecies species = individual.getGenome().getPrimary();
IAlleleSpecies species = individual.getGenome()
.getPrimary();
for (IBeeMutation mutation : speciesRoot.getMutations(false)) {
if(mutation.getAllele0().equals(species) || mutation.getAllele1().equals(species)) {
if(!mutation.isSecret() || ModConfig.shouldShowSecretRecipes) {
if (mutation.getAllele0()
.equals(species)
|| mutation.getAllele1()
.equals(species)) {
if (!mutation.isSecret() || ModConfig.shouldShowSecretRecipes) {
this.arecipes.add(new CachedBeeMutationTree(mutation));
}
}
@@ -305,18 +320,18 @@ public class BBABGuiRecipeTreeHandler extends AbstractTreeGUIHandler {
private void cleanupDuplicateRecipes() {
for (CachedRecipe recipe : arecipes) {
if(recipe instanceof CachedBeeMutationTree) {
if (recipe instanceof CachedBeeMutationTree) {
boolean clean = true;
Iterator<CachedRecipe> iterator = arecipes.iterator();
while (iterator.hasNext()) {
CachedRecipe recipeOther = iterator.next();
if(recipe == recipeOther) continue;
if(recipe.equals(recipeOther)) {
if (recipe == recipeOther) continue;
if (recipe.equals(recipeOther)) {
iterator.remove();
clean = false;
}
}
if(!clean) {
if (!clean) {
cleanupDuplicateRecipes();
break;
}
@@ -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;
@@ -1,21 +1,22 @@
package hellfirepvp.beebetteratbees.client.gui;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Random;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
/**
* HellFirePvP@Admin
* Date: 28.04.2016 / 23:46
* on BeeBetterAtBees
* CachedRecipe
*/
* HellFirePvP@Admin
* Date: 28.04.2016 / 23:46
* on BeeBetterAtBees
* CachedRecipe
*/
public abstract class CachedRecipe {
final long offset = System.currentTimeMillis();
@@ -66,7 +67,7 @@ public abstract class CachedRecipe {
if (NEIServerUtils.areStacksSameTypeCrafting(ingredient, stack.items[i])) {
stack.item = stack.items[i];
stack.item.setTagCompound(ingredient.getTagCompound());
stack.items = new ItemStack[]{stack.item};
stack.items = new ItemStack[] { stack.item };
stack.setPermutationToRender(0);
break;
}
@@ -26,7 +26,7 @@ public class SimpleBinaryTree<E> {
private Node<E> buildSubTree(E superNodeValue, int maxFollowingDepth) {
E[] subNodes = rootProvider.provideSubNodes(superNodeValue);
if(subNodes == null || subNodes.length == 0 || maxFollowingDepth <= 0) {
if (subNodes == null || subNodes.length == 0 || maxFollowingDepth <= 0) {
return new Leaf<E>(superNodeValue);
} else {
Node<E> left = buildSubTree(subNodes[0], maxFollowingDepth - 1);
@@ -99,9 +99,14 @@ public class SimpleBinaryTree<E> {
@Override
public String toString() {
return new StringBuilder().append("[").append(left.toString())
.append("], ").append(value.toString()).append(", [")
.append(right.toString()).append("]").toString();
return new StringBuilder().append("[")
.append(left.toString())
.append("], ")
.append(value.toString())
.append(", [")
.append(right.toString())
.append("]")
.toString();
}
public void removeDuplicate() {
@@ -1,11 +1,12 @@
package hellfirepvp.beebetteratbees.common;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* HellFirePvP@Admin
@@ -13,7 +14,11 @@ import org.apache.logging.log4j.Logger;
* on BeeBetterAtBees
* BeeBetterAtBees
*/
@Mod(modid = BeeBetterAtBees.MODID, name = BeeBetterAtBees.NAME, version = BeeBetterAtBees.VERSION, dependencies = "required-after:NotEnoughItems;required-after:Forestry")
@Mod(
modid = BeeBetterAtBees.MODID,
name = BeeBetterAtBees.NAME,
version = BeeBetterAtBees.VERSION,
dependencies = "required-after:NotEnoughItems;required-after:Forestry")
public class BeeBetterAtBees {
public static final String MODID = "beebetteratbees";
@@ -1,9 +1,9 @@
package hellfirepvp.beebetteratbees.common;
import net.minecraftforge.common.config.Configuration;
import java.io.File;
import net.minecraftforge.common.config.Configuration;
/**
* HellFirePvP@Admin
* Date: 01.05.2016 / 22:46
@@ -30,11 +30,19 @@ public class ModConfig {
}
private static void loadFromConfig() {
shouldShowSecretRecipes = config.getBoolean("shouldShowSecretMutations", "general", false, "Set this to true, if you wish for the mod to show secret bee mutations.");
showDuplicateTrees = config.getBoolean("shouldShowDuplicateTrees", "general", true, "If this is set to false, it will not show the mutation tree for a specific bee if the same tree is already displayed.");
shouldShowSecretRecipes = config.getBoolean(
"shouldShowSecretMutations",
"general",
false,
"Set this to true, if you wish for the mod to show secret bee mutations.");
showDuplicateTrees = config.getBoolean(
"shouldShowDuplicateTrees",
"general",
true,
"If this is set to false, it will not show the mutation tree for a specific bee if the same tree is already displayed.");
}
public static void save() {
config.save();
}
}
}