From a12e293eeda2cb6135b975baece36f18f6d3c1c8 Mon Sep 17 00:00:00 2001 From: mezz Date: Sun, 20 Aug 2017 23:48:43 -0700 Subject: [PATCH] Convert anonymous inner classes to static inner classes. Should fix the build issue, which is caused by the bug described here: https://github.com/MinecraftForge/Srg2Source/pull/17 --- .../botany/blocks/BlockCeramicBrick.java | 2 +- .../botany/genetics/FlowerBreedingSystem.java | 48 +-- .../gui/analyst/AnalystPageAppearance.java | 68 +++-- .../genetics/gui/analyst/AnalystPageSoil.java | 56 ++-- .../gui/database/WindowBotanistDatabase.java | 27 +- .../gui/database/WindowAbstractDatabase.java | 34 ++- .../core/gui/genesis/WindowGenesis.java | 104 ++++--- .../binnie/core/gui/minecraft/Window.java | 24 +- .../inventory/ComponentInventoryTransfer.java | 12 +- .../machines/storage/WindowCompartment.java | 282 +++++++++++------- .../alveary/AlvearyLogicFrameHousing.java | 28 +- .../alveary/AlvearyLogicHatchery.java | 28 +- .../alveary/AlvearyLogicMutator.java | 28 +- .../alveary/AlvearyLogicStimulator.java | 28 +- .../extrabees/genetics/BeeBreedingSystem.java | 50 ++-- .../gui/analyst/AnalystPageBeeProducts.java | 63 ++-- .../extrabees/gui/ControlProductsBox.java | 2 +- .../binnie/extrabees/init/FluidRegister.java | 8 +- .../extrabees/proxy/ExtraBeesClientProxy.java | 52 ++-- .../extratrees/genetics/EnumSaplingType.java | 12 +- .../genetics/MothBreedingSystem.java | 52 ++-- .../gui/database/WindowArboristDatabase.java | 133 ++++++--- .../recipes/LumbermillRecipeManager.java | 8 +- .../binnie/extratrees/proxy/ProxyClient.java | 2 +- .../genetics/genetics/TreeBreedingSystem.java | 46 +-- .../gui/analyst/AnalystPageDatabase.java | 266 ++++++++++------- .../gui/analyst/AnalystPageGenome.java | 36 ++- .../genetics/gui/analyst/AnalystPanel.java | 130 ++++---- .../genetics/gui/analyst/WindowAnalyst.java | 49 ++- .../gui/analyst/tree/AnalystPageClimate.java | 56 ++-- .../machine/EthanolTankValidator.java | 18 ++ .../acclimatiser/PackageAcclimatiser.java | 9 +- .../genetics/machine/analyser/AnalyserFX.java | 68 +++-- .../machine/analyser/PackageAnalyser.java | 35 +-- .../machine/craftgui/WindowGeneBank.java | 68 +++-- .../machine/genepool/PackageGenepool.java | 20 +- .../genetics/machine/incubator/Incubator.java | 18 +- .../incubator/IncubatorRecipeLarvae.java | 29 +- .../machine/inoculator/PackageInoculator.java | 78 ++--- .../machine/isolator/PackageIsolator.java | 13 +- .../polymeriser/PackagePolymeriser.java | 56 ++-- .../machine/splicer/PackageSplicer.java | 52 ++-- .../genetics/machine/splicer/SplicerFX.java | 76 ++--- 43 files changed, 1342 insertions(+), 932 deletions(-) create mode 100644 genetics/src/main/java/binnie/genetics/machine/EthanolTankValidator.java diff --git a/botany/src/main/java/binnie/botany/blocks/BlockCeramicBrick.java b/botany/src/main/java/binnie/botany/blocks/BlockCeramicBrick.java index eb5c7d6c..eceb8814 100644 --- a/botany/src/main/java/binnie/botany/blocks/BlockCeramicBrick.java +++ b/botany/src/main/java/binnie/botany/blocks/BlockCeramicBrick.java @@ -256,7 +256,7 @@ public class BlockCeramicBrick extends Block implements IMultipassBlock getChromosomePickerPositions() { - Map positions = new HashMap<>(); - positions.put(EnumFlowerChromosome.SPECIES, new Point(35, 81)); - positions.put(EnumFlowerChromosome.PRIMARY, new Point(36, 28)); - positions.put(EnumFlowerChromosome.SECONDARY, new Point(27, 13)); - positions.put(EnumFlowerChromosome.FERTILITY, new Point(47, 15)); - positions.put(EnumFlowerChromosome.TERRITORY, new Point(54, 31)); - positions.put(EnumFlowerChromosome.EFFECT, new Point(15, 55)); - positions.put(EnumFlowerChromosome.LIFESPAN, new Point(23, 38)); - positions.put(EnumFlowerChromosome.TEMPERATURE_TOLERANCE, new Point(17, 77)); - positions.put(EnumFlowerChromosome.HUMIDITY_TOLERANCE, new Point(52, 51)); - positions.put(EnumFlowerChromosome.PH_TOLERANCE, new Point(54, 80)); - positions.put(EnumFlowerChromosome.SAPPINESS, new Point(41, 42)); - positions.put(EnumFlowerChromosome.STEM, new Point(37, 63)); - return positions; - } + return new FieldKitPlugin(); + } - @Override - public ITexture getTypeTexture() { - return new StandardTexture(0, 96, 96, 96, BinnieCoreTexture.GUI_BREEDING); - } - }; + private static class FieldKitPlugin implements IFieldKitPlugin { + @Override + public Map getChromosomePickerPositions() { + Map positions = new HashMap<>(); + positions.put(EnumFlowerChromosome.SPECIES, new Point(35, 81)); + positions.put(EnumFlowerChromosome.PRIMARY, new Point(36, 28)); + positions.put(EnumFlowerChromosome.SECONDARY, new Point(27, 13)); + positions.put(EnumFlowerChromosome.FERTILITY, new Point(47, 15)); + positions.put(EnumFlowerChromosome.TERRITORY, new Point(54, 31)); + positions.put(EnumFlowerChromosome.EFFECT, new Point(15, 55)); + positions.put(EnumFlowerChromosome.LIFESPAN, new Point(23, 38)); + positions.put(EnumFlowerChromosome.TEMPERATURE_TOLERANCE, new Point(17, 77)); + positions.put(EnumFlowerChromosome.HUMIDITY_TOLERANCE, new Point(52, 51)); + positions.put(EnumFlowerChromosome.PH_TOLERANCE, new Point(54, 80)); + positions.put(EnumFlowerChromosome.SAPPINESS, new Point(41, 42)); + positions.put(EnumFlowerChromosome.STEM, new Point(37, 63)); + return positions; + } + + @Override + public ITexture getTypeTexture() { + return new StandardTexture(0, 96, 96, 96, BinnieCoreTexture.GUI_BREEDING); + } } } diff --git a/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageAppearance.java b/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageAppearance.java index 079c3b09..e2b955b1 100644 --- a/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageAppearance.java +++ b/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageAppearance.java @@ -24,6 +24,7 @@ import binnie.core.gui.renderer.RenderUtil; import binnie.core.util.I18N; import binnie.genetics.api.analyst.AnalystConstants; +@SideOnly(Side.CLIENT) public class AnalystPageAppearance extends Control implements ITitledWidget { public AnalystPageAppearance(IWidget parent, IArea area, IFlower flower) { super(parent, area); @@ -43,36 +44,51 @@ public class AnalystPageAppearance extends Control implements ITitledWidget { IFlowerType type = genome.getType(); int sections = type.getSections(); int width = (sections > 1) ? 50 : 100; - new ControlIconDisplay(this, (getWidth() - width) / 2, y - ((sections == 1) ? 0 : 0)) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderForeground(int guiWidth, int guiHeight) { - GlStateManager.pushMatrix(); - float scale = width / 16.0f; - int dy = (sections > 1) ? 16 : 0; - GlStateManager.scale(scale, scale, 1.0f); - RenderUtil.setColour(flower.getGenome().getStemColor().getColor(false)); - if (sections > 1) { - RenderUtil.drawSprite(Point.ZERO, FlowerSpriteManager.getStem(type, 1, true)); - } - RenderUtil.drawSprite(new Point(0, dy), FlowerSpriteManager.getStem(type, 0, true)); - RenderUtil.setColour(flower.getGenome().getPrimaryColor().getColor(false)); - if (sections > 1) { - RenderUtil.drawSprite(Point.ZERO, FlowerSpriteManager.getPetal(type, 1, true)); - } - RenderUtil.drawSprite(new Point(0, dy), FlowerSpriteManager.getPetal(type, 0, true)); - RenderUtil.setColour(flower.getGenome().getSecondaryColor().getColor(false)); - if (sections > 1) { - RenderUtil.drawSprite(Point.ZERO, FlowerSpriteManager.getVariant(type, 1, true)); - } - RenderUtil.drawSprite(new Point(0, dy), FlowerSpriteManager.getVariant(type, 0, true)); - GlStateManager.popMatrix(); - } - }; + new FlowerIconDisplay(this, width, y, sections, flower, type); } @Override public String getTitle() { return I18N.localise(AnalystConstants.APPEARANCE_KEY + ".title"); } + + private static class FlowerIconDisplay extends ControlIconDisplay { + private final int width; + private final int sections; + private final IFlower flower; + private final IFlowerType type; + + public FlowerIconDisplay(AnalystPageAppearance analystPageAppearance, int width, int y, int sections, IFlower flower, IFlowerType type) { + super(analystPageAppearance, (analystPageAppearance.getWidth() - width) / 2, y - ((sections == 1) ? 0 : 0)); + this.width = width; + this.sections = sections; + this.flower = flower; + this.type = type; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderForeground(int guiWidth, int guiHeight) { + GlStateManager.pushMatrix(); + float scale = width / 16.0f; + int dy = (sections > 1) ? 16 : 0; + GlStateManager.scale(scale, scale, 1.0f); + RenderUtil.setColour(flower.getGenome().getStemColor().getColor(false)); + if (sections > 1) { + RenderUtil.drawSprite(Point.ZERO, FlowerSpriteManager.getStem(type, 1, true)); + } + RenderUtil.drawSprite(new Point(0, dy), FlowerSpriteManager.getStem(type, 0, true)); + RenderUtil.setColour(flower.getGenome().getPrimaryColor().getColor(false)); + if (sections > 1) { + RenderUtil.drawSprite(Point.ZERO, FlowerSpriteManager.getPetal(type, 1, true)); + } + RenderUtil.drawSprite(new Point(0, dy), FlowerSpriteManager.getPetal(type, 0, true)); + RenderUtil.setColour(flower.getGenome().getSecondaryColor().getColor(false)); + if (sections > 1) { + RenderUtil.drawSprite(Point.ZERO, FlowerSpriteManager.getVariant(type, 1, true)); + } + RenderUtil.drawSprite(new Point(0, dy), FlowerSpriteManager.getVariant(type, 0, true)); + GlStateManager.popMatrix(); + } + } } diff --git a/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageSoil.java b/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageSoil.java index 8961f8af..d489a036 100644 --- a/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageSoil.java +++ b/botany/src/main/java/binnie/botany/genetics/gui/analyst/AnalystPageSoil.java @@ -108,35 +108,47 @@ public class AnalystPageSoil extends Control implements ITitledWidget { } protected void createMoisture(IWidget parent, int x, int y, int w, int h, EnumMoisture value, forestry.api.genetics.EnumTolerance tol) { - new ControlToleranceBar(parent, x, y, w, h, EnumMoisture.class) { - @Override - protected String getName(EnumMoisture value) { - return value.getLocalisedName(false); - } - - @Override - protected int getColour(EnumMoisture value) { - return (new int[]{13434828, 6737151, 3368703})[value.ordinal()]; - } - }.setValues(value, tol); + new MoistureBar(parent, x, y, w, h).setValues(value, tol); } protected void createAcidity(IWidget parent, int x, int y, int w, int h, EnumAcidity value, forestry.api.genetics.EnumTolerance tol) { - new ControlToleranceBar(parent, x, y, w, h, EnumAcidity.class) { - @Override - protected String getName(EnumAcidity value) { - return value.getLocalisedName(false); - } - - @Override - protected int getColour(EnumAcidity value) { - return (new int[]{16711782, 65280, 26367})[value.ordinal()]; - } - }.setValues(value, tol); + new AcidityBar(parent, x, y, w, h).setValues(value, tol); } @Override public String getTitle() { return I18N.localise(AnalystConstants.SOIL_KEY + ".title"); } + + private static class MoistureBar extends ControlToleranceBar { + public MoistureBar(IWidget parent, int x, int y, int w, int h) { + super(parent, x, y, w, h, EnumMoisture.class); + } + + @Override + protected String getName(EnumMoisture value) { + return value.getLocalisedName(false); + } + + @Override + protected int getColour(EnumMoisture value) { + return (new int[]{13434828, 6737151, 3368703})[value.ordinal()]; + } + } + + private static class AcidityBar extends ControlToleranceBar { + public AcidityBar(IWidget parent, int x, int y, int w, int h) { + super(parent, x, y, w, h, EnumAcidity.class); + } + + @Override + protected String getName(EnumAcidity value) { + return value.getLocalisedName(false); + } + + @Override + protected int getColour(EnumAcidity value) { + return (new int[]{16711782, 65280, 26367})[value.ordinal()]; + } + } } diff --git a/botany/src/main/java/binnie/botany/gui/database/WindowBotanistDatabase.java b/botany/src/main/java/binnie/botany/gui/database/WindowBotanistDatabase.java index 0c55f965..efe02bd0 100644 --- a/botany/src/main/java/binnie/botany/gui/database/WindowBotanistDatabase.java +++ b/botany/src/main/java/binnie/botany/gui/database/WindowBotanistDatabase.java @@ -49,7 +49,7 @@ 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()); + createMode(FlowerMode.Color, new FlowerColorModeWidgets(this)); 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,22 +75,29 @@ public class WindowBotanistDatabase extends WindowAbstractDatabase { } @SideOnly(Side.CLIENT) - private class FlowerColorModeWidgets extends ModeWidgets { - public FlowerColorModeWidgets() { - super(FlowerMode.Color, WindowBotanistDatabase.this); + private static class FlowerColorModeWidgets extends ModeWidgets { + public FlowerColorModeWidgets(WindowBotanistDatabase windowBotanistDatabase) { + super(FlowerMode.Color, windowBotanistDatabase); } @Override public void createListBox(IArea area) { - listBox = new ControlListBox(modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12) { - @Override - public IWidget createOption(IFlowerColor value, int y) { - return new ControlColorOption(getContent(), value, y); - } - }; + listBox = new FlowerColorControlListBox(this, area); List colors = Arrays.stream(EnumFlowerColor.values()).map(EnumFlowerColor::getFlowerColorAllele).collect(Collectors.toList()); listBox.setOptions(colors); } + + private static class FlowerColorControlListBox extends ControlListBox { + + 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); + } + } } } diff --git a/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java b/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java index d72dfae4..95311cf4 100644 --- a/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java +++ b/core/src/main/java/binnie/core/gui/database/WindowAbstractDatabase.java @@ -134,17 +134,7 @@ public abstract class WindowAbstractDatabase extends Window { this.createMode(Mode.BRANCHES, new BranchesModeWidgets()); this.createMode(Mode.BREEDER, new BreederModeWidgets()); this.addTabs(); - final ControlTabBar tab = new ControlTabBar(this, 176 + this.selectionBoxWidth, 24, 22, 176, Alignment.RIGHT, this.modePages.getValues()) { - @Override - public ControlTab createTab(final int x, final int y, final int w, final int h, final IDatabaseMode value) { - return new ControlTab(this, x, y, w, h, value) { - @Override - public String getName() { - return this.value.getName(); - } - }; - } - }; + final ControlTabBar tab = new DatabaseTabBar(this); CraftGUIUtil.linkWidgets(tab, this.modePages); this.changeMode(Mode.SPECIES); for (final IDatabaseMode mode : this.modes.keySet()) { @@ -262,4 +252,26 @@ public abstract class WindowAbstractDatabase extends Window { this.listBox = new ControlListBox(this.modePage, area.xPos(), area.yPos(), area.width(), area.height(), 12); } } + + private static class DatabaseTabBar extends ControlTabBar { + public DatabaseTabBar(WindowAbstractDatabase windowAbstractDatabase) { + super(windowAbstractDatabase, 176 + windowAbstractDatabase.selectionBoxWidth, 24, 22, 176, Alignment.RIGHT, windowAbstractDatabase.modePages.getValues()); + } + + @Override + public ControlTab createTab(final int x, final int y, final int w, final int h, final IDatabaseMode value) { + return new DatabaseTab(this, x, y, w, h, value); + } + + private static class DatabaseTab extends ControlTab { + public DatabaseTab(DatabaseTabBar databaseTabBar, int x, int y, int w, int h, IDatabaseMode value) { + super(databaseTabBar, x, y, w, h, value); + } + + @Override + public String getName() { + return this.value.getName(); + } + } + } } diff --git a/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java b/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java index b793dd15..83e63d3a 100644 --- a/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java +++ b/core/src/main/java/binnie/core/gui/genesis/WindowGenesis.java @@ -71,52 +71,15 @@ public class WindowGenesis extends Window { public void initialiseClient() { new ControlPlayerInventory(this); this.setTitle(I18N.localise("binniecore.gui.genesis.title")); - final ControlTabBar tabSystems = new ControlTabBar(this, 8, 28, 23, 100, Alignment.LEFT, Binnie.GENETICS.getActiveSystems()) { - @Override - public ControlTab createTab(final int x, final int y, final int w, final int h, final IBreedingSystem value) { - return new ControlTabIcon(this, x, y, w, h, value) { - @Override - public ItemStack getItemStack() { - final ISpeciesType type = this.value.getDefaultType(); - final IIndividual ind = this.value.getDefaultIndividual(); - return this.value.getSpeciesRoot().getMemberStack(ind, type); - } - - @Override - public String getName() { - return this.value.getName(); - } - - @Override - public int getOutlineColour() { - return this.value.getColour(); - } - - @Override - public boolean hasOutline() { - return true; - } - }; - } - }; + final ControlTabBar tabSystems = new GenesisTabSystems(this); this.root = Binnie.GENETICS.getActiveSystems().iterator().next().getSpeciesRoot(); this.template = this.root.getDefaultTemplate(); final Area one = new Area(32, 28, 170, 100); final Area two = new Area(214, 28, 100, 100); new Panel(this, one.outset(1), MinecraftGUI.PanelType.BLACK); new Panel(this, two.outset(1), MinecraftGUI.PanelType.BLACK); - this.geneList = new ControlListBox(this, one.xPos(), one.yPos(), one.width(), one.height(), 10) { - @Override - public IWidget createOption(final Gene value, final int y) { - return new ControlGenesisOption(this.getContent(), value, y); - } - }; - this.geneOptions = new ControlListBox(this, two.xPos(), two.yPos(), two.width(), two.height(), 10) { - @Override - public IWidget createOption(final Gene value, final int y) { - return new ControlTextOption<>(this.getContent(), value, y); - } - }; + this.geneList = new GeneList(this, one); + this.geneOptions = new GeneOptions(this, two); tabSystems.addEventHandler(EventValueChanged.class, EventHandlerOrigin.SELF, tabSystems, event -> { Object value = event.getValue(); if (!(value instanceof BreedingSystem)) { @@ -227,4 +190,65 @@ public class WindowGenesis extends Window { } } } + + private static class GenesisTabSystems extends ControlTabBar { + public GenesisTabSystems(WindowGenesis windowGenesis) { + super(windowGenesis, 8, 28, 23, 100, Alignment.LEFT, Binnie.GENETICS.getActiveSystems()); + } + + @Override + public ControlTab createTab(final int x, final int y, final int w, final int h, final IBreedingSystem value) { + return new GenesisTabIcon(this, x, y, w, h, value); + } + + private static class GenesisTabIcon extends ControlTabIcon { + public GenesisTabIcon(GenesisTabSystems genesisTabSystems, int x, int y, int w, int h, IBreedingSystem value) { + super(genesisTabSystems, x, y, w, h, value); + } + + @Override + public ItemStack getItemStack() { + final ISpeciesType type = this.value.getDefaultType(); + final IIndividual ind = this.value.getDefaultIndividual(); + return this.value.getSpeciesRoot().getMemberStack(ind, type); + } + + @Override + public String getName() { + return this.value.getName(); + } + + @Override + public int getOutlineColour() { + return this.value.getColour(); + } + + @Override + public boolean hasOutline() { + return true; + } + } + } + + private static class GeneList extends ControlListBox { + public GeneList(WindowGenesis windowGenesis, Area one) { + super(windowGenesis, one.xPos(), one.yPos(), one.width(), one.height(), 10); + } + + @Override + public IWidget createOption(final Gene value, final int y) { + return new ControlGenesisOption(this.getContent(), value, y); + } + } + + private static class GeneOptions extends ControlListBox { + public GeneOptions(WindowGenesis windowGenesis, Area two) { + super(windowGenesis, two.xPos(), two.yPos(), two.width(), two.height(), 10); + } + + @Override + public IWidget createOption(final Gene value, final int y) { + return new ControlTextOption<>(this.getContent(), value, y); + } + } } diff --git a/core/src/main/java/binnie/core/gui/minecraft/Window.java b/core/src/main/java/binnie/core/gui/minecraft/Window.java index ef5fda37..b672da01 100644 --- a/core/src/main/java/binnie/core/gui/minecraft/Window.java +++ b/core/src/main/java/binnie/core/gui/minecraft/Window.java @@ -154,13 +154,7 @@ public abstract class Window extends TopLevelWidget implements INetwork.ReceiveG protected abstract String getBackgroundTextureName(); public IBinnieTexture getBackgroundTextureFile(final int i) { - return new IBinnieTexture() { - @Override - @SideOnly(Side.CLIENT) - public BinnieResource getTexture() { - return Binnie.RESOURCE.getPNG(getModId(), ResourceType.GUI, getBackgroundTextureName() + ((i == 1) ? "" : i)); - } - }; + return new BackgroundTexture(this, i); } public boolean showHelpButton() { @@ -321,4 +315,20 @@ public abstract class Window extends TopLevelWidget implements INetwork.ReceiveG public Texture getBackground2() { return this.bgText2; } + + private static class BackgroundTexture implements IBinnieTexture { + private final int i; + private Window window; + + public BackgroundTexture(Window window, int i) { + this.i = i; + this.window = window; + } + + @Override + @SideOnly(Side.CLIENT) + public BinnieResource getTexture() { + return Binnie.RESOURCE.getPNG(window.getModId(), ResourceType.GUI, window.getBackgroundTextureName() + ((i == 1) ? "" : i)); + } + } } diff --git a/core/src/main/java/binnie/core/machines/inventory/ComponentInventoryTransfer.java b/core/src/main/java/binnie/core/machines/inventory/ComponentInventoryTransfer.java index e6dc67ee..7ac1493a 100644 --- a/core/src/main/java/binnie/core/machines/inventory/ComponentInventoryTransfer.java +++ b/core/src/main/java/binnie/core/machines/inventory/ComponentInventoryTransfer.java @@ -52,14 +52,12 @@ public class ComponentInventoryTransfer extends MachineComponent { this.transfers.add(transfer); } - public abstract static class Condition { - @Nullable - public Transfer transfer; - - public abstract boolean fulfilled(final ItemStack p0); + @FunctionalInterface + public interface Condition { + boolean fulfilled(final ItemStack itemStack); } - public abstract class Transfer { + public abstract static class Transfer { protected final IMachine machine; @Nullable protected Condition condition; @@ -83,7 +81,7 @@ public class ComponentInventoryTransfer extends MachineComponent { public final Transfer setCondition(final Condition condition) { this.condition = condition; - return condition.transfer = this; + return this; } public final IMachine getMachine() { diff --git a/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java b/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java index cb44a755..08ee3801 100644 --- a/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java +++ b/core/src/main/java/binnie/core/machines/storage/WindowCompartment.java @@ -107,32 +107,7 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh final int compartmentWidth = compartmentPageWidth + (doubleTabbed ? 48 : 24); final int compartmentHeight = compartmentPageHeight; final Control controlCompartment = new Control(this, x, y, compartmentWidth, compartmentHeight); - final ControlTabBar tab = new ControlTabBar(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1)) { - @Override - public ControlTab createTab(final int x, final int y, final int w, final int h, final Integer value) { - return new ControlTabIcon(this, x, y, w, h, value) { - @Override - public ItemStack getItemStack() { - return WindowCompartment.this.getTab(this.value).getIcon(); - } - - @Override - public String getName() { - return WindowCompartment.this.getTab(this.value).getName(); - } - - @Override - public int getOutlineColour() { - return WindowCompartment.this.getTab(this.value).getColor().getColor(); - } - - @Override - public boolean hasOutline() { - return true; - } - }; - } - }; + final ControlTabBar tab = new CompartmentTabBar1(this, controlCompartment, compartmentPageHeight, tabs1); final String[] tabHelp = {"Compartment Tab", "Tabs that divide the inventory into sections. Each one can be labelled seperately."}; tab.addHelp(tabHelp); tab.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab, event -> { @@ -155,15 +130,7 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh int i = 0; for (int p2 = 0; p2 < inv.getTabNumber(); ++p2) { final ControlPage thisPage = page[p2]; - final Panel panel = new Panel(thisPage, 0, 0, thisPage.getWidth(), thisPage.getHeight(), MinecraftGUI.PanelType.BLACK) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderForeground(int guiWidth, int guiHeight) { - final ITexture iTexture = CraftGUI.RENDER.getTexture(CraftGUITexture.TAB_OUTLINE); - RenderUtil.setColour(WindowCompartment.this.getTab(WindowCompartment.this.panels.get(this)).getColor().getColor()); - CraftGUI.RENDER.texture(iTexture, this.getArea().inset(3)); - } - }; + final Panel panel = new CompartmentPanel(this, thisPage); this.panels.put(panel, p2); final int[] slotsIDs = new int[inv.getPageSize()]; for (int k = 0; k < inv.getPageSize(); ++k) { @@ -173,32 +140,7 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh } x += compartmentPageWidth; if (tabs2.length > 0) { - final ControlTabBar tab2 = new ControlTabBar(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2)) { - @Override - public ControlTab createTab(final int x, final int y, final int w, final int h, final Integer value) { - return new ControlTabIcon(this, x, y, w, h, value) { - @Override - public ItemStack getItemStack() { - return WindowCompartment.this.getTab(this.value).getIcon(); - } - - @Override - public String getName() { - return WindowCompartment.this.getTab(this.value).getName(); - } - - @Override - public int getOutlineColour() { - return WindowCompartment.this.getTab(this.value).getColor().getColor(); - } - - @Override - public boolean hasOutline() { - return true; - } - }; - } - }; + final ControlTabBar tab2 = new CompartmentTabBar2(this, controlCompartment, compartmentPageWidth, compartmentPageHeight, tabs2); tab2.addHelp(tabHelp); tab2.addEventHandler(EventValueChanged.class, EventHandlerOrigin.DIRECT_CHILD, tab2, event -> { if (event.getValue() == null) { @@ -271,27 +213,14 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh color.addHelp("Select a colour to highlight the current tab"); } y2 += 20; - final ControlButton searchButton = new ControlButton(controlCompartment, compartmentWidth - 24 - 64 - 8, compartmentPageHeight, 64, 16, "Search") { - @Override - @SideOnly(Side.CLIENT) - protected void onMouseClick(final EventMouse.Down event) { - WindowCompartment.this.createSearchDialog(); - } - - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - final Object texture = this.isMouseOver() ? CraftGUITexture.TAB_HIGHLIGHTED : CraftGUITexture.TAB; - CraftGUI.RENDER.texture(CraftGUI.RENDER.getTexture(texture).crop(Alignment.BOTTOM, 8), this.getArea()); - } - }; + final ControlButton searchButton = new SearchButton(this, controlCompartment, compartmentWidth, compartmentPageHeight); searchButton.addHelp("Search Button"); searchButton.addHelp("Clicking this will open the Search dialog. This allows you to search the inventory for specific items."); } @SideOnly(Side.CLIENT) public void createSearchDialog() { - new SearchDialog(); + new SearchDialog(this); } @Override @@ -347,15 +276,17 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh return this.getTab(this.currentTab); } - private class SearchDialog extends Dialog { + private static class SearchDialog extends Dialog { Control slotGrid; String textSearch = ""; boolean sortByName = false; boolean includeItems = true; boolean includeBlocks = true; + private WindowCompartment windowCompartment; - public SearchDialog() { - super(WindowCompartment.this, 252, 192); + public SearchDialog(WindowCompartment windowCompartment) { + super(windowCompartment, 252, 192); + this.windowCompartment = windowCompartment; } @Override @@ -364,14 +295,7 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh @Override public void initialise() { - final ControlScrollableContent scroll = new ControlScrollableContent(this, 124, 16, 116, 92, 6) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - RenderUtil.setColour(11184810); - CraftGUI.RENDER.texture(CraftGUITexture.OUTLINE, this.getArea().inset(new Border(0, 6, 0, 0))); - } - }; + final ControlScrollableContent scroll = new SearchScrollContent(this); scroll.setScrollableContent(this.slotGrid = new Control(scroll, 1, 1, 108, 18)); new ControlPlayerInventory(this, true); new ControlTextEdit(this, 16, 16, 100, 14).addEventHandler(EventTextEdit.class, event -> { @@ -380,33 +304,15 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh }); this.includeItems = true; this.includeBlocks = true; - new ControlCheckbox(this, 16, 40, 100, "Sort A-Z", this.sortByName) { - @Override - protected void onValueChanged(final boolean value) { - sortByName = value; - updateSearch(); - } - }; - new ControlCheckbox(this, 16, 64, 100, "Include Items", this.includeItems) { - @Override - protected void onValueChanged(final boolean value) { - includeItems = value; - updateSearch(); - } - }; - new ControlCheckbox(this, 16, 88, 100, "Include Blocks", this.includeBlocks) { - @Override - protected void onValueChanged(final boolean value) { - includeBlocks = value; - updateSearch(); - } - }; + new SortAlphabeticalCheckbox(this); + new IncludeItemsCheckbox(this); + new IncludeBlocksCheckbox(this); this.updateSearch(); } private void updateSearch() { Map slotIds = new HashMap<>(); - final IInventory inv = WindowCompartment.this.getInventory(); + final IInventory inv = windowCompartment.getInventory(); for (int i = 0; i < inv.getSizeInventory(); ++i) { final ItemStack stack = inv.getStackInSlot(i); if (!stack.isEmpty()) { @@ -453,5 +359,163 @@ public class WindowCompartment extends WindowMachine implements IWindowAffectsSh } } } + + private static class SearchScrollContent extends ControlScrollableContent { + private SearchDialog searchDialog; + + public SearchScrollContent(SearchDialog searchDialog) { + super(searchDialog, 124, 16, 116, 92, 6); + this.searchDialog = searchDialog; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + RenderUtil.setColour(11184810); + CraftGUI.RENDER.texture(CraftGUITexture.OUTLINE, searchDialog.windowCompartment.getArea().inset(new Border(0, 6, 0, 0))); + } + } + + private static class SortAlphabeticalCheckbox extends ControlCheckbox { + private SearchDialog searchDialog; + + public SortAlphabeticalCheckbox(SearchDialog searchDialog) { + super(searchDialog, 16, 40, 100, "Sort A-Z", searchDialog.sortByName); + this.searchDialog = searchDialog; + } + + @Override + protected void onValueChanged(final boolean value) { + searchDialog.sortByName = value; + searchDialog.updateSearch(); + } + } + + private static class IncludeItemsCheckbox extends ControlCheckbox { + private SearchDialog searchDialog; + + public IncludeItemsCheckbox(SearchDialog searchDialog) { + super(searchDialog, 16, 64, 100, "Include Items", searchDialog.includeItems); + this.searchDialog = searchDialog; + } + + @Override + protected void onValueChanged(final boolean value) { + searchDialog.includeItems = value; + searchDialog.updateSearch(); + } + } + + private static class IncludeBlocksCheckbox extends ControlCheckbox { + private SearchDialog searchDialog; + + public IncludeBlocksCheckbox(SearchDialog searchDialog) { + super(searchDialog, 16, 88, 100, "Include Blocks", searchDialog.includeBlocks); + this.searchDialog = searchDialog; + } + + @Override + protected void onValueChanged(final boolean value) { + searchDialog.includeBlocks = value; + searchDialog.updateSearch(); + } + } + } + + private static class CompartmentTabBar1 extends ControlTabBar { + private WindowCompartment windowCompartment; + + public CompartmentTabBar1(final WindowCompartment windowCompartment, Control controlCompartment, int compartmentPageHeight, Integer[] tabs1) { + super(controlCompartment, 0, 0, 24, compartmentPageHeight, Alignment.LEFT, Arrays.asList(tabs1)); + this.windowCompartment = windowCompartment; + } + + @Override + public ControlTab createTab(final int x, final int y, final int w, final int h, final Integer value) { + return new CompartmentTabIcon(this, this.windowCompartment, x, y, w, h, value); + } + } + + private static class CompartmentTabBar2 extends ControlTabBar { + private WindowCompartment windowCompartment; + + public CompartmentTabBar2(WindowCompartment windowCompartment, Control controlCompartment, int compartmentPageWidth, int compartmentPageHeight, Integer[] tabs2) { + super(controlCompartment, 24 + compartmentPageWidth, 0, 24, compartmentPageHeight, Alignment.RIGHT, Arrays.asList(tabs2)); + this.windowCompartment = windowCompartment; + } + + @Override + public ControlTab createTab(final int x, final int y, final int w, final int h, final Integer value) { + return new CompartmentTabIcon(this, this.windowCompartment, x, y, w, h, value); + } + } + + private static class CompartmentTabIcon extends ControlTabIcon { + private WindowCompartment windowCompartment; + + public CompartmentTabIcon(ControlTabBar compartmentTabBar, WindowCompartment windowCompartment, int x, int y, int w, int h, Integer value) { + super(compartmentTabBar, x, y, w, h, value); + this.windowCompartment = windowCompartment; + } + + @Override + public ItemStack getItemStack() { + return windowCompartment.getTab(this.value).getIcon(); + } + + @Override + public String getName() { + return windowCompartment.getTab(this.value).getName(); + } + + @Override + public int getOutlineColour() { + return windowCompartment.getTab(this.value).getColor().getColor(); + } + + @Override + public boolean hasOutline() { + return true; + } + } + + private static class CompartmentPanel extends Panel { + private WindowCompartment windowCompartment; + + public CompartmentPanel(WindowCompartment windowCompartment, ControlPage thisPage) { + super(thisPage, 0, 0, thisPage.getWidth(), thisPage.getHeight(), MinecraftGUI.PanelType.BLACK); + this.windowCompartment = windowCompartment; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderForeground(int guiWidth, int guiHeight) { + final ITexture iTexture = CraftGUI.RENDER.getTexture(CraftGUITexture.TAB_OUTLINE); + CompartmentTab tab = windowCompartment.getTab(windowCompartment.panels.get(this)); + RenderUtil.setColour(tab.getColor().getColor()); + CraftGUI.RENDER.texture(iTexture, this.getArea().inset(3)); + } + } + + private static class SearchButton extends ControlButton { + private WindowCompartment windowCompartment; + + public SearchButton(WindowCompartment windowCompartment, Control controlCompartment, int compartmentWidth, int compartmentPageHeight) { + super(controlCompartment, compartmentWidth - 24 - 64 - 8, compartmentPageHeight, 64, 16, "Search"); + this.windowCompartment = windowCompartment; + } + + @Override + @SideOnly(Side.CLIENT) + protected void onMouseClick(final EventMouse.Down event) { + windowCompartment.createSearchDialog(); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + final Object texture = this.isMouseOver() ? CraftGUITexture.TAB_HIGHLIGHTED : CraftGUITexture.TAB; + CraftGUI.RENDER.texture(CraftGUI.RENDER.getTexture(texture).crop(Alignment.BOTTOM, 8), this.getArea()); + } } } diff --git a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicFrameHousing.java b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicFrameHousing.java index a4e44087..e5918f98 100644 --- a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicFrameHousing.java +++ b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicFrameHousing.java @@ -32,17 +32,7 @@ public class AlvearyLogicFrameHousing extends AbstractAlvearyLogic { public AlvearyLogicFrameHousing(TileEntityExtraBeesAlvearyPart tile) { this.tile = tile; - inv = new ItemStackHandler(1) { - - @Nonnull - @Override - public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { - if (!(stack.getItem() instanceof IHiveFrame)) { - return stack; - } - return super.insertItem(slot, stack, simulate); - } - }; + inv = new HiveFrameItemStackHandler(); } public IItemHandlerModifiable getInventory() { @@ -118,4 +108,20 @@ public class AlvearyLogicFrameHousing extends AbstractAlvearyLogic { public boolean hasGui() { return true; } + + private static class HiveFrameItemStackHandler extends ItemStackHandler { + + public HiveFrameItemStackHandler() { + super(1); + } + + @Nonnull + @Override + public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { + if (!(stack.getItem() instanceof IHiveFrame)) { + return stack; + } + return super.insertItem(slot, stack, simulate); + } + } } diff --git a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicHatchery.java b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicHatchery.java index ceb224ec..6ba50094 100644 --- a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicHatchery.java +++ b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicHatchery.java @@ -28,17 +28,7 @@ public class AlvearyLogicHatchery extends AbstractAlvearyLogic { private final IItemHandlerModifiable inv; public AlvearyLogicHatchery() { - inv = new ItemStackHandler(5) { - - @Nonnull - @Override - public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { - if (!stack.isEmpty() && Utils.getBeeRoot().getType(stack) != EnumBeeType.LARVAE) { - return stack; - } - return super.insertItem(slot, stack, simulate); - } - }; + inv = new LarvaeItemStackHandler(); } public IItemHandlerModifiable getInventory() { @@ -82,4 +72,20 @@ public class AlvearyLogicHatchery extends AbstractAlvearyLogic { public boolean hasGui() { return true; } + + private static class LarvaeItemStackHandler extends ItemStackHandler { + + public LarvaeItemStackHandler() { + super(5); + } + + @Nonnull + @Override + public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { + if (!stack.isEmpty() && Utils.getBeeRoot().getType(stack) != EnumBeeType.LARVAE) { + return stack; + } + return super.insertItem(slot, stack, simulate); + } + } } diff --git a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicMutator.java b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicMutator.java index 00cb6c75..7fa1723a 100644 --- a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicMutator.java +++ b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicMutator.java @@ -25,17 +25,7 @@ public class AlvearyLogicMutator extends AbstractAlvearyLogic { private final IItemHandlerModifiable inv; public AlvearyLogicMutator() { - this.inv = new ItemStackHandler(1) { - - @Nonnull - @Override - public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { - if (!AlvearyMutationHandler.isMutationItem(stack)) { - return stack; - } - return super.insertItem(slot, stack, simulate); - } - }; + this.inv = new MutationItemStackHandler(); } public IItemHandlerModifiable getInventory() { @@ -71,4 +61,20 @@ public class AlvearyLogicMutator extends AbstractAlvearyLogic { public boolean hasGui() { return true; } + + private static class MutationItemStackHandler extends ItemStackHandler { + + public MutationItemStackHandler() { + super(1); + } + + @Nonnull + @Override + public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { + if (!AlvearyMutationHandler.isMutationItem(stack)) { + return stack; + } + return super.insertItem(slot, stack, simulate); + } + } } diff --git a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java index 556bd861..545c47ba 100644 --- a/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java +++ b/extrabees/src/main/java/binnie/extrabees/alveary/AlvearyLogicStimulator.java @@ -40,17 +40,7 @@ public class AlvearyLogicStimulator extends AbstractAlvearyLogic { this.powered = false; this.modifiers = new StimulatorCircuit[0]; this.energyStorage = new EnergyStorage(10000); - this.inv = new ItemStackHandler(1) { - - @Nonnull - @Override - public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { - if (!ChipsetManager.circuitRegistry.isChipset(stack)) { - return stack; - } - return super.insertItem(slot, stack, simulate); - } - }; + this.inv = new ChipsetItemStackHandler(); } public IItemHandlerModifiable getInventory() { @@ -251,4 +241,20 @@ public class AlvearyLogicStimulator extends AbstractAlvearyLogic { public boolean hasGui() { return true; } + + private static class ChipsetItemStackHandler extends ItemStackHandler { + + public ChipsetItemStackHandler() { + super(1); + } + + @Nonnull + @Override + public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { + if (!ChipsetManager.circuitRegistry.isChipset(stack)) { + return stack; + } + return super.insertItem(slot, stack, simulate); + } + } } diff --git a/extrabees/src/main/java/binnie/extrabees/genetics/BeeBreedingSystem.java b/extrabees/src/main/java/binnie/extrabees/genetics/BeeBreedingSystem.java index 7953bf73..b64e0a77 100644 --- a/extrabees/src/main/java/binnie/extrabees/genetics/BeeBreedingSystem.java +++ b/extrabees/src/main/java/binnie/extrabees/genetics/BeeBreedingSystem.java @@ -158,30 +158,32 @@ public class BeeBreedingSystem extends BreedingSystem { @Override public IFieldKitPlugin getFieldKitPlugin() { - return new IFieldKitPlugin() { - @Override - public Map getChromosomePickerPositions() { - Map positions = new HashMap<>(); - positions.put(EnumBeeChromosome.SPECIES, new Point(28, 47)); - positions.put(EnumBeeChromosome.SPEED, new Point(28, 72)); - positions.put(EnumBeeChromosome.LIFESPAN, new Point(19, 20)); - positions.put(EnumBeeChromosome.FERTILITY, new Point(55, 65)); - positions.put(EnumBeeChromosome.TEMPERATURE_TOLERANCE, new Point(28, 1)); - positions.put(EnumBeeChromosome.NEVER_SLEEPS, new Point(61, 37)); - positions.put(EnumBeeChromosome.HUMIDITY_TOLERANCE, new Point(81, 76)); - positions.put(EnumBeeChromosome.TOLERATES_RAIN, new Point(44, 21)); - positions.put(EnumBeeChromosome.CAVE_DWELLING, new Point(3, 37)); - positions.put(EnumBeeChromosome.FLOWER_PROVIDER, new Point(4, 65)); - positions.put(EnumBeeChromosome.FLOWERING, new Point(83, 27)); - positions.put(EnumBeeChromosome.TERRITORY, new Point(71, 10)); - positions.put(EnumBeeChromosome.EFFECT, new Point(84, 54)); - return positions; - } + return new FieldKitPlugin(); + } - @Override - public ITexture getTypeTexture() { - return new StandardTexture(0, 0, 96, 96, BinnieCoreTexture.GUI_BREEDING); - } - }; + private static class FieldKitPlugin implements IFieldKitPlugin { + @Override + public Map getChromosomePickerPositions() { + Map positions = new HashMap<>(); + positions.put(EnumBeeChromosome.SPECIES, new Point(28, 47)); + positions.put(EnumBeeChromosome.SPEED, new Point(28, 72)); + positions.put(EnumBeeChromosome.LIFESPAN, new Point(19, 20)); + positions.put(EnumBeeChromosome.FERTILITY, new Point(55, 65)); + positions.put(EnumBeeChromosome.TEMPERATURE_TOLERANCE, new Point(28, 1)); + positions.put(EnumBeeChromosome.NEVER_SLEEPS, new Point(61, 37)); + positions.put(EnumBeeChromosome.HUMIDITY_TOLERANCE, new Point(81, 76)); + positions.put(EnumBeeChromosome.TOLERATES_RAIN, new Point(44, 21)); + positions.put(EnumBeeChromosome.CAVE_DWELLING, new Point(3, 37)); + positions.put(EnumBeeChromosome.FLOWER_PROVIDER, new Point(4, 65)); + positions.put(EnumBeeChromosome.FLOWERING, new Point(83, 27)); + positions.put(EnumBeeChromosome.TERRITORY, new Point(71, 10)); + positions.put(EnumBeeChromosome.EFFECT, new Point(84, 54)); + return positions; + } + + @Override + public ITexture getTypeTexture() { + return new StandardTexture(0, 0, 96, 96, BinnieCoreTexture.GUI_BREEDING); + } } } diff --git a/extrabees/src/main/java/binnie/extrabees/genetics/gui/analyst/AnalystPageBeeProducts.java b/extrabees/src/main/java/binnie/extrabees/genetics/gui/analyst/AnalystPageBeeProducts.java index c5cbeb50..32561b4a 100644 --- a/extrabees/src/main/java/binnie/extrabees/genetics/gui/analyst/AnalystPageBeeProducts.java +++ b/extrabees/src/main/java/binnie/extrabees/genetics/gui/analyst/AnalystPageBeeProducts.java @@ -143,33 +143,7 @@ public class AnalystPageBeeProducts extends Control implements ITitledWidget { } private void createProductEntry(ItemStack key, Float value, int y, float speed) { - ControlItemDisplay item = new ControlItemDisplay(this, 16, y) { - @Override - @SideOnly(Side.CLIENT) - public void getTooltip(Tooltip tooltip, ITooltipFlag tooltipFlag) { - super.getTooltip(tooltip, tooltipFlag); - NonNullList centrifugeProducts = NonNullList.create(); - ForestryRecipeUtil.getCentrifugeOutputs(key, centrifugeProducts); - if (!centrifugeProducts.isEmpty()) { - tooltip.add(I18N.localise(AnalystConstants.PRODUCTS_KEY + ".centrifuges") + ": "); - for (ItemStack prod : centrifugeProducts) { - NBTTagCompound nbt = new NBTTagCompound(); - prod.writeToNBT(nbt); - tooltip.add(prod, prod.getDisplayName()); - } - } - NonNullList squeezerProducts = NonNullList.create(); - ForestryRecipeUtil.getSqueezerOutputs(key, squeezerProducts); - if (!squeezerProducts.isEmpty()) { - tooltip.add(I18N.localise(AnalystConstants.PRODUCTS_KEY + ".squeezes") + ": "); - for (ItemStack prod2 : squeezerProducts) { - NBTTagCompound nbt2 = new NBTTagCompound(); - prod2.writeToNBT(nbt2); - tooltip.add(prod2, prod2.getDisplayName()); - } - } - } - }; + ControlItemDisplay item = new BeeProductItem(this, y, key); item.setTooltip(); ControlText textWidget = new ControlTextCentered(this, y + 4, ""); @@ -184,4 +158,39 @@ public class AnalystPageBeeProducts extends Control implements ITitledWidget { public String getTitle() { return I18N.localise(AnalystConstants.PRODUCTS_KEY + ".title"); } + + private static class BeeProductItem extends ControlItemDisplay { + private final ItemStack key; + + public BeeProductItem(AnalystPageBeeProducts analystPageBeeProducts, int y, ItemStack key) { + super(analystPageBeeProducts, 16, y); + this.key = key; + } + + @Override + @SideOnly(Side.CLIENT) + public void getTooltip(Tooltip tooltip, ITooltipFlag tooltipFlag) { + super.getTooltip(tooltip, tooltipFlag); + NonNullList centrifugeProducts = NonNullList.create(); + ForestryRecipeUtil.getCentrifugeOutputs(key, centrifugeProducts); + if (!centrifugeProducts.isEmpty()) { + tooltip.add(I18N.localise(AnalystConstants.PRODUCTS_KEY + ".centrifuges") + ": "); + for (ItemStack prod : centrifugeProducts) { + NBTTagCompound nbt = new NBTTagCompound(); + prod.writeToNBT(nbt); + tooltip.add(prod, prod.getDisplayName()); + } + } + NonNullList squeezerProducts = NonNullList.create(); + ForestryRecipeUtil.getSqueezerOutputs(key, squeezerProducts); + if (!squeezerProducts.isEmpty()) { + tooltip.add(I18N.localise(AnalystConstants.PRODUCTS_KEY + ".squeezes") + ": "); + for (ItemStack prod2 : squeezerProducts) { + NBTTagCompound nbt2 = new NBTTagCompound(); + prod2.writeToNBT(nbt2); + tooltip.add(prod2, prod2.getDisplayName()); + } + } + } + } } diff --git a/extrabees/src/main/java/binnie/extrabees/gui/ControlProductsBox.java b/extrabees/src/main/java/binnie/extrabees/gui/ControlProductsBox.java index 76c27b24..2c721b37 100644 --- a/extrabees/src/main/java/binnie/extrabees/gui/ControlProductsBox.java +++ b/extrabees/src/main/java/binnie/extrabees/gui/ControlProductsBox.java @@ -63,7 +63,7 @@ public class ControlProductsBox extends ControlListBox registry) { registry.putObject(new ModelResourceLocation(item, "inventory"), bakeModelFor(block)); } + + private static class BakedModelForBlock extends BlankModel { + + private final Block block; + + public BakedModelForBlock(Block block) { + this.block = block; + } + + @Override + protected ItemOverrideList createOverrides() { + return new BlockItemOverrideList(block); + } + + private static class BlockItemOverrideList extends ItemOverrideList { + private Block block; + + public BlockItemOverrideList(Block block) { + super(ImmutableList.of()); + this.block = block; + } + + @Override + @SuppressWarnings("deprecation") + public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) { + Minecraft minecraft = Minecraft.getMinecraft(); + BlockRendererDispatcher blockRendererDispatcher = minecraft.getBlockRendererDispatcher(); + BlockModelShapes blockModelShapes = blockRendererDispatcher.getBlockModelShapes(); + IBlockState stateFromMeta = block.getStateFromMeta(stack.getMetadata()); + return blockModelShapes.getModelForState(stateFromMeta); + } + } + } } diff --git a/extratrees/src/main/java/binnie/extratrees/genetics/EnumSaplingType.java b/extratrees/src/main/java/binnie/extratrees/genetics/EnumSaplingType.java index 0721a580..d3d302d4 100644 --- a/extratrees/src/main/java/binnie/extratrees/genetics/EnumSaplingType.java +++ b/extratrees/src/main/java/binnie/extratrees/genetics/EnumSaplingType.java @@ -24,28 +24,30 @@ public enum EnumSaplingType { Shrub; public IGermlingModelProvider getGermlingModelProvider(Color leaf, Color wood) { - return new DefaultGermlingModelProvider(this, leaf, wood); + return new DefaultGermlingModelProvider(this, this, leaf, wood); } - private class DefaultGermlingModelProvider implements IGermlingModelProvider { + private static class DefaultGermlingModelProvider implements IGermlingModelProvider { private ModelResourceLocation germlingModel; private ModelResourceLocation pollenModel; private EnumSaplingType saplingType; private Color leaf; private Color wood; + private EnumSaplingType enumSaplingType; - public DefaultGermlingModelProvider(EnumSaplingType saplingType, Color leaf, Color wood) { + public DefaultGermlingModelProvider(EnumSaplingType enumSaplingType, EnumSaplingType saplingType, Color leaf, Color wood) { this.saplingType = saplingType; this.wood = wood; this.leaf = leaf; + this.enumSaplingType = enumSaplingType; } @SideOnly(Side.CLIENT) @Override public void registerModels(Item item, IModelManager manager, EnumGermlingType type) { if (type == EnumGermlingType.SAPLING) { - germlingModel = manager.getModelLocation("extratrees", "saplings/tree_" + name()); - ModelBakery.registerItemVariants(item, new ResourceLocation("extratrees", "saplings/tree_" + name())); + germlingModel = manager.getModelLocation("extratrees", "saplings/tree_" + enumSaplingType.name()); + ModelBakery.registerItemVariants(item, new ResourceLocation("extratrees", "saplings/tree_" + enumSaplingType.name())); } if (type == EnumGermlingType.POLLEN) { pollenModel = manager.getModelLocation("pollen"); diff --git a/extratrees/src/main/java/binnie/extratrees/genetics/MothBreedingSystem.java b/extratrees/src/main/java/binnie/extratrees/genetics/MothBreedingSystem.java index 5a7928cb..a405fa6f 100644 --- a/extratrees/src/main/java/binnie/extratrees/genetics/MothBreedingSystem.java +++ b/extratrees/src/main/java/binnie/extratrees/genetics/MothBreedingSystem.java @@ -160,31 +160,33 @@ public class MothBreedingSystem extends BreedingSystem { @Override public IFieldKitPlugin getFieldKitPlugin() { - return new IFieldKitPlugin() { - @Override - public Map getChromosomePickerPositions() { - Map positions = new HashMap<>(); - positions.put(EnumButterflyChromosome.SPECIES, new Point(40, 40)); - positions.put(EnumButterflyChromosome.SIZE, new Point(63, 32)); - positions.put(EnumButterflyChromosome.SPEED, new Point(32, 63)); - positions.put(EnumButterflyChromosome.LIFESPAN, new Point(11, 27)); - positions.put(EnumButterflyChromosome.METABOLISM, new Point(16, 12)); - positions.put(EnumButterflyChromosome.FERTILITY, new Point(17, 63)); - positions.put(EnumButterflyChromosome.TEMPERATURE_TOLERANCE, new Point(34, 12)); - positions.put(EnumButterflyChromosome.HUMIDITY_TOLERANCE, new Point(22, 46)); - positions.put(EnumButterflyChromosome.NOCTURNAL, new Point(53, 26)); - positions.put(EnumButterflyChromosome.TOLERANT_FLYER, new Point(71, 53)); - positions.put(EnumButterflyChromosome.FIRE_RESIST, new Point(78, 12)); - positions.put(EnumButterflyChromosome.FLOWER_PROVIDER, new Point(55, 55)); - positions.put(EnumButterflyChromosome.EFFECT, new Point(27, 31)); - positions.put(EnumButterflyChromosome.COCOON, new Point(87, 45)); - return positions; - } + return new FieldKitPlugin(); + } - @Override - public ITexture getTypeTexture() { - return new StandardTexture(96, 96, 96, 96, BinnieCoreTexture.GUI_BREEDING); - } - }; + private static class FieldKitPlugin implements IFieldKitPlugin { + @Override + public Map getChromosomePickerPositions() { + Map positions = new HashMap<>(); + positions.put(EnumButterflyChromosome.SPECIES, new Point(40, 40)); + positions.put(EnumButterflyChromosome.SIZE, new Point(63, 32)); + positions.put(EnumButterflyChromosome.SPEED, new Point(32, 63)); + positions.put(EnumButterflyChromosome.LIFESPAN, new Point(11, 27)); + positions.put(EnumButterflyChromosome.METABOLISM, new Point(16, 12)); + positions.put(EnumButterflyChromosome.FERTILITY, new Point(17, 63)); + positions.put(EnumButterflyChromosome.TEMPERATURE_TOLERANCE, new Point(34, 12)); + positions.put(EnumButterflyChromosome.HUMIDITY_TOLERANCE, new Point(22, 46)); + positions.put(EnumButterflyChromosome.NOCTURNAL, new Point(53, 26)); + positions.put(EnumButterflyChromosome.TOLERANT_FLYER, new Point(71, 53)); + positions.put(EnumButterflyChromosome.FIRE_RESIST, new Point(78, 12)); + positions.put(EnumButterflyChromosome.FLOWER_PROVIDER, new Point(55, 55)); + positions.put(EnumButterflyChromosome.EFFECT, new Point(27, 31)); + positions.put(EnumButterflyChromosome.COCOON, new Point(87, 45)); + return positions; + } + + @Override + public ITexture getTypeTexture() { + return new StandardTexture(96, 96, 96, 96, BinnieCoreTexture.GUI_BREEDING); + } } } diff --git a/extratrees/src/main/java/binnie/extratrees/gui/database/WindowArboristDatabase.java b/extratrees/src/main/java/binnie/extratrees/gui/database/WindowArboristDatabase.java index ffe882a0..09cf6b07 100644 --- a/extratrees/src/main/java/binnie/extratrees/gui/database/WindowArboristDatabase.java +++ b/extratrees/src/main/java/binnie/extratrees/gui/database/WindowArboristDatabase.java @@ -51,50 +51,9 @@ 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 ModeWidgets(TreeMode.FRUIT, this) { - @Override - public void createListBox(final IArea area) { - ControlListBox controlListBox = new ControlListBox(this.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); - } - }; - ITreeBreedingSystem breedingSystem = (ITreeBreedingSystem) WindowArboristDatabase.this.getBreedingSystem(); - controlListBox.setOptions(breedingSystem.getAllFruits()); - this.listBox = controlListBox; - } - }); - this.createMode(TreeMode.WOOD, new ModeWidgets(TreeMode.WOOD, this) { - @Override - public void createListBox(final IArea area) { - ControlListBox controlListBox = new ControlListBox(this.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); - } - }; - ITreeBreedingSystem breedingSystem = (ITreeBreedingSystem) WindowArboristDatabase.this.getBreedingSystem(); - controlListBox.setOptions(breedingSystem.getAllWoods()); - this.listBox = controlListBox; - } - }); - this.createMode(TreeMode.PLANKS, new ModeWidgets(TreeMode.PLANKS, this) { - @Override - public void createListBox(final IArea area) { - ControlListBox controlListBox = new ControlListBox(this.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); - } - }; - controlListBox.setOptions(WoodManager.getAllPlankTypes().stream().map(IDesignMaterial::getStack).collect(Collectors.toList())); - this.listBox = controlListBox; - } - }); + this.createMode(TreeMode.FRUIT, new FruitModeWidgets(this)); + this.createMode(TreeMode.WOOD, new WoodModeWidgets(this)); + this.createMode(TreeMode.PLANKS, new PlanksModeWidgets(this)); 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")); @@ -122,4 +81,90 @@ public class WindowArboristDatabase extends WindowAbstractDatabase { return I18N.localise("extratrees.gui.database.mode." + this.name().toLowerCase()); } } + + private static class FruitModeWidgets extends ModeWidgets { + private WindowArboristDatabase windowArboristDatabase; + + public FruitModeWidgets(WindowArboristDatabase windowArboristDatabase) { + super(TreeMode.FRUIT, windowArboristDatabase); + this.windowArboristDatabase = windowArboristDatabase; + } + + @Override + public void createListBox(final IArea area) { + ControlListBox controlListBox = new FruitModeControlListBox(this, area); + ITreeBreedingSystem breedingSystem = (ITreeBreedingSystem) windowArboristDatabase.getBreedingSystem(); + controlListBox.setOptions(breedingSystem.getAllFruits()); + this.listBox = controlListBox; + } + + private static class FruitModeControlListBox extends ControlListBox { + + 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 controlListBox = new WoodModeControlListBox(this, area); + ITreeBreedingSystem breedingSystem = (ITreeBreedingSystem) windowArboristDatabase.getBreedingSystem(); + controlListBox.setOptions(breedingSystem.getAllWoods()); + this.listBox = controlListBox; + } + + private static class WoodModeControlListBox extends ControlListBox { + 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 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 { + + 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); + } + } + } } diff --git a/extratrees/src/main/java/binnie/extratrees/machines/lumbermill/recipes/LumbermillRecipeManager.java b/extratrees/src/main/java/binnie/extratrees/machines/lumbermill/recipes/LumbermillRecipeManager.java index 9a5e5ec7..c45a1fd2 100644 --- a/extratrees/src/main/java/binnie/extratrees/machines/lumbermill/recipes/LumbermillRecipeManager.java +++ b/extratrees/src/main/java/binnie/extratrees/machines/lumbermill/recipes/LumbermillRecipeManager.java @@ -20,7 +20,7 @@ import net.minecraftforge.fml.common.registry.ForgeRegistries; public class LumbermillRecipeManager implements ILumbermillManager { private static final Multimap recipes = ArrayListMultimap.create(); - private static final InventoryCrafting FAKE_CRAFT_INV = new InventoryCrafting(new FakeCraftingHandler(), 3, 3) {}; + private static final InventoryCrafting FAKE_CRAFT_INV = new FakeInventoryCrafting(); public static ItemStack getPlankProduct(ItemStack logStack, World world) { Item logItem = logStack.getItem(); @@ -91,4 +91,10 @@ public class LumbermillRecipeManager implements ILumbermillManager { return false; } } + + private static class FakeInventoryCrafting extends InventoryCrafting { + public FakeInventoryCrafting() { + super(new FakeCraftingHandler(), 3, 3); + } + } } diff --git a/extratrees/src/main/java/binnie/extratrees/proxy/ProxyClient.java b/extratrees/src/main/java/binnie/extratrees/proxy/ProxyClient.java index 51210aab..9a4f3d65 100644 --- a/extratrees/src/main/java/binnie/extratrees/proxy/ProxyClient.java +++ b/extratrees/src/main/java/binnie/extratrees/proxy/ProxyClient.java @@ -94,7 +94,7 @@ public class ProxyClient extends Proxy implements IExtraTreeProxy { getModelManager().registerItemAndBlockColors(); } - class CustomMapper extends StateMapperBase { + static class CustomMapper extends StateMapperBase { ResourceLocation rl; public CustomMapper(String name) { diff --git a/genetics/src/main/java/binnie/genetics/genetics/TreeBreedingSystem.java b/genetics/src/main/java/binnie/genetics/genetics/TreeBreedingSystem.java index 78310082..ef622b48 100644 --- a/genetics/src/main/java/binnie/genetics/genetics/TreeBreedingSystem.java +++ b/genetics/src/main/java/binnie/genetics/genetics/TreeBreedingSystem.java @@ -280,28 +280,7 @@ public class TreeBreedingSystem extends BreedingSystem implements binnie.genetic @Override public IFieldKitPlugin getFieldKitPlugin() { - return new IFieldKitPlugin() { - @Override - public Map getChromosomePickerPositions() { - Map positions = new HashMap<>(); - positions.put(EnumTreeChromosome.SPECIES, new Point(48, 48)); - positions.put(EnumTreeChromosome.HEIGHT, new Point(43, 84)); - positions.put(EnumTreeChromosome.FERTILITY, new Point(25, 63)); - positions.put(EnumTreeChromosome.FRUITS, new Point(72, 57)); - positions.put(EnumTreeChromosome.YIELD, new Point(21, 43)); - positions.put(EnumTreeChromosome.SAPPINESS, new Point(15, 17)); - positions.put(EnumTreeChromosome.EFFECT, new Point(67, 15)); - positions.put(EnumTreeChromosome.MATURATION, new Point(70, 34)); - positions.put(EnumTreeChromosome.GIRTH, new Point(45, 67)); - positions.put(EnumTreeChromosome.FIREPROOF, new Point(5, 70)); - return positions; - } - - @Override - public ITexture getTypeTexture() { - return new StandardTexture(96, 0, 96, 96, BinnieCoreTexture.GUI_BREEDING); - } - }; + return new FieldKitPlugin(); } @Override @@ -313,4 +292,27 @@ public class TreeBreedingSystem extends BreedingSystem implements binnie.genetic public Set getAllWoods() { return allWoods; } + + private static class FieldKitPlugin implements IFieldKitPlugin { + @Override + public Map getChromosomePickerPositions() { + Map positions = new HashMap<>(); + positions.put(EnumTreeChromosome.SPECIES, new Point(48, 48)); + positions.put(EnumTreeChromosome.HEIGHT, new Point(43, 84)); + positions.put(EnumTreeChromosome.FERTILITY, new Point(25, 63)); + positions.put(EnumTreeChromosome.FRUITS, new Point(72, 57)); + positions.put(EnumTreeChromosome.YIELD, new Point(21, 43)); + positions.put(EnumTreeChromosome.SAPPINESS, new Point(15, 17)); + positions.put(EnumTreeChromosome.EFFECT, new Point(67, 15)); + positions.put(EnumTreeChromosome.MATURATION, new Point(70, 34)); + positions.put(EnumTreeChromosome.GIRTH, new Point(45, 67)); + positions.put(EnumTreeChromosome.FIREPROOF, new Point(5, 70)); + return positions; + } + + @Override + public ITexture getTypeTexture() { + return new StandardTexture(96, 0, 96, 96, BinnieCoreTexture.GUI_BREEDING); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageDatabase.java b/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageDatabase.java index 798041dc..71dad32a 100644 --- a/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageDatabase.java +++ b/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageDatabase.java @@ -34,6 +34,7 @@ import binnie.core.gui.resource.textures.CraftGUITexture; import binnie.core.gui.window.Panel; import binnie.core.util.I18N; +@SideOnly(Side.CLIENT) public class AnalystPageDatabase extends Control implements ITitledWidget { private final ControlScrollableContent scroll; boolean isMaster; @@ -45,35 +46,7 @@ public class AnalystPageDatabase extends Control implements ITitledWidget { int y = 4; new ControlTextCentered(this, y, TextFormatting.UNDERLINE + getTitle()).setColor(getColor()); y += 16; - new ControlTextEdit(this, 20, y, getWidth() - 40, 16) { - @Override - public void onTextEdit(String value) { - Collection options = new ArrayList<>(); - getSpecies(system); - for (IAlleleSpecies species : getSpecies(system)) { - if (value != null) { - if (!Objects.equals(value, "")) { - if (!species.getAlleleName().toLowerCase().contains(value.toLowerCase())) { - continue; - } - } - } - options.add(species); - } - scroll.deleteAllChildren(); - scroll.setScrollableContent(getItemScrollList(system, options)); - } - - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - RenderUtil.setColour(5592405); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_SOLID, getArea().inset(1)); - RenderUtil.setColour(AnalystPageDatabase.this.getColor()); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea()); - renderTextField(); - } - }; + new SpeciesSearch(this, y, system); y += 22; new Panel(this, 3, y - 1, getWidth() - 6, getHeight() - y - 8 + 2, MinecraftGUI.PanelType.TAB_OUTLINE).setColor(getColor()); boolean textView = false; @@ -86,41 +59,12 @@ public class AnalystPageDatabase extends Control implements ITitledWidget { String maturation = system.getAlleleName(EnumTreeChromosome.MATURATION, system.getIndividual(species.getUID()).getGenome().getActiveAllele(EnumTreeChromosome.MATURATION)); } if (textView) { - scroll = new ControlListBox(this, 4, y, getWidth() - 8, getHeight() - y - 8 - 20, 0) { - @Override - public void initialise() { - super.initialise(); - setOptions(options); - } - - @Override - public IWidget createOption(IAlleleSpecies v, int y) { - return new Control(getContent(), 0, y, getWidth(), 12) { - IAlleleSpecies value = v; - - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - RenderUtil.drawText(getArea(), TextJustification.MIDDLE_CENTER, value.getAlleleName(), 16777215); - } - }; - } - }; + scroll = new Scroll(this, y, options); } else { scroll = new ControlScrollableContent(this, 4, y, getWidth() - 8, getHeight() - y - 8, 0); scroll.setScrollableContent(getItemScrollList(system, options)); } - new ControlScrollBar(this, scroll.getXPos() + scroll.getWidth() - 6, scroll.getYPos() + 3, 3, scroll.getHeight() - 6, scroll) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - if (!isEnabled()) { - return; - } - RenderUtil.drawGradientRect(getArea(), 1140850688 + AnalystPageDatabase.this.getColor(), 1140850688 + AnalystPageDatabase.this.getColor()); - RenderUtil.drawSolidRect(getRenderArea(), AnalystPageDatabase.this.getColor()); - } - }; + new DatabaseScrollBar(this); } private static int getColor(IBreedingSystem system){ @@ -137,49 +81,7 @@ public class AnalystPageDatabase extends Control implements ITitledWidget { } private IWidget getItemScrollList(IBreedingSystem system, Collection options) { - return new Control(scroll, 0, 0, scroll.getWidth(), scroll.getHeight()) { - @Override - public void initialise() { - int maxBiomePerLine = (getWidth() - 4 + 2) / 18; - int biomeListX = -6 + (getWidth() - (maxBiomePerLine * 18 - 2)) / 2; - int dx = 0; - int dy = 0; - for (IAlleleSpecies species : options) { - IIndividual ind = system.getSpeciesRoot().templateAsIndividual(system.getSpeciesRoot().getTemplate(species)); - new ControlIndividualDisplay(this, biomeListX + dx, 2 + dy, ind) { - @Override - public void initialise() { - addSelfEventHandler(EventMouse.Down.class, event -> { - WindowAnalyst window = (WindowAnalyst) AnalystPageDatabase.this.getTopParent(); - window.setIndividual(ind); - }); - } - - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - WindowAnalyst window = (WindowAnalyst) AnalystPageDatabase.this.getTopParent(); - if (window.getIndividual() != null && window.getIndividual().getGenome().getPrimary() == species) { - RenderUtil.setColour(15658734); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_SOLID, getArea().outset(1)); - RenderUtil.setColour(AnalystPageDatabase.this.getColor()); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea().outset(1)); - } else if (calculateIsMouseOver()) { - RenderUtil.setColour(15658734); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_SOLID, getArea().outset(1)); - } - super.onRenderBackground(guiWidth, guiHeight); - } - }; - dx += 18; - if (dx >= 18 * maxBiomePerLine) { - dx = 0; - dy += 18; - } - } - setSize(new Point(getWidth(), 4 + dy + 18)); - } - }; + return new ItemScrollList(this, options, system); } @Override @@ -192,4 +94,162 @@ public class AnalystPageDatabase extends Control implements ITitledWidget { species.addAll(isMaster ? system.getAllSpecies() : system.getDiscoveredSpecies(getWindow().getWorld(), getWindow().getPlayer().getGameProfile())); return species; } + + private static class Scroll extends ControlListBox { + private final Collection options; + + public Scroll(AnalystPageDatabase analystPageDatabase, int y, Collection options) { + super(analystPageDatabase, 4, y, analystPageDatabase.getWidth() - 8, analystPageDatabase.getHeight() - y - 8 - 20, 0); + this.options = options; + } + + @Override + public void initialise() { + super.initialise(); + setOptions(options); + } + + @Override + public IWidget createOption(IAlleleSpecies v, int y) { + return new ScrollOption(this, y, v); + } + + private static class ScrollOption extends Control { + private final IAlleleSpecies v; + IAlleleSpecies value; + + public ScrollOption(Scroll scroll, int y, IAlleleSpecies v) { + super(scroll.getContent(), 0, y, scroll.getWidth(), 12); + this.v = v; + value = v; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + RenderUtil.drawText(getArea(), TextJustification.MIDDLE_CENTER, value.getAlleleName(), 16777215); + } + } + } + + private static class SpeciesSearch extends ControlTextEdit { + private final IBreedingSystem system; + private AnalystPageDatabase analystPageDatabase; + + public SpeciesSearch(AnalystPageDatabase analystPageDatabase, int y, IBreedingSystem system) { + super(analystPageDatabase, 20, y, analystPageDatabase.getWidth() - 40, 16); + this.system = system; + this.analystPageDatabase = analystPageDatabase; + } + + @Override + public void onTextEdit(String value) { + Collection options = new ArrayList<>(); + analystPageDatabase.getSpecies(system); + for (IAlleleSpecies species : analystPageDatabase.getSpecies(system)) { + if (value == null || Objects.equals(value, "") || species.getAlleleName().toLowerCase().contains(value.toLowerCase())) { + options.add(species); + } + } + analystPageDatabase.scroll.deleteAllChildren(); + analystPageDatabase.scroll.setScrollableContent(analystPageDatabase.getItemScrollList(system, options)); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + RenderUtil.setColour(5592405); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_SOLID, getArea().inset(1)); + RenderUtil.setColour(analystPageDatabase.getColor()); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea()); + renderTextField(); + } + } + + private static class DatabaseScrollBar extends ControlScrollBar { + private AnalystPageDatabase analystPageDatabase; + + public DatabaseScrollBar(AnalystPageDatabase analystPageDatabase) { + super(analystPageDatabase, analystPageDatabase.scroll.getXPos() + analystPageDatabase.scroll.getWidth() - 6, analystPageDatabase.scroll.getYPos() + 3, 3, analystPageDatabase.scroll.getHeight() - 6, analystPageDatabase.scroll); + this.analystPageDatabase = analystPageDatabase; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + if (!isEnabled()) { + return; + } + RenderUtil.drawGradientRect(getArea(), 1140850688 + analystPageDatabase.getColor(), 1140850688 + analystPageDatabase.getColor()); + RenderUtil.drawSolidRect(getRenderArea(), analystPageDatabase.getColor()); + } + } + + private static class ItemScrollList extends Control { + private final Collection options; + private final IBreedingSystem system; + private AnalystPageDatabase analystPageDatabase; + + public ItemScrollList(final AnalystPageDatabase analystPageDatabase, Collection options, IBreedingSystem system) { + super(analystPageDatabase.scroll, 0, 0, analystPageDatabase.scroll.getWidth(), analystPageDatabase.scroll.getHeight()); + this.options = options; + this.system = system; + this.analystPageDatabase = analystPageDatabase; + } + + @Override + public void initialise() { + int maxBiomePerLine = (getWidth() - 4 + 2) / 18; + int biomeListX = -6 + (getWidth() - (maxBiomePerLine * 18 - 2)) / 2; + int dx = 0; + int dy = 0; + for (IAlleleSpecies species : options) { + IIndividual ind = system.getSpeciesRoot().templateAsIndividual(system.getSpeciesRoot().getTemplate(species)); + new SpeciesIndividualDisplay(this, biomeListX, dx, dy, ind, species); + dx += 18; + if (dx >= 18 * maxBiomePerLine) { + dx = 0; + dy += 18; + } + } + setSize(new Point(getWidth(), 4 + dy + 18)); + } + + private static class SpeciesIndividualDisplay extends ControlIndividualDisplay { + private final IIndividual ind; + private final IAlleleSpecies species; + private ItemScrollList itemScrollList; + + public SpeciesIndividualDisplay(ItemScrollList itemScrollList, int biomeListX, int dx, int dy, IIndividual ind, IAlleleSpecies species) { + super(itemScrollList, biomeListX + dx, 2 + dy, ind); + this.ind = ind; + this.species = species; + this.itemScrollList = itemScrollList; + } + + @Override + public void initialise() { + addSelfEventHandler(EventMouse.Down.class, event -> { + WindowAnalyst window = (WindowAnalyst) itemScrollList.analystPageDatabase.getTopParent(); + window.setIndividual(ind); + }); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + WindowAnalyst window = (WindowAnalyst) itemScrollList.analystPageDatabase.getTopParent(); + if (window.getIndividual() != null && window.getIndividual().getGenome().getPrimary() == species) { + RenderUtil.setColour(15658734); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_SOLID, getArea().outset(1)); + RenderUtil.setColour(itemScrollList.analystPageDatabase.getColor()); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea().outset(1)); + } else if (calculateIsMouseOver()) { + RenderUtil.setColour(15658734); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_SOLID, getArea().outset(1)); + } + super.onRenderBackground(guiWidth, guiHeight); + } + } + } } diff --git a/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageGenome.java b/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageGenome.java index 3ed099fc..bfb62861 100644 --- a/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageGenome.java +++ b/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPageGenome.java @@ -42,21 +42,7 @@ public class AnalystPageGenome extends Control implements ITitledWidget { y += 16; ISpeciesRoot root = AlleleManager.alleleRegistry.getSpeciesRoot(ind); IBreedingSystem system = Binnie.GENETICS.getSystem(root); - Control scaled = new Control(this, 0, y, 0, 0) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - GlStateManager.pushMatrix(); - GlStateManager.translate(10.0f, -15.0f, 0.0f); - GlStateManager.scale(0.9f, 0.95f, 1.0f); - } - - @Override - @SideOnly(Side.CLIENT) - public void onRenderForeground(int guiWidth, int guiHeight) { - GlStateManager.popMatrix(); - } - }; + Control scaled = new Scaled(this, y); for (IChromosomeType chromo : system.getActiveKaryotype()) { IAllele allele = active ? ind.getGenome().getActiveAllele(chromo) : ind.getGenome().getInactiveAllele(chromo); String alleleName = system.getAlleleName(chromo, allele); @@ -78,4 +64,24 @@ public class AnalystPageGenome extends Control implements ITitledWidget { } return I18N.localise(AnalystConstants.GENOME_KEY + ".title", I18N.localise(stateKey)); } + + private static class Scaled extends Control { + public Scaled(AnalystPageGenome analystPageGenome, int y) { + super(analystPageGenome, 0, y, 0, 0); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + GlStateManager.pushMatrix(); + GlStateManager.translate(10.0f, -15.0f, 0.0f); + GlStateManager.scale(0.9f, 0.95f, 1.0f); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderForeground(int guiWidth, int guiHeight) { + GlStateManager.popMatrix(); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPanel.java b/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPanel.java index 26432430..e5aca27d 100644 --- a/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPanel.java +++ b/genetics/src/main/java/binnie/genetics/gui/analyst/AnalystPanel.java @@ -21,56 +21,10 @@ public class AnalystPanel extends Panel { this.window = window; setColor(4473924); int sectionWidth = (getWidth() - 8 - 4) / 2; - window.leftPage = new ControlScrollableContent(this, 3, 3, sectionWidth + 2, getHeight() - 8 + 2, 0) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - if (getContent() == null) { - return; - } - RenderUtil.setColour(getContent().getColor()); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea()); - } - }; - new ControlScrollBar(this, sectionWidth + 2 - 3, 6, 3, getHeight() - 8 + 2 - 6, window.leftPage) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - if (!isEnabled()) { - return; - } - if (window.leftPage.getContent() == null) { - return; - } - RenderUtil.drawGradientRect(getArea(), 1140850688 + window.leftPage.getContent().getColor(), 1140850688 + window.leftPage.getContent().getColor()); - RenderUtil.drawSolidRect(getRenderArea(), window.leftPage.getContent().getColor()); - } - }; - window.rightPage = new ControlScrollableContent(this, 3 + sectionWidth + 4, 3, sectionWidth + 2, getHeight() - 8 + 2, 0) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - if (getContent() == null) { - return; - } - RenderUtil.setColour(getContent().getColor()); - CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea()); - } - }; - new ControlScrollBar(this, sectionWidth + 2 - 3 + sectionWidth + 4, 6, 3, getHeight() - 8 + 2 - 6, window.rightPage) { - @Override - @SideOnly(Side.CLIENT) - public void onRenderBackground(int guiWidth, int guiHeight) { - if (!isEnabled()) { - return; - } - if (window.rightPage.getContent() == null) { - return; - } - RenderUtil.drawGradientRect(getArea(), 1140850688 + window.rightPage.getContent().getColor(), 1140850688 + window.rightPage.getContent().getColor()); - RenderUtil.drawSolidRect(getRenderArea(), window.rightPage.getContent().getColor()); - } - }; + window.leftPage = new LeftPage(this, sectionWidth); + new LeftPageScrollBar(this, sectionWidth, window); + window.rightPage = new RightPage(this, sectionWidth); + new RightPageScrollBar(this, sectionWidth, window); window.analystPageSize = new Area(1, 1, sectionWidth, getHeight() - 8); } @@ -80,4 +34,80 @@ public class AnalystPanel extends Panel { RenderUtil.drawGradientRect(getArea(), 1157627903, 1728053247); super.onRenderBackground(guiWidth, guiHeight); } + + private static class LeftPage extends ControlScrollableContent { + public LeftPage(AnalystPanel analystPanel, int sectionWidth) { + super(analystPanel, 3, 3, sectionWidth + 2, analystPanel.getHeight() - 8 + 2, 0); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + if (getContent() == null) { + return; + } + RenderUtil.setColour(getContent().getColor()); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea()); + } + } + + private static class LeftPageScrollBar extends ControlScrollBar { + private final WindowAnalyst window; + + public LeftPageScrollBar(AnalystPanel analystPanel, int sectionWidth, WindowAnalyst window) { + super(analystPanel, sectionWidth + 2 - 3, 6, 3, analystPanel.getHeight() - 8 + 2 - 6, window.leftPage); + this.window = window; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + if (!isEnabled()) { + return; + } + if (window.leftPage.getContent() == null) { + return; + } + RenderUtil.drawGradientRect(getArea(), 1140850688 + window.leftPage.getContent().getColor(), 1140850688 + window.leftPage.getContent().getColor()); + RenderUtil.drawSolidRect(getRenderArea(), window.leftPage.getContent().getColor()); + } + } + + private static class RightPage extends ControlScrollableContent { + public RightPage(AnalystPanel analystPanel, int sectionWidth) { + super(analystPanel, 3 + sectionWidth + 4, 3, sectionWidth + 2, analystPanel.getHeight() - 8 + 2, 0); + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + if (getContent() == null) { + return; + } + RenderUtil.setColour(getContent().getColor()); + CraftGUI.RENDER.texture(CraftGUITexture.TAB_OUTLINE, getArea()); + } + } + + private static class RightPageScrollBar extends ControlScrollBar { + private final WindowAnalyst window; + + public RightPageScrollBar(AnalystPanel analystPanel, int sectionWidth, WindowAnalyst window) { + super(analystPanel, sectionWidth + 2 - 3 + sectionWidth + 4, 6, 3, analystPanel.getHeight() - 8 + 2 - 6, window.rightPage); + this.window = window; + } + + @Override + @SideOnly(Side.CLIENT) + public void onRenderBackground(int guiWidth, int guiHeight) { + if (!isEnabled()) { + return; + } + if (window.rightPage.getContent() == null) { + return; + } + RenderUtil.drawGradientRect(getArea(), 1140850688 + window.rightPage.getContent().getColor(), 1140850688 + window.rightPage.getContent().getColor()); + RenderUtil.drawSolidRect(getRenderArea(), window.rightPage.getContent().getColor()); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/gui/analyst/WindowAnalyst.java b/genetics/src/main/java/binnie/genetics/gui/analyst/WindowAnalyst.java index abbceb2f..e927ffe4 100644 --- a/genetics/src/main/java/binnie/genetics/gui/analyst/WindowAnalyst.java +++ b/genetics/src/main/java/binnie/genetics/gui/analyst/WindowAnalyst.java @@ -87,12 +87,7 @@ public class WindowAnalyst extends Window { private void setupValidators() { if (!isDatabase) { - getWindowInventory().setValidator(0, new SlotValidator.Individual() { - @Override - public boolean isValid(ItemStack itemStack) { - return ManagerGenetics.isAnalysed(itemStack) || (ManagerGenetics.isAnalysable(itemStack) && !getWindowInventory().getStackInSlot(1).isEmpty()); - } - }); + getWindowInventory().setValidator(0, new AnalystSlotValidator(this)); getWindowInventory().setValidator(1, new SlotValidator.Item(GeneticsItems.DNADye.get(1), ModuleMachine.spriteDye)); } } @@ -151,13 +146,7 @@ public class WindowAnalyst extends Window { } }); if (!isDatabase) { - analystNone = new Control(analystPanel, 0, 0, analystPanel.getWidth(), analystPanel.getHeight()) { - @Override - public void initialise() { - new ControlTextCentered(this, 20, I18N.localise("genetics.gui.analyst.desc")).setColor(4473924); - new ControlPlayerInventory(this); - } - }; + analystNone = new AnalystNoneControl(this); } setIndividual(null); @@ -340,4 +329,38 @@ public class WindowAnalyst extends Window { current = null; updatePages(true); } + + private static class AnalystSlotValidator extends SlotValidator.Individual { + private WindowAnalyst windowAnalyst; + + public AnalystSlotValidator(WindowAnalyst windowAnalyst) { + this.windowAnalyst = windowAnalyst; + } + + @Override + public boolean isValid(ItemStack itemStack) { + if (ManagerGenetics.isAnalysed(itemStack)) { + return true; + } + if (ManagerGenetics.isAnalysable(itemStack)) { + WindowInventory windowInventory = windowAnalyst.getWindowInventory(); + if (!windowInventory.getStackInSlot(1).isEmpty()) { + return true; + } + } + return false; + } + } + + private static class AnalystNoneControl extends Control { + public AnalystNoneControl(WindowAnalyst windowAnalyst) { + super(windowAnalyst.analystPanel, 0, 0, windowAnalyst.analystPanel.getWidth(), windowAnalyst.analystPanel.getHeight()); + } + + @Override + public void initialise() { + new ControlTextCentered(this, 20, I18N.localise("genetics.gui.analyst.desc")).setColor(4473924); + new ControlPlayerInventory(this); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/gui/analyst/tree/AnalystPageClimate.java b/genetics/src/main/java/binnie/genetics/gui/analyst/tree/AnalystPageClimate.java index 1f8a6ed0..d37f700d 100644 --- a/genetics/src/main/java/binnie/genetics/gui/analyst/tree/AnalystPageClimate.java +++ b/genetics/src/main/java/binnie/genetics/gui/analyst/tree/AnalystPageClimate.java @@ -87,35 +87,47 @@ public class AnalystPageClimate extends Control implement } protected void createTemperatureBar(IWidget parent, int x, int y, int w, int h, EnumTemperature value, forestry.api.genetics.EnumTolerance tol) { - new ControlToleranceBar(parent, x, y, w, h, EnumTemperature.class) { - @Override - protected String getName(EnumTemperature value) { - return value.name; - } - - @Override - protected int getColour(EnumTemperature value) { - return (new int[]{65531, 7912447, 5242672, 16776960, 16753152, 16711680})[value.ordinal() - 1]; - } - }.setValues(value, tol); + new TemperatureBar(parent, x, y, w, h).setValues(value, tol); } protected void createHumidity(IWidget parent, int x, int y, int w, int h, EnumHumidity value, forestry.api.genetics.EnumTolerance tol) { - new ControlToleranceBar(parent, x, y, w, h, EnumHumidity.class) { - @Override - protected String getName(EnumHumidity value) { - return value.name; - } - - @Override - protected int getColour(EnumHumidity value) { - return (new int[]{16770979, 1769216, 3177727})[value.ordinal()]; - } - }.setValues(value, tol); + new HumidityBar(parent, x, y, w, h).setValues(value, tol); } @Override public String getTitle() { return I18N.localise(AnalystConstants.CLIMATE_KEY + ".title"); } + + private static class TemperatureBar extends ControlToleranceBar { + public TemperatureBar(IWidget parent, int x, int y, int w, int h) { + super(parent, x, y, w, h, EnumTemperature.class); + } + + @Override + protected String getName(EnumTemperature value) { + return value.name; + } + + @Override + protected int getColour(EnumTemperature value) { + return (new int[]{65531, 7912447, 5242672, 16776960, 16753152, 16711680})[value.ordinal() - 1]; + } + } + + private static class HumidityBar extends ControlToleranceBar { + public HumidityBar(IWidget parent, int x, int y, int w, int h) { + super(parent, x, y, w, h, EnumHumidity.class); + } + + @Override + protected String getName(EnumHumidity value) { + return value.name; + } + + @Override + protected int getColour(EnumHumidity value) { + return (new int[]{16770979, 1769216, 3177727})[value.ordinal()]; + } + } } diff --git a/genetics/src/main/java/binnie/genetics/machine/EthanolTankValidator.java b/genetics/src/main/java/binnie/genetics/machine/EthanolTankValidator.java new file mode 100644 index 00000000..3ecb50de --- /dev/null +++ b/genetics/src/main/java/binnie/genetics/machine/EthanolTankValidator.java @@ -0,0 +1,18 @@ +package binnie.genetics.machine; + +import binnie.core.machines.inventory.TankValidator; +import forestry.core.fluids.Fluids; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +public class EthanolTankValidator extends TankValidator { + @Override + public String getTooltip() { + return FluidRegistry.getFluidStack(Fluids.BIO_ETHANOL.getTag(), 1).getLocalizedName(); + } + + @Override + public boolean isValid(final FluidStack stack) { + return Fluids.BIO_ETHANOL.getTag().equals(stack.getFluid().getName()); + } +} diff --git a/genetics/src/main/java/binnie/genetics/machine/acclimatiser/PackageAcclimatiser.java b/genetics/src/main/java/binnie/genetics/machine/acclimatiser/PackageAcclimatiser.java index 7e4d0f7a..f065c229 100644 --- a/genetics/src/main/java/binnie/genetics/machine/acclimatiser/PackageAcclimatiser.java +++ b/genetics/src/main/java/binnie/genetics/machine/acclimatiser/PackageAcclimatiser.java @@ -14,6 +14,7 @@ import binnie.core.machines.power.ComponentPowerReceptor; import binnie.genetics.core.GeneticsGUI; import binnie.genetics.machine.ComponentGeneticGUI; import binnie.genetics.machine.GeneticMachine; +import net.minecraft.util.NonNullList; public class PackageAcclimatiser extends GeneticMachine.PackageGeneticBase implements IMachineInformation { public PackageAcclimatiser() { @@ -41,11 +42,9 @@ public class PackageAcclimatiser extends GeneticMachine.PackageGeneticBase imple } final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); transfer.addRestock(Acclimatiser.SLOT_RESERVE, Acclimatiser.SLOT_TARGET, 1); - transfer.addStorage(Acclimatiser.SLOT_TARGET, Acclimatiser.SLOT_DRONE, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - return !Acclimatiser.canAcclimatise(stack, machine.getMachineUtil().getNonEmptyStacks(Acclimatiser.SLOT_ACCLIMATISER)); - } + transfer.addStorage(Acclimatiser.SLOT_TARGET, Acclimatiser.SLOT_DRONE, (stack) -> { + NonNullList stacks = machine.getMachineUtil().getNonEmptyStacks(Acclimatiser.SLOT_ACCLIMATISER); + return !Acclimatiser.canAcclimatise(stack, stacks); }); new ComponentPowerReceptor(machine, 5000); new AcclimatiserLogic(machine); diff --git a/genetics/src/main/java/binnie/genetics/machine/analyser/AnalyserFX.java b/genetics/src/main/java/binnie/genetics/machine/analyser/AnalyserFX.java index 8f4a06e9..805db7cc 100644 --- a/genetics/src/main/java/binnie/genetics/machine/analyser/AnalyserFX.java +++ b/genetics/src/main/java/binnie/genetics/machine/analyser/AnalyserFX.java @@ -3,6 +3,7 @@ package binnie.genetics.machine.analyser; import java.util.Random; import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleManager; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.entity.item.EntityItem; @@ -33,36 +34,8 @@ public class AnalyserFX extends MachineComponent implements IRender.DisplayTick, @Override public void onDisplayTick(World world, BlockPos pos, Random rand) { if (rand.nextFloat() < 1.0f && this.getUtil().getProcess().isInProgress()) { - BinnieCore.getBinnieProxy().getMinecraftInstance().effectRenderer.addEffect(new Particle(world, pos.getX() + 0.5, pos.getY() + 1.3 + rand.nextDouble() * 0.2, pos.getZ() + 0.5, 0.0, 0.0, 0.0) { - double axisX = this.posX; - double axisZ = this.posZ; - double angle = this.rand.nextDouble() * 2.0 * 3.1415; - - { - this.axisX = 0.0; - this.axisZ = 0.0; - this.angle = 0.0; - this.motionX = 0.05 * (this.rand.nextDouble() - 0.5); - this.motionZ = 0.05 * (this.rand.nextDouble() - 0.5); - this.motionY = 0.0; - this.particleMaxAge = 25; - this.particleGravity = 0.05f; - this.canCollide = true; - this.setRBGColorF(0.6f, 0.0f, 1.0f); - } - - @Override - @SideOnly(Side.CLIENT) - public void onUpdate() { - super.onUpdate(); - this.setAlphaF((float) Math.cos(1.57 * this.particleAge / this.particleMaxAge)); - } - - @Override - public int getFXLayer() { - return 0; - } - }); + ParticleManager effectRenderer = BinnieCore.getBinnieProxy().getMinecraftInstance().effectRenderer; + effectRenderer.addEffect(new AnalyserParticle(world, pos, rand)); } } @@ -118,4 +91,39 @@ public class AnalyserFX extends MachineComponent implements IRender.DisplayTick, //this.getMachine().getWorld().markBlockForUpdate(this.getMachine().getTileEntity().xCoord, this.getMachine().getTileEntity().yCoord, this.getMachine().getTileEntity().zCoord); } } + + private static class AnalyserParticle extends Particle { + private double axisX; + private double axisZ; + private double angle; + + public AnalyserParticle(World world, BlockPos pos, Random rand) { + super(world, pos.getX() + 0.5, pos.getY() + 1.3 + rand.nextDouble() * 0.2, pos.getZ() + 0.5, 0.0, 0.0, 0.0); + axisX = this.posX; + axisZ = this.posZ; + angle = this.rand.nextDouble() * 2.0 * 3.1415; + this.axisX = 0.0; + this.axisZ = 0.0; + this.angle = 0.0; + this.motionX = 0.05 * (this.rand.nextDouble() - 0.5); + this.motionZ = 0.05 * (this.rand.nextDouble() - 0.5); + this.motionY = 0.0; + this.particleMaxAge = 25; + this.particleGravity = 0.05f; + this.canCollide = true; + this.setRBGColorF(0.6f, 0.0f, 1.0f); + } + + @Override + @SideOnly(Side.CLIENT) + public void onUpdate() { + super.onUpdate(); + this.setAlphaF((float) Math.cos(1.57 * this.particleAge / this.particleMaxAge)); + } + + @Override + public int getFXLayer() { + return 0; + } + } } diff --git a/genetics/src/main/java/binnie/genetics/machine/analyser/PackageAnalyser.java b/genetics/src/main/java/binnie/genetics/machine/analyser/PackageAnalyser.java index 257dfa93..17a8e264 100644 --- a/genetics/src/main/java/binnie/genetics/machine/analyser/PackageAnalyser.java +++ b/genetics/src/main/java/binnie/genetics/machine/analyser/PackageAnalyser.java @@ -37,29 +37,14 @@ public class PackageAnalyser extends GeneticMachine.PackageGeneticBase implement slotTarget.forbidInteraction(); InventorySlot slotDye = inventory.addSlot(Analyser.SLOT_DYE, "dye"); slotDye.forbidExtraction(); - slotDye.setValidator(new SlotValidator(ModuleMachine.spriteDye) { - @Override - public boolean isValid(final ItemStack itemStack) { - return itemStack.isItemEqual(GeneticsItems.DNADye.get(1)); - } - - @Override - public String getTooltip() { - return GeneticsItems.DNADye.get(1).getDisplayName(); - } - }); + slotDye.setValidator(new DyeSlotValidator()); for (InventorySlot slot : inventory.addSlotArray(Analyser.SLOT_FINISHED, "output")) { slot.forbidInsertion(); slot.setReadOnly(); } ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); transfer.addRestock(Analyser.SLOT_RESERVE, 6, 1); - transfer.addStorage(6, Analyser.SLOT_FINISHED, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - return ManagerGenetics.isAnalysed(stack); - } - }); + transfer.addStorage(6, Analyser.SLOT_FINISHED, (stack) -> ManagerGenetics.isAnalysed(stack)); new ComponentChargedSlots(machine).addCharge(13); new ComponentPowerReceptor(machine, 500); new AnalyserLogic(machine); @@ -74,4 +59,20 @@ public class PackageAnalyser extends GeneticMachine.PackageGeneticBase implement @Override public void register() { } + + private static class DyeSlotValidator extends SlotValidator { + public DyeSlotValidator() { + super(ModuleMachine.spriteDye); + } + + @Override + public boolean isValid(final ItemStack itemStack) { + return itemStack.isItemEqual(GeneticsItems.DNADye.get(1)); + } + + @Override + public String getTooltip() { + return GeneticsItems.DNADye.get(1).getDisplayName(); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/machine/craftgui/WindowGeneBank.java b/genetics/src/main/java/binnie/genetics/machine/craftgui/WindowGeneBank.java index 8a64822e..70118e17 100644 --- a/genetics/src/main/java/binnie/genetics/machine/craftgui/WindowGeneBank.java +++ b/genetics/src/main/java/binnie/genetics/machine/craftgui/WindowGeneBank.java @@ -110,31 +110,7 @@ public class WindowGeneBank extends WindowMachine { this.genes = new ControlGeneScroll(scroll, 1, 1, geneBoxWidth, 116); scroll.setScrollableContent(this.genes); this.genes.setGenes(Binnie.GENETICS.getFirstActiveSystem()); - final ControlTabBar tabBar = new ControlTabBar(this, boxX, 32, 24, 120, Alignment.LEFT, Binnie.GENETICS.getActiveSystems()) { - @Override - public ControlTab createTab(final int x, final int y, final int w, final int h, final IBreedingSystem value) { - return new ControlTabIcon(this, x, y, w, h, value) { - @Override - public void getTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { - tooltip.add(this.getValue().toString()); - int totalGenes = 0; - int seqGenes = 0; - final GeneTracker tracker = GeneTracker.getTracker(WindowGeneBank.this.getWorld(), WindowGeneBank.this.getUsername()); - final Map> genes = Binnie.GENETICS.getChromosomeMap(this.getValue().getSpeciesRoot()); - for (final Map.Entry> entry : genes.entrySet()) { - totalGenes += entry.getValue().size(); - for (final IAllele allele : entry.getValue()) { - final Gene gene = new Gene(allele, entry.getKey(), this.getValue().getSpeciesRoot()); - if (tracker.isSequenced(gene)) { - ++seqGenes; - } - } - } - tooltip.add("" + seqGenes + "/" + totalGenes + " Genes"); - } - }; - } - }; + final ControlTabBar tabBar = new GeneBankTabBar(this, boxX); tabBar.setValue(Binnie.GENETICS.getFirstActiveSystem()); boxX -= 8; final ControlTabBar infoTabs = new ControlTabBar<>(this, boxX + 8, 160, 16, 50, Alignment.LEFT, Arrays.asList("Info", "Stats", "Ranking")); @@ -187,4 +163,46 @@ public class WindowGeneBank extends WindowMachine { return this.system.getChromosomeName(this.chromosome); } } + + private static class GeneBankTabBar extends ControlTabBar { + private WindowGeneBank windowGeneBank; + + public GeneBankTabBar(final WindowGeneBank windowGeneBank, int boxX) { + super(windowGeneBank, boxX, 32, 24, 120, Alignment.LEFT, Binnie.GENETICS.getActiveSystems()); + this.windowGeneBank = windowGeneBank; + } + + @Override + public ControlTab createTab(final int x, final int y, final int w, final int h, final IBreedingSystem value) { + return new GeneBankTab(this, x, y, w, h, value); + } + + private static class GeneBankTab extends ControlTabIcon { + private GeneBankTabBar geneBankTabBar; + + public GeneBankTab(GeneBankTabBar geneBankTabBar, int x, int y, int w, int h, IBreedingSystem value) { + super(geneBankTabBar, x, y, w, h, value); + this.geneBankTabBar = geneBankTabBar; + } + + @Override + public void getTooltip(final Tooltip tooltip, ITooltipFlag tooltipFlag) { + tooltip.add(this.getValue().toString()); + int totalGenes = 0; + int seqGenes = 0; + final GeneTracker tracker = GeneTracker.getTracker(geneBankTabBar.windowGeneBank.getWorld(), geneBankTabBar.windowGeneBank.getUsername()); + final Map> genes = Binnie.GENETICS.getChromosomeMap(this.getValue().getSpeciesRoot()); + for (final Map.Entry> entry : genes.entrySet()) { + totalGenes += entry.getValue().size(); + for (final IAllele allele : entry.getValue()) { + final Gene gene = new Gene(allele, entry.getKey(), this.getValue().getSpeciesRoot()); + if (tracker.isSequenced(gene)) { + ++seqGenes; + } + } + } + tooltip.add("" + seqGenes + "/" + totalGenes + " Genes"); + } + } + } } diff --git a/genetics/src/main/java/binnie/genetics/machine/genepool/PackageGenepool.java b/genetics/src/main/java/binnie/genetics/machine/genepool/PackageGenepool.java index bab18945..a4acf2dc 100644 --- a/genetics/src/main/java/binnie/genetics/machine/genepool/PackageGenepool.java +++ b/genetics/src/main/java/binnie/genetics/machine/genepool/PackageGenepool.java @@ -1,12 +1,8 @@ package binnie.genetics.machine.genepool; +import binnie.genetics.machine.EthanolTankValidator; import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; - -import forestry.core.fluids.Fluids; - import binnie.core.gui.minecraft.IMachineInformation; import binnie.core.machines.Machine; import binnie.core.machines.TileEntityMachine; @@ -17,7 +13,6 @@ import binnie.core.machines.inventory.ComponentTankContainer; import binnie.core.machines.inventory.InventorySlot; import binnie.core.machines.inventory.SlotValidator; import binnie.core.machines.inventory.TankSlot; -import binnie.core.machines.inventory.TankValidator; import binnie.core.machines.power.ComponentPowerReceptor; import binnie.genetics.core.GeneticsGUI; import binnie.genetics.item.GeneticsItems; @@ -50,17 +45,7 @@ public class PackageGenepool extends GeneticMachine.PackageGeneticBase implement tankDNA.setReadOnly(); TankSlot tankEthanol = tanks.addTank(Genepool.TANK_ETHANOL, "input", 1000); tankEthanol.forbidExtraction(); - tankEthanol.setValidator(new TankValidator() { - @Override - public String getTooltip() { - return FluidRegistry.getFluidStack(Fluids.BIO_ETHANOL.getTag(), 1).getLocalizedName(); - } - - @Override - public boolean isValid(final FluidStack stack) { - return Fluids.BIO_ETHANOL.getTag().equals(stack.getFluid().getName()); - } - }); + tankEthanol.setValidator(new EthanolTankValidator()); ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); transfer.addRestock(Genepool.SLOT_RESERVE, Genepool.SLOT_BEE, 1); new ComponentPowerReceptor(machine, 1600); @@ -78,4 +63,5 @@ public class PackageGenepool extends GeneticMachine.PackageGeneticBase implement @Override public void register() { } + } diff --git a/genetics/src/main/java/binnie/genetics/machine/incubator/Incubator.java b/genetics/src/main/java/binnie/genetics/machine/incubator/Incubator.java index a37514e3..e4115a2d 100644 --- a/genetics/src/main/java/binnie/genetics/machine/incubator/Incubator.java +++ b/genetics/src/main/java/binnie/genetics/machine/incubator/Incubator.java @@ -44,22 +44,8 @@ public class Incubator { Incubator.RECIPES.add(new IncubatorRecipe(new ItemStack(Items.BLAZE_POWDER), GeneticLiquid.Bacteria.get(10), GeneticLiquid.BacteriaVector.get(10), 0.05f)); if (BinnieCore.isApicultureActive()) { final ItemStack beeLarvaeWildcard = Mods.Forestry.stack("bee_larvae_ge", 1, OreDictionary.WILDCARD_VALUE); - Incubator.RECIPES.add(LARVAE_RECIPE = new IncubatorRecipeLarvae(beeLarvaeWildcard, GeneticLiquid.GrowthMedium.get(50), null, 1.0f, 0.05f) { - @Override - public ItemStack getOutputStack(final MachineUtil machine) { - final ItemStack larvae = machine.getStack(3); - final IBee bee = BeeManager.beeRoot.getMember(larvae); - if (bee == null) { - return ItemStack.EMPTY; - } - return BeeManager.beeRoot.getMemberStack(bee, EnumBeeType.DRONE); - } - - @Override - public ItemStack getExpectedOutput() { - return Mods.Forestry.stack("bee_drone_ge", 1, OreDictionary.WILDCARD_VALUE); - } - }); + LARVAE_RECIPE = new IncubatorRecipeLarvae(beeLarvaeWildcard); + Incubator.RECIPES.add(LARVAE_RECIPE); } } diff --git a/genetics/src/main/java/binnie/genetics/machine/incubator/IncubatorRecipeLarvae.java b/genetics/src/main/java/binnie/genetics/machine/incubator/IncubatorRecipeLarvae.java index cb7cadae..2b3fe89d 100644 --- a/genetics/src/main/java/binnie/genetics/machine/incubator/IncubatorRecipeLarvae.java +++ b/genetics/src/main/java/binnie/genetics/machine/incubator/IncubatorRecipeLarvae.java @@ -1,13 +1,32 @@ package binnie.genetics.machine.incubator; -import javax.annotation.Nullable; - +import binnie.core.Mods; +import binnie.core.machines.MachineUtil; +import binnie.genetics.item.GeneticLiquid; +import forestry.api.apiculture.BeeManager; +import forestry.api.apiculture.EnumBeeType; +import forestry.api.apiculture.IBee; import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; public class IncubatorRecipeLarvae extends IncubatorRecipe { - public IncubatorRecipeLarvae(ItemStack itemStack, FluidStack input, @Nullable FluidStack output, float lossChance, float chance) { - super(itemStack, input, output, lossChance, chance); + public IncubatorRecipeLarvae(ItemStack beeLarvaeWildcard) { + super(beeLarvaeWildcard, GeneticLiquid.GrowthMedium.get(50), null, 1.0f, 0.05f); + } + + @Override + public ItemStack getOutputStack(final MachineUtil machine) { + final ItemStack larvae = machine.getStack(3); + final IBee bee = BeeManager.beeRoot.getMember(larvae); + if (bee == null) { + return ItemStack.EMPTY; + } + return BeeManager.beeRoot.getMemberStack(bee, EnumBeeType.DRONE); + } + + @Override + public ItemStack getExpectedOutput() { + return Mods.Forestry.stack("bee_drone_ge", 1, OreDictionary.WILDCARD_VALUE); } } diff --git a/genetics/src/main/java/binnie/genetics/machine/inoculator/PackageInoculator.java b/genetics/src/main/java/binnie/genetics/machine/inoculator/PackageInoculator.java index d9edb0ee..cbc044fb 100644 --- a/genetics/src/main/java/binnie/genetics/machine/inoculator/PackageInoculator.java +++ b/genetics/src/main/java/binnie/genetics/machine/inoculator/PackageInoculator.java @@ -1,5 +1,6 @@ package binnie.genetics.machine.inoculator; +import binnie.core.machines.inventory.TankValidator; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -15,7 +16,6 @@ import binnie.core.machines.inventory.ComponentInventoryTransfer; import binnie.core.machines.inventory.ComponentTankContainer; import binnie.core.machines.inventory.InventorySlot; import binnie.core.machines.inventory.SlotValidator; -import binnie.core.machines.inventory.Validator; import binnie.core.machines.power.ComponentPowerReceptor; import binnie.genetics.api.IItemSerum; import binnie.genetics.core.GeneticsGUI; @@ -37,17 +37,7 @@ public class PackageInoculator extends GeneticMachine.PackageGeneticBase impleme InventorySlot slotSerumVial = inventory.addSlot(Inoculator.SLOT_SERUM_VIAL, "serum.active"); slotSerumVial.forbidInteraction(); slotSerumVial.setReadOnly(); - final SlotValidator serumValid = new SlotValidator(ModuleMachine.spriteSerum) { - @Override - public boolean isValid(final ItemStack itemStack) { - return itemStack.getItem() instanceof IItemSerum; - } - - @Override - public String getTooltip() { - return "Serum Vials & Arrays"; - } - }; + final SlotValidator serumValid = new SerumSlotValidator(); slotSerumVial.setValidator(serumValid); for (InventorySlot slot : inventory.addSlotArray(Inoculator.SLOT_SERUM_RESERVE, "serum.input")) { slot.setValidator(serumValid); @@ -73,39 +63,21 @@ public class PackageInoculator extends GeneticMachine.PackageGeneticBase impleme final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); transfer.addRestock(Inoculator.SLOT_RESERVE, 9, 1); transfer.addRestock(Inoculator.SLOT_SERUM_RESERVE, 0); - transfer.addStorage(Inoculator.SLOT_SERUM_VIAL, Inoculator.SLOT_SERUM_EXPENDED, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - return Engineering.getCharges(stack) == 0; - } - }); - transfer.addStorage(Inoculator.SLOT_TARGET, Inoculator.SLOT_FINISHED, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - if (!stack.isEmpty()) { - IMachine machine = this.transfer.getMachine(); - MachineUtil machineUtil = machine.getMachineUtil(); - if (!machineUtil.getStack(Inoculator.SLOT_SERUM_VIAL).isEmpty() && machine.getInterface(InoculatorLogic.class).isValidSerum() != null) { - return true; - } + transfer.addStorage(Inoculator.SLOT_SERUM_VIAL, Inoculator.SLOT_SERUM_EXPENDED, (stack) -> Engineering.getCharges(stack) == 0); + transfer.addStorage(Inoculator.SLOT_TARGET, Inoculator.SLOT_FINISHED, (stack) -> { + if (!stack.isEmpty()) { + IMachine machine1 = transfer.getMachine(); + MachineUtil machineUtil = machine1.getMachineUtil(); + if (!machineUtil.getStack(Inoculator.SLOT_SERUM_VIAL).isEmpty() && machine1.getInterface(InoculatorLogic.class).isValidSerum() != null) { + return true; } - return false; } + return false; }); new ComponentPowerReceptor(machine, 15000); new InoculatorLogic(machine); new InoculatorFX(machine); - new ComponentTankContainer(machine).addTank(Inoculator.TANK_VEKTOR, "input", 1000).setValidator(new Validator() { - @Override - public boolean isValid(final FluidStack object) { - return GeneticLiquid.BacteriaVector.get(1).isFluidEqual(object); - } - - @Override - public String getTooltip() { - return GeneticLiquid.BacteriaVector.toString(); - } - }); + new ComponentTankContainer(machine).addTank(Inoculator.TANK_VEKTOR, "input", 1000).setValidator(new BacteriaVectorTankValidator()); } @Override @@ -116,4 +88,32 @@ public class PackageInoculator extends GeneticMachine.PackageGeneticBase impleme @Override public void register() { } + + private static class SerumSlotValidator extends SlotValidator { + public SerumSlotValidator() { + super(ModuleMachine.spriteSerum); + } + + @Override + public boolean isValid(final ItemStack itemStack) { + return itemStack.getItem() instanceof IItemSerum; + } + + @Override + public String getTooltip() { + return "Serum Vials & Arrays"; + } + } + + private static class BacteriaVectorTankValidator extends TankValidator { + @Override + public boolean isValid(final FluidStack object) { + return GeneticLiquid.BacteriaVector.get(1).isFluidEqual(object); + } + + @Override + public String getTooltip() { + return GeneticLiquid.BacteriaVector.toString(); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/machine/isolator/PackageIsolator.java b/genetics/src/main/java/binnie/genetics/machine/isolator/PackageIsolator.java index 73f743a3..57b168dd 100644 --- a/genetics/src/main/java/binnie/genetics/machine/isolator/PackageIsolator.java +++ b/genetics/src/main/java/binnie/genetics/machine/isolator/PackageIsolator.java @@ -2,6 +2,7 @@ package binnie.genetics.machine.isolator; import java.util.Objects; +import binnie.genetics.machine.EthanolTankValidator; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.fluids.FluidRegistry; @@ -57,17 +58,7 @@ public class PackageIsolator extends GeneticMachine.PackageGeneticBase implement slot.forbidInsertion(); } final ComponentTankContainer tanks = new ComponentTankContainer(machine); - tanks.addTank(Isolator.TANK_ETHANOL, "input", 1000).setValidator(new TankValidator() { - @Override - public String getTooltip() { - return FluidRegistry.getFluidStack(Fluids.BIO_ETHANOL.getTag(), 1).getLocalizedName(); - } - - @Override - public boolean isValid(final FluidStack stack) { - return Objects.equals(stack.getFluid().getName(), Fluids.BIO_ETHANOL.getTag()); - } - }); + tanks.addTank(Isolator.TANK_ETHANOL, "input", 1000).setValidator(new EthanolTankValidator()); final ComponentChargedSlots chargedSlots = new ComponentChargedSlots(machine); chargedSlots.addCharge(Isolator.SLOT_ENZYME); final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); diff --git a/genetics/src/main/java/binnie/genetics/machine/polymeriser/PackagePolymeriser.java b/genetics/src/main/java/binnie/genetics/machine/polymeriser/PackagePolymeriser.java index 8af69296..73017479 100644 --- a/genetics/src/main/java/binnie/genetics/machine/polymeriser/PackagePolymeriser.java +++ b/genetics/src/main/java/binnie/genetics/machine/polymeriser/PackagePolymeriser.java @@ -1,5 +1,6 @@ package binnie.genetics.machine.polymeriser; +import binnie.core.machines.inventory.TankValidator; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; @@ -51,35 +52,10 @@ public class PackagePolymeriser extends GeneticMachine.PackageGeneticBase implem } ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); transfer.addRestock(Polymeriser.SLOT_SERUM_RESERVE, Polymeriser.SLOT_SERUM, 1); - transfer.addStorage(Polymeriser.SLOT_SERUM, Polymeriser.SLOT_SERUM_FINISHED, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - return !stack.isItemDamaged(); - } - }); + transfer.addStorage(Polymeriser.SLOT_SERUM, Polymeriser.SLOT_SERUM_FINISHED, (stack) -> !stack.isItemDamaged()); ComponentTankContainer tank = new ComponentTankContainer(machine); - tank.addTank(Polymeriser.TANK_BACTERIA, "input", 1000).setValidator(new Validator() { - @Override - public boolean isValid(final FluidStack itemStack) { - return GeneticLiquid.BacteriaPoly.get(1).isFluidEqual(itemStack); - } - - @Override - public String getTooltip() { - return GeneticLiquid.BacteriaPoly.get(1).getLocalizedName(); - } - }); - tank.addTank(Polymeriser.TANK_DNA, "input", 1000).setValidator(new Validator() { - @Override - public boolean isValid(final FluidStack itemStack) { - return GeneticLiquid.RawDNA.get(1).isFluidEqual(itemStack); - } - - @Override - public String getTooltip() { - return GeneticLiquid.RawDNA.get(1).getLocalizedName(); - } - }); + tank.addTank(Polymeriser.TANK_BACTERIA, "input", 1000).setValidator(new BacteriaTankValidator()); + tank.addTank(Polymeriser.TANK_DNA, "input", 1000).setValidator(new DnaTankValidator()); new ComponentChargedSlots(machine).addCharge(1); new ComponentPowerReceptor(machine, 8000); new PolymeriserLogic(machine); @@ -94,4 +70,28 @@ public class PackagePolymeriser extends GeneticMachine.PackageGeneticBase implem @Override public void register() { } + + private static class BacteriaTankValidator extends TankValidator { + @Override + public boolean isValid(final FluidStack itemStack) { + return GeneticLiquid.BacteriaPoly.get(1).isFluidEqual(itemStack); + } + + @Override + public String getTooltip() { + return GeneticLiquid.BacteriaPoly.get(1).getLocalizedName(); + } + } + + private static class DnaTankValidator extends TankValidator { + @Override + public boolean isValid(final FluidStack itemStack) { + return GeneticLiquid.RawDNA.get(1).isFluidEqual(itemStack); + } + + @Override + public String getTooltip() { + return GeneticLiquid.RawDNA.get(1).getLocalizedName(); + } + } } \ No newline at end of file diff --git a/genetics/src/main/java/binnie/genetics/machine/splicer/PackageSplicer.java b/genetics/src/main/java/binnie/genetics/machine/splicer/PackageSplicer.java index f0cd0958..25ecd43f 100644 --- a/genetics/src/main/java/binnie/genetics/machine/splicer/PackageSplicer.java +++ b/genetics/src/main/java/binnie/genetics/machine/splicer/PackageSplicer.java @@ -33,17 +33,7 @@ public class PackageSplicer extends AdvGeneticMachine.PackageAdvGeneticBase impl InventorySlot slotSerumVial = inventory.addSlot(Splicer.SLOT_SERUM_VIAL, "serum.active"); slotSerumVial.forbidInteraction(); slotSerumVial.setReadOnly(); - final SlotValidator serumValid = new SlotValidator(ModuleMachine.spriteSerum) { - @Override - public boolean isValid(final ItemStack itemStack) { - return itemStack.getItem() instanceof IItemSerum; - } - - @Override - public String getTooltip() { - return I18N.localise("genetics.machine.adv_machine.splicer.tooltips.slots.serum"); - } - }; + final SlotValidator serumValid = new SerumSlotValidator(); slotSerumVial.setValidator(serumValid); for (InventorySlot slot : inventory.addSlotArray(Splicer.SLOT_SERUM_RESERVE, "serum.input")) { slot.setValidator(serumValid); @@ -69,24 +59,16 @@ public class PackageSplicer extends AdvGeneticMachine.PackageAdvGeneticBase impl final ComponentInventoryTransfer transfer = new ComponentInventoryTransfer(machine); transfer.addRestock(Splicer.SLOT_RESERVE, Splicer.SLOT_TARGET, 1); transfer.addRestock(Splicer.SLOT_SERUM_RESERVE, Splicer.SLOT_SERUM_VIAL); - transfer.addStorage(Splicer.SLOT_SERUM_VIAL, Splicer.SLOT_SERUM_EXPENDED, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - return Engineering.getCharges(stack) == 0; - } - }); - transfer.addStorage(Splicer.SLOT_TARGET, Splicer.SLOT_FINISHED, new ComponentInventoryTransfer.Condition() { - @Override - public boolean fulfilled(final ItemStack stack) { - if (!stack.isEmpty()) { - IMachine machine = this.transfer.getMachine(); - MachineUtil machineUtil = machine.getMachineUtil(); - if (!machineUtil.getStack(Splicer.SLOT_SERUM_VIAL).isEmpty() && machine.getInterface(SplicerLogic.class).isValidSerum() != null) { - return true; - } + transfer.addStorage(Splicer.SLOT_SERUM_VIAL, Splicer.SLOT_SERUM_EXPENDED, (stack) -> Engineering.getCharges(stack) == 0); + transfer.addStorage(Splicer.SLOT_TARGET, Splicer.SLOT_FINISHED, (stack) -> { + if (!stack.isEmpty()) { + IMachine machine1 = transfer.getMachine(); + MachineUtil machineUtil = machine1.getMachineUtil(); + if (!machineUtil.getStack(Splicer.SLOT_SERUM_VIAL).isEmpty() && machine1.getInterface(SplicerLogic.class).isValidSerum() != null) { + return true; } - return false; } + return false; }); new ComponentPowerReceptor(machine, 20000); new SplicerLogic(machine); @@ -101,4 +83,20 @@ public class PackageSplicer extends AdvGeneticMachine.PackageAdvGeneticBase impl @Override public void register() { } + + private static class SerumSlotValidator extends SlotValidator { + public SerumSlotValidator() { + super(ModuleMachine.spriteSerum); + } + + @Override + public boolean isValid(final ItemStack itemStack) { + return itemStack.getItem() instanceof IItemSerum; + } + + @Override + public String getTooltip() { + return I18N.localise("genetics.machine.adv_machine.splicer.tooltips.slots.serum"); + } + } } diff --git a/genetics/src/main/java/binnie/genetics/machine/splicer/SplicerFX.java b/genetics/src/main/java/binnie/genetics/machine/splicer/SplicerFX.java index fceb3a11..eaf661d3 100644 --- a/genetics/src/main/java/binnie/genetics/machine/splicer/SplicerFX.java +++ b/genetics/src/main/java/binnie/genetics/machine/splicer/SplicerFX.java @@ -3,6 +3,7 @@ package binnie.genetics.machine.splicer; import java.util.Random; import net.minecraft.client.particle.Particle; +import net.minecraft.client.particle.ParticleManager; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; import net.minecraft.entity.item.EntityItem; @@ -34,40 +35,8 @@ public class SplicerFX extends MachineComponent implements IRender.DisplayTick, public void onDisplayTick(World world, BlockPos pos, Random rand) { final int tick = (int) (world.getTotalWorldTime() % 3L); if (tick == 0 && this.getUtil().getProcess().isInProgress()) { - BinnieCore.getBinnieProxy().getMinecraftInstance().effectRenderer.addEffect(new Particle(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, 0.0, 0.0, 0.0) { - double axisX = this.posX; - double axisZ = this.posZ; - double angle = (int) (this.world.getTotalWorldTime() % 4L) * 0.5 * 3.1415; - - { - this.axisX = 0.0; - this.axisZ = 0.0; - this.angle = 0.0; - this.motionX = 0.0; - this.motionZ = 0.0; - this.motionY = (this.rand.nextDouble() - 0.5) * 0.02; - this.particleMaxAge = 240; - this.particleGravity = 0.0f; - this.canCollide = true; - this.setRBGColorF(0.3f + this.rand.nextFloat() * 0.5f, 0.3f + this.rand.nextFloat() * 0.5f, 0.0f); - } - - @Override - @SideOnly(Side.CLIENT) - public void onUpdate() { - super.onUpdate(); - final double speed = 0.04; - this.angle -= speed; - final double dist = 0.25 + 0.2 * Math.sin(this.particleAge / 50.0f); - this.setPosition(this.axisX + dist * Math.sin(this.angle), this.posY, this.axisZ + dist * Math.cos(this.angle)); - this.setAlphaF((float) Math.cos(1.57 * this.particleAge / this.particleMaxAge)); - } - - @Override - public int getFXLayer() { - return 0; - } - }); + ParticleManager effectRenderer = BinnieCore.getBinnieProxy().getMinecraftInstance().effectRenderer; + effectRenderer.addEffect(new SplicerParticle(world, pos)); } } @@ -123,4 +92,43 @@ public class SplicerFX extends MachineComponent implements IRender.DisplayTick, } this.getUtil().refreshBlock(); } + + private static class SplicerParticle extends Particle { + private double axisX; + private double axisZ; + private double angle; + + public SplicerParticle(World world, BlockPos pos) { + super(world, pos.getX() + 0.5, pos.getY() + 1.5, pos.getZ() + 0.5, 0.0, 0.0, 0.0); + axisX = this.posX; + axisZ = this.posZ; + angle = (int) (this.world.getTotalWorldTime() % 4L) * 0.5 * 3.1415; + this.axisX = 0.0; + this.axisZ = 0.0; + this.angle = 0.0; + this.motionX = 0.0; + this.motionZ = 0.0; + this.motionY = (this.rand.nextDouble() - 0.5) * 0.02; + this.particleMaxAge = 240; + this.particleGravity = 0.0f; + this.canCollide = true; + this.setRBGColorF(0.3f + this.rand.nextFloat() * 0.5f, 0.3f + this.rand.nextFloat() * 0.5f, 0.0f); + } + + @Override + @SideOnly(Side.CLIENT) + public void onUpdate() { + super.onUpdate(); + final double speed = 0.04; + this.angle -= speed; + final double dist = 0.25 + 0.2 * Math.sin(this.particleAge / 50.0f); + this.setPosition(this.axisX + dist * Math.sin(this.angle), this.posY, this.axisZ + dist * Math.cos(this.angle)); + this.setAlphaF((float) Math.cos(1.57 * this.particleAge / this.particleMaxAge)); + } + + @Override + public int getFXLayer() { + return 0; + } + } }