Fix #293 Crash when opening Arborist database

This commit is contained in:
mezz committed 2017-08-27 14:58:05 -07:00
1 parent 1a9b0839a1
commit caa307e72e
6 files changed
+92 -178

No files matched your search

+1
View File
@@ -10,3 +10,4 @@ classes/
build/
run/
out/
/changelog.html
@@ -5,6 +5,7 @@ import java.util.List;
import java.util.stream.Collectors;
import binnie.core.api.gui.IArea;
import binnie.core.gui.controls.page.ControlPage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
@@ -49,7 +50,12 @@ public class WindowBotanistDatabase extends WindowAbstractDatabase {
new PageSpeciesMutations(getInfoPages(Mode.SPECIES), new DatabaseTab(Botany.instance, "species.further"));
new PageBranchOverview(getInfoPages(Mode.BRANCHES), new DatabaseTab(Botany.instance, "branches.overview"));
new PageBranchSpecies(getInfoPages(Mode.BRANCHES), new DatabaseTab(Botany.instance, "branches.species"));
createMode(FlowerMode.Color, new FlowerColorModeWidgets(this));
createMode(FlowerMode.Color, new ModeWidgets(FlowerMode.Color, this, (area, modePage) -> {
FlowerColorControlListBox listBox = new FlowerColorControlListBox(modePage, area);
List<IFlowerColor> colors = Arrays.stream(EnumFlowerColor.values()).map(EnumFlowerColor::getFlowerColorAllele).collect(Collectors.toList());
listBox.setOptions(colors);
return listBox;
}));
new PageColorMixResultant(getInfoPages(FlowerMode.Color), new DatabaseTab(Botany.instance, "color.resultant"));
new PageColorMix(getInfoPages(FlowerMode.Color), new DatabaseTab(Botany.instance, "color.further"));
new PageBreeder(getInfoPages(Mode.BREEDER), getUsername(), new DatabaseTab(Botany.instance, "breeder"));
@@ -75,29 +81,14 @@ public class WindowBotanistDatabase extends WindowAbstractDatabase {
}
@SideOnly(Side.CLIENT)
private static class FlowerColorModeWidgets extends ModeWidgets {
public FlowerColorModeWidgets(WindowBotanistDatabase windowBotanistDatabase) {
super(FlowerMode.Color, windowBotanistDatabase);
private static class FlowerColorControlListBox extends ControlListBox<IFlowerColor> {
public FlowerColorControlListBox(ControlPage<IDatabaseMode> modePage, IArea area) {
super(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
@Override
public void createListBox(IArea area) {
listBox = new FlowerColorControlListBox(this, area);
List<IFlowerColor> colors = Arrays.stream(EnumFlowerColor.values()).map(EnumFlowerColor::getFlowerColorAllele).collect(Collectors.toList());
listBox.setOptions(colors);
}
private static class FlowerColorControlListBox extends ControlListBox<IFlowerColor> {
public FlowerColorControlListBox(FlowerColorModeWidgets flowerColorModeWidgets, IArea area) {
super(flowerColorModeWidgets.modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
@Override
public IWidget createOption(IFlowerColor value, int y) {
return new ControlColorOption(getContent(), value, y);
}
public IWidget createOption(IFlowerColor value, int y) {
return new ControlColorOption(getContent(), value, y);
}
}
}
@@ -14,8 +14,11 @@ public class ControlPage<T> extends Control implements IControlValue<T> {
public ControlPage(final IWidget parent, final int x, final int y, final int w, final int h, final T value) {
super(parent, x, y, w, h);
this.value = value;
if (parent instanceof IControlValue && ((IControlValue) parent).getValue() == null) {
((IControlValue) parent).setValue(value);
if (parent instanceof IControlValue) {
IControlValue controlValue = (IControlValue) parent;
if (controlValue.getValue() == null) {
controlValue.setValue(value);
}
}
}
@@ -92,18 +92,21 @@ public abstract class WindowAbstractDatabase extends Window {
public void initialiseClient() {
this.setSize(new Point(176 + this.selectionBoxWidth + 22 + 8, 208));
this.addEventHandler(EventValueChanged.class, event -> {
if (event.getOrigin().getParent() instanceof ControlPage && !(event.getValue() instanceof DatabaseTab)) {
final ControlPage parent = (ControlPage) event.getOrigin().getParent();
Object value = event.getValue();
IWidget eventOriginParent = event.getOrigin().getParent();
if (eventOriginParent instanceof ControlPage && !(value instanceof DatabaseTab)) {
ControlPage parent = (ControlPage) eventOriginParent;
if (parent.getValue() instanceof IDatabaseMode) {
for (final IWidget child : parent.getChildren()) {
for (IWidget child : parent.getChildren()) {
if (child instanceof ControlPages) {
if (event.getValue() == null) {
if (value == null) {
child.hide();
} else {
child.show();
for (final IWidget widget : child.getChildren()) {
for (IWidget widget : child.getChildren()) {
if (widget instanceof PageAbstract) {
((PageAbstract) widget).onValueChanged(event.getValue());
PageAbstract pageAbstract = (PageAbstract) widget;
pageAbstract.onValueChanged(value);
}
}
}
@@ -130,11 +133,26 @@ public abstract class WindowAbstractDatabase extends Window {
(this.panelSearch = new Panel(this, 176, 24, this.selectionBoxWidth, 160, MinecraftGUI.PanelType.BLACK)).setColor(860416);
this.modePages = new ControlPages<>(this, 0, 0, this.getSize().xPos(), this.getSize().yPos());
new ControlTextEdit(this, 176, 184, this.selectionBoxWidth, 16);
this.createMode(Mode.SPECIES, new SpeciesModeWidgets());
this.createMode(Mode.BRANCHES, new BranchesModeWidgets());
this.createMode(Mode.BREEDER, new BreederModeWidgets());
this.createMode(Mode.SPECIES, new ModeWidgets(Mode.SPECIES, this, (area, modePage) -> {
final GameProfile playerName = this.getUsername();
final Collection<IAlleleSpecies> speciesList = this.master ? this.system.getAllSpecies() : this.system.getDiscoveredSpecies(this.getWorld(), playerName);
ControlSpeciesBox controlSpeciesBox = new ControlSpeciesBox(modePage, area.xPos(), area.yPos(), area.width(), area.height());
controlSpeciesBox.setOptions(speciesList);
return controlSpeciesBox;
}));
this.createMode(Mode.BRANCHES, new ModeWidgets(Mode.BRANCHES, this, (area, modePage) -> {
final EntityPlayer player = this.getPlayer();
final GameProfile playerName = player.getGameProfile();
final Collection<IClassification> speciesList = this.master ? this.system.getAllBranches() : this.system.getDiscoveredBranches(this.getWorld(), playerName);
ControlBranchBox controlBranchBox = new ControlBranchBox(modePage, area.xPos(), area.yPos(), area.width(), area.height());
controlBranchBox.setOptions(speciesList);
return controlBranchBox;
}));
this.createMode(Mode.BREEDER, new ModeWidgets(Mode.BREEDER, this, (area, modePage) -> {
return new ControlListBox(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}));
this.addTabs();
final ControlTabBar<IDatabaseMode> tab = new DatabaseTabBar(this);
final ControlTabBar<IDatabaseMode> tab = new ControlTabBar<>(this, 176 + this.selectionBoxWidth, 24, 22, 176, Alignment.RIGHT, this.modePages.getValues(), DatabaseControlTab::new);
CraftGUIUtil.linkWidgets(tab, this.modePages);
this.changeMode(Mode.SPECIES);
for (final IDatabaseMode mode : this.modes.keySet()) {
@@ -188,85 +206,37 @@ public abstract class WindowAbstractDatabase extends Window {
}
}
public abstract static class ModeWidgets {
public static final class ModeWidgets {
@FunctionalInterface
public interface IListBoxCreator {
ControlListBox createListBox(IArea area, ControlPage<IDatabaseMode> modePage);
}
public WindowAbstractDatabase database;
public ControlPage<IDatabaseMode> modePage;
public ControlListBox listBox;
private ControlPages<DatabaseTab> infoPages;
private ControlTabBar<DatabaseTab> infoTabs;
public ModeWidgets(final IDatabaseMode mode, final WindowAbstractDatabase database) {
public ModeWidgets(IDatabaseMode mode, WindowAbstractDatabase database, IListBoxCreator listBoxCreator) {
this.database = database;
this.modePage = new ControlPage<>(database.modePages, 0, 0, database.getSize().xPos(), database.getSize().yPos(), mode);
final IArea listBoxArea = database.panelSearch.getArea().inset(2);
this.createListBox(listBoxArea);
this.listBox = listBoxCreator.createListBox(listBoxArea, this.modePage);
CraftGUIUtil.alignToWidget(this.listBox, database.panelSearch);
CraftGUIUtil.moveWidget(this.listBox, new Point(2, 2));
CraftGUIUtil.alignToWidget(this.infoPages = new ControlPages<>(this.modePage, 0, 0, 144, 176), database.panelInformation);
}
public abstract void createListBox(final IArea p0);
}
@SideOnly(Side.CLIENT)
private class SpeciesModeWidgets extends ModeWidgets {
public SpeciesModeWidgets() {
super(Mode.SPECIES, WindowAbstractDatabase.this);
private static class DatabaseControlTab extends ControlTab<IDatabaseMode> {
public DatabaseControlTab(int x, int y, int w, int h, IDatabaseMode value) {
super(x, y, w, h, value);
}
@Override
public void createListBox(final IArea area) {
final GameProfile playerName = WindowAbstractDatabase.this.getUsername();
final Collection<IAlleleSpecies> speciesList = this.database.master ? this.database.system.getAllSpecies() : this.database.system.getDiscoveredSpecies(this.database.getWorld(), playerName);
ControlSpeciesBox controlSpeciesBox = new ControlSpeciesBox(this.modePage, area.xPos(), area.yPos(), area.width(), area.height());
controlSpeciesBox.setOptions(speciesList);
this.listBox = controlSpeciesBox;
}
}
@SideOnly(Side.CLIENT)
private class BranchesModeWidgets extends ModeWidgets {
public BranchesModeWidgets() {
super(Mode.BRANCHES, WindowAbstractDatabase.this);
}
@Override
public void createListBox(final IArea area) {
final EntityPlayer player = this.database.getPlayer();
final GameProfile playerName = player.getGameProfile();
final Collection<IClassification> speciesList = this.database.master ? this.database.system.getAllBranches() : this.database.system.getDiscoveredBranches(this.database.getWorld(), playerName);
ControlBranchBox controlBranchBox = new ControlBranchBox(this.modePage, area.xPos(), area.yPos(), area.width(), area.height());
controlBranchBox.setOptions(speciesList);
this.listBox = controlBranchBox;
}
}
@SideOnly(Side.CLIENT)
private class BreederModeWidgets extends ModeWidgets {
public BreederModeWidgets() {
super(Mode.BREEDER, WindowAbstractDatabase.this);
}
@Override
public void createListBox(final IArea area) {
this.listBox = new ControlListBox(this.modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
}
private static class DatabaseTabBar extends ControlTabBar<IDatabaseMode> {
public DatabaseTabBar(WindowAbstractDatabase windowAbstractDatabase) {
super(windowAbstractDatabase, 176 + windowAbstractDatabase.selectionBoxWidth, 24, 22, 176, Alignment.RIGHT, windowAbstractDatabase.modePages.getValues(), DatabaseTab::new);
}
private static class DatabaseTab extends ControlTab<IDatabaseMode> {
public DatabaseTab(int x, int y, int w, int h, IDatabaseMode value) {
super(x, y, w, h, value);
}
@Override
public String getName() {
return this.value.getName();
}
public String getName() {
return this.value.getName();
}
}
}
@@ -1,9 +1,11 @@
package binnie.extratrees.gui.database;
import java.util.List;
import java.util.stream.Collectors;
import binnie.core.Binnie;
import binnie.core.api.gui.IArea;
import binnie.core.gui.controls.page.ControlPage;
import binnie.genetics.api.ITreeBreedingSystem;
import forestry.api.arboriculture.TreeManager;
import net.minecraft.entity.player.EntityPlayer;
@@ -51,9 +53,24 @@ public class WindowArboristDatabase extends WindowAbstractDatabase {
new PageBranchOverview(this.getInfoPages(Mode.BRANCHES), new DatabaseTab(ExtraTrees.instance, "branches.overview"));
new PageBranchSpecies(this.getInfoPages(Mode.BRANCHES), new DatabaseTab(ExtraTrees.instance, "branches.species"));
new PageBreeder(this.getInfoPages(Mode.BREEDER), this.getUsername(), new DatabaseTab(ExtraTrees.instance, "breeder"));
this.createMode(TreeMode.FRUIT, new FruitModeWidgets(this));
this.createMode(TreeMode.WOOD, new WoodModeWidgets(this));
this.createMode(TreeMode.PLANKS, new PlanksModeWidgets(this));
this.createMode(TreeMode.FRUIT, new ModeWidgets(TreeMode.FRUIT, this, (area, modePage) -> {
ControlListBox<ItemStack> controlListBox = new ModeControlListBox(modePage, area);
ITreeBreedingSystem breedingSystem = this.getBreedingSystem();
controlListBox.setOptions(breedingSystem.getAllFruits());
return controlListBox;
}));
this.createMode(TreeMode.WOOD, new ModeWidgets(TreeMode.WOOD, this, (area, modePage) -> {
ControlListBox<ItemStack> controlListBox = new ModeControlListBox(modePage, area);
ITreeBreedingSystem breedingSystem = this.getBreedingSystem();
controlListBox.setOptions(breedingSystem.getAllWoods());
return controlListBox;
}));
this.createMode(TreeMode.PLANKS, new ModeWidgets(TreeMode.PLANKS, this, (area, modePage) -> {
ControlListBox<ItemStack> controlListBox = new ModeControlListBox(modePage, area);
List<ItemStack> planks = WoodManager.getAllPlankTypes().stream().map(IDesignMaterial::getStack).collect(Collectors.toList());
controlListBox.setOptions(planks);
return controlListBox;
}));
new PageFruit(this.getInfoPages(TreeMode.FRUIT), new DatabaseTab(ExtraTrees.instance, "fruit.natural"), true);
new PageFruit(this.getInfoPages(TreeMode.FRUIT), new DatabaseTab(ExtraTrees.instance, "fruit.potential"), false);
new PageWood(this.getInfoPages(TreeMode.WOOD), new DatabaseTab(ExtraTrees.instance, "wood.natural"));
@@ -71,6 +88,11 @@ public class WindowArboristDatabase extends WindowAbstractDatabase {
return "TreeDatabase";
}
@Override
public ITreeBreedingSystem getBreedingSystem() {
return (ITreeBreedingSystem) super.getBreedingSystem();
}
enum TreeMode implements IDatabaseMode {
FRUIT,
WOOD,
@@ -82,89 +104,15 @@ public class WindowArboristDatabase extends WindowAbstractDatabase {
}
}
private static class FruitModeWidgets extends ModeWidgets {
private WindowArboristDatabase windowArboristDatabase;
public FruitModeWidgets(WindowArboristDatabase windowArboristDatabase) {
super(TreeMode.FRUIT, windowArboristDatabase);
this.windowArboristDatabase = windowArboristDatabase;
private static class ModeControlListBox extends ControlListBox<ItemStack> {
public ModeControlListBox(ControlPage<IDatabaseMode> modePage, IArea area) {
super(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
@Override
public void createListBox(final IArea area) {
ControlListBox<ItemStack> controlListBox = new FruitModeControlListBox(this, area);
ITreeBreedingSystem breedingSystem = (ITreeBreedingSystem) windowArboristDatabase.getBreedingSystem();
controlListBox.setOptions(breedingSystem.getAllFruits());
this.listBox = controlListBox;
}
private static class FruitModeControlListBox extends ControlListBox<ItemStack> {
public FruitModeControlListBox(FruitModeWidgets fruitModeWidgets, IArea area) {
super(fruitModeWidgets.modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
@Override
@SideOnly(Side.CLIENT)
public IWidget createOption(final ItemStack value, final int y) {
return new ControlItemStackOption(this.getContent(), value, y);
}
}
}
private static class WoodModeWidgets extends ModeWidgets {
private WindowArboristDatabase windowArboristDatabase;
public WoodModeWidgets(WindowArboristDatabase windowArboristDatabase) {
super(TreeMode.WOOD, windowArboristDatabase);
this.windowArboristDatabase = windowArboristDatabase;
}
@Override
public void createListBox(final IArea area) {
ControlListBox<ItemStack> controlListBox = new WoodModeControlListBox(this, area);
ITreeBreedingSystem breedingSystem = (ITreeBreedingSystem) windowArboristDatabase.getBreedingSystem();
controlListBox.setOptions(breedingSystem.getAllWoods());
this.listBox = controlListBox;
}
private static class WoodModeControlListBox extends ControlListBox<ItemStack> {
public WoodModeControlListBox(WoodModeWidgets woodModeWidgets, IArea area) {
super(woodModeWidgets.modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
@Override
@SideOnly(Side.CLIENT)
public IWidget createOption(final ItemStack value, final int y) {
return new ControlItemStackOption(this.getContent(), value, y);
}
}
}
private static class PlanksModeWidgets extends ModeWidgets {
public PlanksModeWidgets(WindowArboristDatabase windowArboristDatabase) {
super(TreeMode.PLANKS, windowArboristDatabase);
}
@Override
public void createListBox(final IArea area) {
ControlListBox<ItemStack> controlListBox = new PlanksModeControlListBox(this, area);
controlListBox.setOptions(WoodManager.getAllPlankTypes().stream().map(IDesignMaterial::getStack).collect(Collectors.toList()));
this.listBox = controlListBox;
}
private static class PlanksModeControlListBox extends ControlListBox<ItemStack> {
public PlanksModeControlListBox(PlanksModeWidgets planksModeWidgets, IArea area) {
super(planksModeWidgets.modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12);
}
@Override
@SideOnly(Side.CLIENT)
public IWidget createOption(final ItemStack value, final int y) {
return new ControlItemStackOption(this.getContent(), value, y);
}
@SideOnly(Side.CLIENT)
public IWidget createOption(final ItemStack value, final int y) {
return new ControlItemStackOption(this.getContent(), value, y);
}
}
}
@@ -3,12 +3,13 @@ package binnie.genetics.api;
import java.util.Collection;
import java.util.Set;
import binnie.core.api.genetics.IBreedingSystem;
import com.mojang.authlib.GameProfile;
import forestry.api.genetics.IAlleleSpecies;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public interface ITreeBreedingSystem {
public interface ITreeBreedingSystem extends IBreedingSystem {
Collection<IAlleleSpecies> getTreesThatBearFruit(ItemStack fruit, boolean nei, World world, GameProfile player);
Collection<IAlleleSpecies> getTreesThatCanBearFruit(ItemStack fruit, boolean nei, World world, GameProfile player);