aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-05-12 10:36:42 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-05-12 10:36:42 +0800
commiteab120d5619f972e29afc9776959f6d6096d3926 (patch)
tree6e33b3cdac62e9bafd18aee65b42ace098c9028a /src/main/java/me
parent7e1e39d8453b0a5b5c7c1045fc5e6bb428b840d8 (diff)
downloadRoughlyEnoughItems-eab120d5619f972e29afc9776959f6d6096d3926.tar.gz
RoughlyEnoughItems-eab120d5619f972e29afc9776959f6d6096d3926.tar.bz2
RoughlyEnoughItems-eab120d5619f972e29afc9776959f6d6096d3926.zip
More docs
Diffstat (limited to 'src/main/java/me')
-rw-r--r--src/main/java/me/shedaniel/rei/api/DisplayHelper.java86
-rw-r--r--src/main/java/me/shedaniel/rei/api/ItemRegistry.java23
-rw-r--r--src/main/java/me/shedaniel/rei/api/RecipeCategory.java76
-rw-r--r--src/main/java/me/shedaniel/rei/api/RecipeHelper.java23
-rw-r--r--src/main/java/me/shedaniel/rei/api/Renderable.java3
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/Widget.java11
6 files changed, 221 insertions, 1 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
index 37d2db76c..51e54302c 100644
--- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java
@@ -15,41 +15,127 @@ import static net.minecraft.util.ActionResult.PASS;
public interface DisplayHelper {
+ /**
+ * Gets the sorted version of all responsible bounds handlers
+ *
+ * @param screenClass the class for checking responsible bounds handlers
+ * @return the sorted list of responsible bounds handlers
+ * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version
+ */
List<DisplayBoundsHandler> getSortedBoundsHandlers(Class screenClass);
+ /**
+ * Gets all registered bounds handlers
+ *
+ * @return the list of registered bounds handlers
+ */
List<DisplayBoundsHandler> getAllBoundsHandlers();
+ /**
+ * Gets all responsible bounds handlers
+ *
+ * @param screenClass the class for checking responsible bounds handlers
+ * @return the the list of responsible bounds handlers
+ * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version
+ */
DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass);
+ /**
+ * Registers a bounds handler
+ *
+ * @param handler the handler to register
+ */
void registerBoundsHandler(DisplayBoundsHandler handler);
+ /**
+ * Gets the base bounds handler api for exclusion zones
+ *
+ * @return the base bounds handler
+ */
BaseBoundsHandler getBaseBoundsHandler();
public static interface DisplayBoundsHandler<T> {
+ /**
+ * An empty rectangle
+ */
public static final Rectangle EMPTY = new Rectangle();
+ /**
+ * Gets the base supported class for the bounds handler
+ *
+ * @return
+ */
Class getBaseSupportedClass();
+ /**
+ * Gets the left bounds of the overlay
+ *
+ * @param screen the current screen
+ * @return the left bounds
+ */
Rectangle getLeftBounds(T screen);
+ /**
+ * Gets the right bounds of the overlay
+ *
+ * @param screen the current screen
+ * @return the right bounds
+ */
Rectangle getRightBounds(T screen);
+ /**
+ * Checks if item slot can fit the screen
+ *
+ * @param isOnRightSide whether the user has set the overlay to the right
+ * @param left the left x coordinates of the stack
+ * @param top the top y coordinates for the stack
+ * @param screen the current screen
+ * @param fullBounds the current bounds
+ * @return whether the item slot can fit
+ * @see BaseBoundsHandler#registerExclusionZones(Class, BaseBoundsHandler.ExclusionZoneSupplier) for easier api
+ */
default ActionResult canItemSlotWidgetFit(boolean isOnRightSide, int left, int top, T screen, Rectangle fullBounds) {
return PASS;
}
+ /**
+ * Checks if mouse is inside the overlay
+ *
+ * @param isOnRightSide whether the user has set the overlay to the right
+ * @param mouseX mouse's x coordinates
+ * @param mouseY mouse's y coordinates
+ * @return whether mouse is inside the overlay
+ */
default ActionResult isInZone(boolean isOnRightSide, double mouseX, double mouseY) {
return PASS;
}
+ /**
+ * Gets the item list bounds by the overlay bounds
+ *
+ * @param rectangle the overlay bounds
+ * @return the item list bounds
+ */
default Rectangle getItemListArea(Rectangle rectangle) {
return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField ? 27 + 22 : 27));
}
+ /**
+ * Checks if REI should recalculate the overlay bounds
+ *
+ * @param isOnRightSide whether the user has set the overlay to the right
+ * @param rectangle the current overlay bounds
+ * @return whether REI should recalculate the overlay bounds
+ */
default boolean shouldRecalculateArea(boolean isOnRightSide, Rectangle rectangle) {
return false;
}
+ /**
+ * Gets the priority of the handler, the higher it is, the earlier it is called.
+ *
+ * @return the priority in float
+ */
default float getPriority() {
return 0f;
}
diff --git a/src/main/java/me/shedaniel/rei/api/ItemRegistry.java b/src/main/java/me/shedaniel/rei/api/ItemRegistry.java
index 6d8b39d24..8751da416 100644
--- a/src/main/java/me/shedaniel/rei/api/ItemRegistry.java
+++ b/src/main/java/me/shedaniel/rei/api/ItemRegistry.java
@@ -12,12 +12,29 @@ import java.util.List;
public interface ItemRegistry {
+ /**
+ * Gets the current unmodifiable item list
+ *
+ * @return an unmodifiable item list
+ */
List<ItemStack> getItemList();
+ /**
+ * Gets the current modifiable item list
+ *
+ * @return an modifiable item list
+ */
+ @Deprecated
List<ItemStack> getModifiableItemList();
ItemStack[] getAllStacksFromItem(Item item);
+ /**
+ * Registers an new stack to the item list
+ *
+ * @param afterItem
+ * @param stack the stack to register
+ */
void registerItemStack(Item afterItem, ItemStack stack);
default void registerItemStack(Item afterItem, ItemStack... stacks) {
@@ -32,6 +49,12 @@ public interface ItemRegistry {
registerItemStack(null, stack);
}
+ /**
+ * Checks if a stack is already registered
+ *
+ * @param stack the stack to check
+ * @return whether the stack has been registered
+ */
default boolean alreadyContain(ItemStack stack) {
return getItemList().stream().anyMatch(stack1 -> ItemStack.areEqual(stack, stack1));
}
diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java
index f62cebbda..6993b45c4 100644
--- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java
+++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java
@@ -22,30 +22,80 @@ import java.util.function.Supplier;
public interface RecipeCategory<T extends RecipeDisplay> {
+ /**
+ * Gets the identifier of the category, must be unique
+ *
+ * @return the unique identifier of the category
+ */
Identifier getIdentifier();
- ItemStack getCategoryIcon();
+ /**
+ * Gets the stack to render for the icon
+ *
+ * @return the stack to render
+ * @deprecated use {@link RecipeCategory#getIcon()} instead
+ */
+ @Deprecated
+ default ItemStack getCategoryIcon() {
+ return ItemStack.EMPTY;
+ }
+ /**
+ * Gets the renderer of the icon, allowing developers to render things other than items
+ *
+ * @return the renderer of the icon
+ */
default Renderer getIcon() {
return Renderable.fromItemStackSupplier(this::getCategoryIcon);
}
+ /**
+ * Gets the category name
+ *
+ * @return the name
+ */
String getCategoryName();
+ /**
+ * Gets the recipe renderer for the category, used in {@link me.shedaniel.rei.gui.VillagerRecipeViewingScreen} for rendering simple recipes
+ *
+ * @param recipe the recipe to render
+ * @return the recipe renderer
+ */
default RecipeRenderer getSimpleRenderer(T recipe) {
return Renderable.fromRecipe(recipe::getInput, recipe::getOutput);
}
+ /**
+ * Setup the widgets for displaying the recipe
+ *
+ * @param recipeDisplaySupplier the supplier for getting the recipe
+ * @param bounds the bounds of the display, configurable with overriding {@link RecipeCategory#getDisplaySettings()}
+ * @return the list of widgets
+ */
default List<Widget> setupDisplay(Supplier<T> recipeDisplaySupplier, Rectangle bounds) {
return Collections.singletonList(new RecipeBaseWidget(bounds));
}
+ /**
+ * Draws the category background, used in {@link RecipeViewingScreen}
+ *
+ * @param bounds the bounds of the whole recipe viewing screen
+ * @param mouseX the x coordinates for the mouse
+ * @param mouseY the y coordinates for the mouse
+ * @param delta the delta
+ */
default void drawCategoryBackground(Rectangle bounds, int mouseX, int mouseY, float delta) {
new CategoryBaseWidget(bounds).render();
DrawableHelper.fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, RecipeViewingScreen.SUB_COLOR.getRGB());
DrawableHelper.fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, RecipeViewingScreen.SUB_COLOR.getRGB());
}
+ /**
+ * Gets the display settings for the category, used for getting the bounds for the display
+ *
+ * @return the display settings
+ */
default DisplaySettings getDisplaySettings() {
return new DisplaySettings<T>() {
@Override
@@ -65,18 +115,42 @@ public interface RecipeCategory<T extends RecipeDisplay> {
};
}
+ /**
+ * Gets the recipe display height
+ *
+ * @return the recipe display height
+ * @apiNote Please do not override this, use {@link RecipeCategory#getDisplaySettings()} instead
+ */
default int getDisplayHeight() {
return RecipeHelper.getInstance().getCachedCategorySettings(getIdentifier()).map(settings -> settings.getDisplayHeight(this)).orElse(0);
}
+ /**
+ * Gets the recipe display width
+ *
+ * @param display the recipe display
+ * @return the recipe display width
+ * @apiNote Please do not override this, use {@link RecipeCategory#getDisplaySettings()} instead
+ */
default int getDisplayWidth(T display) {
return RecipeHelper.getInstance().getCachedCategorySettings(getIdentifier()).map(settings -> settings.getDisplayWidth(this, display)).orElse(0);
}
+ /**
+ * Gets the maximum recipe per page
+ *
+ * @return the maximum amount of recipes for page
+ * @apiNote Please do not override this, use {@link RecipeCategory#getDisplaySettings()} instead
+ */
default int getMaximumRecipePerPage() {
return RecipeHelper.getInstance().getCachedCategorySettings(getIdentifier()).map(settings -> settings.getMaximumRecipePerPage(this)).orElse(0);
}
+ /**
+ * Gets whether the category will check tags, useful for potions
+ *
+ * @return whether the category will check tags
+ */
default boolean checkTags() {
return false;
}
diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
index e5e89cdd0..58d67e97a 100644
--- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
+++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java
@@ -17,6 +17,9 @@ import java.util.Optional;
public interface RecipeHelper {
+ /**
+ * @return the api instance of {@link me.shedaniel.rei.client.RecipeHelperImpl}
+ */
static RecipeHelper getInstance() {
return RoughlyEnoughItemsCore.getRecipeHelper();
}
@@ -27,14 +30,34 @@ public interface RecipeHelper {
List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems);
+ /**
+ * Registers a category
+ *
+ * @param category the category to register
+ */
void registerCategory(RecipeCategory category);
+ /**
+ * Registers a recipe display
+ *
+ * @param categoryIdentifier the category to display in
+ * @param display the recipe display
+ */
void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display);
Map<RecipeCategory, List<RecipeDisplay>> getRecipesFor(ItemStack stack);
+ /**
+ * Gets the vanilla recipe manager
+ *
+ * @return the recipe manager
+ */
RecipeManager getRecipeManager();
+ /**
+ * Gets all registered categories
+ * @return the list of categories
+ */
List<RecipeCategory> getAllCategories();
Map<RecipeCategory, List<RecipeDisplay>> getUsagesFor(ItemStack stack);
diff --git a/src/main/java/me/shedaniel/rei/api/Renderable.java b/src/main/java/me/shedaniel/rei/api/Renderable.java
index f76a2fdb1..47b8f4beb 100644
--- a/src/main/java/me/shedaniel/rei/api/Renderable.java
+++ b/src/main/java/me/shedaniel/rei/api/Renderable.java
@@ -14,6 +14,9 @@ import net.minecraft.util.math.MathHelper;
import java.util.List;
import java.util.function.Supplier;
+/**
+ * The base class for renderables
+ */
public interface Renderable {
static ItemStackRenderer fromItemStackSupplier(Supplier<ItemStack> supplier) {
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/Widget.java b/src/main/java/me/shedaniel/rei/gui/widget/Widget.java
index 6882483f1..d7e47da15 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/Widget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/Widget.java
@@ -10,9 +10,20 @@ import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.AbstractParentElement;
import net.minecraft.client.gui.Drawable;
+/**
+ * The base class for a screen widget
+ *
+ * @see HighlightableWidget for a widget with bounds
+ */
public abstract class Widget extends AbstractParentElement implements Drawable {
+ /**
+ * The Minecraft Client instance
+ */
protected final MinecraftClient minecraft = MinecraftClient.getInstance();
+ /**
+ * The font for rendering text
+ */
protected final TextRenderer font = minecraft.textRenderer;
}