mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 15:36:18 +00:00
Add Guide Book and Analyzer Screen (#2073)
This commit is contained in:
1 parent
b5a8740e4a
commit
8ba478d758
251 files changed
+7985
-2550
No files matched your search
@@ -0,0 +1,50 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
|
||||
/**
|
||||
* The deserialized content data of a book page. It creates a gui element at the moment the entry gets opened.
|
||||
*/
|
||||
public abstract class BookContent<D> {
|
||||
public String type;
|
||||
|
||||
/**
|
||||
* A data object that was deserialized from the json object of this content.
|
||||
* Can be everything from an image to a crafting recipe.
|
||||
*/
|
||||
@Nullable
|
||||
public D data = null;
|
||||
|
||||
/**
|
||||
* The class of the data field. Used for the deserialization. If the result of this method is null the data field
|
||||
* will be null too.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract Class<? extends D> getDataClass();
|
||||
|
||||
/**
|
||||
* Called after the deserialization.
|
||||
*/
|
||||
public void onDeserialization() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the content to the page by adding a {@link IGuiElement} or at the content to the previous element.
|
||||
*
|
||||
* @param page The gui element that represents a book page
|
||||
* @param previous The content of the previous element.
|
||||
* @param previousElement The element that was previously added to the page.
|
||||
* @param pageHeight The max height of the current page.
|
||||
* @return True if you added an element.
|
||||
*/
|
||||
public abstract boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight);
|
||||
}
|
||||
+3
-6
@@ -3,11 +3,8 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core;
|
||||
package forestry.api.book;
|
||||
|
||||
/**
|
||||
* The alignment of the text in a text gui element.
|
||||
*/
|
||||
public enum GuiElementAlignment {
|
||||
LEFT, CENTER, RIGHT
|
||||
public class BookManager {
|
||||
public static IBookLoader loader;
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IBookCategory {
|
||||
/**
|
||||
* @return the {@link ItemStack} that represents this category at the front page.
|
||||
*/
|
||||
ItemStack getStack();
|
||||
|
||||
IBookCategory setStack(ItemStack stack);
|
||||
|
||||
/**
|
||||
* Adds an custom entry to the category.
|
||||
*/
|
||||
IBookCategory addEntry(IBookEntry entry);
|
||||
|
||||
/**
|
||||
* Adds an entry with the given name and the given icon to the category.
|
||||
*
|
||||
* @param name A unique name for this entry.
|
||||
* @param stack The stack that will be displayed next to the entry title at the category page.
|
||||
*/
|
||||
IBookCategory addEntry(String name, ItemStack stack);
|
||||
|
||||
/**
|
||||
* Creates a entry builder with the given name.
|
||||
* <p>
|
||||
* At the end of your creation you have to call {@link IBookEntryBuilder#addToCategory()} to add the entry to this
|
||||
* category.
|
||||
*
|
||||
* @param name A unique name for this entry.
|
||||
*/
|
||||
IBookEntryBuilder createEntry(String name);
|
||||
|
||||
/**
|
||||
* Creates a entry builder with the given name and the given icon.
|
||||
* <p>
|
||||
* At the end of your creation you have to call {@link IBookEntryBuilder#addToCategory()} to add the entry to this
|
||||
* category.
|
||||
*
|
||||
* @param name A unique name for this entry.
|
||||
* @param stack The stack that will be displayed next to the entry title at the category page.
|
||||
*/
|
||||
IBookEntryBuilder createEntry(String name, ItemStack stack);
|
||||
|
||||
/**
|
||||
* @return a collection that contains all entries of this category.
|
||||
*/
|
||||
Collection<IBookEntry> getEntries();
|
||||
|
||||
/**
|
||||
* @return the entry with the given unique name.
|
||||
*/
|
||||
@Nullable
|
||||
IBookEntry getEntry(String name);
|
||||
|
||||
/**
|
||||
* @return the localized name of this category.
|
||||
*/
|
||||
String getLocalizedName();
|
||||
|
||||
/**
|
||||
* Currently unused
|
||||
*/
|
||||
String getTooltip();
|
||||
|
||||
/**
|
||||
* @return the unique name of this category
|
||||
*/
|
||||
String getName();
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
|
||||
public interface IBookContent {
|
||||
/**
|
||||
* Called after the deserialization.
|
||||
*/
|
||||
default void onDeserialization() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the content to the page by adding a {@link IGuiElement} or at the content to the previous element.
|
||||
*
|
||||
* @param page The gui element that represents a book page
|
||||
* @param previous The content of the previous element.
|
||||
* @param previousElement The element that was previously added to the page.
|
||||
* @param pageHeight The max height of the current page.
|
||||
* @return True if you added an element.
|
||||
*/
|
||||
boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* A entry in the {@link IForesterBook}.
|
||||
* <p>
|
||||
* Forestry crates them with the help of json file, but you can add you own custom ones with
|
||||
* {@link IBookCategory#addEntry(IBookEntry)}.
|
||||
*/
|
||||
public interface IBookEntry {
|
||||
|
||||
/**
|
||||
* @return The stack that is displayed before the entry name.
|
||||
*/
|
||||
ItemStack getStack();
|
||||
|
||||
/**
|
||||
* @return A unique string identifier for this entry.
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return the object that creates the book pages at the moment the bock opens.
|
||||
*/
|
||||
IBookPageFactory getPageFactory();
|
||||
|
||||
/**
|
||||
* All sub entries of this entry are reachable over the buttons on the left side of the book.
|
||||
*/
|
||||
IBookEntry[] getSubEntries();
|
||||
|
||||
/**
|
||||
* The parent of the entry if this entry is a sub entry. Null if the entry is no sub entry.
|
||||
*/
|
||||
@Nullable
|
||||
IBookEntry getParent();
|
||||
|
||||
/**
|
||||
* @return the localized title of this entry.
|
||||
*/
|
||||
String getTitle();
|
||||
|
||||
/**
|
||||
* @return the content that was deserialized from the json file of this entry.
|
||||
*/
|
||||
BookContent[][] getContent();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IBookEntryBuilder {
|
||||
|
||||
/**
|
||||
* Sets the content of the entry.
|
||||
*/
|
||||
IBookEntryBuilder setContent(BookContent[][] content);
|
||||
|
||||
/**
|
||||
* Sets the localized name of entry.
|
||||
*/
|
||||
IBookEntryBuilder setTitle(String title);
|
||||
|
||||
IBookEntryBuilder setStack(ItemStack stack);
|
||||
|
||||
IBookEntryBuilder setLoader(IBookPageFactory loader);
|
||||
|
||||
/**
|
||||
* Creates a sub entry.
|
||||
* <p>
|
||||
* Important: You not have to call {@link #addToCategory()} at the end of the creation of the sub entry
|
||||
*
|
||||
* @param name The unique name of the sub entry.
|
||||
* @return The entry builder of the sub entry.
|
||||
*/
|
||||
default IBookEntryBuilder createSubEntry(String name) {
|
||||
return createSubEntry(name, ItemStack.EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a sub entry.
|
||||
* <p>
|
||||
* Important: You not have to call {@link #addToCategory()} at the end of the creation of the sub entry
|
||||
*
|
||||
* @param name The unique name of the sub entry.
|
||||
* @param stack The stack that represents the sub entry.
|
||||
* @return The entry builder of the sub entry.
|
||||
*/
|
||||
IBookEntryBuilder createSubEntry(String name, ItemStack stack);
|
||||
|
||||
IBookEntry build(@Nullable IBookEntry parent);
|
||||
|
||||
/**
|
||||
* Builds a entry with the current information.
|
||||
*/
|
||||
IBookEntry build();
|
||||
|
||||
/**
|
||||
* Builds the entry and adds it to the category.
|
||||
*/
|
||||
IBookCategory addToCategory();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
public interface IBookLoader {
|
||||
|
||||
/**
|
||||
* Adds a content type.
|
||||
*
|
||||
* @param name The name of the content type.
|
||||
* @param contentClass The class for the deserialization of the content.
|
||||
*/
|
||||
void registerContentType(String name, Class<? extends BookContent> contentClass);
|
||||
|
||||
void registerPageFactory(String name, IBookPageFactory factory);
|
||||
|
||||
IBookPageFactory getPageFactory(String name);
|
||||
|
||||
/**
|
||||
* Loads the book if it was not loaded already or if it was invalidated. Otherwise it returns the last loaded
|
||||
* instance.
|
||||
*
|
||||
* @return The current instance of the forestry guide book.
|
||||
*/
|
||||
IForesterBook loadBook();
|
||||
|
||||
/**
|
||||
* Invalidates the current instance of the book.
|
||||
* The next time {@link #loadBook()} gets called a new instance of the book will be loaded.
|
||||
*/
|
||||
void invalidateBook();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.gui.IGuiElement;
|
||||
|
||||
/**
|
||||
* A factory that creates book pages for a book entry.
|
||||
*/
|
||||
public interface IBookPageFactory {
|
||||
/**
|
||||
* Usually called at the moment the player opens the given entry.
|
||||
* Creates a collection of gui elements that represent a page of the book.
|
||||
*
|
||||
* @param entry The opened book entry.
|
||||
* @param leftPageHeight The height of a page on the left side of the book.
|
||||
* @param rightPageHeight The height of a page on the right side of the book.
|
||||
* @param pageWidth The width of a book page.
|
||||
* @return A collection where every member represent a page of the book.
|
||||
*/
|
||||
Collection<IGuiElement> load(IBookEntry entry, int leftPageHeight, int rightPageHeight, int pageWidth);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* IForesterBook is the interface that the forestry guide book class implements.
|
||||
* <p>
|
||||
* You can get the current instance of the guide book from {@link IBookLoader#loadBook()}.
|
||||
*/
|
||||
public interface IForesterBook {
|
||||
|
||||
/**
|
||||
* Creates a category, add it to this book and returns it.
|
||||
*
|
||||
* @param name A unique identifier for the category.
|
||||
* @return The created category.
|
||||
*/
|
||||
IBookCategory addCategory(String name);
|
||||
|
||||
/**
|
||||
* @return The category with the given unique name.
|
||||
*/
|
||||
@Nullable
|
||||
IBookCategory getCategory(String name);
|
||||
|
||||
/**
|
||||
* @return All categories of this book.
|
||||
*/
|
||||
Collection<IBookCategory> getCategories();
|
||||
|
||||
/**
|
||||
* @return A collection that contains all unique names of the categories
|
||||
*/
|
||||
Collection<String> getCategoryNames();
|
||||
|
||||
/**
|
||||
* @return A collection that contains all entries of the category with the given name.
|
||||
*/
|
||||
Collection<IBookEntry> getEntries(String category);
|
||||
|
||||
/**
|
||||
* @return the entry with the given unique name.
|
||||
*/
|
||||
@Nullable
|
||||
IBookEntry getEntry(String name);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@API(apiVersion = "5.8.1", owner = "ForestryAPI|core", provides = "ForestryAPI|book")
|
||||
package forestry.api.book;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -1,43 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiElement {
|
||||
int getX();
|
||||
|
||||
int getY();
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
|
||||
void setXOffset(int xOffset);
|
||||
|
||||
void setYOffset(int yOffset);
|
||||
|
||||
@Nullable
|
||||
IGuiElement getParent();
|
||||
|
||||
void setParent(@Nullable IGuiElement parent);
|
||||
|
||||
void draw(int startX, int startY);
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
default List<String> getToolTip(int mouseX, int mouseY){
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
boolean isMouseOver(int mouseX, int mouseY);
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IGuiElementLayoutHelper.LayoutFactory;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleInteger;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
|
||||
/**
|
||||
* A helper interface to add gui elements.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiElementHelper {
|
||||
/**
|
||||
* Adds a {@link IGuiElement} to the parent of this.
|
||||
*/
|
||||
void add(IGuiElement element);
|
||||
|
||||
/**
|
||||
* Centers a element to the center of the x axis of the parent element.
|
||||
*
|
||||
* @return the element
|
||||
*/
|
||||
IGuiElement centerElement(IGuiElement element);
|
||||
|
||||
/**
|
||||
* Creates and adds an item gui element.
|
||||
*/
|
||||
void addItem(int x, ItemStack itemStack);
|
||||
|
||||
IGuiElementLayoutHelper layoutHelper(LayoutFactory layoutFactory, int width, int height);
|
||||
|
||||
/**
|
||||
* Adds the chromosomeName and the name of the active/not active allele, of the chromosome, with {@link #addText}.
|
||||
*/
|
||||
void addAllele(String chromosomeName, IIndividual individual, IChromosomeType chromosome, boolean active);
|
||||
|
||||
/**
|
||||
* Adds the chromosomeName and the result of toString with {@link #addText}.
|
||||
*/
|
||||
<A extends IAllele> void addAllele(String chromosomeName, Function<A, String> toString, IIndividual individual, IChromosomeType chromosome, boolean active);
|
||||
|
||||
void addFertilityInfo(IAlleleInteger fertilityAllele, int x, int texOffset);
|
||||
|
||||
void addToleranceInfo(IAlleleTolerance toleranceAllele, IAlleleSpecies species, String text);
|
||||
|
||||
void addMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker);
|
||||
|
||||
void addMutationResultant(int x, int y, int width, int height, IMutation mutation, IBreedingTracker breedingTracker);
|
||||
|
||||
/**
|
||||
* Adds a text element with the default color,the align {@link GuiElementAlignment#LEFT} and the height 12.
|
||||
*/
|
||||
void addText(String text);
|
||||
|
||||
/**
|
||||
* Adds a text element with the align {@link GuiElementAlignment#LEFT} and the height 12.
|
||||
*/
|
||||
void addText(String text, int color);
|
||||
|
||||
/**
|
||||
* Adds a text element with the default color and the height 12.
|
||||
*/
|
||||
void addText(String text, GuiElementAlignment align);
|
||||
|
||||
/**
|
||||
* Adds a text element with the height 12.
|
||||
*/
|
||||
void addText(String text,GuiElementAlignment align, int color);
|
||||
|
||||
/**
|
||||
* Adds a text element.
|
||||
*/
|
||||
void addText(int x, int height, String text, GuiElementAlignment align, int color);
|
||||
|
||||
/**
|
||||
* @return The element to which all elements are added.
|
||||
*/
|
||||
IGuiElement getParent();
|
||||
|
||||
IGuiElementFactory factory();
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiElementLayout extends IGuiElement {
|
||||
/**
|
||||
* Adds a element to this layout.
|
||||
*/
|
||||
IGuiElementLayout addElement(IGuiElement element);
|
||||
|
||||
/**
|
||||
* Removes a element from this layout.
|
||||
*/
|
||||
IGuiElementLayout removeElement(IGuiElement element);
|
||||
|
||||
default IGuiElementLayout addElements(IGuiElement... elements){
|
||||
for(IGuiElement element : elements){
|
||||
addElement(element);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default IGuiElementLayout removeElements(IGuiElement... elements){
|
||||
for(IGuiElement element : elements){
|
||||
removeElement(element);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default IGuiElementLayout addElements(Collection<IGuiElement> elements){
|
||||
elements.forEach(element -> addElement(element));
|
||||
return this;
|
||||
}
|
||||
|
||||
default IGuiElementLayout removeElements(Collection<IGuiElement> elements){
|
||||
elements.forEach(element -> removeElement(element));
|
||||
return this;
|
||||
}
|
||||
|
||||
List<IGuiElement> getElements();
|
||||
|
||||
IGuiElementLayout setDistance(int distance);
|
||||
|
||||
void addTooltip(String line);
|
||||
|
||||
/**
|
||||
* @return The tooltip that is displayed if the mouse is over this element and no element of this layout is under it.
|
||||
*/
|
||||
List<String> getTooltip();
|
||||
|
||||
/**
|
||||
* @return The distance between the different elements of this layout.
|
||||
*/
|
||||
int getDistance();
|
||||
|
||||
int getSize();
|
||||
}
|
||||
@@ -8,6 +8,10 @@ package forestry.api.core;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* @deprecated TODO Remove in 1.13: Not needed in the api
|
||||
*/
|
||||
@Deprecated
|
||||
public interface IStateMapperRegister {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
||||
@@ -9,10 +9,12 @@ import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.genetics.IClassification.EnumClassLevel;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.genetics.IClassification.EnumClassLevel;
|
||||
|
||||
/**
|
||||
* Manages {@link ISpeciesRoot}, {@link IAllele}s, {@link IFruitFamily}s, {@link IClassification}, the blacklist and allows creation of research notes.
|
||||
*
|
||||
|
||||
@@ -10,9 +10,12 @@ import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.gui.IElementGenetic;
|
||||
|
||||
public interface IAlyzerPlugin {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@@ -24,7 +27,40 @@ public interface IAlyzerPlugin {
|
||||
@SideOnly(Side.CLIENT)
|
||||
void drawAnalyticsPage3(GuiScreen gui, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Creates the first page of the alyzer.
|
||||
*
|
||||
* @param gui A instance of the alyzer gui.
|
||||
* @param container A helper to create the gui elements.
|
||||
* @param individual The individual that is currently in the alyzer slot.
|
||||
*/
|
||||
default void createFirstPage(GuiScreen gui, IElementGenetic container, IIndividual individual){
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the second page of the alyzer.
|
||||
*
|
||||
* @param gui A instance of the alyzer gui.
|
||||
* @param container A helper to create the gui elements.
|
||||
* @param individual The individual that is currently in the alyzer slot.
|
||||
*/
|
||||
default void createSecondPage(GuiScreen gui, IElementGenetic container, IIndividual individual){
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the third page of the alyzer. This page is usually used to display the products of the individual.
|
||||
*
|
||||
* @param gui A instance of the alyzer gui.
|
||||
* @param container A helper to create the gui elements.
|
||||
* @param individual The individual that is currently in the alyzer slot.
|
||||
*/
|
||||
default void createThirdPage(GuiScreen gui, IElementGenetic container, IIndividual individual){
|
||||
}
|
||||
|
||||
Map<String, ItemStack> getIconStacks();
|
||||
|
||||
/**
|
||||
* The hints that will be shown in the alyzer gui.
|
||||
*/
|
||||
List<String> getHints();
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* An ISpeciesPlugin provides methods that are used in the alyzer and database to display information about an
|
||||
* individual.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IDatabasePlugin<I extends IIndividual> {
|
||||
|
||||
/**
|
||||
* A map that contains a {@link ItemStack} for every possible {@link IAlleleSpecies}.
|
||||
* This item stack represents the species in the database and alyzer gui.
|
||||
*
|
||||
* The key of the map is the uid of the species.
|
||||
*/
|
||||
Map<String, ItemStack> getIndividualStacks();
|
||||
|
||||
/* ALYZER */
|
||||
List<String> getHints();
|
||||
|
||||
IDatabaseTab[] getTabs();
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IGuiElementHelper;
|
||||
import forestry.api.gui.IElementGenetic;
|
||||
|
||||
/**
|
||||
* A tab of the database screen that shows some information about a {@link IIndividual}.
|
||||
@@ -18,14 +18,11 @@ public interface IDatabaseTab<I extends IIndividual> {
|
||||
* Creates the gui elements that are displayed if this tab is selected in the database.
|
||||
*
|
||||
* @param individual The individual that is currently in the database selected.
|
||||
* @param elementHelper A helper to create the gui elements.
|
||||
* @param container A helper to create the gui elements.
|
||||
*/
|
||||
void createElements(IGuiElementHelper elementHelper, I individual, ItemStack itemStack);
|
||||
void createElements(IElementGenetic container, I individual, ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* @return The slot of this tab.
|
||||
*/
|
||||
EnumDatabaseTab getTab();
|
||||
ItemStack getIconStack();
|
||||
|
||||
/**
|
||||
* Can be used to give the tab a custom tooltip.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package forestry.api.genetics;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import forestry.api.gui.IGuiElement;
|
||||
|
||||
public interface IGeneticAnalyzer extends IGuiElement {
|
||||
IGeneticAnalyzerProvider getProvider();
|
||||
|
||||
/**
|
||||
* @return True if the analyzer is currently visible.
|
||||
*/
|
||||
boolean isVisible();
|
||||
|
||||
void setVisible(boolean visible);
|
||||
|
||||
/**
|
||||
* Called at the end of the constructor of the analyzer provider.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Updates the displayed content of the analyzer.
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Draws the tooltip of the element that is under the mouse.
|
||||
*/
|
||||
void drawTooltip(GuiScreen gui, int mouseX, int mouseY);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
IGuiElement getItemElement();
|
||||
|
||||
void updateSelected();
|
||||
|
||||
void setSelectedSlot(int selectedSlot);
|
||||
|
||||
int getSelected();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package forestry.api.genetics;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IGeneticAnalyzerProvider {
|
||||
|
||||
ItemStack getSpecimen(int index);
|
||||
|
||||
boolean onUpdateSelected();
|
||||
|
||||
void onSelection(int index, boolean changed);
|
||||
|
||||
int getSelectedSlot(int index);
|
||||
|
||||
int getSlotCount();
|
||||
|
||||
int getFirstSlot();
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package forestry.api.genetics;
|
||||
|
||||
public class IGeneticPlugin {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package forestry.api.genetics;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ISpeciesDisplayHelper {
|
||||
/**
|
||||
* Plugin to add information for the genetic database.
|
||||
*/
|
||||
Optional<IDatabasePlugin> getDatabasePlugin();
|
||||
|
||||
/**
|
||||
* Plugin to add information for the handheld genetic analyzer.
|
||||
*/
|
||||
Optional<IAlyzerPlugin> getAlyzerPlugin();
|
||||
|
||||
/**
|
||||
* Retrieves a stack that can and should only be used on the client side in a gui.
|
||||
*
|
||||
* @return A empty stack, if the species was not registered before the creation of this handler or if the species is
|
||||
* not a species of the {@link ISpeciesRoot}.
|
||||
*/
|
||||
ItemStack getDisplayStack(IAlleleSpecies species, ISpeciesType type);
|
||||
|
||||
ItemStack getDisplayStack(IAlleleSpecies species);
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.genetics;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.IGuiElementHelper;
|
||||
|
||||
/**
|
||||
* An ISpeciesPlugin provides methods that are used in the alyzer and database to display information about an
|
||||
* individual.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface ISpeciesPlugin<I extends IIndividual> {
|
||||
|
||||
/**
|
||||
* A map that contains a {@link ItemStack} for every possible {@link IAlleleSpecies}.
|
||||
* This item stack represents the species in the database and alyzer gui.
|
||||
*
|
||||
* The key of the map is the uid of the species.
|
||||
*/
|
||||
Map<String, ItemStack> getIndividualStacks();
|
||||
|
||||
|
||||
/* ALYZER */
|
||||
/**
|
||||
* Creates the first page of the alyzer.
|
||||
*
|
||||
* @param gui A instance of the alyzer gui.
|
||||
* @param elementHelper A helper to create the gui elements.
|
||||
* @param individual The individual that is currently in the alyzer slot.
|
||||
*/
|
||||
default void createFirstPage(GuiScreen gui, IGuiElementHelper elementHelper, I individual){
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the second page of the alyzer.
|
||||
*
|
||||
* @param gui A instance of the alyzer gui.
|
||||
* @param elementHelper A helper to create the gui elements.
|
||||
* @param individual The individual that is currently in the alyzer slot.
|
||||
*/
|
||||
default void createSecondPage(GuiScreen gui, IGuiElementHelper elementHelper, I individual){
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the third page of the alyzer. This page is usually used to display the products of the individual.
|
||||
*
|
||||
* @param gui A instance of the alyzer gui.
|
||||
* @param elementHelper A helper to create the gui elements.
|
||||
* @param individual The individual that is currently in the alyzer slot.
|
||||
*/
|
||||
default void createThirdPage(GuiScreen gui, IGuiElementHelper elementHelper, I individual){
|
||||
}
|
||||
|
||||
/**
|
||||
* The hints that will be shown in the alyzer gui.
|
||||
*/
|
||||
List<String> getHints();
|
||||
|
||||
/* DATABASE */
|
||||
/**
|
||||
* Provides a instance of a {@link IDatabaseTab} that is used to display information about the species of a individual in the
|
||||
* database.
|
||||
*
|
||||
* @param active True if this tab is used to display the active species of the individual.
|
||||
*
|
||||
* @return null if this plugin does not support the database.
|
||||
*/
|
||||
default IDatabaseTab<I> getSpeciesTab(boolean active){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to provide a custom products tab for the database.
|
||||
* If this is Null forestry uses the default mutation tab to display the products.
|
||||
*/
|
||||
@Nullable
|
||||
default IDatabaseTab<I> getProductsTab(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used to provide a custom mutation tab for the database.
|
||||
* If this is Null forestry uses the default mutation tab to display the mutations.
|
||||
*/
|
||||
@Nullable
|
||||
default IDatabaseTab<I> getMutationTab(){
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A item stack that represents the database tab in the database gui.
|
||||
*/
|
||||
ItemStack getTabDatabaseIconItem(EnumDatabaseTab tab);
|
||||
}
|
||||
@@ -86,8 +86,20 @@ public interface ISpeciesRoot {
|
||||
*/
|
||||
ISpeciesType getIconType();
|
||||
|
||||
default ISpeciesType[] getTypes(){
|
||||
return new ISpeciesType[0];
|
||||
}
|
||||
|
||||
ItemStack getMemberStack(IIndividual individual, ISpeciesType type);
|
||||
|
||||
default ItemStack getMemberStack(IAlleleSpecies species, ISpeciesType type){
|
||||
return getMemberStack(getTemplate(species), type);
|
||||
}
|
||||
|
||||
default ItemStack getMemberStack(IAllele[] template, ISpeciesType type){
|
||||
return getMemberStack(templateAsIndividual(template), type);
|
||||
}
|
||||
|
||||
/* BREEDING TRACKER */
|
||||
IBreedingTracker getBreedingTracker(World world, @Nullable GameProfile player);
|
||||
|
||||
@@ -148,6 +160,15 @@ public interface ISpeciesRoot {
|
||||
|
||||
List<? extends IIndividual> getIndividualTemplates();
|
||||
|
||||
/**
|
||||
* The type of the species that will be used at the given position of the mutation recipe in the gui.
|
||||
*
|
||||
* @param position 0 = first parent, 1 = second parent, 2 = result
|
||||
*/
|
||||
default ISpeciesType getTypeForMutation(int position){
|
||||
return getIconType();
|
||||
}
|
||||
|
||||
/* MUTATIONS */
|
||||
|
||||
/**
|
||||
@@ -210,18 +231,13 @@ public interface ISpeciesRoot {
|
||||
*/
|
||||
IAlyzerPlugin getAlyzerPlugin();
|
||||
|
||||
/**
|
||||
* A array with the size of 4. With the database tabs of this {@link IIndividual}.
|
||||
*/
|
||||
//IDatabaseTab[] getDatabaseTabs();
|
||||
|
||||
/**
|
||||
* Plugin to add information for the handheld genetic analyzer and the database.
|
||||
* @since 5.7
|
||||
*/
|
||||
@Nullable
|
||||
@SideOnly(Side.CLIENT)
|
||||
default ISpeciesPlugin getSpeciesPlugin(){
|
||||
default IDatabasePlugin getSpeciesPlugin(){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.gui;
|
||||
|
||||
/**
|
||||
* The alignment of a gui element.
|
||||
*/
|
||||
public enum GuiElementAlignment {
|
||||
TOP_LEFT(0.0f, 0.0f),
|
||||
TOP_CENTER(0.5f, 0.0f),
|
||||
TOP_RIGHT(1.0f, 0.0f),
|
||||
MIDDLE_LEFT(0.0f, 0.5f),
|
||||
MIDDLE_CENTER(0.5f, 0.5f),
|
||||
MIDDLE_RIGHT(1.0f, 0.5f),
|
||||
BOTTOM_LEFT(0.0f, 1.0f),
|
||||
BOTTOM_CENTER(0.5f, 1.0f),
|
||||
BOTTOM_RIGHT(1.0f, 1.0f);
|
||||
|
||||
private final float xOffset;
|
||||
private final float yOffset;
|
||||
|
||||
GuiElementAlignment(float xOffset, float yOffset) {
|
||||
this.xOffset = xOffset;
|
||||
this.yOffset = yOffset;
|
||||
}
|
||||
|
||||
public float getXOffset() {
|
||||
return xOffset;
|
||||
}
|
||||
|
||||
public float getYOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package forestry.api.gui;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleInteger;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
|
||||
public interface IElementGenetic extends IElementGroup {
|
||||
|
||||
/**
|
||||
* Adds the chromosomeName and the name of the active/not active allele, of the chromosome, with {@link #text}.
|
||||
*/
|
||||
void addAlleleRow(String chromosomeName, IIndividual individual, IChromosomeType chromosome, boolean active);
|
||||
|
||||
/**
|
||||
* Adds the chromosomeName and the result of toString with {@link #text}.
|
||||
*/
|
||||
<A extends IAllele> void addAlleleRow(String chromosomeName, Function<A, String> toString, IIndividual individual, IChromosomeType chromosome, boolean active);
|
||||
|
||||
void addFertilityInfo(String chromosomeName, IAlleleInteger fertilityAllele, int texOffset);
|
||||
|
||||
void addToleranceInfo(String chromosomeName, IAlleleTolerance toleranceAllele, IAlleleSpecies species, String text);
|
||||
|
||||
void addMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker);
|
||||
|
||||
void addMutationResultant(int x, int y, int width, int height, IMutation mutation, IBreedingTracker breedingTracker);
|
||||
|
||||
void addRow(String firstText, String secondText, int firstColor, int secondColor);
|
||||
|
||||
void addRow(String leftText, String rightText, boolean dominant);
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package forestry.api.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IElementGroup extends IGuiElement {
|
||||
/**
|
||||
* Adds a element to this layout.
|
||||
*/
|
||||
<E extends IGuiElement> E add(E element);
|
||||
|
||||
/**
|
||||
* Removes a element from this layout.
|
||||
*/
|
||||
<E extends IGuiElement> E remove(E element);
|
||||
|
||||
default IElementGroup add(IGuiElement... elements) {
|
||||
for (IGuiElement element : elements) {
|
||||
add(element);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default IElementGroup remove(IGuiElement... elements) {
|
||||
for (IGuiElement element : elements) {
|
||||
remove(element);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
default IElementGroup add(Collection<IGuiElement> elements) {
|
||||
elements.forEach(this::add);
|
||||
return this;
|
||||
}
|
||||
|
||||
default IElementGroup remove(Collection<IGuiElement> elements) {
|
||||
elements.forEach(this::remove);
|
||||
return this;
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
@Nullable
|
||||
IGuiElement getLastElement();
|
||||
|
||||
/**
|
||||
* @return All elements that this layout contains.
|
||||
*/
|
||||
List<IGuiElement> getElements();
|
||||
|
||||
IGuiElement item(int xPos, int yPos, ItemStack itemStack);
|
||||
|
||||
default IGuiElement item(ItemStack itemStack) {
|
||||
return item(0, 0, itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a text element with the default color,the align {@link GuiElementAlignment#TOP_LEFT} and the height 12.
|
||||
*/
|
||||
IGuiElement text(String text);
|
||||
|
||||
/**
|
||||
* Adds a text element with the align {@link GuiElementAlignment#TOP_LEFT} and the height 12.
|
||||
*/
|
||||
IGuiElement text(String text, int color);
|
||||
|
||||
/**
|
||||
* Adds a text element with the default color and the height 12.
|
||||
*/
|
||||
IGuiElement text(String text, GuiElementAlignment align);
|
||||
|
||||
IGuiElement text(String text, GuiElementAlignment align, int color, boolean unicode);
|
||||
|
||||
/**
|
||||
* Adds a text element with the height 12.
|
||||
*/
|
||||
IGuiElement text(String text, GuiElementAlignment align, int color);
|
||||
|
||||
IGuiElement text(int x, String text, GuiElementAlignment align, int color);
|
||||
|
||||
/**
|
||||
* Adds a text element.
|
||||
*/
|
||||
IGuiElement text(int x, int height, String text, GuiElementAlignment align, int color);
|
||||
|
||||
IGuiElement text(int x, int y, int width, int height, String text);
|
||||
|
||||
/**
|
||||
* Adds a text element.
|
||||
*/
|
||||
IGuiElement text(int x, int height, String text, GuiElementAlignment align, int color, boolean unicode);
|
||||
|
||||
default IElementLayout vertical(int width) {
|
||||
return vertical(0, 0, width);
|
||||
}
|
||||
|
||||
IElementLayout vertical(int xPos, int yPos, int width);
|
||||
|
||||
IElementLayout horizontal(int xPos, int yPos, int height);
|
||||
|
||||
default IElementLayout horizontal(int height) {
|
||||
return horizontal(0, 0, height);
|
||||
}
|
||||
|
||||
IElementGroup panel(int xPos, int yPos, int width, int height);
|
||||
|
||||
default IElementGroup panel(int width, int height) {
|
||||
return panel(0, 0, width, height);
|
||||
}
|
||||
|
||||
IElementLayoutHelper layoutHelper(IElementLayoutHelper.LayoutFactory layoutFactory, int width, int height);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.gui;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IElementLayout extends IElementGroup {
|
||||
/**
|
||||
* @param distance
|
||||
* @return
|
||||
*/
|
||||
IElementLayout setDistance(int distance);
|
||||
|
||||
/**
|
||||
* @return The distance between the different elements of this layout.
|
||||
*/
|
||||
int getDistance();
|
||||
|
||||
int getSize();
|
||||
}
|
||||
+10
-6
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core;
|
||||
package forestry.api.gui;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiElementLayoutHelper {
|
||||
public interface IElementLayoutHelper {
|
||||
/**
|
||||
* @return Only false if the helper has no space to add this element.
|
||||
*/
|
||||
@@ -23,19 +23,23 @@ public interface IGuiElementLayoutHelper {
|
||||
void clear();
|
||||
|
||||
/**
|
||||
* Adds the layouts to the parent of the {@link IGuiElementHelper}. And calls {@link #clear()}
|
||||
* Adds the layouts to the parent of the {@link IElementGroup}. And calls {@link #clear()}
|
||||
*/
|
||||
void finish();
|
||||
void finish(boolean centerX);
|
||||
|
||||
default void finish() {
|
||||
finish(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return All layouts that were created with the help of this helper since the last {@link #clear()} or {@link #finish()}.
|
||||
*/
|
||||
Collection<IGuiElementLayout> layouts();
|
||||
Collection<IElementLayout> layouts();
|
||||
|
||||
interface LayoutFactory {
|
||||
/**
|
||||
* A factory method to create new layouts if the last layout is full.
|
||||
*/
|
||||
IGuiElementLayout createLayout(int xOffset, int yOffset);
|
||||
IElementLayout createLayout(int xOffset, int yOffset);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiElement {
|
||||
/* Position and Size*/
|
||||
/**
|
||||
* @return the x position of this element relative to the position of the top widget.
|
||||
*/
|
||||
int getX();
|
||||
|
||||
/**
|
||||
* @return the y position of this element relative to the position of the top widget.
|
||||
*/
|
||||
int getY();
|
||||
|
||||
void setAlign(GuiElementAlignment align);
|
||||
|
||||
GuiElementAlignment getAlign();
|
||||
|
||||
int getAbsoluteX();
|
||||
|
||||
int getAbsoluteY();
|
||||
|
||||
/**
|
||||
* @return the size of the element on the x-axis.
|
||||
*/
|
||||
int getWidth();
|
||||
|
||||
/**
|
||||
* @return the size of the element on the y-axis.
|
||||
*/
|
||||
int getHeight();
|
||||
|
||||
void setSize(int width, int height);
|
||||
|
||||
void setLocation(int xPos, int yPos);
|
||||
|
||||
void setBounds(int xPos, int yPos, int width, int height);
|
||||
|
||||
/**
|
||||
* Sets the x-axis offset to the original x-axis position.
|
||||
*/
|
||||
void setXPosition(int xPos);
|
||||
|
||||
/**
|
||||
* Sets the y-axis offset to the original y-axis position.
|
||||
*/
|
||||
void setYPosition(int yPos);
|
||||
|
||||
/* Parent */
|
||||
/**
|
||||
* @return the element that contains this element and handles all events.
|
||||
*/
|
||||
@Nullable
|
||||
IGuiElement getParent();
|
||||
|
||||
void setParent(@Nullable IGuiElement parent);
|
||||
|
||||
/* Rendering */
|
||||
/**
|
||||
* Draws the element and his children.
|
||||
*
|
||||
* @param mouseX The x position of the mouse relative to the parent of the element.
|
||||
* @param mouseY The y position of the mouse relative to the parent of the element.
|
||||
*/
|
||||
void draw(int mouseX, int mouseY);
|
||||
|
||||
/**
|
||||
* Draws the element itself at the current position.
|
||||
*/
|
||||
void drawElement(int mouseX, int mouseY);
|
||||
|
||||
/* Events */
|
||||
/**
|
||||
* @param mouseX The x position of the mouse relative to the parent of the element.
|
||||
* @param mouseY The y position of the mouse relative to the parent of the element.
|
||||
* @param mouseButton The pressed mouse button.
|
||||
*/
|
||||
void mouseClicked(int mouseX, int mouseY, int mouseButton);
|
||||
|
||||
/**
|
||||
* @param mouseX The x position of the mouse relative to the parent of the element.
|
||||
* @param mouseY The y position of the mouse relative to the parent of the element.
|
||||
* @param mouseButton The pressed mouse button.
|
||||
*/
|
||||
void mouseReleased(int mouseX, int mouseY, int mouseButton);
|
||||
|
||||
void mouseClickMove(int mouseX, int mouseY, int mouseButton);
|
||||
|
||||
boolean keyTyped(char typedChar, int keyCode);
|
||||
|
||||
/**
|
||||
* @param mouseX The x position of the mouse relative to the parent of the element.
|
||||
* @param mouseY The y position of the mouse relative to the parent of the element.
|
||||
* @return True if the mouse is currently over the element.
|
||||
*/
|
||||
boolean isMouseOver(int mouseX, int mouseY);
|
||||
|
||||
/**
|
||||
* @return True if the mouse is currently over the element.
|
||||
*/
|
||||
boolean isMouseOver();
|
||||
|
||||
/* Tooltip */
|
||||
IGuiElement addTooltip(String line);
|
||||
|
||||
IGuiElement addTooltip(Collection<String> lines);
|
||||
|
||||
void clearTooltip();
|
||||
|
||||
/**
|
||||
* Returns the tooltip that this element provides at the given mouse position.
|
||||
*
|
||||
* @param mouseX The x position of the mouse relative to the parent of the element.
|
||||
* @param mouseY The y position of the mouse relative to the parent of the element.
|
||||
*/
|
||||
List<String> getTooltip(int mouseX, int mouseY);
|
||||
|
||||
List<String> getTooltip();
|
||||
|
||||
@Nullable
|
||||
IGuiState getGuiState();
|
||||
}
|
||||
+16
-8
@@ -3,7 +3,9 @@
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
package forestry.api.core;
|
||||
package forestry.api.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -13,6 +15,8 @@ import forestry.api.genetics.IAlleleInteger;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IGeneticAnalyzer;
|
||||
import forestry.api.genetics.IGeneticAnalyzerProvider;
|
||||
import forestry.api.genetics.IMutation;
|
||||
|
||||
/**
|
||||
@@ -21,12 +25,12 @@ import forestry.api.genetics.IMutation;
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiElementFactory {
|
||||
|
||||
IGuiElementHelper createHelper(IGuiElementLayout element);
|
||||
IGeneticAnalyzer createAnalyzer(int xPos, int yPos, boolean rightBoarder, IGeneticAnalyzerProvider provider);
|
||||
|
||||
/* GENETIC*/
|
||||
|
||||
/**
|
||||
* @param dominant True if you want the dominant color and false if you want the recessive color.
|
||||
*
|
||||
* @param dominant True if you want the dominant color and false if you want the recessive color.
|
||||
* @return The color code that forestry uses to show if a allele is dominant (true) or recessive (false).
|
||||
*/
|
||||
int getColorCoding(boolean dominant);
|
||||
@@ -34,21 +38,25 @@ public interface IGuiElementFactory {
|
||||
/**
|
||||
* @return Null if the mutation is secret and undiscovered. {@link IMutation#isSecret()}
|
||||
*/
|
||||
@Nullable
|
||||
IGuiElement createMutation(int x, int y, int width, int height, IMutation mutation, IAllele species, IBreedingTracker breedingTracker);
|
||||
|
||||
/**
|
||||
* @return Null if the mutation is secret and undiscovered. {@link IMutation#isSecret()}
|
||||
*/
|
||||
@Nullable
|
||||
IGuiElement createMutationResultant(int x, int y, int width, int height, IMutation mutation, IBreedingTracker breedingTracker);
|
||||
|
||||
IGuiElement createFertilityInfo(IAlleleInteger fertilityAllele, int x, int texOffset);
|
||||
IGuiElement createFertilityInfo(IAlleleInteger fertilityAllele, int texOffset);
|
||||
|
||||
IGuiElement createToleranceInfo(IAlleleTolerance toleranceAllele, IAlleleSpecies species, String text);
|
||||
|
||||
IGuiElement createToleranceInfo(IAlleleTolerance toleranceAllele);
|
||||
|
||||
/* LAYOUTS */
|
||||
IGuiElementLayout createHorizontal(int xPos, int yPos, int height);
|
||||
IElementLayout createHorizontal(int xPos, int yPos, int height);
|
||||
|
||||
IGuiElementLayout createVertical(int xPos, int yPos, int width);
|
||||
IElementLayout createVertical(int xPos, int yPos, int width);
|
||||
|
||||
IGuiElementLayout createPanel(int xPos, int yPos, int width, int height);
|
||||
IElementGroup createPanel(int xPos, int yPos, int width, int height);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package forestry.api.gui;
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public interface IGuiState {
|
||||
|
||||
/**
|
||||
* Returns the mouse position.
|
||||
*/
|
||||
int getMouseX();
|
||||
|
||||
/**
|
||||
* Returns the mouse position.
|
||||
*/
|
||||
int getMouseY();
|
||||
|
||||
/**
|
||||
* Returns the mouse position relative to the given element.
|
||||
*/
|
||||
int getRelativeMouseX(IGuiElement element);
|
||||
|
||||
/**
|
||||
* Returns the mouse position relative to the given element.
|
||||
*/
|
||||
int getRelativeMouseY(IGuiElement element);
|
||||
|
||||
/**
|
||||
* Returns the current screen width.
|
||||
*/
|
||||
int getScreenWidth();
|
||||
|
||||
/**
|
||||
* Returns the current screen height.
|
||||
*/
|
||||
int getScreenHeight();
|
||||
|
||||
/**
|
||||
* Returns the current gui height.
|
||||
*/
|
||||
int getGuiHeight();
|
||||
|
||||
/**
|
||||
* Returns the current gui width.
|
||||
*/
|
||||
int getGuiWidth();
|
||||
|
||||
int getGuiLeft();
|
||||
|
||||
int getGuiTop();
|
||||
|
||||
TextureManager getTextureManager();
|
||||
|
||||
FontRenderer getFontRenderer();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011-2014 SirSengir
|
||||
*
|
||||
* This work (the API) is licensed under the "MIT" License, see LICENSE.txt for details.
|
||||
******************************************************************************/
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@API(apiVersion = "5.8.0", owner = "ForestryAPI|core", provides = "ForestryAPI|gui")
|
||||
package forestry.api.gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -11,13 +11,6 @@
|
||||
|
||||
package forestry.apiculture;
|
||||
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.apiculture.blocks.BlockApiculture;
|
||||
import forestry.apiculture.items.ItemBeeGE;
|
||||
import forestry.apiculture.tiles.TileBeeHouse;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.ai.EntityAIMoveToBlock;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
@@ -26,6 +19,13 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.apiculture.blocks.BlockApiculture;
|
||||
import forestry.apiculture.items.ItemBeeGE;
|
||||
import forestry.apiculture.tiles.TileBeeHouse;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
|
||||
public class ApiaristAI extends EntityAIMoveToBlock {
|
||||
private final EntityVillager villager;
|
||||
private boolean hasDrone;
|
||||
|
||||
@@ -135,7 +135,7 @@ import forestry.food.ModuleFood;
|
||||
import forestry.food.items.ItemRegistryFood;
|
||||
import forestry.modules.BlankForestryModule;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
import forestry.modules.ModuleManager;
|
||||
import forestry.modules.ModuleHelper;
|
||||
|
||||
@ForestryModule(containerID = Constants.MOD_ID, moduleID = ForestryModuleUids.APICULTURE, name = "Apiculture", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.module.apiculture.description", lootTable = "apiculture")
|
||||
public class ModuleApiculture extends BlankForestryModule {
|
||||
@@ -237,7 +237,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
// Commands
|
||||
ModuleCore.rootCommand.addChildCommand(new CommandBee());
|
||||
|
||||
if (ModuleManager.getInstance().isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.SORTING)) {
|
||||
if(ModuleHelper.isEnabled(ForestryModuleUids.SORTING)){
|
||||
ApicultureFilterRuleType.init();
|
||||
ApicultureFilterRule.init();
|
||||
}
|
||||
@@ -550,7 +550,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
}
|
||||
|
||||
// FOOD STUFF
|
||||
if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FOOD))) {
|
||||
if (ModuleHelper.isEnabled(ForestryModuleUids.FOOD)) {
|
||||
ItemRegistryFood foodItems = ModuleFood.getItems();
|
||||
RecipeUtil.addRecipe("honeyed_slice", new ItemStack(foodItems.honeyedSlice, 4),
|
||||
"###", "#X#", "###",
|
||||
@@ -607,7 +607,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'#', coreItems.beeswax);
|
||||
|
||||
// / ALVEARY
|
||||
ItemStack alvearyPlainBlock = blocks.getAlvearyBlock(BlockAlvearyType.PLAIN);
|
||||
ItemStack alvearyPlainBlock = blocks.getAlvearyBlockStack(BlockAlvearyType.PLAIN);
|
||||
RecipeUtil.addRecipe("alveary_plain", alvearyPlainBlock,
|
||||
"###",
|
||||
"#X#",
|
||||
@@ -615,7 +615,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'X', coreItems.impregnatedCasing,
|
||||
'#', coreItems.craftingMaterial.getScentedPaneling());
|
||||
// SWARMER
|
||||
RecipeUtil.addRecipe("alveary_swarmer", blocks.getAlvearyBlock(BlockAlvearyType.SWARMER),
|
||||
RecipeUtil.addRecipe("alveary_swarmer", blocks.getAlvearyBlockStack(BlockAlvearyType.SWARMER),
|
||||
"#G#",
|
||||
" X ",
|
||||
"#G#",
|
||||
@@ -623,7 +623,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'X', alvearyPlainBlock,
|
||||
'G', OreDictUtil.INGOT_GOLD);
|
||||
// FAN
|
||||
RecipeUtil.addRecipe("alveary_fan", blocks.getAlvearyBlock(BlockAlvearyType.FAN),
|
||||
RecipeUtil.addRecipe("alveary_fan", blocks.getAlvearyBlockStack(BlockAlvearyType.FAN),
|
||||
"I I",
|
||||
" X ",
|
||||
"I#I",
|
||||
@@ -631,7 +631,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'X', alvearyPlainBlock,
|
||||
'I', OreDictUtil.INGOT_IRON);
|
||||
// HEATER
|
||||
RecipeUtil.addRecipe("alveary_heater", blocks.getAlvearyBlock(BlockAlvearyType.HEATER),
|
||||
RecipeUtil.addRecipe("alveary_heater", blocks.getAlvearyBlockStack(BlockAlvearyType.HEATER),
|
||||
"#I#",
|
||||
" X ",
|
||||
"YYY",
|
||||
@@ -639,7 +639,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'X', alvearyPlainBlock,
|
||||
'I', OreDictUtil.INGOT_IRON, 'Y', OreDictUtil.STONE);
|
||||
// HYGROREGULATOR
|
||||
RecipeUtil.addRecipe("alveary_hygro", blocks.getAlvearyBlock(BlockAlvearyType.HYGRO),
|
||||
RecipeUtil.addRecipe("alveary_hygro", blocks.getAlvearyBlockStack(BlockAlvearyType.HYGRO),
|
||||
"GIG",
|
||||
"GXG",
|
||||
"GIG",
|
||||
@@ -647,14 +647,14 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'I', OreDictUtil.INGOT_IRON,
|
||||
'G', OreDictUtil.BLOCK_GLASS);
|
||||
// STABILISER
|
||||
RecipeUtil.addRecipe("alveary_stabiliser", blocks.getAlvearyBlock(BlockAlvearyType.STABILISER),
|
||||
RecipeUtil.addRecipe("alveary_stabiliser", blocks.getAlvearyBlockStack(BlockAlvearyType.STABILISER),
|
||||
"G G",
|
||||
"GXG",
|
||||
"G G",
|
||||
'X', alvearyPlainBlock,
|
||||
'G', OreDictUtil.GEM_QUARTZ);
|
||||
// SIEVE
|
||||
RecipeUtil.addRecipe("alveary_sieve", blocks.getAlvearyBlock(BlockAlvearyType.SIEVE),
|
||||
RecipeUtil.addRecipe("alveary_sieve", blocks.getAlvearyBlockStack(BlockAlvearyType.SIEVE),
|
||||
"III",
|
||||
" X ",
|
||||
"WWW",
|
||||
@@ -662,7 +662,7 @@ public class ModuleApiculture extends BlankForestryModule {
|
||||
'I', OreDictUtil.INGOT_IRON,
|
||||
'W', coreItems.craftingMaterial.getWovenSilk());
|
||||
|
||||
if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FACTORY))) {
|
||||
if (ModuleHelper.isEnabled(ForestryModuleUids.FACTORY)) {
|
||||
// / SQUEEZER
|
||||
FluidStack honeyDropFluid = Fluids.FOR_HONEY.getFluid(Constants.FLUID_PER_HONEY_DROP);
|
||||
RecipeManagers.squeezerManager.addRecipe(10, items.honeyDrop.getItemStack(), honeyDropFluid, items.propolis.getItemStack(), 5);
|
||||
|
||||
@@ -12,14 +12,15 @@ package forestry.apiculture.blocks;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.apiculture.items.ItemBlockCandle;
|
||||
import forestry.apiculture.items.ItemBlockHoneyComb;
|
||||
import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.blocks.BlockRegistry;
|
||||
import forestry.core.items.ItemBlockForestry;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class BlockRegistryApiculture extends BlockRegistry {
|
||||
public final BlockApiculture apiary;
|
||||
@@ -63,7 +64,12 @@ public class BlockRegistryApiculture extends BlockRegistry {
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack getAlvearyBlock(BlockAlvearyType type) {
|
||||
public BlockAlveary getAlvearyBlock(BlockAlvearyType type) {
|
||||
BlockAlveary alvearyBlock = alvearyBlockMap.get(type);
|
||||
return alvearyBlock;
|
||||
}
|
||||
|
||||
public ItemStack getAlvearyBlockStack(BlockAlvearyType type) {
|
||||
BlockAlveary alvearyBlock = alvearyBlockMap.get(type);
|
||||
return new ItemStack(alvearyBlock);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package forestry.apiculture.genetics;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -10,14 +9,13 @@ import forestry.api.apiculture.BeeManager;
|
||||
import forestry.api.apiculture.EnumBeeChromosome;
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.core.GuiElementAlignment;
|
||||
import forestry.api.core.IGuiElementHelper;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.EnumDatabaseTab;
|
||||
import forestry.api.genetics.IAlleleInteger;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IAlleleTolerance;
|
||||
import forestry.api.genetics.IDatabaseTab;
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.api.gui.IElementGenetic;
|
||||
import forestry.api.lepidopterology.EnumButterflyChromosome;
|
||||
import forestry.core.genetics.alleles.AlleleBoolean;
|
||||
import forestry.core.render.ColourProperties;
|
||||
@@ -26,49 +24,45 @@ import forestry.core.utils.Translator;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BeeDatabaseTab implements IDatabaseTab<IBee> {
|
||||
private final EnumDatabaseTab tab;
|
||||
private final boolean active;
|
||||
|
||||
BeeDatabaseTab(EnumDatabaseTab tab) {
|
||||
this.tab = tab;
|
||||
BeeDatabaseTab(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createElements(IGuiElementHelper elementHelper, IBee bee, ItemStack itemStack) {
|
||||
public void createElements(IElementGenetic container, IBee bee, ItemStack itemStack) {
|
||||
EnumBeeType type = BeeManager.beeRoot.getType(itemStack);
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
IAlleleSpecies primarySpecies = bee.getGenome().getPrimary();
|
||||
boolean active = tab == EnumDatabaseTab.ACTIVE_SPECIES;
|
||||
|
||||
elementHelper.addText(Translator.translateToLocal("for.gui.database.tab." + tab.name().toLowerCase() + ".name"), GuiElementAlignment.CENTER, 0xcfb53b);
|
||||
container.text(Translator.translateToLocal("for.gui.database.tab." + (active ? "active" : "inactive") + "_species.name"), GuiElementAlignment.TOP_CENTER, 0xcfb53b);
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.species"), bee, EnumBeeChromosome.SPECIES, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.species"), bee, EnumBeeChromosome.SPECIES, active);
|
||||
|
||||
IAlleleTolerance tempTolerance = (IAlleleTolerance) (active ? bee.getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE) : bee.getGenome().getInactiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE));
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.climate"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addToleranceInfo(tempTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getTemperature()));
|
||||
//container.text(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.climate"), GuiElementAlignment.CENTER);
|
||||
container.addToleranceInfo(Translator.translateToLocal("for.gui.climate"), tempTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getTemperature()));
|
||||
|
||||
IAlleleTolerance humidTolerance = (IAlleleTolerance) (active ? bee.getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE) : bee.getGenome().getInactiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE));
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.humidity"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addToleranceInfo(humidTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getHumidity()));
|
||||
//container.text(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.humidity"), GuiElementAlignment.CENTER);
|
||||
container.addToleranceInfo(Translator.translateToLocal("for.gui.humidity"), humidTolerance, primarySpecies, AlleleManager.climateHelper.toDisplay(primarySpecies.getHumidity()));
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.lifespan"), bee, EnumBeeChromosome.LIFESPAN, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.lifespan"), bee, EnumBeeChromosome.LIFESPAN, active);
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.speed"), bee, EnumBeeChromosome.SPEED, active);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.pollination"), bee, EnumBeeChromosome.FLOWERING, active);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.flowers"), bee, EnumBeeChromosome.FLOWER_PROVIDER, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.speed"), bee, EnumBeeChromosome.SPEED, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.pollination"), bee, EnumBeeChromosome.FLOWERING, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.flowers"), bee, EnumBeeChromosome.FLOWER_PROVIDER, active);
|
||||
|
||||
IAlleleInteger primaryFertility = (IAlleleInteger) (active ? bee.getGenome().getActiveAllele(EnumBeeChromosome.FERTILITY) : bee.getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY));
|
||||
container.addFertilityInfo(Translator.translateToLocal("for.gui.fertility"), primaryFertility, 0);
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.fertility"), GuiElementAlignment.CENTER);
|
||||
|
||||
elementHelper.addFertilityInfo(primaryFertility, 0, 0);
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.area"), bee, EnumBeeChromosome.TERRITORY, active);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.effect"), bee, EnumBeeChromosome.EFFECT, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.area"), bee, EnumBeeChromosome.TERRITORY, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.effect"), bee, EnumBeeChromosome.EFFECT, active);
|
||||
|
||||
String yes = Translator.translateToLocal("for.yes");
|
||||
String no = Translator.translateToLocal("for.no");
|
||||
@@ -90,17 +84,21 @@ public class BeeDatabaseTab implements IDatabaseTab<IBee> {
|
||||
}
|
||||
}
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.diurnal"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addText(diurnal, GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(false));
|
||||
container.addRow(Translator.translateToLocal("for.gui.diurnal"), diurnal, false);
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.nocturnal"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addText(nocturnal, GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(false));
|
||||
//elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.diurnal"), GuiElementAlignment.CENTER);
|
||||
//elementHelper.addText(diurnal, GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(false));
|
||||
|
||||
container.addRow(Translator.translateToLocal("for.gui.nocturnal"), nocturnal, false);
|
||||
|
||||
//elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.nocturnal"), GuiElementAlignment.CENTER);
|
||||
//elementHelper.addText(nocturnal, GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(false));
|
||||
|
||||
String flyer = StringUtil.readableBoolean(active ? bee.getGenome().getToleratesRain() : ((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TOLERATES_RAIN)).getValue(), yes, no);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.flyer"), (a) -> flyer, bee, EnumButterflyChromosome.TOLERANT_FLYER, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.flyer"), (a) -> flyer, bee, EnumButterflyChromosome.TOLERANT_FLYER, active);
|
||||
|
||||
String cave = StringUtil.readableBoolean(active ? bee.getGenome().getCaveDwelling() : ((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.CAVE_DWELLING)).getValue(), yes, no);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.fireresist"), (a) -> cave, bee, EnumButterflyChromosome.FIRE_RESIST, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.cave"), (a) -> cave, bee, EnumButterflyChromosome.FIRE_RESIST, active);
|
||||
|
||||
String displayText;
|
||||
if (type == EnumBeeType.PRINCESS || type == EnumBeeType.QUEEN) {
|
||||
@@ -109,12 +107,12 @@ public class BeeDatabaseTab implements IDatabaseTab<IBee> {
|
||||
displayTextKey = "for.bees.stock.ignoble";
|
||||
}
|
||||
displayText = Translator.translateToLocal(displayTextKey);
|
||||
elementHelper.addText(displayText, GuiElementAlignment.CENTER, ColourProperties.INSTANCE.get("gui.beealyzer.binomial"));
|
||||
container.text(displayText, GuiElementAlignment.TOP_CENTER, ColourProperties.INSTANCE.get("gui.beealyzer.binomial"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumDatabaseTab getTab() {
|
||||
return tab;
|
||||
public ItemStack getIconStack() {
|
||||
return BeeDefinition.MEADOWS.getMemberStack(active ? EnumBeeType.PRINCESS : EnumBeeType.DRONE);
|
||||
}
|
||||
}
|
||||
@@ -10,26 +10,26 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.apiculture.EnumBeeType;
|
||||
import forestry.api.apiculture.IAlleleBeeSpecies;
|
||||
import forestry.api.apiculture.IBee;
|
||||
import forestry.api.genetics.EnumDatabaseTab;
|
||||
import forestry.api.genetics.IDatabaseTab;
|
||||
import forestry.api.genetics.ISpeciesPlugin;
|
||||
import forestry.apiculture.ModuleApiculture;
|
||||
import forestry.apiculture.items.EnumHoneyComb;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.genetics.analyzer.DatabasePlugin;
|
||||
import forestry.core.genetics.analyzer.MutationsTab;
|
||||
import forestry.core.genetics.analyzer.ProductsTab;
|
||||
|
||||
//TODO: Add support for the alyzer
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class BeePlugin implements ISpeciesPlugin<IBee> {
|
||||
public class BeePlugin extends DatabasePlugin<IBee> {
|
||||
public static final BeePlugin INSTANCE = new BeePlugin();
|
||||
private static final BeeDatabaseTab ACTIVE = new BeeDatabaseTab(EnumDatabaseTab.ACTIVE_SPECIES);
|
||||
private static final BeeDatabaseTab INACTIVE = new BeeDatabaseTab(EnumDatabaseTab.INACTIVE_SPECIES);
|
||||
|
||||
protected final Map<String, ItemStack> iconStacks = new HashMap<>();
|
||||
|
||||
private BeePlugin() {
|
||||
super(new BeeDatabaseTab(true),
|
||||
new BeeDatabaseTab(false),
|
||||
new ProductsTab(()->ModuleApiculture.getItems().beeComb.get(EnumHoneyComb.HONEY, 1)),
|
||||
new MutationsTab(()-> ModuleApiculture.getItems().frameImpregnated.getItemStack()));
|
||||
NonNullList<ItemStack> beeList = NonNullList.create();
|
||||
ModuleApiculture.getItems().beeDroneGE.addCreativeItems(beeList, false);
|
||||
for (ItemStack beeStack : beeList) {
|
||||
@@ -47,25 +47,4 @@ public class BeePlugin implements ISpeciesPlugin<IBee> {
|
||||
public List<String> getHints() {
|
||||
return Config.hints.get("beealyzer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDatabaseTab getSpeciesTab(boolean active) {
|
||||
if(active){
|
||||
return ACTIVE;
|
||||
}
|
||||
return INACTIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTabDatabaseIconItem(EnumDatabaseTab tab) {
|
||||
switch (tab){
|
||||
case ACTIVE_SPECIES:
|
||||
return BeeDefinition.MEADOWS.getMemberStack(EnumBeeType.QUEEN);
|
||||
case PRODUCTS:
|
||||
return ModuleApiculture.getItems().beeComb.get(EnumHoneyComb.HONEY, 1);
|
||||
case MUTATIONS:
|
||||
return ModuleApiculture.getItems().frameImpregnated.getItemStack();
|
||||
}
|
||||
return BeeDefinition.MEADOWS.getMemberStack(EnumBeeType.DRONE);
|
||||
}
|
||||
}
|
||||
@@ -49,9 +49,9 @@ import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlyzerPlugin;
|
||||
import forestry.api.genetics.IChromosome;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IDatabasePlugin;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.ISpeciesPlugin;
|
||||
import forestry.api.genetics.ISpeciesType;
|
||||
import forestry.apiculture.BeeHousingListener;
|
||||
import forestry.apiculture.BeeHousingModifier;
|
||||
@@ -176,6 +176,24 @@ public class BeeRoot extends SpeciesRoot implements IBeeRoot {
|
||||
return EnumBeeType.DRONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpeciesType[] getTypes() {
|
||||
return EnumBeeType.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpeciesType getTypeForMutation(int position) {
|
||||
switch (position){
|
||||
case 0:
|
||||
return EnumBeeType.PRINCESS;
|
||||
case 1:
|
||||
return EnumBeeType.DRONE;
|
||||
case 2:
|
||||
return EnumBeeType.QUEEN;
|
||||
}
|
||||
return getIconType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrone(ItemStack stack) {
|
||||
return getType(stack) == EnumBeeType.DRONE;
|
||||
@@ -385,7 +403,7 @@ public class BeeRoot extends SpeciesRoot implements IBeeRoot {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ISpeciesPlugin getSpeciesPlugin() {
|
||||
public IDatabasePlugin getSpeciesPlugin() {
|
||||
return BeePlugin.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gui;
|
||||
|
||||
import forestry.apiculture.tiles.TileBeeHousingBase;
|
||||
import forestry.core.gui.ContainerTile;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.packets.PacketGuiUpdate;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
public class ContainerBeeHousing extends ContainerTile<TileBeeHousingBase> implements IContainerBeeHousing {
|
||||
import forestry.apiculture.tiles.TileBeeHousingBase;
|
||||
import forestry.core.gui.ContainerAnalyzerProvider;
|
||||
import forestry.core.network.IForestryPacketClient;
|
||||
import forestry.core.network.packets.PacketGuiUpdate;
|
||||
|
||||
public class ContainerBeeHousing extends ContainerAnalyzerProvider<TileBeeHousingBase> implements IContainerBeeHousing {
|
||||
|
||||
public ContainerBeeHousing(InventoryPlayer player, TileBeeHousingBase tile, boolean hasFrames) {
|
||||
super(tile, player, 8, 108);
|
||||
|
||||
@@ -10,12 +10,16 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gui;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.render.EnumTankLevel;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class GuiBeeHousing<C extends Container & IContainerBeeHousing> extends GuiForestryTitled<C> {
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.ContainerForestry;
|
||||
import forestry.core.gui.GuiAnalyzerProvider;
|
||||
import forestry.core.gui.slots.SlotWatched;
|
||||
import forestry.core.render.EnumTankLevel;
|
||||
|
||||
public class GuiBeeHousing<C extends ContainerForestry & IContainerBeeHousing> extends GuiAnalyzerProvider<C> {
|
||||
private final IGuiBeeHousingDelegate delegate;
|
||||
|
||||
public enum Icon {
|
||||
@@ -30,18 +34,36 @@ public class GuiBeeHousing<C extends Container & IContainerBeeHousing> extends G
|
||||
}
|
||||
|
||||
public GuiBeeHousing(IGuiBeeHousingDelegate delegate, C container, Icon icon) {
|
||||
super(Constants.TEXTURE_PATH_GUI + icon.path, container, delegate);
|
||||
super(Constants.TEXTURE_PATH_GUI + icon.path, container, delegate, 25, 7, 2, 0);
|
||||
this.delegate = delegate;
|
||||
this.ySize = 190;
|
||||
|
||||
for(int i = 0;i < 2;i++) {
|
||||
Slot queenSlot = container.getForestrySlot(1 + i);
|
||||
if (queenSlot instanceof SlotWatched) {
|
||||
SlotWatched watched = (SlotWatched) queenSlot;
|
||||
watched.setChangeWatcher(this);
|
||||
}
|
||||
}
|
||||
analyzer.init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
bindTexture(textureFile);
|
||||
drawHealthMeter(guiLeft + 20, guiTop + 37, delegate.getHealthScaled(46), EnumTankLevel.rateTankLevel(delegate.getHealthScaled(100)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSelectedSlot(int selectedSlot) {
|
||||
Slot slot = container.getForestrySlot(1 + selectedSlot);
|
||||
if(slot != null){
|
||||
SELECTED_COMB_SLOT.draw(guiLeft + slot.xPos -3, guiTop + slot.yPos - 3);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) {
|
||||
int i = 176 + rated.getLevelScaled(16);
|
||||
int k = 0;
|
||||
@@ -56,4 +78,25 @@ public class GuiBeeHousing<C extends Container & IContainerBeeHousing> extends G
|
||||
addHintLedger(delegate.getHintKey());
|
||||
addOwnerLedger(delegate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getSpecimen(int index) {
|
||||
Slot slot = container.getForestrySlot(getSelectedSlot(index));
|
||||
return slot.getStack();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasErrors() {
|
||||
return delegate.getErrorLogic().hasErrors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUpdateSelected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelection(int index, boolean changed) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -93,13 +93,13 @@ public class GuiImprinter extends GuiForestry<ContainerImprinter> {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int i, int j, int k) throws IOException {
|
||||
super.mouseClicked(i, j, k);
|
||||
protected void mouseClicked(int mouseX, int mouseY, int k) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, k);
|
||||
|
||||
int cornerX = (width - xSize) / 2;
|
||||
int cornerY = (height - ySize) / 2;
|
||||
|
||||
int slot = getHabitatSlotAtPosition(i - cornerX, j - cornerY);
|
||||
int slot = getHabitatSlotAtPosition(mouseX - cornerX, mouseY - cornerY);
|
||||
if (slot < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
@@ -53,7 +52,6 @@ import forestry.api.arboriculture.TreeManager;
|
||||
import forestry.api.arboriculture.WoodBlockKind;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.apiculture.ModuleApiculture;
|
||||
import forestry.apiculture.flowers.Flower;
|
||||
@@ -65,6 +63,7 @@ import forestry.core.blocks.BlockBase;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
import forestry.modules.ModuleHelper;
|
||||
|
||||
public class VillageApiaristHouse extends StructureVillagePieces.House1 {
|
||||
|
||||
@@ -383,7 +382,7 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 {
|
||||
|
||||
if (villagerCount <= 0) {
|
||||
return registry.getID(ModuleApiculture.villagerApiarist);
|
||||
} else if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.ARBORICULTURE))) {
|
||||
} else if (ModuleHelper.isEnabled(ForestryModuleUids.ARBORICULTURE)) {
|
||||
return registry.getID(ModuleArboriculture.villagerArborist);
|
||||
} else {
|
||||
return currentVillagerProfession;
|
||||
@@ -408,7 +407,7 @@ public class VillageApiaristHouse extends StructureVillagePieces.House1 {
|
||||
IWoodType woodType;
|
||||
boolean fireproof;
|
||||
|
||||
if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.ARBORICULTURE))) {
|
||||
if (ModuleHelper.isEnabled(ForestryModuleUids.ARBORICULTURE)) {
|
||||
woodType = EnumForestryWoodType.getRandom(random);
|
||||
fireproof = random.nextInt(4) == 0;
|
||||
} else {
|
||||
|
||||
@@ -14,7 +14,6 @@ import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
@@ -110,7 +109,7 @@ import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.VillagerTradeLists;
|
||||
import forestry.modules.BlankForestryModule;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
import forestry.modules.ModuleManager;
|
||||
import forestry.modules.ModuleHelper;
|
||||
|
||||
@ForestryModule(containerID = Constants.MOD_ID, moduleID = ForestryModuleUids.ARBORICULTURE, name = "Arboriculture", author = "Binnie & SirSengir", url = Constants.URL, unlocalizedDescription = "for.module.arboriculture.description", lootTable = "arboriculture")
|
||||
public class ModuleArboriculture extends BlankForestryModule {
|
||||
@@ -215,7 +214,7 @@ public class ModuleArboriculture extends BlankForestryModule {
|
||||
// Commands
|
||||
ModuleCore.rootCommand.addChildCommand(new CommandTree());
|
||||
|
||||
if(ModuleManager.getInstance().isModuleEnabled(Constants.MOD_ID, ForestryModuleUids.SORTING)){
|
||||
if(ModuleHelper.isEnabled( ForestryModuleUids.SORTING)){
|
||||
ArboricultureFilterRuleType.init();
|
||||
}
|
||||
}
|
||||
@@ -391,7 +390,7 @@ public class ModuleArboriculture extends BlankForestryModule {
|
||||
'#', fireproofPlanks.copy());
|
||||
|
||||
// Fabricator recipes
|
||||
if (ForestryAPI.enabledModules.containsAll(Arrays.asList(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FACTORY), new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.APICULTURE)))) {
|
||||
if (ModuleHelper.isEnabled(ForestryModuleUids.FACTORY, ForestryModuleUids.APICULTURE)) {
|
||||
logs.setCount(1);
|
||||
fireproofLogs.setCount(1);
|
||||
RecipeManagers.fabricatorManager.addRecipe(ItemStack.EMPTY, Fluids.GLASS.getFluid(500), fireproofLogs.copy(), new Object[]{
|
||||
@@ -412,7 +411,7 @@ public class ModuleArboriculture extends BlankForestryModule {
|
||||
}
|
||||
}
|
||||
|
||||
if (ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.FACTORY))) {
|
||||
if (ModuleHelper.isEnabled(ForestryModuleUids.FACTORY)) {
|
||||
|
||||
// SQUEEZER RECIPES
|
||||
int seedOilMultiplier = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed");
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.genetics;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.ICheckPollinatable;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.apiculture.ModuleApiculture;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
public class CheckPollinatableTree implements ICheckPollinatable {
|
||||
private final ITree tree;
|
||||
|
||||
|
||||
@@ -11,82 +11,80 @@ import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.EnumFruitFamily;
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.EnumTreeChromosome;
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.core.GuiElementAlignment;
|
||||
import forestry.api.core.IGuiElementHelper;
|
||||
import forestry.api.genetics.EnumDatabaseTab;
|
||||
import forestry.api.genetics.IAlleleInteger;
|
||||
import forestry.api.genetics.IDatabaseTab;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.api.gui.IElementGenetic;
|
||||
import forestry.arboriculture.genetics.alleles.AlleleFruits;
|
||||
import forestry.core.gui.elements.GuiElementFactory;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TreeDatabaseTab implements IDatabaseTab<ITree> {
|
||||
private final EnumDatabaseTab tab;
|
||||
private final boolean active;
|
||||
|
||||
TreeDatabaseTab(EnumDatabaseTab tab) {
|
||||
this.tab = tab;
|
||||
TreeDatabaseTab(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createElements(IGuiElementHelper elementHelper, ITree tree, ItemStack itemStack) {
|
||||
public void createElements(IElementGenetic container, ITree tree, ItemStack itemStack) {
|
||||
IAlleleTreeSpecies primarySpecies = tree.getGenome().getPrimary();
|
||||
boolean active = tab == EnumDatabaseTab.ACTIVE_SPECIES;
|
||||
IAlleleTreeSpecies species = active ? primarySpecies : tree.getGenome().getSecondary();
|
||||
int speciesColor = elementHelper.factory().getColorCoding(species.isDominant());
|
||||
int speciesColor = GuiElementFactory.INSTANCE.getColorCoding(species.isDominant());
|
||||
|
||||
elementHelper.addText(Translator.translateToLocal("for.gui.database.tab." + tab.name().toLowerCase() + ".name"), GuiElementAlignment.CENTER, 0xcfb53b);
|
||||
container.text(Translator.translateToLocal("for.gui.database.tab." + (active ? "active" : "inactive") + "_species.name"), GuiElementAlignment.TOP_CENTER, 0xcfb53b);
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.species"), tree, EnumTreeChromosome.SPECIES, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.species"), tree, EnumTreeChromosome.SPECIES, active);
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.saplings"), tree, EnumTreeChromosome.FERTILITY, active);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.maturity"), tree, EnumTreeChromosome.MATURATION, active);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.height"), tree, EnumTreeChromosome.HEIGHT, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.saplings"), tree, EnumTreeChromosome.FERTILITY, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.maturity"), tree, EnumTreeChromosome.MATURATION, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.height"), tree, EnumTreeChromosome.HEIGHT, active);
|
||||
|
||||
IAlleleInteger girth = (IAlleleInteger) (active ? tree.getGenome().getActiveAllele(EnumTreeChromosome.GIRTH) : tree.getGenome().getInactiveAllele(EnumTreeChromosome.GIRTH));
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.girth"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addText(String.format("%sx%s", girth.getValue(), girth.getValue()), GuiElementAlignment.CENTER, elementHelper.factory().getColorCoding(girth.isDominant()));
|
||||
container.addRow(Translator.translateToLocal("for.gui.girth"), String.format("%sx%s", girth.getValue(), girth.getValue()), girth.isDominant());
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.yield"), tree, EnumTreeChromosome.YIELD, active);
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.sappiness"), tree, EnumTreeChromosome.SAPPINESS, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.yield"), tree, EnumTreeChromosome.YIELD, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.sappiness"), tree, EnumTreeChromosome.SAPPINESS, active);
|
||||
|
||||
elementHelper.addAllele(Translator.translateToLocal("for.gui.effect"), tree, EnumTreeChromosome.EFFECT, active);
|
||||
container.addAlleleRow(Translator.translateToLocal("for.gui.effect"), tree, EnumTreeChromosome.EFFECT, active);
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.native"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addText(Translator.translateToLocal("for.gui." + tree.getGenome().getPrimary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), GuiElementAlignment.CENTER, speciesColor);
|
||||
container.addRow(Translator.translateToLocal("for.gui.native"), Translator.translateToLocal("for.gui." + tree.getGenome().getPrimary().getPlantType().toString().toLowerCase(Locale.ENGLISH)), species.isDominant());
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.supports"), GuiElementAlignment.CENTER);
|
||||
container.text(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.supports"), GuiElementAlignment.TOP_CENTER);
|
||||
List<IFruitFamily> families = new ArrayList<>(tree.getGenome().getPrimary().getSuitableFruit());
|
||||
|
||||
for (IFruitFamily fruitFamily : families) {
|
||||
elementHelper.addText(fruitFamily.getName(), GuiElementAlignment.CENTER, speciesColor);
|
||||
container.text(fruitFamily.getName(), GuiElementAlignment.TOP_CENTER, speciesColor);
|
||||
}
|
||||
|
||||
IAlleleFruit fruit = (IAlleleFruit) (active ? tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS) : tree.getGenome().getInactiveAllele(EnumTreeChromosome.FRUITS));
|
||||
int colorCoding = elementHelper.factory().getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).isDominant());
|
||||
int colorCoding = GuiElementFactory.INSTANCE.getColorCoding(tree.getGenome().getActiveAllele(EnumTreeChromosome.FRUITS).isDominant());
|
||||
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.fruits"), GuiElementAlignment.CENTER);
|
||||
container.text(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.fruits"), GuiElementAlignment.TOP_CENTER);
|
||||
String strike = "";
|
||||
if (!species.getSuitableFruit().contains(fruit.getProvider().getFamily()) && fruit != AlleleFruits.fruitNone) {
|
||||
strike = TextFormatting.STRIKETHROUGH.toString();
|
||||
}
|
||||
elementHelper.addText(strike + fruit.getProvider().getDescription(), GuiElementAlignment.CENTER, colorCoding);
|
||||
container.text(strike + fruit.getProvider().getDescription(), GuiElementAlignment.TOP_CENTER, colorCoding);
|
||||
|
||||
IFruitFamily family = fruit.getProvider().getFamily();
|
||||
|
||||
if (family != null && !family.getUID().equals(EnumFruitFamily.NONE.getUID())) {
|
||||
elementHelper.addText(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.family"), GuiElementAlignment.CENTER);
|
||||
elementHelper.addText(family.getName(), GuiElementAlignment.CENTER, colorCoding);
|
||||
container.text(TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.family"), GuiElementAlignment.TOP_CENTER);
|
||||
container.text(family.getName(), GuiElementAlignment.TOP_CENTER, colorCoding);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumDatabaseTab getTab() {
|
||||
return tab;
|
||||
public ItemStack getIconStack() {
|
||||
return TreeDefinition.Cherry.getMemberStack(active ? EnumGermlingType.SAPLING : EnumGermlingType.POLLEN);
|
||||
}
|
||||
}
|
||||
@@ -10,26 +10,26 @@ import net.minecraft.util.NonNullList;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.IAlleleTreeSpecies;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.EnumDatabaseTab;
|
||||
import forestry.api.genetics.IDatabaseTab;
|
||||
import forestry.api.genetics.ISpeciesPlugin;
|
||||
import forestry.arboriculture.ModuleArboriculture;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.genetics.analyzer.DatabasePlugin;
|
||||
import forestry.core.genetics.analyzer.MutationsTab;
|
||||
import forestry.core.genetics.analyzer.ProductsTab;
|
||||
import forestry.core.items.ItemFruit;
|
||||
|
||||
//TODO: Add support for the alyzer
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TreePlugin implements ISpeciesPlugin<ITree> {
|
||||
public class TreePlugin extends DatabasePlugin<ITree> {
|
||||
public static final TreePlugin INSTANCE = new TreePlugin();
|
||||
private static final TreeDatabaseTab ACTIVE = new TreeDatabaseTab(EnumDatabaseTab.ACTIVE_SPECIES);
|
||||
private static final TreeDatabaseTab INACTIVE = new TreeDatabaseTab(EnumDatabaseTab.INACTIVE_SPECIES);
|
||||
|
||||
protected final Map<String, ItemStack> iconStacks = new HashMap<>();
|
||||
|
||||
private TreePlugin() {
|
||||
super(new TreeDatabaseTab(true),
|
||||
new TreeDatabaseTab(false),
|
||||
new ProductsTab(()-> ItemFruit.EnumFruit.CHERRY.getStack()),
|
||||
new MutationsTab(()->ModuleArboriculture.getItems().grafter.getItemStack()));
|
||||
NonNullList<ItemStack> treeList = NonNullList.create();
|
||||
ModuleArboriculture.getItems().sapling.addCreativeItems(treeList, false);
|
||||
for (ItemStack treeStack : treeList) {
|
||||
@@ -47,25 +47,4 @@ public class TreePlugin implements ISpeciesPlugin<ITree> {
|
||||
public List<String> getHints() {
|
||||
return Config.hints.get("treealyzer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IDatabaseTab getSpeciesTab(boolean active) {
|
||||
if(active){
|
||||
return ACTIVE;
|
||||
}
|
||||
return INACTIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getTabDatabaseIconItem(EnumDatabaseTab tab) {
|
||||
switch (tab){
|
||||
case ACTIVE_SPECIES:
|
||||
return TreeDefinition.Cherry.getMemberStack(EnumGermlingType.SAPLING);
|
||||
case PRODUCTS:
|
||||
return ItemFruit.EnumFruit.CHERRY.getStack();
|
||||
case MUTATIONS:
|
||||
return ModuleArboriculture.getItems().grafter.getItemStack();
|
||||
}
|
||||
return TreeDefinition.Cherry.getMemberStack(EnumGermlingType.POLLEN);
|
||||
}
|
||||
}
|
||||
@@ -60,11 +60,11 @@ import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlyzerPlugin;
|
||||
import forestry.api.genetics.ICheckPollinatable;
|
||||
import forestry.api.genetics.IChromosomeType;
|
||||
import forestry.api.genetics.IDatabasePlugin;
|
||||
import forestry.api.genetics.IFruitFamily;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.api.genetics.ISpeciesPlugin;
|
||||
import forestry.api.genetics.ISpeciesType;
|
||||
import forestry.arboriculture.ModuleArboriculture;
|
||||
import forestry.arboriculture.blocks.BlockFruitPod;
|
||||
@@ -158,6 +158,11 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
return EnumGermlingType.SAPLING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISpeciesType[] getTypes() {
|
||||
return EnumGermlingType.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITree getTree(World world, BlockPos pos) {
|
||||
return TileUtil.getResultFromTile(world, pos, TileSapling.class, TileSapling::getTree);
|
||||
@@ -435,7 +440,7 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public ISpeciesPlugin getSpeciesPlugin() {
|
||||
public IDatabasePlugin getSpeciesPlugin() {
|
||||
return TreePlugin.INSTANCE;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package forestry.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.api.book.IBookEntryBuilder;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public class BookCategory implements IBookCategory {
|
||||
private final String name;
|
||||
private final transient Map<String, IBookEntry> entries = new LinkedHashMap<>();
|
||||
private ItemStack stack = ItemStack.EMPTY;
|
||||
|
||||
public BookCategory(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookCategory setStack(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookCategory addEntry(IBookEntry entry) {
|
||||
entries.put(entry.getName(), entry);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookCategory addEntry(String name, ItemStack stack) {
|
||||
BookEntryBuilder builder = new BookEntryBuilder(this, name);
|
||||
builder.setStack(stack);
|
||||
builder.addToCategory();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntryBuilder createEntry(String name) {
|
||||
return new BookEntryBuilder(this, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntryBuilder createEntry(String name, ItemStack stack) {
|
||||
return new BookEntryBuilder(this, name).setStack(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IBookEntry> getEntries() {
|
||||
return entries.values();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBookEntry getEntry(String name) {
|
||||
return entries.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedName() {
|
||||
return Translator.translateToLocal("for.gui.book.category." + name + ".title");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return "for.gui.book.category." + name + ".tooltip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package forestry.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.api.book.IBookPageFactory;
|
||||
|
||||
public class BookEntry implements IBookEntry {
|
||||
private final String name;
|
||||
private final ItemStack stack;
|
||||
private final IBookPageFactory loader;
|
||||
@Nullable
|
||||
private final IBookEntry parent;
|
||||
private final IBookEntry[] subEntries;
|
||||
private final BookContent[][] content;
|
||||
private final String title;
|
||||
|
||||
BookEntry(String name, ItemStack stack, IBookPageFactory loader, Function<IBookEntry, IBookEntry[]> subEntryFactory, BookContent[][] content, String title, @Nullable IBookEntry parent) {
|
||||
this.name = name;
|
||||
this.stack = stack;
|
||||
this.loader = loader;
|
||||
this.subEntries = subEntryFactory.apply(this);
|
||||
this.content = content;
|
||||
this.title = title;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookContent[][] getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookPageFactory getPageFactory() {
|
||||
return loader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntry[] getSubEntries() {
|
||||
return subEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public IBookEntry getParent() {
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package forestry.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.api.book.IBookEntryBuilder;
|
||||
import forestry.api.book.IBookPageFactory;
|
||||
import forestry.book.pages.JsonPageFactory;
|
||||
|
||||
public class BookEntryBuilder implements IBookEntryBuilder {
|
||||
private final String name;
|
||||
private final IBookCategory category;
|
||||
private ItemStack stack = ItemStack.EMPTY;
|
||||
private IBookPageFactory loader = JsonPageFactory.INSTANCE;
|
||||
private List<IBookEntryBuilder> subEntries = new LinkedList<>();
|
||||
private String title = "missing.title";
|
||||
private BookContent[][] content = new BookContent[0][0];
|
||||
|
||||
BookEntryBuilder(IBookCategory category, String name) {
|
||||
this.category = category;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookEntryBuilder setStack(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookEntryBuilder setLoader(IBookPageFactory loader) {
|
||||
this.loader = loader;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BookEntryBuilder createSubEntry(String name, ItemStack stack) {
|
||||
BookEntryBuilder builder = new BookEntryBuilder(category, name).setStack(stack);
|
||||
subEntries.add(builder);
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntryBuilder setContent(BookContent[][] content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntryBuilder setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntry build(@Nullable IBookEntry parent) {
|
||||
return new BookEntry(name, stack, loader, entry -> subEntries.stream().map(builder -> builder.build(entry)).toArray(IBookEntry[]::new), content, title, parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookEntry build() {
|
||||
return build(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookCategory addToCategory() {
|
||||
category.addEntry(build());
|
||||
return category;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
package forestry.book;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
import net.minecraft.client.resources.IResourceManagerReloadListener;
|
||||
import net.minecraft.client.resources.Language;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.book.IBookEntryBuilder;
|
||||
import forestry.api.book.IBookLoader;
|
||||
import forestry.api.book.IBookPageFactory;
|
||||
import forestry.api.book.IForesterBook;
|
||||
import forestry.book.data.EntryData;
|
||||
import forestry.book.data.content.CarpenterContent;
|
||||
import forestry.book.data.content.CraftingContent;
|
||||
import forestry.book.data.content.FabricatorContent;
|
||||
import forestry.book.data.content.ImageContent;
|
||||
import forestry.book.data.content.IndexContent;
|
||||
import forestry.book.data.content.MutationContent;
|
||||
import forestry.book.data.content.StructureContent;
|
||||
import forestry.book.data.content.TextContent;
|
||||
import forestry.book.data.deserializer.BookCategoryDeserializer;
|
||||
import forestry.book.data.deserializer.BookContentDeserializer;
|
||||
import forestry.book.pages.JsonPageFactory;
|
||||
import forestry.core.utils.JsonUtil;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.ResourceUtil;
|
||||
import forestry.modules.ModuleHelper;
|
||||
|
||||
public class BookLoader implements IResourceManagerReloadListener, IBookLoader {
|
||||
public static final Gson GSON = new GsonBuilder()
|
||||
.registerTypeAdapter(BookContent.class, new BookContentDeserializer())
|
||||
.registerTypeAdapter(BookCategory.class, new BookCategoryDeserializer())
|
||||
.registerTypeAdapter(ResourceLocation.class, (JsonDeserializer<ResourceLocation>) (json, typeOfT, context) -> new ResourceLocation(JsonUtils.getString(json, "location")))
|
||||
.registerTypeAdapter(ItemStack.class, (JsonDeserializer<ItemStack>) (json, typeOfT, context) -> JsonUtil.deserializeItemStack(json.getAsJsonObject(), ItemStack.EMPTY))
|
||||
.registerTypeAdapter(Entries.class, new EntriesDeserializer())
|
||||
.create();
|
||||
public static final BookLoader INSTANCE = new BookLoader();
|
||||
private static final String BOOK_LOCATION = "forestry:manual/";
|
||||
private static final String BOOK_LOCATION_LANG = BOOK_LOCATION + "%s/%s";
|
||||
private final Map<String, Class<? extends BookContent>> contentByType = new HashMap<>();
|
||||
private final Map<String, IBookPageFactory> factoryByName = new HashMap<>();
|
||||
@Nullable
|
||||
private ForesterBook book = null;
|
||||
|
||||
private BookLoader() {
|
||||
registerContentType("text", TextContent.class);
|
||||
registerContentType("image", ImageContent.class);
|
||||
registerContentType("crafting", CraftingContent.class);
|
||||
registerContentType("mutation", MutationContent.class);
|
||||
registerContentType("carpenter", CarpenterContent.class);
|
||||
registerContentType("structure", StructureContent.class);
|
||||
registerContentType("index", IndexContent.class);
|
||||
registerContentType("fabricator", FabricatorContent.class);
|
||||
registerPageFactory(JsonPageFactory.NAME, JsonPageFactory.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerContentType(String name, Class<? extends BookContent> contentClass) {
|
||||
contentByType.put(name, contentClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerPageFactory(String name, IBookPageFactory factory) {
|
||||
factoryByName.put(name, factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookPageFactory getPageFactory(String name) {
|
||||
IBookPageFactory factory = factoryByName.get(name);
|
||||
if (factory == null) {
|
||||
return JsonPageFactory.INSTANCE;
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
public IForesterBook loadBook() {
|
||||
if (book != null) {
|
||||
return book;
|
||||
}
|
||||
book = new ForesterBook();
|
||||
BookCategory[] categories = fromJson(new ResourceLocation(BOOK_LOCATION + "categories.json"), BookCategory[].class, new BookCategory[0]);
|
||||
if (categories != null) {
|
||||
book.addCategories(categories);
|
||||
for (BookCategory category : categories) {
|
||||
loadCategory(category);
|
||||
}
|
||||
}
|
||||
return book;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidateBook() {
|
||||
book = null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation getResourceLocation(String path) {
|
||||
if (!path.contains(":")) {
|
||||
Language currentLanguage = Minecraft.getMinecraft().getLanguageManager().getCurrentLanguage();
|
||||
String lang = currentLanguage.getLanguageCode();
|
||||
String defaultLang = "en_US";
|
||||
|
||||
ResourceLocation location = new ResourceLocation(String.format(BOOK_LOCATION_LANG, lang, path));
|
||||
if (ResourceUtil.resourceExists(location)) {
|
||||
return location;
|
||||
}
|
||||
location = new ResourceLocation(String.format(BOOK_LOCATION_LANG, defaultLang, path));
|
||||
if (ResourceUtil.resourceExists(location)) {
|
||||
return location;
|
||||
}
|
||||
location = new ResourceLocation(BOOK_LOCATION + path);
|
||||
if (ResourceUtil.resourceExists(location)) {
|
||||
return location;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
ResourceLocation location = new ResourceLocation(path);
|
||||
if (ResourceUtil.resourceExists(location)) {
|
||||
return location;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<? extends BookContent> getContentType(String name) {
|
||||
return contentByType.get(name);
|
||||
}
|
||||
|
||||
private void loadCategory(BookCategory category) {
|
||||
ResourceLocation entriesLocation = new ResourceLocation(BOOK_LOCATION + "entries/" + category.getName() + ".json");
|
||||
Set<String> entryNames = new HashSet<>();
|
||||
for (IResource entryResource : ResourceUtil.getResources(entriesLocation)) {
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(entryResource.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
Entries entries = GSON.fromJson(reader, Entries.class);
|
||||
entryNames.addAll(entries.names);
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to parse entries file {}.{}", entriesLocation, e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(entryResource);
|
||||
}
|
||||
}
|
||||
Map<String, EntryData> entries = new MapMaker().concurrencyLevel(ForkJoinPool.commonPool().getPoolSize() + 1).initialCapacity(entryNames.size()).makeMap();
|
||||
entryNames.parallelStream().forEach(entry -> loadEntries(entries, entry));
|
||||
entryNames.parallelStream().forEach(entry -> {
|
||||
EntryData data = entries.get(entry);
|
||||
if (data != null) {
|
||||
IBookEntryBuilder builder = category.createEntry(entry);
|
||||
builder.setStack(data.icon);
|
||||
builder.setContent(data.content);
|
||||
builder.setTitle(data.title);
|
||||
builder.setLoader(BookLoader.INSTANCE.getPageFactory(data.loader));
|
||||
for (String subEntry : data.subEntries) {
|
||||
EntryData subData = entries.get(subEntry);
|
||||
if (subData != null) {
|
||||
IBookEntryBuilder subBuilder = builder.createSubEntry(subEntry, subData.icon);
|
||||
subBuilder.setContent(subData.content);
|
||||
subBuilder.setTitle(subData.title);
|
||||
builder.setLoader(BookLoader.INSTANCE.getPageFactory(subData.loader));
|
||||
}
|
||||
}
|
||||
builder.addToCategory();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void loadEntries(Map<String, EntryData> entries, String entry) {
|
||||
ResourceLocation location = getResourceLocation(entry + ".json");
|
||||
EntryData data = fromJson(location, EntryData.class, null);
|
||||
if (data != null) {
|
||||
entries.put(entry, data);
|
||||
for (String subEntry : data.subEntries) {
|
||||
loadEntries(entries, subEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private <T> T fromJson(@Nullable ResourceLocation location, Class<T> classOfT, @Nullable T fallback) {
|
||||
if (location == null) {
|
||||
return fallback;
|
||||
}
|
||||
IResource resource = ResourceUtil.getResource(location);
|
||||
if (resource == null) {
|
||||
return fallback;
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
return GSON.fromJson(reader, classOfT);
|
||||
} catch (Exception e) {
|
||||
Log.error("Failed to load resource {}: {}", location, e);
|
||||
return fallback;
|
||||
} finally {
|
||||
IOUtils.closeQuietly(resource);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResourceManagerReload(IResourceManager resourceManager) {
|
||||
invalidateBook();
|
||||
}
|
||||
|
||||
private static class Entries {
|
||||
private final Set<String> names = new HashSet<>();
|
||||
}
|
||||
|
||||
private static class EntriesDeserializer implements JsonDeserializer<Entries> {
|
||||
@Override
|
||||
public Entries deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
|
||||
Entries entries = new Entries();
|
||||
parseElement(entries, json, context);
|
||||
return entries;
|
||||
}
|
||||
|
||||
private void parseElement(Entries entries, JsonElement element, JsonDeserializationContext context) {
|
||||
if (element.isJsonArray()) {
|
||||
String[] array = context.deserialize(element, String[].class);
|
||||
entries.names.addAll(Arrays.asList(array));
|
||||
} else {
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
for (Map.Entry<String, JsonElement> member : object.entrySet()) {
|
||||
if (ModuleHelper.isEnabled(member.getKey())) {
|
||||
parseElement(entries, member.getValue(), context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package forestry.book;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
|
||||
|
||||
import forestry.core.config.Config;
|
||||
|
||||
public class EventHandlerBook {
|
||||
|
||||
private static final String HAS_BOOK = "forestry.spawned_book";
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
if (Config.spawnWithBook) {
|
||||
NBTTagCompound playerData = event.player.getEntityData();
|
||||
NBTTagCompound data = playerData.hasKey(EntityPlayer.PERSISTED_NBT_TAG) ? playerData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG) : new NBTTagCompound();
|
||||
|
||||
if (!data.getBoolean(HAS_BOOK)) {
|
||||
ItemHandlerHelper.giveItemToPlayer(event.player, new ItemStack(ModuleBook.getItems().book));
|
||||
data.setBoolean(HAS_BOOK, true);
|
||||
playerData.setTag(EntityPlayer.PERSISTED_NBT_TAG, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package forestry.book;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.api.book.IForesterBook;
|
||||
|
||||
public class ForesterBook implements IForesterBook {
|
||||
|
||||
private final Map<String, IBookCategory> categoriesByName = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public Collection<String> getCategoryNames() {
|
||||
return categoriesByName.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBookCategory addCategory(String name) {
|
||||
IBookCategory category = getCategory(name);
|
||||
if (category == null) {
|
||||
categoriesByName.put(name, category = new BookCategory(name));
|
||||
}
|
||||
return category;
|
||||
}
|
||||
|
||||
void addCategories(IBookCategory[] categories) {
|
||||
for (IBookCategory category : categories) {
|
||||
categoriesByName.put(category.getName(), category);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBookCategory getCategory(String name) {
|
||||
return categoriesByName.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IBookCategory> getCategories() {
|
||||
return categoriesByName.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IBookEntry> getEntries(String category) {
|
||||
IBookCategory c = getCategory(category);
|
||||
return c == null ? Collections.emptySet() : c.getEntries();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBookEntry getEntry(String name) {
|
||||
for (IBookCategory category : categoriesByName.values()) {
|
||||
for (IBookEntry entry : category.getEntries()) {
|
||||
if (entry.getName().equalsIgnoreCase(name)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package forestry.book;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
|
||||
import forestry.api.book.BookManager;
|
||||
import forestry.api.modules.ForestryModule;
|
||||
import forestry.book.items.ItemRegistryBook;
|
||||
import forestry.book.proxy.ProxyBook;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.utils.OreDictUtil;
|
||||
import forestry.lepidopterology.ModuleLepidopterology;
|
||||
import forestry.lepidopterology.items.ItemRegistryLepidopterology;
|
||||
import forestry.modules.BlankForestryModule;
|
||||
import forestry.modules.ForestryModuleUids;
|
||||
import forestry.modules.ModuleHelper;
|
||||
import forestry.modules.ModuleManager;
|
||||
|
||||
@ForestryModule(containerID = Constants.MOD_ID, moduleID = ForestryModuleUids.BOOK, name = "Book", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.module.book.description")
|
||||
public class ModuleBook extends BlankForestryModule {
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@SidedProxy(clientSide = "forestry.book.proxy.ProxyBookClient", serverSide = "forestry.book.proxy.ProxyBook")
|
||||
public static ProxyBook proxy;
|
||||
|
||||
@Nullable
|
||||
private static ItemRegistryBook items;
|
||||
|
||||
public static ItemRegistryBook getItems() {
|
||||
Preconditions.checkState(items != null);
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupAPI() {
|
||||
BookManager.loader = BookLoader.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerItemsAndBlocks() {
|
||||
items = new ItemRegistryBook();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInit() {
|
||||
proxy.preInit();
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandlerBook());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerRecipes() {
|
||||
RecipeUtil.addShapelessRecipe("book_honey", new ItemStack(getItems().book), Items.BOOK, OreDictUtil.DROP_HONEY);
|
||||
RecipeUtil.addShapelessRecipe("book_tree", new ItemStack(getItems().book), Items.BOOK, OreDictUtil.TREE_SAPLING);
|
||||
if (ModuleHelper.isEnabled(ForestryModuleUids.LEPIDOPTEROLOGY)) {
|
||||
ItemRegistryLepidopterology itemsLepi = ModuleLepidopterology.getItems();
|
||||
RecipeUtil.addShapelessRecipe("book_butterfly", new ItemStack(getItems().book), Items.BOOK, itemsLepi.butterflyGE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit() {
|
||||
ModuleManager.getInternalHandler().runBookInit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package forestry.book.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class CraftingData {
|
||||
/**
|
||||
* The {@link ResourceLocation}s of the recipes of this crafting data.
|
||||
*/
|
||||
public ResourceLocation[] locations = new ResourceLocation[0];
|
||||
/**
|
||||
* The result stack of the recipes of this crafting data.
|
||||
*/
|
||||
public ItemStack stack = ItemStack.EMPTY;
|
||||
/**
|
||||
* The result stacks of the recipes of this crafting data.
|
||||
*/
|
||||
public ItemStack[] stacks = new ItemStack[0];
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package forestry.book.data;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
|
||||
public class EntryData {
|
||||
/**
|
||||
* The localized title of the entry.
|
||||
*/
|
||||
public String title = "";
|
||||
/**
|
||||
* The content that gets displayed on the pages of the entry.
|
||||
*/
|
||||
public BookContent[][] content = new BookContent[0][0];
|
||||
/**
|
||||
* All sub entries of this entry.
|
||||
*/
|
||||
public String[] subEntries = new String[0];
|
||||
/**
|
||||
* The name of the page factory.
|
||||
*/
|
||||
public String loader;
|
||||
/**
|
||||
* The item that will be displayed next to the title.
|
||||
*/
|
||||
public ItemStack icon = ItemStack.EMPTY;
|
||||
|
||||
public EntryData() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package forestry.book.data;
|
||||
|
||||
public class IndexData {
|
||||
/**
|
||||
* All entries of this index.
|
||||
*/
|
||||
public IndexEntry[] entries = new IndexEntry[0];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package forestry.book.data;
|
||||
|
||||
/**
|
||||
* A entry of an index.
|
||||
*/
|
||||
public class IndexEntry {
|
||||
/**
|
||||
* The localized name of the entry.
|
||||
*/
|
||||
public String title;
|
||||
/**
|
||||
* The page that a mouse click on this entry opens.
|
||||
*/
|
||||
public int page;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package forestry.book.data;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class TextData {
|
||||
public String text = "";
|
||||
|
||||
public String color = "black";
|
||||
public boolean bold = false;
|
||||
public boolean italic = false;
|
||||
public boolean underlined = false;
|
||||
public boolean strikethrough = false;
|
||||
public boolean obfuscated = false;
|
||||
public boolean paragraph = false;
|
||||
public boolean dropshadow = false;
|
||||
|
||||
public TextData() {
|
||||
}
|
||||
|
||||
public TextData(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.book.data.CraftingData;
|
||||
import forestry.book.gui.elements.CarpenterElement;
|
||||
|
||||
/**
|
||||
* A book content that displays a carpenter recipe.
|
||||
*/
|
||||
public class CarpenterContent extends BookContent<CraftingData> {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Class<? extends CraftingData> getDataClass() {
|
||||
return CraftingData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (data == null || (data.stack.isEmpty() && data.stacks.length == 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!data.stack.isEmpty()) {
|
||||
page.add(new CarpenterElement(0, 0, data.stack));
|
||||
} else {
|
||||
page.add(new CarpenterElement(0, 0, data.stacks));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fml.common.registry.ForgeRegistries;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.book.data.CraftingData;
|
||||
import forestry.book.gui.elements.CraftingElement;
|
||||
|
||||
/**
|
||||
* A book content that displays one ore more crafting recipes.
|
||||
*/
|
||||
public class CraftingContent extends BookContent<CraftingData> {
|
||||
@Override
|
||||
public Class<CraftingData> getDataClass() {
|
||||
return CraftingData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (data == null || data.locations.length == 0) {
|
||||
return false;
|
||||
}
|
||||
List<IRecipe> recipes = new LinkedList<>();
|
||||
for (ResourceLocation location : data.locations) {
|
||||
IRecipe recipe = ForgeRegistries.RECIPES.getValue(location);
|
||||
if (recipe != null) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
page.add(new CraftingElement(0, 0, recipes.toArray(new IRecipe[0])));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.api.recipes.IFabricatorSmeltingRecipe;
|
||||
import forestry.book.data.CraftingData;
|
||||
import forestry.book.gui.elements.FabricatorElement;
|
||||
import forestry.factory.recipes.FabricatorSmeltingRecipeManager;
|
||||
|
||||
public class FabricatorContent extends BookContent<CraftingData> {
|
||||
|
||||
@Override
|
||||
public Class<? extends CraftingData> getDataClass() {
|
||||
return CraftingData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (data == null || (data.stack.isEmpty() && data.stacks.length == 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!data.stack.isEmpty()) {
|
||||
page.add(new FabricatorElement(0, 0, data.stack));
|
||||
} else {
|
||||
page.add(new FabricatorElement(0, 0, data.stacks));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Map<Fluid, List<IFabricatorSmeltingRecipe>> getSmeltingInputs() {
|
||||
Map<Fluid, List<IFabricatorSmeltingRecipe>> smeltingInputs = new HashMap<>();
|
||||
for (IFabricatorSmeltingRecipe smelting : FabricatorSmeltingRecipeManager.recipes) {
|
||||
Fluid fluid = smelting.getProduct().getFluid();
|
||||
if (!smeltingInputs.containsKey(fluid)) {
|
||||
smeltingInputs.put(fluid, new ArrayList<>());
|
||||
}
|
||||
smeltingInputs.get(fluid).add(smelting);
|
||||
}
|
||||
return smeltingInputs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.core.gui.Drawable;
|
||||
import forestry.core.gui.elements.DrawableElement;
|
||||
|
||||
/**
|
||||
* A book content that displays a image.
|
||||
*/
|
||||
public class ImageContent extends BookContent<Drawable> {
|
||||
//The size fo the gui element.
|
||||
private int width;
|
||||
private int height;
|
||||
//Centers the element between the end of the page and the last element
|
||||
private boolean center;
|
||||
|
||||
@Override
|
||||
public Class<? extends Drawable> getDataClass() {
|
||||
return Drawable.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
if (center) {
|
||||
page.panel(page.getWidth(), pageHeight - page.getHeight())
|
||||
.add(new DrawableElement(0, 0, width, height, data)).setAlign(GuiElementAlignment.MIDDLE_CENTER);
|
||||
} else {
|
||||
page.add(new DrawableElement(0, 0, width, height, data)).setAlign(GuiElementAlignment.TOP_CENTER);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.book.data.IndexData;
|
||||
import forestry.book.gui.elements.IndexElement;
|
||||
|
||||
/**
|
||||
* A book
|
||||
*/
|
||||
public class IndexContent extends BookContent<IndexData> {
|
||||
@Nullable
|
||||
@Override
|
||||
public Class<? extends IndexData> getDataClass() {
|
||||
return IndexData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (data == null || data.entries.length <= 0) {
|
||||
return false;
|
||||
}
|
||||
page.add(new IndexElement(0, 0, data.entries));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.IAlleleSpecies;
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.book.gui.elements.MutationElement;
|
||||
|
||||
/**
|
||||
* A book content that displays one or more mutations.
|
||||
*/
|
||||
public class MutationContent extends BookContent {
|
||||
public String species = "";
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Class getDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
IAllele allele = AlleleManager.alleleRegistry.getAllele(species);
|
||||
if (!(allele instanceof IAlleleSpecies)) {
|
||||
return false;
|
||||
}
|
||||
IAlleleSpecies s = (IAlleleSpecies) allele;
|
||||
ISpeciesRoot root = s.getRoot();
|
||||
page.add(new MutationElement(0, 0, root.getResultantMutations(s).toArray(new IMutation[0])));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
/*******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Any alternate licenses are noted where appropriate.
|
||||
******************************************************************************/
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import net.minecraft.client.resources.IResource;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.book.BookLoader;
|
||||
import forestry.book.data.structure.BlockData;
|
||||
import forestry.book.data.structure.StructureData;
|
||||
import forestry.book.gui.elements.MultiblockElement;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.core.utils.ResourceUtil;
|
||||
|
||||
/**
|
||||
* A book content that displays a multiblock structure.
|
||||
*/
|
||||
public class StructureContent extends BookContent {
|
||||
@Nullable
|
||||
private String structureFile = null;
|
||||
private transient StructureData structureData;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Class getDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeserialization() {
|
||||
if (structureFile == null || structureFile.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation location = BookLoader.getResourceLocation(structureFile);
|
||||
|
||||
if (location != null && ResourceUtil.resourceExists(location)) {
|
||||
IResource resource = ResourceUtil.getResource(location);
|
||||
if (resource == null) {
|
||||
return;
|
||||
}
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8))) {
|
||||
structureData = BookLoader.GSON.fromJson(reader, StructureData.class);
|
||||
} catch (IOException e) {
|
||||
Log.error("Failed to load structure file {}.{}", location, e);
|
||||
} finally {
|
||||
IOUtils.closeQuietly(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (structureFile == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int offset = 0;
|
||||
int structureSizeX = page.getWidth();
|
||||
int structureSizeY = 155 - 10;
|
||||
|
||||
int[] size = structureData.size;
|
||||
BlockData[] structure = structureData.structure;
|
||||
|
||||
if (size.length == 3 && structure.length > 0) {
|
||||
boolean showButtons = size[1] > 1;
|
||||
if (showButtons) {
|
||||
//structureSizeX -= GuiArrow.ArrowType.REFRESH.w;
|
||||
}
|
||||
MultiblockElement elementStructure = new MultiblockElement(offset, 0, structureSizeX, structureSizeY, size, structure);
|
||||
page.add(elementStructure);
|
||||
|
||||
/*if(showButtons) {
|
||||
int col = book.appearance.structureButtonColor;
|
||||
int colHover = book.appearance.structureButtonColorHovered;
|
||||
int colToggled = book.appearance.structureButtonColorToggled;
|
||||
|
||||
int midY = y + structureSizeY / 2 - (GuiArrow.ArrowType.UP.h + GuiArrow.ArrowType.DOWN.h) / 2;
|
||||
|
||||
int dx = (GuiArrow.ArrowType.REFRESH.w - GuiArrow.ArrowType.UP.w) / 2;
|
||||
|
||||
//list.add(new ElementArrow(ElementStructure.BUTTON_ID_LAYER_UP, elementStructure, structureSizeX + offset + dx, midY, GuiArrow.ArrowType.UP, col, colHover));
|
||||
//midY += GuiArrow.ArrowType.UP.h + 2;
|
||||
//list.add(new ElementArrow(ElementStructure.BUTTON_ID_LAYER_DOWN, elementStructure, structureSizeX + offset + dx, midY, GuiArrow.ArrowType.DOWN, col, colHover));
|
||||
|
||||
list.add(new ElementAnimationToggle(ElementStructure.BUTTON_ID_ANIMATE, elementStructure, GuiBook.PAGE_WIDTH - GuiArrow.ArrowType.REFRESH.w, 0, GuiArrow.ArrowType.REFRESH, col, colHover, colToggled));
|
||||
}*/
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.api.gui.IGuiElementFactory;
|
||||
import forestry.book.data.TextData;
|
||||
import forestry.book.gui.elements.TextDataElement;
|
||||
|
||||
/**
|
||||
* A book content that displays one or more texts.
|
||||
*/
|
||||
public class TextContent extends BookContent<TextData> {
|
||||
@Override
|
||||
public Class<? extends TextData> getDataClass() {
|
||||
return TextData.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addElements(IElementGroup page, IGuiElementFactory factory, @Nullable BookContent previous, @Nullable IGuiElement previousElement, int pageHeight) {
|
||||
if (data == null) {
|
||||
return false;
|
||||
}
|
||||
TextDataElement element;
|
||||
if (previousElement instanceof TextDataElement) {
|
||||
element = (TextDataElement) previousElement;
|
||||
} else {
|
||||
element = new TextDataElement(0, 0, page.getWidth(), 0);
|
||||
page.add(element);
|
||||
}
|
||||
element.addData(data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.data.content;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,26 @@
|
||||
package forestry.book.data.deserializer;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
|
||||
import forestry.book.BookCategory;
|
||||
import forestry.core.utils.JsonUtil;
|
||||
|
||||
public class BookCategoryDeserializer implements JsonDeserializer<BookCategory> {
|
||||
@Override
|
||||
public BookCategory deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
String name = JsonUtils.getString(object, "name");
|
||||
ItemStack stack = JsonUtil.deserializeItemStack(JsonUtils.getJsonObject(object, "icon"));
|
||||
BookCategory category = new BookCategory(name);
|
||||
category.setStack(stack);
|
||||
return category;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package forestry.book.data.deserializer;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import net.minecraft.util.JsonUtils;
|
||||
|
||||
import forestry.api.book.BookContent;
|
||||
import forestry.book.BookLoader;
|
||||
import forestry.book.data.content.TextContent;
|
||||
|
||||
public class BookContentDeserializer implements JsonDeserializer<BookContent> {
|
||||
@Override
|
||||
public BookContent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
|
||||
JsonObject object = json.getAsJsonObject();
|
||||
String type = JsonUtils.getString(object, "type", "text");
|
||||
Class<? extends BookContent> typeClass = BookLoader.INSTANCE.getContentType(type);
|
||||
BookContent content = context.deserialize(object, typeClass == null ? TextContent.class : typeClass);
|
||||
content.type = type;
|
||||
if (content.getDataClass() != null) {
|
||||
content.data = context.deserialize(object, content.getDataClass());
|
||||
}
|
||||
content.onDeserialization();
|
||||
return content;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.data.deserializer;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.data;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,26 @@
|
||||
/*******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Any alternate licenses are noted where appropriate.
|
||||
******************************************************************************/
|
||||
package forestry.book.data.structure;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockData {
|
||||
public int[] pos;
|
||||
public int[] endPos;
|
||||
public String block;
|
||||
public byte meta;
|
||||
public JsonObject nbt;
|
||||
public Map<String, String> state;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Any alternate licenses are noted where appropriate.
|
||||
******************************************************************************/
|
||||
package forestry.book.data.structure;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
|
||||
public class StructureBlockAccess implements IBlockAccess {
|
||||
|
||||
private final StructureInfo data;
|
||||
private final IBlockState[][][] structure;
|
||||
|
||||
public StructureBlockAccess(StructureInfo data) {
|
||||
this.data = data;
|
||||
this.structure = data.data;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public TileEntity getTileEntity(BlockPos pos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCombinedLight(BlockPos pos, int lightValue) {
|
||||
// full brightness always
|
||||
return 15 << 20 | 15 << 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getBlockState(BlockPos pos) {
|
||||
int x = pos.getX();
|
||||
int y = pos.getY();
|
||||
int z = pos.getZ();
|
||||
|
||||
if (y >= 0 && y < structure.length) {
|
||||
if (x >= 0 && x < structure[y].length) {
|
||||
if (z >= 0 && z < structure[y][x].length) {
|
||||
int index = y * (data.structureLength * data.structureWidth) + x * data.structureWidth + z;
|
||||
if (index <= data.getLimiter()) {
|
||||
return structure[y][x][z] != null ? structure[y][x][z] : Blocks.AIR.getDefaultState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAirBlock(BlockPos pos) {
|
||||
return getBlockState(pos).getBlock() == Blocks.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiome(BlockPos pos) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStrongPower(BlockPos pos, EnumFacing direction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldType getWorldType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package forestry.book.data.structure;
|
||||
|
||||
public class StructureData {
|
||||
public int[] size = new int[0];
|
||||
public BlockData[] structure = new BlockData[0];
|
||||
|
||||
public StructureData() {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/*******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Any alternate licenses are noted where appropriate.
|
||||
******************************************************************************/
|
||||
package forestry.book.data.structure;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
public class StructureInfo {
|
||||
public IBlockState[][][] data;
|
||||
public int blockCount = 0;
|
||||
public int[] countPerLevel;
|
||||
public int structureHeight = 0;
|
||||
public int structureLength = 0;
|
||||
public int structureWidth = 0;
|
||||
public int showLayer = -1;
|
||||
|
||||
private int blockIndex = 0;
|
||||
private int maxBlockIndex;
|
||||
|
||||
public StructureInfo(int length, int height, int width, BlockData[] blockData) {
|
||||
this.structureWidth = width;
|
||||
this.structureHeight = height;
|
||||
this.structureLength = length;
|
||||
IBlockState[][][] states = new IBlockState[height][length][width];
|
||||
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < length; x++) {
|
||||
for (int z = 0; z < width; z++) {
|
||||
for (BlockData data : blockData) {
|
||||
if (inside(x, y, z, data.pos, data.endPos)) {
|
||||
states[y][x][z] = convert(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data = states;
|
||||
maxBlockIndex = blockIndex = structureHeight * structureLength * structureWidth;
|
||||
}
|
||||
|
||||
private IBlockState convert(BlockData data) {
|
||||
Block block = Block.getBlockFromName(data.block);
|
||||
if (block == null) {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
IBlockState state;
|
||||
if (data.state == null || data.state.isEmpty()) {
|
||||
state = block.getStateFromMeta(data.meta);
|
||||
} else {
|
||||
state = block.getDefaultState();
|
||||
|
||||
for (Map.Entry<String, String> entry : data.state.entrySet()) {
|
||||
Optional<IProperty<?>> property = state.getPropertyKeys().stream().filter(iProperty -> entry.getKey().equals(iProperty.getName())).findFirst();
|
||||
|
||||
if (property.isPresent()) {
|
||||
state = setProperty(state, property.get(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private <T extends Comparable<T>> IBlockState setProperty(IBlockState state, IProperty<T> prop, String valueString) {
|
||||
com.google.common.base.Optional<T> value = prop.parseValue(valueString);
|
||||
if (value.isPresent()) {
|
||||
state = state.withProperty(prop, value.get());
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
private boolean inside(int x, int y, int z, int[] rangeStart, int[] rangeEnd) {
|
||||
if (x >= rangeStart[0] && x <= rangeEnd[0]) {
|
||||
if (y >= rangeStart[1] && y <= rangeEnd[1]) {
|
||||
if (z >= rangeStart[2] && z <= rangeEnd[2]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setShowLayer(int layer) {
|
||||
showLayer = layer;
|
||||
blockIndex = (layer + 1) * (structureLength * structureWidth) - 1;
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
blockIndex = maxBlockIndex;
|
||||
}
|
||||
|
||||
public boolean canStep() {
|
||||
int index = blockIndex;
|
||||
do {
|
||||
if (++index >= maxBlockIndex) {
|
||||
return false;
|
||||
}
|
||||
} while (isEmpty(index));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void step() {
|
||||
int start = blockIndex;
|
||||
do {
|
||||
if (++blockIndex >= maxBlockIndex) {
|
||||
blockIndex = 0;
|
||||
}
|
||||
} while (isEmpty(blockIndex) && blockIndex != start);
|
||||
}
|
||||
|
||||
private boolean isEmpty(int index) {
|
||||
int y = index / (structureLength * structureWidth);
|
||||
int r = index % (structureLength * structureWidth);
|
||||
int x = r / structureWidth;
|
||||
int z = r % structureWidth;
|
||||
|
||||
return data[y][x][z] == null || data[y][x][z].getBlock() == Blocks.AIR;
|
||||
}
|
||||
|
||||
public int getLimiter() {
|
||||
return blockIndex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.data.structure;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,174 @@
|
||||
package forestry.book.gui;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import net.minecraftforge.fml.client.config.GuiUtils;
|
||||
|
||||
import forestry.api.book.IForesterBook;
|
||||
import forestry.book.gui.buttons.GuiButtonBack;
|
||||
import forestry.book.gui.buttons.GuiButtonPage;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiUtil;
|
||||
import forestry.core.gui.IGuiSizable;
|
||||
import forestry.core.gui.elements.ElementManager;
|
||||
|
||||
public abstract class GuiForesterBook extends GuiScreen implements IGuiSizable {
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(Constants.MOD_ID, Constants.TEXTURE_PATH_GUI + "/almanac/almanac.png");
|
||||
static final int LEFT_PAGE_START_X = 16;
|
||||
static final int RIGHT_PAGE_START_X = 132;
|
||||
static final int PAGE_START_Y = 12;
|
||||
static final int LEFT_PAGE_START_Y = 25;
|
||||
static final int RIGHT_PAGE_START_Y = PAGE_START_Y;
|
||||
public static final int PAGE_WIDTH = 108;
|
||||
public static final int PAGE_HEIGHT = 155;
|
||||
|
||||
private static final int X_SIZE = 256;
|
||||
private static final int Y_SIZE = 181;
|
||||
@Nullable
|
||||
public static GuiForesterBook guiScreen;
|
||||
protected final IForesterBook book;
|
||||
final ElementManager<GuiForesterBook> elementManager;
|
||||
|
||||
protected int guiLeft;
|
||||
protected int guiTop;
|
||||
|
||||
protected GuiForesterBook(IForesterBook book) {
|
||||
this.book = book;
|
||||
setGuiScreen(this);
|
||||
this.elementManager = new ElementManager<>(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
this.guiLeft = (this.width - X_SIZE) / 2;
|
||||
this.guiTop = (this.height - Y_SIZE) / 2;
|
||||
elementManager.init(guiLeft, guiTop);
|
||||
this.buttonList.clear();
|
||||
if (hasButtons()) {
|
||||
GuiButtonPage leftButton = addButton(new GuiButtonPage(0, guiLeft + 24, guiTop + Y_SIZE - 20, true));
|
||||
GuiButtonPage rightButton = addButton(new GuiButtonPage(1, guiLeft + X_SIZE - 44, guiTop + Y_SIZE - 20, false));
|
||||
GuiButtonBack backButton = addButton(new GuiButtonBack(2, guiLeft + X_SIZE / 2 - 12, guiTop + Y_SIZE - 20));
|
||||
initButtons(leftButton, rightButton, backButton);
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasButtons() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void initButtons(GuiButtonPage leftButton, GuiButtonPage rightButton, GuiButtonBack backButton) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
TextureManager manager = mc.renderEngine;
|
||||
|
||||
manager.bindTexture(TEXTURE);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, X_SIZE, Y_SIZE);
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
boolean unicode = fontRenderer.getUnicodeFlag();
|
||||
fontRenderer.setUnicodeFlag(true);
|
||||
drawCenteredString(fontRenderer, TextFormatting.UNDERLINE + getTitle(), guiLeft + LEFT_PAGE_START_X + 52, guiTop + PAGE_START_Y, 0xD3D3D3);
|
||||
|
||||
drawText();
|
||||
|
||||
fontRenderer.setUnicodeFlag(unicode);
|
||||
|
||||
elementManager.draw(mouseX, mouseY);
|
||||
|
||||
InventoryPlayer playerInv = mc.player.inventory;
|
||||
|
||||
if (playerInv.getItemStack().isEmpty()) {
|
||||
GuiUtil.drawToolTips(this, buttonList, mouseX, mouseY);
|
||||
elementManager.drawTooltip(mouseX, mouseY);
|
||||
List<String> tooltip = getTooltip(mouseX, mouseY);
|
||||
if (!tooltip.isEmpty()) {
|
||||
ScaledResolution scaledresolution = new ScaledResolution(mc);
|
||||
GuiUtils.drawHoveringText(tooltip, mouseX, mouseY, scaledresolution.getScaledWidth(), scaledresolution.getScaledHeight(), -1, fontRenderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawText() {
|
||||
}
|
||||
|
||||
protected List<String> getTooltip(int mouseX, int mouseY) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
protected abstract String getTitle();
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if (elementManager.keyTyped(typedChar, keyCode)) {
|
||||
return;
|
||||
}
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
elementManager.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) {
|
||||
super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick);
|
||||
elementManager.mouseClickMove(mouseX, mouseY, clickedMouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
super.mouseReleased(mouseX, mouseY, state);
|
||||
elementManager.mouseReleased(mouseX, mouseY, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiLeft() {
|
||||
return guiLeft;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGuiTop() {
|
||||
return guiTop;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeX() {
|
||||
return X_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeY() {
|
||||
return Y_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Minecraft getMC() {
|
||||
return mc;
|
||||
}
|
||||
|
||||
public static void setGuiScreen(@Nullable GuiForesterBook guiScreen) {
|
||||
GuiForesterBook.guiScreen = guiScreen;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package forestry.book.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.api.book.IForesterBook;
|
||||
import forestry.book.gui.buttons.GuiButtonBookCategory;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.Drawable;
|
||||
import forestry.core.utils.Translator;
|
||||
|
||||
public class GuiForestryBookCategories extends GuiForesterBook {
|
||||
public static final Drawable LOGO = new Drawable(new ResourceLocation(Constants.MOD_ID, "textures/gui/almanac/logo.png"), 0, 0, 256, 58, 256, 58);
|
||||
|
||||
public GuiForestryBookCategories(IForesterBook book) {
|
||||
super(book);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for (IBookCategory category : book.getCategories()) {
|
||||
if (category.getEntries().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
buttonList.add(new GuiButtonBookCategory(y * 3 + x, guiLeft + LEFT_PAGE_START_X + x * 36, guiTop + 25 + y * 36, category));
|
||||
x++;
|
||||
if (x == 3) {
|
||||
y++;
|
||||
x = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean hasButtons() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawText() {
|
||||
drawCenteredString(fontRenderer, TextFormatting.UNDERLINE + Translator.translateToLocal("for.gui.book.about.title"), guiLeft + RIGHT_PAGE_START_X + 52, guiTop + PAGE_START_Y, 0xD3D3D3);
|
||||
String about = Translator.translateToLocal("for.gui.book.about");
|
||||
fontRenderer.drawSplitString(about, guiLeft + RIGHT_PAGE_START_X, guiTop + LEFT_PAGE_START_Y, 108, 0);
|
||||
fontRenderer.drawString(Translator.translateToLocal("for.gui.book.about.author"), guiLeft + RIGHT_PAGE_START_X, guiTop + LEFT_PAGE_START_Y + fontRenderer.getWordWrappedHeight(about, 108), 0);
|
||||
LOGO.draw(guiLeft + RIGHT_PAGE_START_X, guiTop + LEFT_PAGE_START_Y + 110, 108, 24);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if (button instanceof GuiButtonBookCategory) {
|
||||
GuiButtonBookCategory buttonCategory = (GuiButtonBookCategory) button;
|
||||
mc.displayGuiScreen(new GuiForestryBookEntries(book, buttonCategory.category));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return Translator.translateToLocal("for.gui.book.categories");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package forestry.book.gui;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.api.book.IForesterBook;
|
||||
import forestry.book.gui.buttons.GuiButtonBack;
|
||||
import forestry.book.gui.buttons.GuiButtonEntry;
|
||||
import forestry.book.gui.buttons.GuiButtonPage;
|
||||
|
||||
public class GuiForestryBookEntries extends GuiForesterBook {
|
||||
private final IBookCategory category;
|
||||
private int entryIndex = 0;
|
||||
|
||||
public GuiForestryBookEntries(IForesterBook book, IBookCategory category) {
|
||||
super(book);
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
int offset = entryIndex * 24;
|
||||
int yOffset = 0;
|
||||
List<IBookEntry> entries = new ArrayList<>(category.getEntries());
|
||||
for (IBookEntry entry : entries.subList(offset, entries.size() > offset + 12 ? offset + 12 : entries.size())) {
|
||||
addButton(new GuiButtonEntry(yOffset, guiLeft + LEFT_PAGE_START_X, guiTop + LEFT_PAGE_START_Y + yOffset * (fontRenderer.FONT_HEIGHT + 2), entry));
|
||||
yOffset++;
|
||||
}
|
||||
offset += 12;
|
||||
yOffset = 0;
|
||||
if (entries.size() > offset) {
|
||||
for (IBookEntry entry : entries.subList(offset, entries.size() > offset + 12 ? offset + 12 : entries.size())) {
|
||||
addButton(new GuiButtonEntry(yOffset, guiLeft + RIGHT_PAGE_START_X, guiTop + LEFT_PAGE_START_Y + yOffset * (fontRenderer.FONT_HEIGHT + 2), entry));
|
||||
yOffset++;
|
||||
}
|
||||
}
|
||||
elementManager.init(guiLeft, guiTop);
|
||||
elementManager.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initButtons(GuiButtonPage leftButton, GuiButtonPage rightButton, GuiButtonBack backButton) {
|
||||
leftButton.visible = entryIndex > 0;
|
||||
rightButton.visible = category.getEntries().size() > (entryIndex + 1) * 24;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if (button instanceof GuiButtonPage) {
|
||||
GuiButtonPage pageButton = (GuiButtonPage) button;
|
||||
if (pageButton.left) {
|
||||
entryIndex--;
|
||||
} else {
|
||||
entryIndex++;
|
||||
}
|
||||
initGui();
|
||||
} else if (button instanceof GuiButtonBack) {
|
||||
displayCategories();
|
||||
} else if (button instanceof GuiButtonEntry) {
|
||||
GuiButtonEntry entry = (GuiButtonEntry) button;
|
||||
mc.displayGuiScreen(new GuiForestryBookPages(book, category, entry.entry, null));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTooltip(int mouseX, int mouseY) {
|
||||
return elementManager.getTooltip(mouseX, mouseY);
|
||||
}
|
||||
|
||||
private void displayCategories() {
|
||||
mc.displayGuiScreen(new GuiForestryBookCategories(book));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return category.getLocalizedName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
package forestry.book.gui;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.api.book.IForesterBook;
|
||||
import forestry.api.gui.IElementGroup;
|
||||
import forestry.api.gui.IGuiElement;
|
||||
import forestry.book.gui.buttons.GuiButtonBack;
|
||||
import forestry.book.gui.buttons.GuiButtonPage;
|
||||
import forestry.book.gui.buttons.GuiButtonSubEntry;
|
||||
import forestry.core.gui.elements.layouts.ElementGroup;
|
||||
|
||||
public class GuiForestryBookPages extends GuiForesterBook {
|
||||
private final IBookCategory category;
|
||||
private final IBookEntry entry;
|
||||
@Nullable
|
||||
private final IBookEntry parent;
|
||||
private final List<GuiButtonSubEntry> subButtons = new ArrayList<>();
|
||||
private List<IGuiElement> pages;
|
||||
private int pageIndex = 0;
|
||||
private IElementGroup leftPage;
|
||||
private IElementGroup rightPage;
|
||||
private int nextPage = -1;
|
||||
private int lastPage = -1;
|
||||
|
||||
public GuiForestryBookPages(IForesterBook book, IBookCategory category, IBookEntry entry, @Nullable IBookEntry parent) {
|
||||
super(book);
|
||||
this.category = category;
|
||||
this.entry = entry;
|
||||
this.parent = parent;
|
||||
ElementGroup group = elementManager.group();
|
||||
leftPage = group.panel(LEFT_PAGE_START_X, LEFT_PAGE_START_Y, PAGE_WIDTH, PAGE_HEIGHT);
|
||||
rightPage = group.panel(RIGHT_PAGE_START_X, RIGHT_PAGE_START_Y, PAGE_WIDTH, PAGE_HEIGHT);
|
||||
pages = ImmutableList.copyOf(entry.getPageFactory().load(entry, GuiForesterBook.PAGE_HEIGHT - 13, GuiForesterBook.PAGE_HEIGHT, GuiForesterBook.PAGE_WIDTH));
|
||||
setPages(0);
|
||||
}
|
||||
|
||||
private void setPages(int index) {
|
||||
leftPage.clear();
|
||||
rightPage.clear();
|
||||
if (index < 0 || index >= pages.size()) {
|
||||
pageIndex = 0;
|
||||
return;
|
||||
}
|
||||
leftPage.add(pages.get(index));
|
||||
if (pages.size() > index + 1) {
|
||||
rightPage.add(pages.get(index + 1));
|
||||
}
|
||||
pageIndex = index;
|
||||
}
|
||||
|
||||
public void switchPage(int page) {
|
||||
if (page % 2 == 1) {
|
||||
page -= 1;
|
||||
}
|
||||
this.nextPage = page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
if (nextPage >= 0) {
|
||||
lastPage = pageIndex;
|
||||
setPages(nextPage);
|
||||
nextPage = -1;
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initButtons(GuiButtonPage leftButton, GuiButtonPage rightButton, GuiButtonBack backButton) {
|
||||
leftButton.visible = pageIndex > 0;
|
||||
rightButton.visible = pages.size() > (pageIndex + 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
IBookEntry firstEntry = parent != null ? parent : entry;
|
||||
subButtons.add(addButton(new GuiButtonSubEntry(buttonList.size(), guiLeft + -24, guiTop + 12, firstEntry, entry)));
|
||||
IBookEntry[] subEntries = firstEntry.getSubEntries();
|
||||
for (int i = 0; i < subEntries.length; i++) {
|
||||
IBookEntry subEntry = subEntries[i];
|
||||
subButtons.add(addButton(new GuiButtonSubEntry(buttonList.size(), guiLeft + -24, guiTop + 12 + ((i + 1) * 22), subEntry, entry)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTooltip(int mouseX, int mouseY) {
|
||||
List<String> tooltip = new LinkedList<>();
|
||||
for (GuiButtonSubEntry subEntry : subButtons) {
|
||||
if (subEntry.isMouseOver(mouseX, mouseY)) {
|
||||
tooltip.addAll(subEntry.getToolTip());
|
||||
}
|
||||
}
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return entry.getTitle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if (button instanceof GuiButtonPage) {
|
||||
GuiButtonPage pageButton = (GuiButtonPage) button;
|
||||
if (pageButton.left) {
|
||||
setPages(pageIndex - 2);
|
||||
} else {
|
||||
setPages(pageIndex + 2);
|
||||
}
|
||||
initGui();
|
||||
if (lastPage >= 0) {
|
||||
lastPage = -1;
|
||||
}
|
||||
} else if (button instanceof GuiButtonSubEntry) {
|
||||
GuiButtonSubEntry subEntry = (GuiButtonSubEntry) button;
|
||||
mc.displayGuiScreen(new GuiForestryBookPages(book, category, subEntry.subEntry, parent != null ? parent : entry));
|
||||
} else if (button instanceof GuiButtonBack || pages.isEmpty()) {
|
||||
if (lastPage >= 0) {
|
||||
setPages(lastPage);
|
||||
lastPage = -1;
|
||||
initGui();
|
||||
} else {
|
||||
displayEntries();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void displayEntries() {
|
||||
mc.displayGuiScreen(new GuiForestryBookEntries(book, category));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package forestry.book.gui.buttons;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.tooltips.IToolTipProvider;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
|
||||
public class GuiButtonBack extends GuiButton implements IToolTipProvider {
|
||||
public GuiButtonBack(int buttonId, int x, int y) {
|
||||
super(buttonId, x, y, 18, 9, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (visible) {
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
|
||||
TextureManager manager = mc.renderEngine;
|
||||
manager.bindTexture(GuiForesterBook.TEXTURE);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
drawTexturedModalRect(x, y, 36 + (hovered ? 18 : 0), 181, 18, 9);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToolTipVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package forestry.book.gui.buttons;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
|
||||
import forestry.api.book.IBookCategory;
|
||||
import forestry.core.gui.GuiUtil;
|
||||
import forestry.core.gui.tooltips.IToolTipProvider;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
|
||||
public class GuiButtonBookCategory extends GuiButton implements IToolTipProvider {
|
||||
public final IBookCategory category;
|
||||
|
||||
public GuiButtonBookCategory(int buttonId, int x, int y, IBookCategory category) {
|
||||
super(buttonId, x, y, 32, 32, "");
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (visible) {
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
FontRenderer fontRenderer = mc.fontRenderer;
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(x, y, zLevel);
|
||||
GlStateManager.scale(2F, 2F, 2F);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GuiUtil.drawItemStack(fontRenderer, category.getStack(), 0, 0);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
ToolTip toolTip = new ToolTip();
|
||||
toolTip.add(category.getLocalizedName());
|
||||
return toolTip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToolTipVisible() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRelativeToGui() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package forestry.book.gui.buttons;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.core.gui.GuiUtil;
|
||||
|
||||
public class GuiButtonEntry extends GuiButton {
|
||||
public final IBookEntry entry;
|
||||
|
||||
public GuiButtonEntry(int buttonId, int x, int y, IBookEntry entry) {
|
||||
super(buttonId, x, y, Minecraft.getMinecraft().fontRenderer.getStringWidth(entry.getTitle()) + 9, 11, entry.getTitle());
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (this.visible) {
|
||||
FontRenderer fontRenderer = mc.fontRenderer;
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
|
||||
String text = displayString;
|
||||
if (hovered) {
|
||||
text = TextFormatting.GOLD + text;
|
||||
} else {
|
||||
text = TextFormatting.DARK_GRAY + text;
|
||||
}
|
||||
|
||||
boolean unicode = fontRenderer.getUnicodeFlag();
|
||||
fontRenderer.setUnicodeFlag(true);
|
||||
fontRenderer.drawString(text, this.x + 9, this.y, 0);
|
||||
fontRenderer.setUnicodeFlag(unicode);
|
||||
|
||||
ItemStack stack = entry.getStack();
|
||||
if (!stack.isEmpty()) {
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.translate(x, y, zLevel);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.scale(0.5F, 0.5F, 0.5F);
|
||||
GuiUtil.drawItemStack(fontRenderer, stack, 0, 0);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package forestry.book.gui.buttons;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.tooltips.IToolTipProvider;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
|
||||
public class GuiButtonPage extends GuiButton implements IToolTipProvider {
|
||||
public boolean left;
|
||||
|
||||
public GuiButtonPage(int buttonId, int x, int y, boolean left) {
|
||||
super(buttonId, x, y, 18, 10, "");
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (visible) {
|
||||
this.hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
|
||||
TextureManager manager = mc.renderEngine;
|
||||
manager.bindTexture(GuiForesterBook.TEXTURE);
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.enableAlpha();
|
||||
GlStateManager.disableBlend();
|
||||
drawTexturedModalRect(x, y, hovered ? 18 : 0, 181 + (left ? 10 : 0), 18, 10);
|
||||
GlStateManager.enableBlend();
|
||||
GlStateManager.disableAlpha();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ToolTip getToolTip(int mouseX, int mouseY) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isToolTipVisible() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package forestry.book.gui.buttons;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
|
||||
import forestry.api.book.IBookEntry;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.GuiUtil;
|
||||
|
||||
public class GuiButtonSubEntry extends GuiButton {
|
||||
public final IBookEntry selectedEntry;
|
||||
public final IBookEntry subEntry;
|
||||
|
||||
public GuiButtonSubEntry(int buttonId, int x, int y, IBookEntry subEntry, IBookEntry selectedEntry) {
|
||||
super(buttonId, x, y, 24, 21, "");
|
||||
this.subEntry = subEntry;
|
||||
this.selectedEntry = selectedEntry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY, float partialTicks) {
|
||||
if (!visible) {
|
||||
return;
|
||||
}
|
||||
boolean active = subEntry == selectedEntry;
|
||||
TextureManager manager = mc.renderEngine;
|
||||
manager.bindTexture(GuiForesterBook.TEXTURE);
|
||||
GlStateManager.pushMatrix();
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
drawTexturedModalRect(x, y, 48 + (active ? 24 : 0), 201, 24, 21);
|
||||
|
||||
GlStateManager.translate(x + 8.0F, y + 4.0F, zLevel);
|
||||
GlStateManager.scale(0.85F, 0.85F, 0.85F);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
GlStateManager.enableRescaleNormal();
|
||||
|
||||
GuiUtil.drawItemStack(mc.fontRenderer, subEntry.getStack(), 0, 0);
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
public List<String> getToolTip() {
|
||||
return Collections.singletonList(subEntry.getTitle());
|
||||
}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY) {
|
||||
return mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.gui.buttons;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,59 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.recipes.ICarpenterRecipe;
|
||||
import forestry.api.recipes.IDescriptiveRecipe;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.Drawable;
|
||||
import forestry.core.gui.elements.IngredientElement;
|
||||
import forestry.core.gui.elements.TankElement;
|
||||
import forestry.factory.recipes.CarpenterRecipeManager;
|
||||
|
||||
public class CarpenterElement extends SelectionElement<ICarpenterRecipe> {
|
||||
private static final ResourceLocation BOOK_CRAFTING_TEXTURE = new ResourceLocation(Constants.MOD_ID, Constants.TEXTURE_PATH_GUI + "/almanac/crafting.png");
|
||||
private static final Drawable CARPENTER_BACKGROUND = new Drawable(BOOK_CRAFTING_TEXTURE, 0, 0, 108, 60);
|
||||
private static final Drawable CARPENTER_TANK_OVERLAY = new Drawable(BOOK_CRAFTING_TEXTURE, 109, 1, 16, 58);
|
||||
|
||||
public CarpenterElement(int xPos, int yPos, ItemStack stack) {
|
||||
this(0, 0, new ItemStack[]{stack});
|
||||
}
|
||||
|
||||
public CarpenterElement(int xPos, int yPos, ItemStack[] stacks) {
|
||||
this(0, 0, Stream.of(stacks).map(CarpenterRecipeManager::getRecipes).flatMap(Collection::stream).toArray(ICarpenterRecipe[]::new));
|
||||
}
|
||||
|
||||
public CarpenterElement(int xPos, int yPos, ICarpenterRecipe[] recipes) {
|
||||
super(xPos, yPos, 108, 62, recipes, 2);
|
||||
|
||||
drawable(0, 2, CARPENTER_BACKGROUND);
|
||||
add(selectedElement);
|
||||
setIndex(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIndexUpdate(int index, ICarpenterRecipe recipe) {
|
||||
selectedElement.add(new TankElement(91, 1, null, () -> new FluidTankInfo(recipe.getFluidResource(), Constants.PROCESSOR_TANK_CAPACITY), CARPENTER_TANK_OVERLAY));
|
||||
IDescriptiveRecipe gridRecipe = recipe.getCraftingGridRecipe();
|
||||
NonNullList<NonNullList<ItemStack>> ingredients = gridRecipe.getRawIngredients();
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
int ingredientIndex = y * 3 + x;
|
||||
if (ingredientIndex >= ingredients.size()) {
|
||||
continue;
|
||||
}
|
||||
NonNullList<ItemStack> items = ingredients.get(ingredientIndex);
|
||||
selectedElement.add(new IngredientElement(1 + x * 19, 3 + y * 19, Ingredient.fromStacks(items.toArray(new ItemStack[items.size()]))));
|
||||
}
|
||||
}
|
||||
selectedElement.item(71, 41, gridRecipe.getOutput());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.Drawable;
|
||||
import forestry.core.gui.elements.IngredientElement;
|
||||
|
||||
public class CraftingElement extends SelectionElement<IRecipe> {
|
||||
private static final Drawable CRAFTING_GRID = new Drawable(GuiForesterBook.TEXTURE, 158, 181, 98, 58);
|
||||
|
||||
public CraftingElement(int xPos, int yPos, IRecipe[] recipes) {
|
||||
super(xPos, yPos, 98, 62, recipes, 2);
|
||||
|
||||
setAlign(GuiElementAlignment.TOP_CENTER);
|
||||
//Background
|
||||
drawable(0, 2, CRAFTING_GRID);
|
||||
add(selectedElement);
|
||||
setIndex(0);
|
||||
}
|
||||
|
||||
protected void onIndexUpdate(int index, IRecipe recipe) {
|
||||
NonNullList<Ingredient> ingredients = recipe.getIngredients();
|
||||
//Output
|
||||
selectedElement.item(81, 21, recipe.getRecipeOutput());
|
||||
//Grid
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
int i = y * 3 + x;
|
||||
if (ingredients.size() <= i) {
|
||||
continue;
|
||||
}
|
||||
Ingredient ingredient = ingredients.get(i);
|
||||
selectedElement.add(new IngredientElement(1 + x * 20, 1 + y * 20, ingredient));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.api.recipes.IFabricatorRecipe;
|
||||
import forestry.api.recipes.IFabricatorSmeltingRecipe;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.Drawable;
|
||||
import forestry.core.gui.elements.IngredientElement;
|
||||
import forestry.core.gui.elements.TankElement;
|
||||
import forestry.factory.recipes.FabricatorRecipeManager;
|
||||
import forestry.factory.recipes.FabricatorSmeltingRecipeManager;
|
||||
|
||||
public class FabricatorElement extends SelectionElement<IFabricatorRecipe> {
|
||||
private static final ResourceLocation BOOK_CRAFTING_TEXTURE = new ResourceLocation(Constants.MOD_ID, Constants.TEXTURE_PATH_GUI + "/almanac/crafting.png");
|
||||
private static final Drawable FABRICATOR_BACKGROUND = new Drawable(BOOK_CRAFTING_TEXTURE, 0, 60, 108, 56);
|
||||
private static final Drawable FABRICATOR_TANK_OVERLAY = new Drawable(BOOK_CRAFTING_TEXTURE, 109, 61, 16, 16);
|
||||
|
||||
public FabricatorElement(int xPos, int yPos, ItemStack stack) {
|
||||
this(0, 0, new ItemStack[]{stack});
|
||||
}
|
||||
|
||||
public FabricatorElement(int xPos, int yPos, ItemStack[] stacks) {
|
||||
this(0, 0, Stream.of(stacks).map(FabricatorRecipeManager::getRecipes).flatMap(Collection::stream).toArray(IFabricatorRecipe[]::new));
|
||||
}
|
||||
|
||||
public FabricatorElement(int xPos, int yPos, IFabricatorRecipe[] recipes) {
|
||||
super(xPos, yPos, 108, 58, recipes, 2);
|
||||
|
||||
drawable(0, 2, FABRICATOR_BACKGROUND);
|
||||
add(selectedElement);
|
||||
setIndex(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIndexUpdate(int index, IFabricatorRecipe recipe) {
|
||||
selectedElement.add(new TankElement(1, 33, null, () -> new FluidTankInfo(recipe.getLiquid(), 2000), FABRICATOR_TANK_OVERLAY, 16, 16));
|
||||
NonNullList<NonNullList<ItemStack>> ingredients = recipe.getIngredients();
|
||||
for (int x = 0; x < 3; x++) {
|
||||
for (int y = 0; y < 3; y++) {
|
||||
int ingredientIndex = y * 3 + x;
|
||||
if (ingredientIndex >= ingredients.size()) {
|
||||
continue;
|
||||
}
|
||||
NonNullList<ItemStack> items = ingredients.get(ingredientIndex);
|
||||
selectedElement.add(new IngredientElement(21 + x * 19, 1 + y * 19, Ingredient.fromStacks(items.toArray(new ItemStack[items.size()]))));
|
||||
}
|
||||
}
|
||||
ItemStack plan = recipe.getPlan();
|
||||
if (!plan.isEmpty()) {
|
||||
selectedElement.item(91, 1, plan);
|
||||
}
|
||||
selectedElement.item(91, 39, recipe.getRecipeOutput());
|
||||
NonNullList<ItemStack> smeltingInput = NonNullList.create();
|
||||
Fluid recipeFluid = recipe.getLiquid().getFluid();
|
||||
for (IFabricatorSmeltingRecipe s : getSmeltingInputs().get(recipeFluid)) {
|
||||
smeltingInput.add(s.getResource());
|
||||
}
|
||||
if (!smeltingInput.isEmpty()) {
|
||||
selectedElement.add(new IngredientElement(1, 6, smeltingInput));
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<Fluid, List<IFabricatorSmeltingRecipe>> getSmeltingInputs() {
|
||||
Map<Fluid, List<IFabricatorSmeltingRecipe>> smeltingInputs = new HashMap<>();
|
||||
for (IFabricatorSmeltingRecipe smelting : FabricatorSmeltingRecipeManager.recipes) {
|
||||
Fluid fluid = smelting.getProduct().getFluid();
|
||||
if (!smeltingInputs.containsKey(fluid)) {
|
||||
smeltingInputs.put(fluid, new ArrayList<>());
|
||||
}
|
||||
smeltingInputs.get(fluid).add(smelting);
|
||||
}
|
||||
return smeltingInputs;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.book.data.IndexEntry;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.book.gui.GuiForestryBookPages;
|
||||
import forestry.core.gui.elements.TextElement;
|
||||
import forestry.core.gui.elements.layouts.VerticalLayout;
|
||||
|
||||
public class IndexElement extends VerticalLayout {
|
||||
public IndexElement(int xPos, int yPos, IndexEntry[] data) {
|
||||
super(xPos, yPos, 108);
|
||||
for (IndexEntry index : data) {
|
||||
add(new IndexEntryElement(index));
|
||||
}
|
||||
}
|
||||
|
||||
private class IndexEntryElement extends TextElement {
|
||||
private final IndexEntry data;
|
||||
|
||||
public IndexEntryElement(IndexEntry data) {
|
||||
super(-1, 9, data.title, GuiElementAlignment.TOP_LEFT, 0, true);
|
||||
width += TextElement.FONT_RENDERER.getStringWidth(" > ");
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawElement(int mouseX, int mouseY) {
|
||||
boolean mouseOver = isMouseOver(mouseX, mouseY);
|
||||
boolean unicode = FONT_RENDERER.getUnicodeFlag();
|
||||
String preFix = mouseOver ? TextFormatting.GOLD + " > " : TextFormatting.DARK_GRAY + "- ";
|
||||
FONT_RENDERER.setUnicodeFlag(this.unicode);
|
||||
FONT_RENDERER.drawString(preFix + text, 0, 0, color);
|
||||
FONT_RENDERER.setUnicodeFlag(unicode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
GuiForesterBook bookGui = GuiForesterBook.guiScreen;
|
||||
if (bookGui instanceof GuiForestryBookPages) {
|
||||
GuiForestryBookPages pagesGui = (GuiForestryBookPages) bookGui;
|
||||
pagesGui.switchPage(data.page);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/*******************************************************************************
|
||||
* The MIT License (MIT)
|
||||
* Copyright (c) 2013-2014 Slime Knights (mDiyo, fuj1n, Sunstrike, progwml6, pillbox, alexbegt)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* Any alternate licenses are noted where appropriate.
|
||||
******************************************************************************/
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.client.renderer.texture.TextureMap;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import forestry.book.data.structure.BlockData;
|
||||
import forestry.book.data.structure.StructureBlockAccess;
|
||||
import forestry.book.data.structure.StructureInfo;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.elements.GuiElement;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class MultiblockElement extends GuiElement {
|
||||
private float scale = 50.0F;
|
||||
private float xTranslate = 0F;
|
||||
private float yTranslate = 0F;
|
||||
private boolean canTick = false;
|
||||
private int tick = 0;
|
||||
|
||||
private float rotX = 0;
|
||||
private float rotY = 0;
|
||||
|
||||
private StructureInfo structureData;
|
||||
private StructureBlockAccess blockAccess;
|
||||
|
||||
@Nullable
|
||||
private int[] lastClick = null;
|
||||
private int fullStructureSteps = 5;
|
||||
|
||||
public MultiblockElement(int x, int y, int width, int height, int[] size, BlockData[] structure) {
|
||||
super(x, y, width, height);
|
||||
if (size.length == 3) {
|
||||
scale = 100f / (float) IntStream.of(size).max().getAsInt();
|
||||
|
||||
float sx = (float) width / (float) GuiForesterBook.PAGE_WIDTH;
|
||||
float sy = (float) height / (float) GuiForesterBook.PAGE_HEIGHT;
|
||||
|
||||
scale *= Math.min(sx, sy);
|
||||
|
||||
xTranslate = x + (float) width / 2.0F;
|
||||
yTranslate = y + (float) height / 2.0F;
|
||||
}
|
||||
structureData = new StructureInfo(size[0], size[1], size[2], structure);
|
||||
blockAccess = new StructureBlockAccess(structureData);
|
||||
|
||||
|
||||
rotX = 25;
|
||||
rotY = -45;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawElement(int mouseX, int mouseY) {
|
||||
if (lastClick != null) {
|
||||
if (Mouse.isButtonDown(0) || Mouse.isButtonDown(1)) {
|
||||
int dx = mouseX - lastClick[0];
|
||||
int dy = mouseY - lastClick[1];
|
||||
float maxSpeed = 10f;
|
||||
float changeY = Math.min(maxSpeed, dx / 10f);
|
||||
float changeX = Math.min(maxSpeed, dy / 10f);
|
||||
|
||||
rotY += changeY;
|
||||
rotX += changeX;
|
||||
} else {
|
||||
lastClick = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (canTick) {
|
||||
if (++tick % 20 == 0 && (structureData.canStep() || ++fullStructureSteps >= 5)) {
|
||||
structureData.step();
|
||||
fullStructureSteps = 0;
|
||||
}
|
||||
} else {
|
||||
structureData.reset();
|
||||
structureData.setShowLayer(9);
|
||||
}
|
||||
|
||||
int structureLength = structureData.structureLength;
|
||||
int structureWidth = structureData.structureWidth;
|
||||
int structureHeight = structureData.structureHeight;
|
||||
|
||||
GlStateManager.enableRescaleNormal();
|
||||
GlStateManager.pushMatrix();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
|
||||
final BlockRendererDispatcher blockRender = Minecraft.getMinecraft().getBlockRendererDispatcher();
|
||||
final TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
|
||||
|
||||
GlStateManager.translate(xTranslate, yTranslate, Math.max(structureHeight, Math.max(structureWidth, structureLength)));
|
||||
GlStateManager.scale(scale, -scale, 1);
|
||||
GlStateManager.rotate(rotX, 1, 0, 0);
|
||||
GlStateManager.rotate(rotY, 0, 1, 0);
|
||||
|
||||
GlStateManager.translate((float) structureLength / -2f, (float) structureHeight / -2f, (float) structureWidth / -2f);
|
||||
|
||||
GlStateManager.disableLighting();
|
||||
|
||||
if (Minecraft.isAmbientOcclusionEnabled()) {
|
||||
GlStateManager.shadeModel(GL11.GL_SMOOTH);
|
||||
} else {
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
}
|
||||
|
||||
textureManager.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
|
||||
for (int h = 0; h < structureData.structureHeight; h++) {
|
||||
for (int l = 0; l < structureData.structureLength; l++) {
|
||||
for (int w = 0; w < structureData.structureWidth; w++) {
|
||||
BlockPos pos = new BlockPos(l, h, w);
|
||||
if (!blockAccess.isAirBlock(pos)) {
|
||||
IBlockState state = blockAccess.getBlockState(pos);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder buffer = tessellator.getBuffer();
|
||||
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
|
||||
blockRender.renderBlock(state, pos, blockAccess, buffer);
|
||||
tessellator.draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GlStateManager.popMatrix();
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GlStateManager.disableRescaleNormal();
|
||||
GlStateManager.shadeModel(GL11.GL_FLAT);
|
||||
GlStateManager.enableBlend();
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
lastClick = new int[]{mouseX, mouseY};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int clickedMouseButton) {
|
||||
super.mouseReleased(mouseX, mouseY, clickedMouseButton);
|
||||
lastClick = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.api.genetics.IMutation;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.Drawable;
|
||||
|
||||
public class MutationElement extends SelectionElement<IMutation> {
|
||||
private static final Drawable SLOT = new Drawable(GuiForesterBook.TEXTURE, 0, 223, 18, 18);
|
||||
private static final Drawable MUTATION_PLUS = new Drawable(GuiForesterBook.TEXTURE, 0, 241, 15, 15);
|
||||
private static final Drawable MUTATION_ARROW = new Drawable(GuiForesterBook.TEXTURE, 15, 241, 18, 15);
|
||||
|
||||
public MutationElement(int xPos, int yPos, IMutation[] mutations) {
|
||||
super(xPos, yPos, 108, 20, mutations, 2);
|
||||
|
||||
setAlign(GuiElementAlignment.TOP_CENTER);
|
||||
|
||||
drawable(0, 2, SLOT);
|
||||
drawable(21, 4, MUTATION_PLUS);
|
||||
drawable(39, 2, SLOT);
|
||||
drawable(84, 2, SLOT);
|
||||
add(selectedElement);
|
||||
setIndex(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onIndexUpdate(int index, IMutation mutation) {
|
||||
ISpeciesRoot root = mutation.getRoot();
|
||||
//
|
||||
Collection<String> conditions = mutation.getSpecialConditions();
|
||||
String conditionText;
|
||||
if (!conditions.isEmpty()) {
|
||||
conditionText = String.format("[%.0f%%]", mutation.getBaseChance());
|
||||
} else {
|
||||
conditionText = String.format("%.0f%%", mutation.getBaseChance());
|
||||
}
|
||||
selectedElement.text(58, conditionText, GuiElementAlignment.TOP_LEFT, 0).addTooltip(conditions);
|
||||
selectedElement.drawable(62, 6, MUTATION_ARROW).addTooltip(conditions);
|
||||
//
|
||||
selectedElement.item(1, 1, root.getMemberStack(mutation.getAllele0(), root.getTypeForMutation(0)));
|
||||
selectedElement.item(40, 1, root.getMemberStack(mutation.getAllele1(), root.getTypeForMutation(1)));
|
||||
selectedElement.item(85, 1, root.getMemberStack(mutation.getTemplate(), root.getTypeForMutation(2)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import forestry.api.gui.GuiElementAlignment;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.core.gui.Drawable;
|
||||
import forestry.core.gui.elements.ButtonElement;
|
||||
import forestry.core.gui.elements.GuiElementFactory;
|
||||
import forestry.core.gui.elements.layouts.ElementGroup;
|
||||
import forestry.core.gui.elements.layouts.PaneLayout;
|
||||
|
||||
public abstract class SelectionElement<R> extends PaneLayout {
|
||||
private static final Drawable CRAFTING_COUNT = new Drawable(GuiForesterBook.TEXTURE, 104, 181, 34, 14);
|
||||
private static final Drawable RIGHT_BUTTON = new Drawable(GuiForesterBook.TEXTURE, 138, 181, 10, 9);
|
||||
private static final Drawable LEFT_BUTTON = new Drawable(GuiForesterBook.TEXTURE, 148, 181, 10, 9);
|
||||
|
||||
private int index = -1;
|
||||
|
||||
@Nullable
|
||||
protected final ButtonElement leftButton;
|
||||
@Nullable
|
||||
protected final ButtonElement rightButton;
|
||||
@Nullable
|
||||
protected final ElementGroup text;
|
||||
protected final ElementGroup selectedElement;
|
||||
protected final R[] recipes;
|
||||
|
||||
protected SelectionElement(int xPos, int yPos, int width, int height, R[] recipes) {
|
||||
this(xPos, yPos, width, height, recipes, 0);
|
||||
}
|
||||
|
||||
protected SelectionElement(int xPos, int yPos, int width, int height, R[] recipes, int yOffset) {
|
||||
super(xPos, yPos, width, height + (recipes.length > 1 ? 16 : 0));
|
||||
this.recipes = recipes;
|
||||
if (recipes.length > 1) {
|
||||
drawable(0, 0, CRAFTING_COUNT).setAlign(GuiElementAlignment.BOTTOM_CENTER);
|
||||
text = panel(width, this.height);
|
||||
leftButton = add(new ButtonElement(-27, -2, LEFT_BUTTON, e -> setIndex(index - 1)));
|
||||
leftButton.setAlign(GuiElementAlignment.BOTTOM_CENTER);
|
||||
|
||||
rightButton = add(new ButtonElement(27, -2, RIGHT_BUTTON, e -> setIndex(index + 1)));
|
||||
rightButton.setAlign(GuiElementAlignment.BOTTOM_CENTER);
|
||||
} else {
|
||||
text = null;
|
||||
leftButton = null;
|
||||
rightButton = null;
|
||||
}
|
||||
selectedElement = GuiElementFactory.INSTANCE.createPanel(0, 2, width, this.height);
|
||||
}
|
||||
|
||||
protected final void setIndex(int index) {
|
||||
if (index == this.index || index >= recipes.length || index < 0) {
|
||||
return;
|
||||
}
|
||||
this.index = index;
|
||||
selectedElement.clear();
|
||||
onIndexUpdate(index, recipes[index]);
|
||||
if (text != null) {
|
||||
text.clear();
|
||||
text.text(TextFormatting.BLACK.toString() + (index + 1) + "/" + recipes.length, GuiElementAlignment.BOTTOM_CENTER, 0).setYPosition(2);
|
||||
}
|
||||
if (leftButton != null) {
|
||||
leftButton.setEnabled(index > 0);
|
||||
}
|
||||
if (rightButton != null) {
|
||||
rightButton.setEnabled(index < recipes.length - 1);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void onIndexUpdate(int index, R recipe);
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
||||
import forestry.book.data.TextData;
|
||||
import forestry.core.gui.elements.GuiElement;
|
||||
|
||||
public class TextDataElement extends GuiElement {
|
||||
|
||||
private final List<TextData> textElements = new ArrayList<>();
|
||||
|
||||
public TextDataElement(int xPos, int yPos, int width, int height) {
|
||||
super(xPos, yPos, width, height);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
if (height >= 0) {
|
||||
return height;
|
||||
}
|
||||
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
boolean unicode = fontRenderer.getUnicodeFlag();
|
||||
fontRenderer.setUnicodeFlag(true);
|
||||
boolean lastEmpty = false;
|
||||
for (TextData data : textElements) {
|
||||
if (data.text.equals("\n")) {
|
||||
if (lastEmpty) {
|
||||
height += fontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
lastEmpty = true;
|
||||
continue;
|
||||
}
|
||||
lastEmpty = false;
|
||||
|
||||
if (data.paragraph) {
|
||||
height += fontRenderer.FONT_HEIGHT * 1.6D;
|
||||
}
|
||||
|
||||
String modifiers = "";
|
||||
|
||||
modifiers += TextFormatting.getValueByName(data.color);
|
||||
|
||||
if (data.bold) {
|
||||
modifiers += TextFormatting.BOLD;
|
||||
}
|
||||
if (data.italic) {
|
||||
modifiers += TextFormatting.ITALIC;
|
||||
}
|
||||
if (data.underlined) {
|
||||
modifiers += TextFormatting.UNDERLINE;
|
||||
}
|
||||
if (data.strikethrough) {
|
||||
modifiers += TextFormatting.STRIKETHROUGH;
|
||||
}
|
||||
if (data.obfuscated) {
|
||||
modifiers += TextFormatting.OBFUSCATED;
|
||||
}
|
||||
height += fontRenderer.getWordWrappedHeight(modifiers + data.text, width);
|
||||
}
|
||||
fontRenderer.setUnicodeFlag(unicode);
|
||||
return height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawElement(int mouseX, int mouseY) {
|
||||
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
boolean unicode = fontRenderer.getUnicodeFlag();
|
||||
fontRenderer.setUnicodeFlag(true);
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
for (TextData data : textElements) {
|
||||
if (data.text.equals("\n")) {
|
||||
x = 0;
|
||||
y += fontRenderer.FONT_HEIGHT;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (data.paragraph) {
|
||||
x = 0;
|
||||
y += fontRenderer.FONT_HEIGHT * 1.6D;
|
||||
}
|
||||
|
||||
String text = getFormattedString(data);
|
||||
List<String> split = fontRenderer.listFormattedStringToWidth(text, width);
|
||||
for (int i = 0; i < split.size(); i++) {
|
||||
String s = split.get(i);
|
||||
int textLength = fontRenderer.drawString(s, x, y, 0, data.dropshadow);
|
||||
if (i == split.size() - 1) {
|
||||
x += textLength;
|
||||
} else {
|
||||
y += fontRenderer.FONT_HEIGHT;
|
||||
}
|
||||
}
|
||||
}
|
||||
fontRenderer.setUnicodeFlag(unicode);
|
||||
}
|
||||
|
||||
private String getFormattedString(TextData data) {
|
||||
StringBuilder modifiers = new StringBuilder();
|
||||
|
||||
modifiers.append(TextFormatting.getValueByName(data.color));
|
||||
|
||||
if (data.bold) {
|
||||
modifiers.append(TextFormatting.BOLD);
|
||||
}
|
||||
if (data.italic) {
|
||||
modifiers.append(TextFormatting.ITALIC);
|
||||
}
|
||||
if (data.underlined) {
|
||||
modifiers.append(TextFormatting.UNDERLINE);
|
||||
}
|
||||
if (data.strikethrough) {
|
||||
modifiers.append(TextFormatting.STRIKETHROUGH);
|
||||
}
|
||||
if (data.obfuscated) {
|
||||
modifiers.append(TextFormatting.OBFUSCATED);
|
||||
}
|
||||
modifiers.append(data.text);
|
||||
return modifiers.toString();
|
||||
}
|
||||
|
||||
public void addData(TextData textData) {
|
||||
textElements.add(textData);
|
||||
height = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.gui.elements;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.book.gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,44 @@
|
||||
package forestry.book.items;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.book.IForesterBook;
|
||||
import forestry.book.BookLoader;
|
||||
import forestry.book.gui.GuiForesterBook;
|
||||
import forestry.book.gui.GuiForestryBookCategories;
|
||||
import forestry.core.items.ItemWithGui;
|
||||
|
||||
public class ItemForesterBook extends ItemWithGui {
|
||||
public ItemForesterBook() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
|
||||
openGui(playerIn);
|
||||
|
||||
ItemStack stack = playerIn.getHeldItem(handIn);
|
||||
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiScreen getGui(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
IForesterBook book = BookLoader.INSTANCE.loadBook();
|
||||
return GuiForesterBook.guiScreen != null ? GuiForesterBook.guiScreen : new GuiForestryBookCategories(book);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Container getContainer(EntityPlayer player, ItemStack heldItem, int data) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package forestry.book.items;
|
||||
|
||||
import forestry.core.items.ItemRegistry;
|
||||
|
||||
public class ItemRegistryBook extends ItemRegistry {
|
||||
public final ItemForesterBook book;
|
||||
|
||||
public ItemRegistryBook() {
|
||||
book = registerItem(new ItemForesterBook(), "book_forester");
|
||||
}
|
||||
}
|
||||
Loaded 100 of 251 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user