Compare commits

..
83 changed files with 1409 additions and 2017 deletions

No files matched your search

@@ -10,7 +10,6 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -21,7 +20,6 @@ import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.io.IOUtils;
@@ -194,10 +192,9 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
builder = BookmarkItem.builder(groupId, itemStack, recipe, BookmarkItemType.RESULT).multiplier(1);
} else if (recipeId != null) {
builder = BookmarkItem.builder(groupId, itemStack).recipeId(recipeId)
.factor(StackInfo.getAmountLong(itemStack)).multiplier(1);
.factor(StackInfo.getAmount(itemStack)).multiplier(1);
} else {
builder = BookmarkItem.builder(groupId, itemStack).factor(1)
.multiplier(StackInfo.getAmountLong(itemStack));
builder = BookmarkItem.builder(groupId, itemStack).factor(1).multiplier(StackInfo.getAmount(itemStack));
}
if (existsRecipe) {
@@ -264,7 +261,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
builder = BookmarkItem.builder(groupId, stack, recipe, BookmarkItemType.RESULT);
} else {
builder = BookmarkItem.builder(groupId, stack).recipeId(recipeId)
.factor(StackInfo.getAmountLong(stack));
.factor(StackInfo.getAmount(stack));
}
this.grid.addItem(builder.multiplier(1).type(BookmarkItemType.ITEM).build(), true);
@@ -556,7 +553,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
}
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmountLong(itemStack));
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmount(itemStack));
}
@Override
@@ -1136,11 +1133,6 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
return pullBookmarkItems(this.grid.createRecipeChainMath(groupId), shift);
}
private static long fluidPerContainer(ItemStack stack) {
final FluidStack fluid = StackInfo.isFluidContainer(stack) ? StackInfo.getFluid(stack) : null;
return fluid != null ? fluid.amount : 0;
}
public boolean pullBookmarkItems(RecipeChainMath math, boolean shift) {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final IBookmarkContainerHandler containerHandler = BookmarkContainerInfo
@@ -1188,11 +1180,7 @@ public class BookmarkPanel extends PanelWidget<BookmarkGrid> {
math.initialItems.add(BookmarkItem.of(-1, stack));
}
// The chain takes storage items in this order, so partly filled fluid containers are used up first
final List<ItemStack> storageStacks = containerStorage.values();
storageStacks.sort(Comparator.comparingLong(BookmarkPanel::fluidPerContainer));
for (ItemStack stack : storageStacks) {
for (ItemStack stack : containerStorage.values()) {
math.initialItems.add(BookmarkItem.of(-2, stack));
}
+1 -18
View File
@@ -11,31 +11,14 @@ public class ColorUtils {
textGray = color.rgb("textGray", "0x404040"),
textLightGray = color.rgb("textLightGray", "0x606060"),
recipeTitle = color.rgb("recipeTitle", "0xFFFFFF"),
recipeTitleBG = color.argb("recipeTitleBG", "0x30000000"),
recipeTitleHover = color.rgb("recipeTitleHover", "0xFFFF55"),
recipeBadge = color.rgb("recipeBadge", "0xFDD835"),
subsetWidget = color.rgb("subsetWidget", "0xAA00AA"),
recipeBadge = color.rgb("recipeBadge", "0xFDD835"),
buttonLabelNormal = color.rgb("buttonLabelNormal", "0xE0E0E0"),
buttonLabelHover = color.rgb("buttonLabelHover", "0xFFFFA0"),
buttonLabelDisabled = color.rgb("buttonLabelDisabled", "0x601010"),
buttonLabelInactive = color.rgb("buttonLabelInactive", "0xA0A0A0"),
buttonIconNormal = color.argb("buttonIconNormal", "0xFFFFFFFF"),
buttonIconHover = color.argb("buttonIconHover", "0xFFFFFFA0"),
buttonIconActive = color.argb("buttonIconActive", "0xFFFFFFA0"),
buttonIconDisabled = color.argb("buttonIconDisabled", "0xFF808080"),
buttonIconFavoriteNormal = color.argb("buttonIconFavoriteNormal", "0xFF75C775"),
buttonIconFavoriteHover = color.argb("buttonIconFavoriteHover", "0xFF9ED89E"),
buttonIconFavoriteActive = color.argb("buttonIconFavoriteActive", "0xFF9ED89E"),
buttonIconFavoriteDisabled = color.argb("buttonIconFavoriteDisabled", "0xFF3A633A"),
buttonIconOverlayErrorNormal = color.argb("buttonIconOverlayErrorNormal", "0xFFD14545"),
buttonIconOverlayErrorHover = color.argb("buttonIconOverlayErrorHover", "0xFFDF7D7D"),
buttonIconOverlayErrorActive = color.argb("buttonIconOverlayErrorActive", "0xFFDF7D7D"),
buttonIconOverlayErrorDisabled = color.argb("buttonIconOverlayErrorDisabled", "0xFF682222"),
craftingTreeLine = color.argb("craftingTreeLine", "0xFF888888");
// spotless:on
}
@@ -8,7 +8,6 @@ import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import codechicken.nei.api.IBookmarkContainerHandler;
import codechicken.nei.recipe.StackInfo;
public class DefaultBookmarkContainerHandler implements IBookmarkContainerHandler {
@@ -20,7 +19,7 @@ public class DefaultBookmarkContainerHandler implements IBookmarkContainerHandle
for (ItemStack bookmarkItem : bookmarkItems) {
for (int i = 0; i < slots.size() - 4 * 9; i++) {
final Slot slot = slots.get(i);
if (slot.getHasStack() && matches(bookmarkItem, slot.getStack())) {
if (slot.getHasStack() && bookmarkItem.isItemEqual(slot.getStack())) {
final int transferAmount = Math.min(bookmarkItem.stackSize, slot.getStack().stackSize);
manager.transferItems(guiContainer, i, transferAmount);
bookmarkItem.stackSize -= transferAmount;
@@ -28,15 +27,4 @@ public class DefaultBookmarkContainerHandler implements IBookmarkContainerHandle
}
}
}
/**
* If either stack holds a fluid, both need the same NBT, so a filled fluid cell is not taken for an empty one.
* Other items match as in crafting, so an item that got its NBT later is still pulled.
*/
private static boolean matches(ItemStack bookmarkItem, ItemStack stack) {
if (StackInfo.getFluid(bookmarkItem) != null || StackInfo.getFluid(stack) != null) {
return bookmarkItem.isItemEqual(stack) && StackInfo.equalItemAndNBT(bookmarkItem, stack, true);
}
return NEIServerUtils.areStacksSameTypeCraftingWithNBT(bookmarkItem, stack);
}
}
@@ -7,13 +7,13 @@ import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
public class GuiNEIButton extends GuiButton {
protected static final ResourceLocation guiTex = new ResourceLocation("textures/gui/widgets.png");
private static final Drawable[] BACKGROUNDS = new Drawable[3];
private static final DrawableResource[] BACKGROUNDS = new DrawableResource[3];
static {
for (int state = 0; state < BACKGROUNDS.length; state++) {
@@ -25,7 +25,7 @@ public class GuiNEIButton extends GuiButton {
super(i, j, k, l, i1, s);
}
protected Drawable getBackground(int mouseX, int mouseY, boolean mouseOver) {
protected DrawableResource getBackground(int mouseX, int mouseY, boolean mouseOver) {
return BACKGROUNDS[getHoverState(mouseOver)];
}
@@ -52,8 +52,8 @@ public class GuiNEIButton extends GuiButton {
}
protected void drawContent(Minecraft minecraft, int x, int y, boolean mouseOver) {
final FontRenderer fontrenderer = minecraft.fontRenderer;
final int color = getTextColour(mouseOver);
FontRenderer fontrenderer = minecraft.fontRenderer;
int color = getTextColour(mouseOver);
drawCenteredString(fontrenderer, displayString, xPosition + width / 2, yPosition + (height - 8) / 2, color);
}
@@ -18,6 +18,7 @@ import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.ItemsGrid.ItemsGridSlot;
import codechicken.nei.ItemsGrid.MouseContext;
import codechicken.nei.NEIClientUtils.Alignment;
import codechicken.nei.recipe.AutoCraftingManager;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.ICraftingHandler;
@@ -26,6 +27,7 @@ import codechicken.nei.recipe.Recipe;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.RecipeInfo;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.util.ReadableNumberConverter;
public class ItemCraftablesPanel
extends AbstractSubpanel<ItemsGrid<ItemCraftablesPanel.CraftablesGridSlot, MouseContext>> {
@@ -35,15 +37,12 @@ public class ItemCraftablesPanel
protected final long realAmount;
protected final boolean isFluidDisplay;
protected final RecipeId recipeId;
protected final ItemStack drawnItemStack;
public CraftablesGridSlot(int slotIndex, int itemIndex, ItemStack itemStack, RecipeId recipeId) {
super(slotIndex, itemIndex, itemStack);
this.realAmount = StackInfo.getAmountLong(itemStack);
this.realAmount = StackInfo.getAmount(itemStack);
this.isFluidDisplay = StackInfo.isFluidDisplayItem(itemStack);
this.recipeId = recipeId;
final ItemStack empty = this.isFluidDisplay ? StackInfo.withAmount(itemStack, 0) : null;
this.drawnItemStack = empty != null ? empty : itemStack;
}
@Override
@@ -51,11 +50,6 @@ public class ItemCraftablesPanel
return this.recipeId;
}
@Override
public void drawItem(Rectangle4i rect) {
super.drawItem(this.drawnItemStack, rect);
}
@Override
public <M extends MouseContext> void afterDraw(Rectangle4i rect, M mouseContext) {
drawStackSize(rect);
@@ -66,7 +60,17 @@ public class ItemCraftablesPanel
if (stackSize > 1) {
final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2);
final String amountString = NEIClientUtils.formatSlotAmount(stackSize, this.isFluidDisplay);
String amountString = "";
if (stackSize < 10_000) {
amountString = String.valueOf(stackSize);
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
}
if (this.isFluidDisplay) {
amountString += "L";
}
NEIClientUtils.drawNEIOverlayText(
amountString,
@@ -212,7 +216,7 @@ public class ItemCraftablesPanel
@Override
protected ItemStack getDraggedStackWithQuantity(ItemStack itemStack) {
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmountLong(itemStack));
return ItemQuantityField.prepareStackWithQuantity(itemStack, StackInfo.getAmount(itemStack));
}
@Override
@@ -264,7 +268,7 @@ public class ItemCraftablesPanel
if (firstGui != null && !ItemCraftablesPanel.guiBlacklist.contains(firstGui.getClass().getName())) {
final boolean showOnlyFavorites = NEIClientConfig
.getBooleanSetting("inventory.craftables.favoritesOnly");
final ItemStackAmount inv = ItemStackAmount.of(firstGui);
final ItemStackAmount inv = AutoCraftingManager.getInventoryItems(firstGui);
if (this.lastGuiContainer != firstGui
|| showOnlyFavorites && this.lastFavoritesCount != FavoriteRecipes.size()
@@ -313,7 +317,7 @@ public class ItemCraftablesPanel
final Map<ItemStack, RecipeId> availableRecipes = new HashMap<>();
if (!availableHandlers.isEmpty()) {
final Map<Item, List<ItemStack>> invByItem = snapshot.inventory.groupByItem();
final Map<Item, List<ItemStack>> invByItem = indexInventoryByItem(snapshot.inventory.values());
if (snapshot.showOnlyFavorites) {
for (IRecipeHandler handler : availableHandlers) {
@@ -345,6 +349,16 @@ public class ItemCraftablesPanel
return availableHandlers;
}
private static Map<Item, List<ItemStack>> indexInventoryByItem(List<ItemStack> invStacks) {
final Map<Item, List<ItemStack>> index = new HashMap<>();
for (ItemStack stack : invStacks) {
index.computeIfAbsent(stack.getItem(), i -> new ArrayList<>()).add(stack);
}
return index;
}
private void collectHandlerCandidates(IRecipeHandler handler, Map<Item, List<ItemStack>> invByItem,
List<RecipeCandidate> candidates) {
IntStream.range(0, handler.numRecipes()).parallel().forEach(recipeIndex -> {
@@ -386,11 +400,11 @@ public class ItemCraftablesPanel
}
final ItemStack stack = Recipe.getMainResult(results, pStack -> pStack.items[0]).item;
long stackSize = 0;
int stackSize = 0;
for (PositionedStack result : results) {
if (containsSameType(result, stack)) {
stackSize += StackInfo.getAmountLong(result.item);
stackSize += StackInfo.getAmount(result.item);
}
}
@@ -434,8 +448,36 @@ public class ItemCraftablesPanel
return availableRecipes;
}
private static boolean existsIngredients(List<PositionedStack> ingredients, Map<Item, List<ItemStack>> invByItem) {
return !ingredients.isEmpty() && NEIClientUtils.countMissingIngredients(ingredients, invByItem, 1) == 0;
private boolean existsIngredients(List<PositionedStack> ingredients, Map<Item, List<ItemStack>> invByItem) {
final Map<ItemStack, Integer> usedItems = new HashMap<>();
for (PositionedStack pStack : ingredients) {
ItemStack used = null;
for (ItemStack permutation : pStack.items) {
final List<ItemStack> candidates = invByItem.get(permutation.getItem());
if (candidates == null) continue;
for (ItemStack is : candidates) {
if (usedItems.getOrDefault(is, is.stackSize) >= pStack.item.stackSize
&& NEIServerUtils.areStacksSameTypeCrafting(permutation, is)) {
used = is;
break;
}
}
if (used != null) break;
}
if (used != null) {
usedItems.put(used, usedItems.getOrDefault(used, used.stackSize) - pStack.item.stackSize);
} else {
return false;
}
}
return !usedItems.isEmpty();
}
}
@@ -1,17 +1,12 @@
package codechicken.nei;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Predicate;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -34,7 +29,7 @@ public class ItemStackAmount {
}
public void add(ItemStack item) {
add(item, StackInfo.getAmountLong(item));
add(item, (long) StackInfo.getAmount(item));
}
public void add(ItemStack stack, Long value) {
@@ -101,16 +96,6 @@ public class ItemStackAmount {
return list;
}
public Map<Item, List<ItemStack>> groupByItem() {
final Map<Item, List<ItemStack>> groups = new HashMap<>();
for (ItemStack stack : values()) {
groups.computeIfAbsent(stack.getItem(), i -> new ArrayList<>()).add(stack);
}
return groups;
}
public int size() {
return this.itemMap.size();
}
@@ -155,16 +140,4 @@ public class ItemStackAmount {
return result;
}
public static ItemStackAmount of(GuiContainer gui) {
final ItemStackAmount result = new ItemStackAmount();
for (Slot slot : gui.inventorySlots.inventorySlots) {
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(gui.mc.thePlayer)) {
result.add(slot.getStack());
}
}
return result;
}
}
@@ -68,9 +68,10 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
protected void drawAmount(Rectangle4i rect, ItemStack stack, long amount) {
final AmountText amountText = this.cache.computeIfAbsent(stack, key -> {
final boolean isFluidDisplay = StackInfo.isFluidDisplayItem(key);
final String text = formatAmount(key, amount);
return new AmountText(
formatAmount(key, amount),
isFluidDisplay && !text.isEmpty() ? text + "L" : text,
isFluidDisplay ? Alignment.BottomLeft : Alignment.BottomRight);
});
@@ -80,7 +81,7 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler {
}
protected String formatAmount(ItemStack stack, long amount) {
return amount == 0 ? "" : NEIClientUtils.formatSlotAmount(amount, StackInfo.isFluidDisplayItem(stack));
return amount == 0 ? "" : ReadableNumberConverter.INSTANCE.toWideReadableForm(amount);
}
}
@@ -891,13 +891,8 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH
GL11.glColor4f(1, 1, 1, 1);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
if (!isDrawableResource) {
drawTexturedModalRect(x, y, image.x, image.y, image.width, image.height);
} else {
((DrawableResource) image).draw(x, y);
}
if (!isDrawableResource) drawTexturedModalRect(x, y, image.x, image.y, image.width, image.height);
else((DrawableResource) image).draw(x, y);
GL11.glDisable(GL11.GL_BLEND);
}
@@ -11,9 +11,8 @@ import codechicken.nei.api.LayoutStyle;
public class LayoutStyleMinecraft extends LayoutStyle {
public static final int BUTTON_SIZE = 20;
public static final int MARGIN = 2;
public static final int SUBSET_BAR_HEIGHT = 16;
protected static final int BUTTON_SIZE = 20;
protected static final int MARGIN = 2;
public int buttonCount;
public int leftSize;
@@ -148,7 +147,7 @@ public class LayoutStyleMinecraft extends LayoutStyle {
LayoutManager.searchField.x += BUTTON_SIZE;
LayoutManager.searchField.w -= BUTTON_SIZE;
} else {
LayoutManager.dropDown.h = SUBSET_BAR_HEIGHT;
LayoutManager.dropDown.h = 16;
LayoutManager.dropDown.w = 150;
LayoutManager.dropDown.y = MARGIN;
LayoutManager.dropDown.x = (gui.width - LayoutManager.dropDown.w) / 2;
@@ -59,7 +59,6 @@ import codechicken.nei.config.preset.GuiPresetList;
import codechicken.nei.event.NEIConfigsLoadedEvent;
import codechicken.nei.moboverlay.MobOverlayScan;
import codechicken.nei.moboverlay.MobOverlayStyle;
import codechicken.nei.recipe.HandlerInfo;
import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.InformationHandler;
import codechicken.nei.recipe.RecipeCatalysts;
@@ -271,20 +270,9 @@ public class NEIClientConfig {
.getBooleanValue(false);
API.addOption(new OptionToggleButton("inventory.guirecipe.infiniteScroll", true));
tag.getTag("inventory.guirecipe.evenRecipeSpacing").setComment("Spread recipes evenly across the page height")
.getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.guirecipe.evenRecipeSpacing", true));
tag.getTag("inventory.guirecipe.topMargin").setComment("Recipe GUI Top Margin").getIntValue(0);
API.addOption(new OptionIntegerField("inventory.guirecipe.topMargin", 0, 200));
tag.getTag("inventory.guirecipe.maxHeight").setComment("Recipe GUI Max Height").getIntValue(370);
API.addOption(new OptionIntegerField("inventory.guirecipe.maxHeight", 166, 4000));
tag.getTag("inventory.guirecipe.minWidth").setComment("Recipe GUI Min Width")
.getIntValue(HandlerInfo.DEFAULT_WIDTH);
API.addOption(new OptionIntegerField("inventory.guirecipe.minWidth", HandlerInfo.DEFAULT_WIDTH, 4000));
tag.getTag("inventory.guirecipe.shiftOverlayRecipe")
.setComment("Require holding shift to move items when overlaying recipe").getBooleanValue(true);
API.addOption(new OptionToggleButton("inventory.guirecipe.shiftOverlayRecipe", true));
@@ -53,7 +53,6 @@ import org.lwjgl.opengl.GL11;
import com.google.common.collect.Iterables;
import com.gtnewhorizon.gtnhlib.util.numberformatting.NumberFormatUtil;
import com.gtnewhorizon.gtnhlib.util.numberformatting.options.CompactOptions;
import codechicken.lib.gui.GuiDraw;
import codechicken.lib.inventory.InventoryRange;
@@ -66,7 +65,6 @@ import codechicken.nei.api.ItemInfo;
import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.util.NEIKeyboardUtils;
import codechicken.nei.util.ReadableNumberConverter;
public class NEIClientUtils extends NEIServerUtils {
@@ -156,23 +154,6 @@ public class NEIClientUtils extends NEIServerUtils {
return getDecimalFormat().format(aNumber) + " L";
}
/** Only loaded when GTNHLib is, since CompactOptions comes from it. */
private static final class FluidSlotAmountFormat {
private static final CompactOptions OPTIONS = new CompactOptions().setCompactThreshold(10_000)
.setDecimalPlaces(1).setRoundingMode(RoundingMode.DOWN);
}
/** The amount drawn over a slot. Fluids use GTNHLib's compact formatting when it's loaded and have no unit. */
public static String formatSlotAmount(long amount, boolean isFluid) {
if (isFluid && NEIModContainer.isGTNHLibLoaded()) {
return NumberFormatUtil.formatNumberCompact(amount, FluidSlotAmountFormat.OPTIONS);
}
return amount < 10_000 ? String.valueOf(amount) : ReadableNumberConverter.INSTANCE.toWideReadableForm(amount);
}
public static String formatChance(float chance) {
return CHANCE_FORMAT.format(chance);
}
@@ -331,8 +312,7 @@ public class NEIClientUtils extends NEIServerUtils {
if (StackInfo.isFluidDisplayItem(stack.item)) {
final FluidStack requiredFluid = StackInfo.getFluid(stack.item);
found = requiredFluid != null
&& consumeFluid(invStacks, remainingFluid, requiredFluid, StackInfo.getAmountLong(stack.item));
found = requiredFluid != null && consumeFluid(invStacks, remainingFluid, requiredFluid);
} else {
found = false;
@@ -352,8 +332,8 @@ public class NEIClientUtils extends NEIServerUtils {
}
private static boolean consumeFluid(List<ItemStack> invStacks, Map<ItemStack, Long> remainingFluid,
FluidStack requiredFluid, long requiredAmount) {
long need = requiredAmount;
FluidStack requiredFluid) {
long need = requiredFluid.amount;
final List<ItemStack> matched = new ArrayList<>();
for (ItemStack is : invStacks) {
@@ -384,7 +364,7 @@ public class NEIClientUtils extends NEIServerUtils {
return false;
}
long remainingNeed = requiredAmount;
long remainingNeed = requiredFluid.amount;
for (ItemStack is : matched) {
final long available = remainingFluid.get(is);
final long consumed = Math.min(available, remainingNeed);
@@ -558,40 +538,6 @@ public class NEIClientUtils extends NEIServerUtils {
return null;
}
public static int countMissingIngredients(List<PositionedStack> ingredients, Map<Item, List<ItemStack>> index,
int limit) {
Map<ItemStack, Integer> usedItems = new HashMap<>();
int missing = 0;
for (PositionedStack pStack : ingredients) {
ItemStack used = null;
for (ItemStack permutation : pStack.items) {
final List<ItemStack> candidates = index.get(permutation.getItem());
if (candidates == null) continue;
for (ItemStack is : candidates) {
if (usedItems.getOrDefault(is, is.stackSize) >= pStack.item.stackSize
&& NEIServerUtils.areStacksSameTypeCrafting(permutation, is)) {
used = is;
break;
}
}
if (used != null) break;
}
if (used != null) {
usedItems.put(used, usedItems.getOrDefault(used, used.stackSize) - pStack.item.stackSize);
} else if (++missing >= limit) {
return missing;
}
}
return missing;
}
public static boolean altKey() {
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
}
@@ -238,7 +238,6 @@ public class PositionedStack implements Cloneable {
/** The tank size the fill level is measured against, in mB. 0 means "always render full". */
protected int capacity = 0;
protected boolean flowingTexture = false;
protected boolean amountTooltip = true;
protected FillDirection fillDirection = FillDirection.AUTO;
private ItemStack cachedFluidItem;
@@ -277,15 +276,6 @@ public class PositionedStack implements Cloneable {
return this;
}
public boolean hasAmountTooltip() {
return this.amountTooltip;
}
public Tank setAmountTooltip(boolean amountTooltip) {
this.amountTooltip = amountTooltip;
return this;
}
public FillDirection getFillDirection() {
return this.fillDirection;
}
@@ -311,11 +301,10 @@ public class PositionedStack implements Cloneable {
final List<String> customTooltip = super.getTooltip();
final FluidStack fluidStack = getFluidStack();
if (fluidStack != null && this.amountTooltip) {
if (fluidStack != null && this.capacity > 0) {
tooltip.add(
EnumChatFormatting.GRAY + NEIClientUtils.translate(
"recipe.fluid.tank.amount",
NEIClientUtils.formatFluid(StackInfo.getAmountLong(this.item))));
EnumChatFormatting.GRAY + NEIClientUtils
.translate("recipe.fluid.tank.amount", NEIClientUtils.formatFluid(fluidStack.amount)));
}
if (customTooltip != null) {
@@ -30,6 +30,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
private static final MobOverlayScan MOB_OVERLAY_SCAN = new MobOverlayScan();
private static final MobOverlayFace MARKED_FACE = new MobOverlayFace();
private static final MobOverlayDisplayList MOB_OVERLAY_LIST = new MobOverlayDisplayList();
private static final byte[] COLUMN_CELLS = new byte[2 * MobOverlayScan.MAX_VERTICAL_RADIUS + 1];
public static void reset() {
mobOverlay = 0;
@@ -83,10 +84,6 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
GL11.glPopAttrib();
}
/**
* The model view matrix is relative to ({@code intOffsetX}, {@code intOffsetY}, {@code intOffsetZ}), the camera
* position cast to {@code int}.
*/
private static void renderMobSpawnOverlay(Entity entity, int intOffsetX, int intOffsetY, int intOffsetZ) {
if (mobOverlay == 0) {
MOB_OVERLAY_SCAN.clear();
@@ -110,29 +107,49 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
endMobOverlayDraw();
}
/**
* Add a marked face to {@link #MOB_OVERLAY_LIST} for each block of {@link #MOB_OVERLAY_SCAN} where mobs can spawn.
*/
private static void compileMobOverlayList(MobOverlayStyle style, long worldTicks) {
MOB_OVERLAY_LIST.beginCompile(MOB_OVERLAY_SCAN, style, worldTicks);
for (int chunkX = MOB_OVERLAY_SCAN.getMinChunkX(); chunkX <= MOB_OVERLAY_SCAN.getMaxChunkX(); chunkX++) {
for (int chunkZ = MOB_OVERLAY_SCAN.getMinChunkZ(); chunkZ <= MOB_OVERLAY_SCAN.getMaxChunkZ(); chunkZ++) {
if (!MOB_OVERLAY_LIST.beginChunk(MOB_OVERLAY_SCAN, chunkX, chunkZ)) continue;
MOB_OVERLAY_LIST.endChunk(compileChunkFaces(style, chunkX, chunkZ));
}
}
MOB_OVERLAY_LIST.endCompile(MOB_OVERLAY_SCAN);
}
private static boolean compileChunkFaces(MobOverlayStyle style, int chunkX, int chunkZ) {
final int CHUNK_WIDTH = 1 << MobOverlayScan.CHUNK_SHIFT;
final float alpha = style.computeAlpha();
final Tessellator tess = Tessellator.instance;
tess.startDrawing(style.glMode);
final int cornerX = chunkX << MobOverlayScan.CHUNK_SHIFT;
final int cornerZ = chunkZ << MobOverlayScan.CHUNK_SHIFT;
final int minX = MOB_OVERLAY_SCAN.getMinX();
final int minZ = MOB_OVERLAY_SCAN.getMinZ();
final int span = MOB_OVERLAY_SCAN.getSpan();
for (int i = 0; i < span; i++) {
for (int j = 0; j < span; j++) {
for (int k = 0; k < MOB_OVERLAY_SCAN.getHeight(); k++) {
if (MOB_OVERLAY_SCAN.readSpawnMode(i, k, j) == 0) continue;
final int height = MOB_OVERLAY_SCAN.getHeight();
boolean hasFaces = false;
tess.startDrawing(style.glMode);
for (int i = Math.max(cornerX - minX, 0); i < Math.min(cornerX + CHUNK_WIDTH - minX, span); i++) {
for (int j = Math.max(cornerZ - minZ, 0); j < Math.min(cornerZ + CHUNK_WIDTH - minZ, span); j++) {
MOB_OVERLAY_SCAN.readColumn(i, j, COLUMN_CELLS);
for (int k = 0; k < height; k++) {
if (MobOverlayScan.extractSpawnMode(COLUMN_CELLS[k]) == 0) continue;
MARKED_FACE.moveTo(i, k + MOB_OVERLAY_SCAN.readOverlayYOffset(i, k, j), j);
MARKED_FACE.moveTo(
minX + i - cornerX,
k + MobOverlayScan.computeOverlayYOffset(COLUMN_CELLS[k]),
minZ + j - cornerZ);
loadNeighbourModes(i, k, j);
MARKED_FACE.applyColor(style.colouring, alpha);
style.addVertices(MARKED_FACE);
hasFaces = true;
}
}
}
tess.draw();
MOB_OVERLAY_LIST.endCompile();
return hasFaces;
}
private static void beginMobOverlayDraw(MobOverlayStyle style) {
@@ -147,7 +164,7 @@ public class WorldOverlayRenderer implements IKeyStateTracker {
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glLineWidth(1.5F);
// the outline of `MobOverlayStyle.CONNECTED` lies in the plane of the tint. With depth writes on, the depth
// the outline of `MobOverlayStyle.CONNECTED` lies in the plane of the tint. When depth writes are on, the depth
// test discards most of the outline
GL11.glDepthMask(false);
}
@@ -21,7 +21,6 @@ import codechicken.nei.BookmarkContainerInfo;
import codechicken.nei.FavoriteRecipes;
import codechicken.nei.ItemPanels;
import codechicken.nei.ItemQuantityField;
import codechicken.nei.ItemStackAmount;
import codechicken.nei.KeyManager;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
@@ -718,7 +717,7 @@ public abstract class ShortcutInputHandler {
private static void autocraftingIgnoreInventory(RecipeChainMath math) {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final List<ItemStack> playerInventory = ItemStackAmount.of(guiContainer).values();
final List<ItemStack> playerInventory = AutoCraftingManager.getInventoryItems(guiContainer).values();
final RecipeId rootRecipeId = math.createMasterRoot();
for (int i = 0; i < math.recipeIngredients.size(); i++) {
@@ -729,7 +728,7 @@ public abstract class ShortcutInputHandler {
for (ItemStack stack : playerInventory) {
if (NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
amount += StackInfo.getAmountLong(stack);
amount += StackInfo.getAmount(stack);
}
}
@@ -194,8 +194,7 @@ public class BookmarkGridGenerator {
|| group.crafting.calculatedItems.get(shadowIndex).calculatedType == CalculatedType.INGREDIENT;
final BookmarkItem shadowBookmarkItem = BookmarkItem.builder(bookmarkItem.groupId, bookmarkItem.itemStack)
.multiplier(1).factor(StackInfo.getAmountLong(bookmarkItem.itemStack))
.recipeId(bookmarkItem.recipeId)
.multiplier(1).factor(StackInfo.getAmount(bookmarkItem.itemStack)).recipeId(bookmarkItem.recipeId)
.type(isIngredient ? BookmarkItemType.INGREDIENT : BookmarkItemType.RESULT)
.permutations(Collections.emptyMap()).build();
@@ -42,7 +42,7 @@ public class BookmarkItem {
this.groupId = groupId;
this.stack = stack;
this.factor = StackInfo.isFluidDisplayItem(stack) ? Math.max(nbTag.getLong("Count"), 1) : 1;
this.factor = StackInfo.isFluidDisplayItem(stack) ? Math.max(nbTag.getInteger("Count"), 1) : 1;
}
public Builder factor(long factor) {
@@ -105,7 +105,7 @@ public class BookmarkItem {
if (this.multiplier >= 0) {
multiplier = this.multiplier;
} else if (this.factor > 0) {
multiplier = StackInfo.getAmountLong(this.stack) / this.factor;
multiplier = StackInfo.getAmount(this.stack) / this.factor;
}
return new BookmarkItem(
@@ -234,7 +234,7 @@ public class BookmarkItem {
for (RecipeIngredient res : items) {
for (ItemStack perm : res.getPermutations()) {
if (NEIClientUtils.areStacksSameTypeWithNBT(emptyStack, StackInfo.withAmount(perm, 0))) {
amount += 1L * StackInfo.getAmountLong(perm) * res.getChance();
amount += 1L * StackInfo.getAmount(perm) * res.getChance();
break;
}
}
@@ -271,15 +271,15 @@ public class BookmarkItem {
}
if (jsonObject.has("multiplier")) {
builder.multiplier(jsonObject.get("multiplier").getAsLong());
builder.multiplier(jsonObject.get("multiplier").getAsInt());
}
if (jsonObject.has("factor")) {
builder.factor(jsonObject.get("factor").getAsLong());
builder.factor(jsonObject.get("factor").getAsInt());
}
if (jsonObject.has("chance")) {
builder.chance(jsonObject.get("chance").getAsLong());
builder.chance(jsonObject.get("chance").getAsInt());
}
if (jsonObject.get("recipeId") instanceof JsonObject recipeJson) {
@@ -320,9 +320,8 @@ public class BookmarkItem {
final ItemStack newPerm = findPermutation(stack);
if (oldPerm != null && newPerm != null) {
final long oldAmount = StackInfo.getAmountLong(oldPerm);
final long amount = oldAmount > 0
? this.factor * this.chance * StackInfo.getAmountLong(newPerm) / oldAmount
final long oldAmount = StackInfo.getAmount(oldPerm);
final long amount = oldAmount > 0 ? this.factor * this.chance * StackInfo.getAmount(newPerm) / oldAmount
: 0;
final long factor = (amount % PositionedStack.CHANCE_FULL) == 0 ? amount / PositionedStack.CHANCE_FULL
: 1;
@@ -370,9 +369,8 @@ public class BookmarkItem {
final ItemStack newPerm = findPermutation(perm);
if (oldPerm != null && newPerm != null) {
final long oldAmount = StackInfo.getAmountLong(oldPerm);
final long amount = oldAmount > 0
? this.factor * this.chance * StackInfo.getAmountLong(newPerm) / oldAmount
final long oldAmount = StackInfo.getAmount(oldPerm);
final long amount = oldAmount > 0 ? this.factor * this.chance * StackInfo.getAmount(newPerm) / oldAmount
: 0;
final long factor = (amount % PositionedStack.CHANCE_FULL) == 0 ? amount / PositionedStack.CHANCE_FULL
: 1;
@@ -363,7 +363,17 @@ public class BookmarksGridSlot extends ItemsGridSlot {
final float panelFactor = (rect.w - 2) / (DEFAULT_SLOT_SIZE - 2);
final long stackSize = this.bookmarkItem.getStackSize(amount);
int color = 0xFFFFFF;
String amountString = NEIClientUtils.formatSlotAmount(stackSize, this.isFluidDisplay);
String amountString = "";
if (stackSize < 10_000) {
amountString = String.valueOf(stackSize);
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
}
if (this.isFluidDisplay) {
amountString += "L";
}
if (this.bookmarkItem.chance != PositionedStack.CHANCE_FULL) {
amountString = "~" + amountString;
@@ -29,6 +29,7 @@ import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.scroll.GuiHelper;
import codechicken.nei.util.ReadableNumberConverter;
class CraftingTreeCanvas {
@@ -408,7 +409,12 @@ class CraftingTreeCanvas {
}
protected void drawStackSize(ItemTreeSlot node, long stackSize, int x, int y, boolean resolved) {
String amountString = NEIClientUtils.formatSlotAmount(stackSize, node.isFluidDisplay);
String amountString = stackSize < 10_000 ? String.valueOf(stackSize)
: ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
if (node.isFluidDisplay) {
amountString += "L";
}
final boolean hasOutputChance = node.prefItem != null && node.prefItem.chance != PositionedStack.CHANCE_FULL;
int color = 0xFFFFFF;
@@ -36,7 +36,6 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.ItemStackAmount;
import codechicken.nei.KeyManager;
import codechicken.nei.LRUCache;
import codechicken.nei.NEICPH;
@@ -61,6 +60,7 @@ import codechicken.nei.guihook.IGuiClientSide;
import codechicken.nei.guihook.IGuiHandleMouseWheel;
import codechicken.nei.guihook.IGuiHotkeyListener;
import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler;
import codechicken.nei.recipe.AutoCraftingManager;
import codechicken.nei.recipe.GuiCraftingRecipe;
import codechicken.nei.recipe.GuiOverlayButton;
import codechicken.nei.recipe.GuiRecipe;
@@ -284,8 +284,10 @@ public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGu
final GuiContainer firstGui = getFirstScreen();
if (firstGui != null) {
for (ItemStack stack : ItemStackAmount.of(firstGui).values()) {
this.math.initialItems.add(BookmarkItem.of(-1, stack));
for (ItemStack stack : AutoCraftingManager.getInventoryItems(firstGui).values()) {
if (stack != null) {
this.math.initialItems.add(BookmarkItem.of(-1, stack));
}
}
}
}
@@ -143,7 +143,12 @@ class StatsPanel extends ScrollContainer {
}
private void drawStackSize() {
final String amountString = NEIClientUtils.formatSlotAmount(stackSize, this.isFluidDisplay);
String amountString = stackSize < 10_000 ? String.valueOf(stackSize)
: ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize);
if (this.isFluidDisplay) {
amountString += "L";
}
NEIClientUtils.drawNEIOverlayText(
amountString,
@@ -519,7 +524,7 @@ class StatsPanel extends ScrollContainer {
public ItemStack getStackMouseOver(int mouseX, int mouseY) {
final Widget widget = getWidgetUnderMouse(mouseX, mouseY);
return widget instanceof ItemStatsSlot slot ? slot.getStack() : null;
return widget instanceof ItemStatsSlot slot && slot.recipeId == null ? slot.getStack() : null;
}
public void setHighlight(SearchResult searchResult) {
@@ -3,15 +3,25 @@ package codechicken.nei.bookmark.tree;
import java.util.List;
import java.util.Map;
import net.minecraft.client.Minecraft;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.recipe.GuiRecipeButton;
import codechicken.nei.recipe.Recipe;
import codechicken.nei.recipe.RecipeHandlerRef;
import codechicken.nei.theme.UIRecipeTexture;
public class TreeOverlayButton extends GuiRecipeButton {
protected static final DrawableResource ICON_FILL = new DrawableBuilder(
"nei:textures/nei_sprites.png",
28,
76,
9,
10).build();
protected static final int BUTTON_ID_SHIFT = 4;
public final GuiCraftingTree treeGui;
@@ -40,8 +50,16 @@ public class TreeOverlayButton extends GuiRecipeButton {
}
@Override
protected Drawable getIcon(boolean mouseOver) {
return UIRecipeTexture.ICON_OVERLAY_FILL;
protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) {
final int iconX = this.xPosition + (this.width - ICON_FILL.width - 1) / 2;
final int iconY = this.yPosition + (this.height - ICON_FILL.height) / 2;
GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
ICON_FILL.draw(iconX, iconY);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1, 1, 1, 1);
}
@Override
@@ -109,8 +109,6 @@ public class IMCHandler {
info.setShowFavoritesButton(!tag.hasKey("showFavoritesButton") || tag.getBoolean("showFavoritesButton"));
info.setShowOverlayButton(!tag.hasKey("showOverlayButton") || tag.getBoolean("showOverlayButton"));
info.setShowBadge(tag.hasKey("showBadge") && tag.getBoolean("showBadge"));
info.setWindowWidth(tag.getInteger("windowWidth"));
info.setRecipeSpacing(tag.getBoolean("recipeSpacing"));
GuiRecipeTab.handlerAdderFromIMC.remove(handler);
GuiRecipeTab.handlerAdderFromIMC.put(handler, info);
@@ -1,57 +0,0 @@
package codechicken.nei.drawable;
public interface Drawable {
@FunctionalInterface
public interface Painter {
public void draw(int x, int y, int width, int height);
}
public int getWidth();
public int getHeight();
public void draw(int x, int y, int width, int height);
default void draw(int x, int y) {
draw(x, y, getWidth(), getHeight());
}
public static Drawable of(int width, int height, Painter painter) {
return new Drawable() {
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public void draw(int x, int y, int w, int h) {
painter.draw(x, y, w, h);
}
};
}
// every layer is drawn into the whole rectangle, the first one at the bottom
public static Drawable stack(Drawable... layers) {
int width = 0;
int height = 0;
for (Drawable layer : layers) {
width = Math.max(width, layer.getWidth());
height = Math.max(height, layer.getHeight());
}
return of(width, height, (x, y, w, h) -> {
for (Drawable layer : layers) {
layer.draw(x, y, w, h);
}
});
}
}
@@ -8,7 +8,7 @@ import org.lwjgl.opengl.GL11;
import codechicken.nei.Image;
public class DrawableResource extends Image implements Drawable {
public class DrawableResource extends Image {
private final ResourceLocation resourceLocation;
private final int textureWidth;
@@ -51,7 +51,6 @@ import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.NEIModContainer;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
import codechicken.nei.util.ItemUntranslator;
import codechicken.nei.util.ReadableNumberConverter;
import codechicken.nei.util.RenderTooltipEventHelper;
@@ -230,9 +229,7 @@ public class GuiContainerManager {
public static String itemCountDetails(ItemStack stack) {
final FluidStack fluid = StackInfo.getFluid(stack);
if (fluid != null) {
// The fluid of a display item is limited to an int, its stored amount is not
final long amount = StackInfo.isFluidDisplayItem(stack) ? StackInfo.getAmountLong(stack) : fluid.amount;
return fluidAmountDetails(amount * Math.max(1, stack.stackSize));
return fluidAmountDetails(fluid.amount * Math.max(1, stack.stackSize));
} else {
return countDetails(
stack.stackSize,
@@ -246,35 +243,17 @@ public class GuiContainerManager {
@SuppressWarnings("unused")
@Nullable
public static String fluidAmountDetails(FluidStack fluid) {
return fluidAmountDetails(GTFluidStackStringifyHandler.getFluidAmount(fluid));
return fluidAmountDetails(fluid.amount);
}
@Nullable
public static String fluidAmountDetails(int amount) {
return fluidAmountDetails((long) amount);
}
@Nullable
public static String fluidAmountDetails(long amount) {
if (amount <= 144) return null;
final long remainder = amount % 144;
final String units = NEIClientUtils.formatNumber(amount / 144);
if (remainder > 0) {
return String.format(
translate("inventory.tooltip.count.fluid", "%s = %s * %s + %s"),
NEIClientUtils.formatFluid(amount),
units,
NEIClientUtils.formatFluid(144),
NEIClientUtils.formatFluid(remainder));
}
return String.format(
return countDetails(
amount,
144,
translate("inventory.tooltip.count.fluid", "%s = %s * %s + %s"),
translate("inventory.tooltip.count.fluid", "%s = %s * %s"),
NEIClientUtils.formatFluid(amount),
units,
NEIClientUtils.formatFluid(144));
NEIClientUtils::formatFluid);
}
/**
@@ -661,7 +640,7 @@ public class GuiContainerManager {
tooltip = handler.handleTooltip(window, mousex, mousey, tooltip);
}
ItemStack stack = tooltip.isEmpty() ? getStackMouseOver(window) : null;
ItemStack stack = getStackMouseOver(window);
boolean showTooltip = shouldShowTooltip(window);
if (tooltip.isEmpty() && showTooltip) { // mouseover tip, not holding an item
font = getFontRenderer(stack);
@@ -9,8 +9,8 @@ import net.minecraftforge.fluids.FluidRegistry;
import org.lwjgl.opengl.GL11;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.item.FluidDrawer.FillDirection;
import codechicken.nei.util.ReadableNumberConverter;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -48,7 +48,14 @@ public class FluidDisplayRenderer implements IItemRenderer {
return;
}
final String amountString = NEIClientUtils.formatSlotAmount(amount, true);
String amountString = "";
if (amount < 10_000) {
amountString = String.valueOf(amount) + "L";
} else {
amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(amount) + "L";
}
final FontRenderer fontRender = Minecraft.getMinecraft().fontRenderer;
float smallTextScale = fontRender.getUnicodeFlag() ? 3F / 4F : 1F / 2F;
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
@@ -17,7 +17,6 @@ import net.minecraftforge.fluids.IFluidContainerItem;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -47,8 +46,7 @@ public class ItemFluidDisplay extends Item implements IFluidContainerItem {
}
public static ItemStack createStack(FluidStack fluidStack) {
return fluidStack == null ? null
: createStack(fluidStack.getFluid(), GTFluidStackStringifyHandler.getFluidAmount(fluidStack));
return fluidStack == null ? null : createStack(fluidStack.getFluid(), fluidStack.amount);
}
public static ItemStack createStack(Fluid fluid, long amount) {
@@ -1,65 +1,117 @@
package codechicken.nei.moboverlay;
import java.util.Arrays;
import net.minecraft.client.renderer.GLAllocation;
import org.lwjgl.opengl.GL11;
/** The mob spawn overlay quads, compiled into a GL display list. */
/**
* {@code MobOverlayDisplayList} compiles the overlay quads of each chunk column of a {@link MobOverlayScan} box into
* one GL display list. A compile rebuilds only the lists whose {@link MobOverlayScan#readChunkVersion} changed.
*/
public final class MobOverlayDisplayList {
private int listId = -1;
private static final int NO_LIST = -1;
private int firstListId = NO_LIST;
private int parentListId = NO_LIST;
private int anchorX;
private int anchorY;
private int anchorZ;
private int chunkSpan;
private boolean[] isCompiled = new boolean[0];
private boolean[] hasFaces = new boolean[0];
private int[] compiledChunkVersion = new int[0];
private int modesVersion;
private MobOverlayStyle style;
private int minX;
private int minY;
private int minZ;
private long compiledTicks;
private int compilingChunk;
/**
* Compiles after a {@link MobOverlayScan#getModesVersion} change are debounced to one per {@code MIN_COMPILE_TICKS}
* ticks, because the version changes several times per second while the player moves fast, and a compile runs for a
* millisecond or more.
*/
public boolean isCompileDue(int currentModesVersion, MobOverlayStyle currentStyle, long worldTicks) {
final int MIN_COMPILE_TICKS = 5;
if (listId < 0 || style != currentStyle) return true;
if (firstListId == NO_LIST || style != currentStyle) return true;
// after a dimension change or a server switch, `worldTicks` can be lower than `compiledTicks`
final boolean isWaitOver = worldTicks - compiledTicks >= MIN_COMPILE_TICKS || worldTicks < compiledTicks;
return modesVersion != currentModesVersion && isWaitOver;
}
/**
* Quad positions are relative to block ({@link MobOverlayScan#getMinX}, {@link MobOverlayScan#getMinY},
* {@link MobOverlayScan#getMinZ}) of {@code scan}.
*/
public void beginCompile(MobOverlayScan scan, MobOverlayStyle newStyle, long worldTicks) {
if (listId < 0) listId = GLAllocation.generateDisplayLists(1);
if (chunkSpan != scan.getChunkSpan()) resize(scan.getChunkSpan());
if (style != newStyle) Arrays.fill(isCompiled, false);
modesVersion = scan.getModesVersion();
style = newStyle;
minX = scan.getMinX();
minY = scan.getMinY();
minZ = scan.getMinZ();
compiledTicks = worldTicks;
GL11.glNewList(listId, GL11.GL_COMPILE);
anchorX = scan.getMinX();
anchorY = scan.getMinY();
anchorZ = scan.getMinZ();
}
public void endCompile() {
public boolean beginChunk(MobOverlayScan scan, int chunkX, int chunkZ) {
final int chunk = scan.findChunk(chunkX, chunkZ);
final int chunkVersion = scan.readChunkVersion(chunkX, chunkZ);
if (isCompiled[chunk] && compiledChunkVersion[chunk] == chunkVersion) return false;
isCompiled[chunk] = true;
compiledChunkVersion[chunk] = chunkVersion;
compilingChunk = chunk;
GL11.glNewList(firstListId + chunk, GL11.GL_COMPILE);
return true;
}
public void endChunk(boolean hasChunkFaces) {
GL11.glEndList();
hasFaces[compilingChunk] = hasChunkFaces;
}
public void endCompile(MobOverlayScan scan) {
GL11.glNewList(parentListId, GL11.GL_COMPILE);
for (int chunkX = scan.getMinChunkX(); chunkX <= scan.getMaxChunkX(); chunkX++) {
for (int chunkZ = scan.getMinChunkZ(); chunkZ <= scan.getMaxChunkZ(); chunkZ++) {
final int chunk = scan.findChunk(chunkX, chunkZ);
if (!hasFaces[chunk]) continue;
GL11.glPushMatrix();
GL11.glTranslated(
(chunkX << MobOverlayScan.CHUNK_SHIFT) - anchorX,
0,
(chunkZ << MobOverlayScan.CHUNK_SHIFT) - anchorZ);
GL11.glCallList(firstListId + chunk);
GL11.glPopMatrix();
}
}
GL11.glEndList();
}
/** The model view matrix is relative to block ({@code cameraX}, {@code cameraY}, {@code cameraZ}). */
public void draw(int cameraX, int cameraY, int cameraZ) {
GL11.glPushMatrix();
GL11.glTranslated(minX - cameraX, minY - cameraY, minZ - cameraZ);
GL11.glCallList(listId);
GL11.glTranslated(anchorX - cameraX, anchorY - cameraY, anchorZ - cameraZ);
GL11.glCallList(parentListId);
GL11.glPopMatrix();
}
public void delete() {
if (listId < 0) return;
private void resize(int newChunkSpan) {
final int chunkCount = newChunkSpan * newChunkSpan;
delete();
GLAllocation.deleteDisplayLists(listId);
listId = -1;
chunkSpan = newChunkSpan;
firstListId = GLAllocation.generateDisplayLists(chunkCount + 1);
parentListId = firstListId + chunkCount;
isCompiled = new boolean[chunkCount];
hasFaces = new boolean[chunkCount];
compiledChunkVersion = new int[chunkCount];
}
public void delete() {
if (firstListId == NO_LIST) return;
GLAllocation.deleteDisplayLists(firstListId);
firstListId = NO_LIST;
parentListId = NO_LIST;
chunkSpan = 0;
Arrays.fill(isCompiled, false);
}
}
@@ -2,7 +2,7 @@ package codechicken.nei.moboverlay;
import net.minecraft.client.renderer.Tessellator;
/** Vertex builder for one block's top face in the mob spawn overlay. */
/** {@code MobOverlayFace} adds the vertices of the mark on one block's top face to {@link Tessellator#instance}. */
public final class MobOverlayFace {
public static final byte OUTSIDE_SCAN = -2;
@@ -36,7 +36,7 @@ public final class MobOverlayFace {
public boolean isJoined(int offsetX, int offsetZ) {
final byte neighbourMode = neighbourModes[indexNeighbour(offsetX, offsetZ)];
// no outline along the edge of the scan
// `MobOverlayStyle.CONNECTED` doesn't outline the edge of the scan
return neighbourMode == neighbourModes[indexNeighbour(0, 0)] || neighbourMode == OUTSIDE_SCAN;
}
@@ -67,7 +67,6 @@ public final class MobOverlayFace {
addTexturedVertex(1, 0);
}
/** @param offsetX 0 at the west edge, 1 at the east edge */
public void addVertex(double offsetX, double offsetZ) {
Tessellator.instance.addVertex(x + offsetX, y, z + offsetZ);
}
@@ -1,5 +1,7 @@
package codechicken.nei.moboverlay;
import java.util.Arrays;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EnumCreatureType;
@@ -16,11 +18,8 @@ import net.minecraft.world.chunk.Chunk;
import codechicken.lib.math.MathHelper;
/**
* Spawn modes, and the tops of flat blocks such as carpets, in a box around the player. The spawn modes are from
* {@link Column#getSpawnMode}: 0 for no spawns, 1 for night only and 2 for any time. The box moves with the player once
* the player is a few blocks from the box's centre, and {@link #update} scans only the blocks that enter the box.
* {@link #update} rescans the column of a block or light change on the next tick. On each tick, {@link #update} also
* rescans a slice of the columns, for changes with no block update, such as a boat that moves into the box.
* Spawn modes of the blocks in a box around the player. {@link #update} scans the blocks that enter the box, the
* columns of block and light changes, and a slice of the box on each tick.
*/
public final class MobOverlayScan {
@@ -31,6 +30,7 @@ public final class MobOverlayScan {
public static final int MIN_VERTICAL_RADIUS = 4;
public static final int MAX_VERTICAL_RADIUS = 64;
public static final int DEFAULT_VERTICAL_RADIUS = 16;
public static final int CHUNK_SHIFT = 4;
private static final int RECENTRE_DISTANCE = 4;
private static final int VERTICAL_RECENTRE_DISTANCE = 2;
private static final int RESCAN_TICKS = 40;
@@ -47,18 +47,21 @@ public final class MobOverlayScan {
// a ring buffer over the box, indexed by `findCell()`. A cell has the spawn mode in the bits of `SPAWN_MODE_MASK`,
// and `Column.readCoverTop()` shifted left by `COVER_TOP_SHIFT`
private byte[] modes = new byte[0];
// indexed by `findColumn(x, z)`
private boolean[] dirty = new boolean[0];
private boolean hasDirtyColumns;
private int minX;
private int minY;
private int minZ;
// the slice rescan of `update()` continues from this column, numbered `(x - minX) * span + (z - minZ)`
private int nextRescanColumn;
private int modesVersion;
private int chunkSpan;
// The version of a chunk column changes when a cell in or beside the chunk column changes, and when an edge of the
// box moves into, out of, within or across the chunk column. A full scan and a vertical move change the version of
// every chunk column
private int[] chunkVersions = new int[0];
private int chunkVersionCount;
private boolean hasModes;
private long scannedTick;
// world of `modes`, with `changeListener` added
private World scannedWorld;
public void clear() {
@@ -71,17 +74,17 @@ public final class MobOverlayScan {
height = 0;
modes = new byte[0];
dirty = new boolean[0];
chunkSpan = 0;
chunkVersions = new int[0];
hasModes = false;
scannedWorld = null;
// `Chunk.worldObj` references the world
// a world isn't garbage-collected while `column.chunk` references a chunk of the world
column.chunk = null;
}
/**
* Scan every column in this call after {@link #clear}, a change of either radius, a world change, or a move of
* {@link #getSpan} blocks or more across or {@link #getHeight} blocks or more up or down. {@code newRadius} is
* clamped between {@link #MIN_RADIUS} and {@link #MAX_RADIUS}, and {@code newVerticalRadius} between
* {@link #MIN_VERTICAL_RADIUS} and {@link #MAX_VERTICAL_RADIUS}.
* {@link #getSpan} blocks or more across or {@link #getHeight} blocks or more up or down.
*/
public void update(Entity entity, int newRadius, int newVerticalRadius) {
final World world = entity.worldObj;
@@ -112,11 +115,14 @@ public final class MobOverlayScan {
if (isChanged) modesVersion++;
}
/** The version changes when a spawn mode or the top of a flat block changes, or the box moves. */
public int getModesVersion() {
return modesVersion;
}
public int getChunkSpan() {
return chunkSpan;
}
public int getSpan() {
return span;
}
@@ -137,19 +143,44 @@ public final class MobOverlayScan {
return minZ;
}
/** {@code i} and {@code j} are from 0 to {@link #getSpan}, and {@code k} is from 0 to {@link #getHeight}. */
public byte readSpawnMode(int i, int k, int j) {
return (byte) (modes[findCell(minX + i, minY + k, minZ + j)] & SPAWN_MODE_MASK);
public int getMinChunkX() {
return minX >> CHUNK_SHIFT;
}
/**
* Height of the overlay above the bottom of the block, so that a flat block such as a carpet does not cover the
* overlay. The indices are those of {@link #readSpawnMode}.
*/
public double readOverlayYOffset(int i, int k, int j) {
public int getMaxChunkX() {
return (minX + span - 1) >> CHUNK_SHIFT;
}
public int getMinChunkZ() {
return minZ >> CHUNK_SHIFT;
}
public int getMaxChunkZ() {
return (minZ + span - 1) >> CHUNK_SHIFT;
}
public int readChunkVersion(int chunkX, int chunkZ) {
return chunkVersions[findChunk(chunkX, chunkZ)];
}
public byte readSpawnMode(int i, int k, int j) {
return extractSpawnMode(modes[findCell(minX + i, minY + k, minZ + j)]);
}
public void readColumn(int i, int j, byte[] columnCells) {
final int columnStart = findColumn(minX + i, minZ + j) * height;
final int bottomCell = Math.floorMod(minY, height);
System.arraycopy(modes, columnStart + bottomCell, columnCells, 0, height - bottomCell);
System.arraycopy(modes, columnStart, columnCells, height - bottomCell, bottomCell);
}
public static byte extractSpawnMode(byte cell) {
return (byte) (cell & SPAWN_MODE_MASK);
}
public static double computeOverlayYOffset(byte cell) {
final double OVERLAY_GAP = 0.02;
final int coverTopSteps = modes[findCell(minX + i, minY + k, minZ + j)] >> COVER_TOP_SHIFT;
return (double) coverTopSteps / COVER_TOP_STEPS + OVERLAY_GAP;
return (double) (cell >> COVER_TOP_SHIFT) / COVER_TOP_STEPS + OVERLAY_GAP;
}
private void resize(int newRadius, int newVerticalRadius) {
@@ -159,6 +190,8 @@ public final class MobOverlayScan {
height = 2 * newVerticalRadius + 1;
modes = new byte[span * span * height];
dirty = new boolean[span * span];
chunkSpan = ((span - 1) >> CHUNK_SHIFT) + 2;
chunkVersions = new int[chunkSpan * chunkSpan];
hasModes = false;
nextRescanColumn = 0;
}
@@ -172,6 +205,7 @@ public final class MobOverlayScan {
scanColumn(x, z);
}
}
markAllChunks();
hasModes = true;
modesVersion++;
scannedTick = scannedWorld.getTotalWorldTime();
@@ -189,6 +223,7 @@ public final class MobOverlayScan {
final int offsetX = centreX - radius - minX;
if (Math.abs(offsetX) > RECENTRE_DISTANCE) {
final int enteringX = offsetX > 0 ? minX + span : minX + offsetX;
markMovedEdgeChunks(minX, offsetX, Axis.X);
minX += offsetX;
for (int x = enteringX; x < enteringX + Math.abs(offsetX); x++) {
for (int z = minZ; z < minZ + span; z++) {
@@ -201,6 +236,7 @@ public final class MobOverlayScan {
final int offsetZ = centreZ - radius - minZ;
if (Math.abs(offsetZ) > RECENTRE_DISTANCE) {
final int enteringZ = offsetZ > 0 ? minZ + span : minZ + offsetZ;
markMovedEdgeChunks(minZ, offsetZ, Axis.Z);
minZ += offsetZ;
for (int x = minX; x < minX + span; x++) {
for (int z = enteringZ; z < enteringZ + Math.abs(offsetZ); z++) {
@@ -220,6 +256,7 @@ public final class MobOverlayScan {
column.scan(enteringY, enteringY + Math.abs(offsetY));
}
}
markAllChunks();
isMoved = true;
}
return isMoved;
@@ -230,7 +267,7 @@ public final class MobOverlayScan {
boolean isChanged = false;
for (int x = minX; x < minX + span; x++) {
for (int z = minZ; z < minZ + span; z++) {
if (dirty[findColumn(x, z)]) isChanged |= scanColumn(x, z);
if (dirty[findColumn(x, z)]) isChanged |= rescanColumn(x, z);
}
}
return isChanged;
@@ -243,7 +280,7 @@ public final class MobOverlayScan {
for (; nextRescanColumn < sliceEnd; nextRescanColumn++) {
final int x = minX + nextRescanColumn / span;
final int z = minZ + nextRescanColumn % span;
isChanged |= scanColumn(x, z);
isChanged |= rescanColumn(x, z);
}
if (nextRescanColumn >= columnCount) nextRescanColumn = 0;
return isChanged;
@@ -256,6 +293,60 @@ public final class MobOverlayScan {
return column.scan(minY, minY + height);
}
private boolean rescanColumn(int x, int z) {
final boolean isChanged = scanColumn(x, z);
// the connected outline of a cell depends on the spawn modes of the cells beside the cell
if (isChanged) {
for (int offsetX = -1; offsetX <= 1; offsetX++) {
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
markChunk((x + offsetX) >> CHUNK_SHIFT, (z + offsetZ) >> CHUNK_SHIFT);
}
}
}
return isChanged;
}
private void markMovedEdgeChunks(int oldMin, int offset, Axis moveAxis) {
final int lowFrom = Math.min(oldMin, oldMin + offset);
final int lowTo = Math.max(oldMin, oldMin + offset);
markStripChunks(lowFrom, lowTo, moveAxis);
markStripChunks(lowFrom + span - 1, lowTo + span - 1, moveAxis);
}
private void markStripChunks(int from, int to, Axis moveAxis) {
final int acrossMin = switch (moveAxis) {
case X -> minZ;
case Z -> minX;
};
final int minAcrossChunk = acrossMin >> CHUNK_SHIFT;
final int maxAcrossChunk = (acrossMin + span - 1) >> CHUNK_SHIFT;
for (int alongChunk = from >> CHUNK_SHIFT; alongChunk <= to >> CHUNK_SHIFT; alongChunk++) {
for (int acrossChunk = minAcrossChunk; acrossChunk <= maxAcrossChunk; acrossChunk++) {
final int chunkX = switch (moveAxis) {
case X -> alongChunk;
case Z -> acrossChunk;
};
final int chunkZ = switch (moveAxis) {
case X -> acrossChunk;
case Z -> alongChunk;
};
markChunk(chunkX, chunkZ);
}
}
}
private void markAllChunks() {
Arrays.fill(chunkVersions, ++chunkVersionCount);
}
private void markChunk(int chunkX, int chunkZ) {
chunkVersions[findChunk(chunkX, chunkZ)] = ++chunkVersionCount;
}
public int findChunk(int chunkX, int chunkZ) {
return Math.floorMod(chunkX, chunkSpan) * chunkSpan + Math.floorMod(chunkZ, chunkSpan);
}
private int findColumn(int x, int z) {
return Math.floorMod(x, span) * span + Math.floorMod(z, span);
}
@@ -264,10 +355,6 @@ public final class MobOverlayScan {
return findColumn(x, z) * height + Math.floorMod(y, height);
}
/**
* {@link #moveTo} reads a column's chunk, biome and highest non-air block in the box, and {@link #scan} reads the
* column's blocks.
*/
private final class Column {
private final Entity dummyEntity = new EntityPig(null);
@@ -285,10 +372,8 @@ public final class MobOverlayScan {
canBiomeSpawn = !biome.getSpawnableList(EnumCreatureType.monster).isEmpty()
&& biome.getSpawningChance() > 0;
chunk = scannedWorld.getChunkFromBlockCoords(x, z);
// `getHeightValue()` is the height above the highest block with a light opacity above 0. A block with a
// light opacity of 0 can be higher: Tinkers' Construct slime grass, a hopper or a snow layer. A mob can
// spawn on top of slime grass, a hopper or a full snow block. Search the blocks for the highest non-air
// block
// `getHeightValue()` skips blocks with a light opacity of 0. A mob can spawn on some of these blocks, such
// as Tinkers' Construct slime grass, a hopper or a full snow block. Search for the highest non-air block
final int SECTION_HEIGHT = 16;
int y = Math.min(minY + height - 1, chunk.getTopFilledSegment() + SECTION_HEIGHT - 1);
while (y >= minY && chunk.getBlock(x & 15, y, z & 15).isAir(chunk.worldObj, x, y, z)) y--;
@@ -308,12 +393,15 @@ public final class MobOverlayScan {
return isChanged;
}
/** The spawn mode of the block at height {@code y} in this column. */
private byte getSpawnMode(int y) {
if (y >= chunk.worldObj.getHeight()) {
return 0;
}
// vanilla `SpawnerAnimals.canCreatureTypeSpawnAtLocation()` rejects a normal cube in the cell (such as the
// inside of a stone block). Test the block before the light read
if (chunk.getBlock(x & 15, y, z & 15).isNormalCube()) return 0;
if (chunk.getSavedLightValue(EnumSkyBlock.Block, x & 15, y, z & 15) >= 8 || !SpawnerAnimals
.canCreatureTypeSpawnAtLocation(EnumCreatureType.monster, chunk.worldObj, x, y, z)) {
return 0;
@@ -337,10 +425,6 @@ public final class MobOverlayScan {
return (byte) (chunk.getSavedLightValue(EnumSkyBlock.Sky, x & 15, y, z & 15) >= 8 ? 1 : 2);
}
/**
* The top of the block at height {@code y}, in fractions of a block with {@link MobOverlayScan#COVER_TOP_STEPS}
* as the denominator, or 0 for a tall block.
*/
private int readCoverTop(int y) {
final double MAX_COVER_TOP = 0.25;
final Block block = chunk.getBlock(x & 15, y, z & 15);
@@ -352,7 +436,6 @@ public final class MobOverlayScan {
}
}
/** Marks the columns of the block and light changes in {@link #scannedWorld}. */
private final class ChangeListener implements IWorldAccess {
@Override
@@ -417,4 +500,9 @@ public final class MobOverlayScan {
hasDirtyColumns = true;
}
}
private enum Axis {
X,
Z
}
}
@@ -27,9 +27,7 @@ public enum MobOverlayStyle {
}
},
/**
* A light tint, with a stronger outline around each area of one spawn mode, like a connected texture.
*/
/** A light tint and a stronger connected-texture outline around each area of one spawn mode. */
CONNECTED(GL11.GL_QUADS) {
@Override
@@ -39,7 +37,8 @@ public enum MobOverlayStyle {
face.applyColor(Colouring.OVERLAY, MARK_ALPHA);
for (int offsetX = -1; offsetX <= 1; offsetX++) {
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
// a corner cell is drawn when either edge next to the corner is outlined, and on an inside corner
// a corner cell is drawn when either edge next to the corner is outlined or when the corner is an
// inside corner
final boolean isOutline = !(face.isJoined(offsetX, offsetZ) && face.isJoined(offsetX, 0)
&& face.isJoined(0, offsetZ));
if (isOutline) face.addCell(offsetX, offsetZ, OUTLINE_WIDTH);
@@ -48,7 +47,7 @@ public enum MobOverlayStyle {
}
},
/** A small square in the middle of the block, with no tint. */
/** A small square in the middle of an untinted block. */
SQUARE(GL11.GL_QUADS) {
@Override
@@ -62,7 +61,7 @@ public enum MobOverlayStyle {
}
},
/** The pufferfish sticker. */
/** A pufferfish sticker on the block. */
PUFFERFISH("pufferfish", Colouring.STICKER) {
@Override
@@ -102,7 +101,6 @@ public enum MobOverlayStyle {
return DEFAULT;
}
/** @return the {@link #formatName} of every style, separated by commas */
public static String formatAllNames() {
final StringJoiner names = new StringJoiner(", ");
for (MobOverlayStyle style : values()) {
@@ -119,7 +117,7 @@ public enum MobOverlayStyle {
return switch (this) {
case CONNECTED -> TINT_ALPHA;
case SQUARE -> MARK_ALPHA;
// opaque lines for X, and the alpha of the PNG for PUFFERFISH
// the lines of X are opaque, and the alpha of PUFFERFISH comes from the PNG
case X, PUFFERFISH -> 1.0F;
};
}
@@ -127,9 +125,9 @@ public enum MobOverlayStyle {
public abstract void addVertices(MobOverlayFace face);
public enum Colouring {
/** Yellow where mobs spawn only at night, red where mobs spawn at any time. */
/** Yellow marks where mobs spawn only at night and red marks where mobs spawn at any time. */
OVERLAY,
/** The texture's colours, tinted red where mobs spawn at any time. */
/** Texture colours with a red tint where mobs spawn at any time. */
STICKER
}
}
@@ -0,0 +1,45 @@
# Mob overlay TODO: spawn rules from other mods
`MobOverlayScan` reads the block, the light and the biome of each cell. Some mods set the result of Forge's
`LivingSpawnEvent.CheckSpawn` from the monster's position, and `MobOverlayScan` doesn't call these handlers.
A monster spawns when the result is `ALLOW`, or when the result is `DEFAULT` and `getCanSpawnHere()` returns
true. So `ALLOW` skips the light test.
## DENY: marked cells where a monster can't spawn
GregTech and Extra Utilities measure a range from the centre of the block.
| mod in 2.9.0 | handler | range | on the client? |
|---|---|---|---|
| GregTech Monster Repellator | `GTSpawnEventHandler.denyMobSpawn()` | sphere. The radius is 4 + 12 × tier without power and 16 + 48 × tier with power | no. `MTEMonsterRepellent.onPostTick()` registers the range on the server only |
| Extra Utilities magnum torch | `EventHandlerServer.magnumTorchDenySpawn()` | ellipsoid 128 blocks out and 32 blocks up and down | maybe. `TileEntityAntiMobTorch` adds itself to the static `magnumTorchRegistry` and doesn't check the side. The bytecode is the source of this row, and the row isn't tested in game |
| Extra Utilities chandelier | the same handler | sphere, radius 16 | maybe. The chandelier's tile entity is a `TileEntityAntiMobTorch` too |
| Gadomancy aura pylon with Lux | `EventHandlerEntityServer.on(CheckSpawn)` | sphere, radius `AuraEffects.LUX.getRange()` | not checked. `AuraEffects.LUX` adds the pylon to `registeredLuxPylons` when the pylon's effect runs on an entity |
| Blood Magic Ward of Sacrosanctity (`AW028SpawnWard`) | `AlchemicalWizardryEventHooks.onLivingSpawnEvent()` | box from the ritual's horizontal and vertical radii | not checked. `RitualEffectSpawnWard` fills `respawnMap` |
| Botania Emptiness potion | `PotionEmptiness.onSpawn()` | sphere around each player with the effect | the player's potion effects |
| ServerUtilities | `ServerUtilitiesWorldEventHandler.onMobSpawned()` | chunks of the safe spawn area, and claimed chunks by the team's settings | no. The claims are server data |
| Et Futurum Requiem | `ServerEventHandler.spawnEvent()` | in the Nether, a cell above `ModBlocks.NETHER_WART` at meta 0, for a mob that doesn't fly | yes. The block below is in the client world |
## ALLOW: monsters spawn in unmarked lit cells
| mod in 2.9.0 | handler | range |
|---|---|---|
| Blood Magic Veil of Evil (`AW029VeilOfEvil`) | `AlchemicalWizardryEventHooks.onLivingSpawnEvent()` | box from the ritual's radii. Creepers are excluded |
| Botania Bloodthirst potion | `PotionBloodthirst.onSpawn()` | sphere around each player with the effect |
Thaumcraft 4.2.3.5 doesn't have a `CheckSpawn` handler. The list comes from a scan of the 2.9.0 pack's jars for
`LivingSpawnEvent$CheckSpawn`. Handlers that test only the mob type, the dimension or the mob count are left out:
AMDIForge, EnderZoo, Automagy, the Extra Utilities Underdark, and the slime handlers of Biomes O' Plenty and Botania.
The Extra Utilities siege handler (`EventHandlerSiege.SiegeCheckSpawn()`) isn't checked.
## To do
- [ ] Add an NEI API: a mod registers a cell test that returns `DENY`, `ALLOW` or `DEFAULT`. `MobOverlayScan` calls
each test for each cell in the box.
- [ ] Add an API call to mark an area dirty. `MobOverlayScan` then rescans the area when a range is added or
removed.
- [ ] Ask GregTech, Gadomancy, Blood Magic and ServerUtilities to send their ranges to the client.
- [ ] Test the Extra Utilities registry on a client with a dedicated server.
- [ ] Find out how the handlers combine. `GTSpawnEventHandler` returns early on `DENY`, and Blood Magic's handler
changes `ALLOW` to `DEFAULT`, so the result depends on the order of the handlers on the event bus.
@@ -32,7 +32,7 @@ public class AutoCraftingManager {
public void execute() {
final GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final ItemStack[] layout = snapshotLayout(guiContainer);
final List<BookmarkItem> initialItems = prepareInitialItems(math, ItemStackAmount.of(guiContainer));
final List<BookmarkItem> initialItems = prepareInitialItems(math, getInventoryItems(guiContainer));
boolean processed = false;
boolean changed = false;
@@ -43,7 +43,7 @@ public class AutoCraftingManager {
changed = false;
RecipeChainIterator iterator = new RecipeChainIterator(math, initialItems);
iterator.updateInventory(ItemStackAmount.of(guiContainer));
iterator.updateInventory(getInventoryItems(guiContainer));
while (iterator.hasNext() && !interrupted(guiContainer)) {
final Map<RecipeId, Long> recipes = iterator.next();
@@ -69,7 +69,7 @@ public class AutoCraftingManager {
if (craft) {
changed = true;
processed = true;
iterator.updateInventory(ItemStackAmount.of(guiContainer));
iterator.updateInventory(getInventoryItems(guiContainer));
}
}
@@ -138,6 +138,18 @@ public class AutoCraftingManager {
return AutoCraftingManager.math != null && !task.interrupted();
}
public static ItemStackAmount getInventoryItems(GuiContainer guiContainer) {
final ItemStackAmount inventory = new ItemStackAmount();
for (Slot slot : guiContainer.inventorySlots.inventorySlots) {
if (slot.getHasStack() && !(slot instanceof SlotCrafting) && slot.canTakeStack(guiContainer.mc.thePlayer)) {
inventory.add(slot.getStack());
}
}
return inventory;
}
private static ItemStack[] snapshotLayout(GuiContainer guiContainer) {
final List<Slot> slots = guiContainer.inventorySlots.inventorySlots;
final ItemStack[] layout = new ItemStack[slots.size()];
@@ -11,27 +11,41 @@ import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.BookmarkPanel.BookmarkViewMode;
import codechicken.nei.FavoriteRecipes;
import codechicken.nei.Image;
import codechicken.nei.ItemPanels;
import codechicken.nei.ItemStackSet;
import codechicken.nei.KeyManager;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.bookmark.tree.GuiCraftingTree;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.Recipe.RecipeIngredient;
import codechicken.nei.theme.ButtonSkin;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.theme.UIWidgetTexture;
import codechicken.nei.util.NEIMouseUtils;
public class GuiFavoriteButton extends GuiRecipeButton {
private static final int BUTTON_ID_START = 14;
protected static final Drawable ICON_FAVORITE = UIRecipeTexture.ICON_FAVORITE;
protected static final DrawableResource ICON_STATE_OFF = new DrawableBuilder(
"nei:textures/nei_sprites.png",
10,
76,
9,
10).build();
protected static final DrawableResource ICON_STATE_ON = new DrawableBuilder(
"nei:textures/nei_sprites.png",
19,
76,
9,
10).build();
protected final Recipe recipe;
protected boolean favorite = false;
@@ -80,18 +94,17 @@ public class GuiFavoriteButton extends GuiRecipeButton {
}
@Override
protected Drawable getIcon(boolean mouseOver) {
return ICON_FAVORITE;
}
protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) {
final DrawableResource icon = isFavorite() ? ICON_STATE_ON : ICON_STATE_OFF;
final int iconX = this.xPosition + (this.width - icon.width - 1) / 2;
final int iconY = this.yPosition + (this.height - icon.height) / 2;
@Override
protected ButtonSkin getSkin() {
return isFavorite() ? UIWidgetTexture.BUTTON_FAVORITE : super.getSkin();
}
@Override
protected void drawContent(Minecraft minecraft, int mouseX, int mouseY, boolean mouseOver) {
super.drawContent(minecraft, mouseX, mouseY, mouseOver);
GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
icon.draw(iconX, iconY);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1, 1, 1, 1);
if (!mouseOver) {
this.selectedResult = null;
@@ -167,15 +180,11 @@ public class GuiFavoriteButton extends GuiRecipeButton {
this.selectedResult.height,
0x66333333));
getSkin().drawIcon(
this.selectedResult.relx,
this.selectedResult.rely,
this.selectedResult.width,
this.selectedResult.height + 2,
ICON_FAVORITE,
this.enabled,
false,
false);
final Image icon = isFavorite() ? ICON_STATE_ON : ICON_STATE_OFF;
final int iconX = this.selectedResult.relx + (this.selectedResult.width - icon.width) / 2;
final int iconY = this.selectedResult.rely + (this.selectedResult.height + 2 - icon.height) / 2;
LayoutManager.drawIcon(iconX, iconY, icon);
}
@Override
@@ -5,30 +5,38 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.ItemPanels;
import codechicken.nei.ItemsTooltipLineHandler;
import codechicken.nei.KeyManager;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.api.IOverlayHandler;
import codechicken.nei.bookmark.BookmarkGrid;
import codechicken.nei.bookmark.BookmarkPayload;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.theme.ButtonSkin;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.theme.UIWidgetTexture;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.util.NEIMouseUtils;
public class GuiOverlayButton extends GuiRecipeButton {
protected static Drawable notPresent = UIRecipeTexture.ITEM_MISSING;
protected static Drawable present = UIRecipeTexture.ITEM_PRESENT;
protected static DrawableResource notPresent = new DrawableBuilder(
"nei:textures/nei_tabbed_sprites.png",
0,
40,
8,
8).build();
protected static DrawableResource present = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 8, 40, 8, 8)
.build();
public enum ItemOverlayFormat {
@@ -69,17 +77,34 @@ public class GuiOverlayButton extends GuiRecipeButton {
this.slot.height,
isPresent ? 0x8000AA00 : 0x80AA0000));
} else {
final Drawable icon = isPresent ? present : notPresent;
icon.draw(
this.slot.relx + this.slot.width - icon.getWidth(),
this.slot.rely + this.slot.height - icon.getHeight());
final DrawableResource icon = isPresent ? present : notPresent;
LayoutManager.drawIcon(
this.slot.relx + this.slot.width - icon.width,
this.slot.rely + this.slot.height - icon.height,
icon);
}
}
}
protected static final Drawable ICON_FILL = UIRecipeTexture.ICON_OVERLAY_FILL;
protected static final Drawable ICON_OVERLAY = UIRecipeTexture.ICON_OVERLAY;
protected static final DrawableResource ICON_FILL = new DrawableBuilder(
"nei:textures/nei_sprites.png",
28,
76,
9,
10).build();
protected static final DrawableResource ICON_FILL_ERROR = new DrawableBuilder(
"nei:textures/nei_sprites.png",
37,
76,
9,
10).build();
protected static final DrawableResource ICON_OVERLAY = new DrawableBuilder(
"nei:textures/nei_sprites.png",
46,
76,
9,
10).build();
protected static final int BUTTON_ID_SHIFT = 4;
public final GuiContainer firstGui;
@@ -192,21 +217,22 @@ public class GuiOverlayButton extends GuiRecipeButton {
}
@Override
protected Drawable getIcon(boolean mouseOver) {
return isFillMode() ? ICON_FILL : ICON_OVERLAY;
}
protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) {
DrawableResource icon = ICON_OVERLAY;
@Override
protected ButtonSkin getSkin() {
if (isFillMode() && this.missedMaterialsTooltipLineHandler != null) {
return UIWidgetTexture.BUTTON_OVERLAY_ERROR;
if (this.canFillCraftingGrid && (!requireShiftForOverlayRecipe() || NEIClientUtils.shiftKey())) {
icon = this.missedMaterialsTooltipLineHandler == null ? ICON_FILL : ICON_FILL_ERROR;
}
return super.getSkin();
}
final int iconX = this.xPosition + (this.width - icon.width - 1) / 2;
final int iconY = this.yPosition + (this.height - icon.height) / 2;
private boolean isFillMode() {
return this.canFillCraftingGrid && (!requireShiftForOverlayRecipe() || NEIClientUtils.shiftKey());
GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
icon.draw(iconX, iconY);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1, 1, 1, 1);
}
@Override
File diff suppressed because it is too large. Load diff
@@ -9,7 +9,7 @@ import net.minecraftforge.client.event.GuiScreenEvent;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.GuiNEIButton;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.theme.ButtonSkin;
import codechicken.nei.theme.UIWidgetTexture;
import cpw.mods.fml.common.eventhandler.Cancelable;
@@ -62,33 +62,21 @@ public abstract class GuiRecipeButton extends GuiNEIButton {
this.handlerRef = point;
}
protected Drawable getIcon(boolean mouseOver) {
protected DrawableResource getIcon() {
return null;
}
protected ButtonSkin getSkin() {
return UIWidgetTexture.BUTTON;
}
@Override
protected Drawable getBackground(int mouseX, int mouseY, boolean mouseOver) {
return getSkin().background(this.enabled, false, mouseOver);
protected DrawableResource getBackground(int mouseX, int mouseY, boolean mouseOver) {
return UIWidgetTexture.BUTTON.background(this.enabled, false, mouseOver);
}
@Override
protected void drawContent(Minecraft minecraft, int mouseX, int mouseY, boolean mouseOver) {
final Drawable icon = getIcon(mouseOver);
final DrawableResource icon = getIcon();
if (icon != null) {
getSkin().drawIcon(
this.xPosition,
this.yPosition,
this.width,
this.height,
icon,
this.enabled,
false,
mouseOver);
ButtonSkin.drawIcon(this.xPosition, this.yPosition, this.width, this.height, icon, this.enabled);
} else {
super.drawContent(minecraft, mouseX, mouseY, mouseOver);
}
@@ -13,10 +13,11 @@ import codechicken.nei.NEIServerUtils;
import codechicken.nei.PositionedStack;
import codechicken.nei.Widget;
import codechicken.nei.api.ShortcutInputHandler;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.scroll.ScrollBar;
import codechicken.nei.scroll.ScrollContainer;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.theme.UIWidgetTexture;
public class GuiRecipeCatalyst extends ScrollContainer {
@@ -50,11 +51,26 @@ public class GuiRecipeCatalyst extends ScrollContainer {
private static final int SLOT_SIZE = 16;
private static final int BORDER_PADDING = 6;
private static final int COLUMNS_BOTTOM_INSET = 5;
private static final int TRANSPARENCY_BORDER = 4;
private static final DrawableResource BG_TEXTURE = new DrawableBuilder(
"nei:textures/catalyst_tab.png",
0,
0,
28 + TRANSPARENCY_BORDER * 2,
28 + TRANSPARENCY_BORDER * 2)
.setTextureSize(28 + TRANSPARENCY_BORDER * 2, 28 + TRANSPARENCY_BORDER * 2)
.setSlices(
BORDER_PADDING + TRANSPARENCY_BORDER,
BORDER_PADDING + TRANSPARENCY_BORDER,
BORDER_PADDING + TRANSPARENCY_BORDER,
BORDER_PADDING + TRANSPARENCY_BORDER)
.build();
private static final DrawableResource FG_TEXTURE = new DrawableBuilder("nei:textures/slot.png", 0, 0, 18, 18)
.setTextureSize(18, 18).setSlices(1, 1, 1, 1).build();
private static final ScrollBar VERTICAL_SCROLLBAR = UIWidgetTexture.verticalScrollBar()
.setOverflowType(ScrollBar.OverflowType.AUTO)
.setTrackPadding(0, BORDER_PADDING - 1, -13, BORDER_PADDING - 1)
.setOverflowType(ScrollBar.OverflowType.AUTO).setTrackPadding(0, BORDER_PADDING, -13, BORDER_PADDING)
.setScrollPlace(ScrollBar.ScrollPlace.START);
private List<PositionedStack> items = Collections.emptyList();
@@ -63,7 +79,7 @@ public class GuiRecipeCatalyst extends ScrollContainer {
private int style = -1;
public GuiRecipeCatalyst() {
setPaddingBlock(BORDER_PADDING, BORDER_PADDING);
setPaddingBlock(BORDER_PADDING + 1, BORDER_PADDING + 1);
}
public void setCatalysts(List<PositionedStack> items) {
@@ -82,15 +98,13 @@ public class GuiRecipeCatalyst extends ScrollContainer {
return this.availableHeight;
}
@Override
public boolean isVisible() {
return this.showWidget && NEIClientConfig.getJEIStyleRecipeCatalysts() != 0;
public boolean isShowWidget() {
return this.showWidget;
}
public int getColumnCount() {
if (NEIClientConfig.getJEIStyleRecipeCatalysts() == 1) {
final int maxItemsPerColumn = Math
.max(0, this.availableHeight - COLUMNS_BOTTOM_INSET - 2 - BORDER_PADDING * 2) / SLOT_SIZE;
final int maxItemsPerColumn = Math.max(0, this.availableHeight - 2 - BORDER_PADDING * 2) / SLOT_SIZE;
return maxItemsPerColumn > 0 ? NEIServerUtils.divideCeil(this.items.size(), maxItemsPerColumn) : 0;
}
return 1;
@@ -106,7 +120,7 @@ public class GuiRecipeCatalyst extends ScrollContainer {
final int rows = getRowCount();
setVerticalScroll(null);
setPaddingInline(BORDER_PADDING, BORDER_PADDING - 3);
setPaddingInline(BORDER_PADDING + 1, BORDER_PADDING - 3);
this.style = NEIClientConfig.getJEIStyleRecipeCatalysts();
this.h = rows * SLOT_SIZE + this.paddingBlockStart + this.paddingBlockEnd;
@@ -118,7 +132,7 @@ public class GuiRecipeCatalyst extends ScrollContainer {
this.w += VERTICAL_SCROLLBAR.getTrackWidth();
setVerticalScroll(VERTICAL_SCROLLBAR);
setPaddingInline(this.paddingInlineStart + VERTICAL_SCROLLBAR.getTrackWidth(), this.paddingInlineEnd);
setPaddingInline(BORDER_PADDING + 1 + VERTICAL_SCROLLBAR.getTrackWidth(), this.paddingInlineEnd);
}
this.showWidget = rows * columns > 0;
@@ -148,14 +162,12 @@ public class GuiRecipeCatalyst extends ScrollContainer {
if (!this.showWidget) return;
GL11.glColor4f(1, 1, 1, 1);
if (this.h < this.availableHeight) {
UIRecipeTexture.CATALYST_TAB_JOINED.draw(this.x, this.y, this.w, this.h);
} else {
UIRecipeTexture.CATALYST_TAB.draw(this.x, this.y, this.w, this.h);
}
UIRecipeTexture.CATALYST_SLOT.draw(
BG_TEXTURE.draw(
this.x - TRANSPARENCY_BORDER,
this.y - TRANSPARENCY_BORDER,
this.w + TRANSPARENCY_BORDER * 2,
this.h + TRANSPARENCY_BORDER * 2);
FG_TEXTURE.draw(
this.x + this.paddingInlineStart - 1,
this.y + this.paddingBlockStart - 1,
this.w - this.paddingInlineStart - this.paddingInlineEnd + 2,
@@ -10,6 +10,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.MinecraftForge;
@@ -25,11 +26,11 @@ import codechicken.nei.ColorUtils;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.Widget;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.event.NEIRegisterHandlerInfosEvent;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.debug.DebugHandlerWidget;
import codechicken.nei.theme.UIRecipeTexture;
import cpw.mods.fml.common.Loader;
public abstract class GuiRecipeTab extends Widget {
@@ -43,14 +44,29 @@ public abstract class GuiRecipeTab extends Widget {
protected final String handlerName;
protected final String handlerID;
public static final int TAB_WIDTH = 24;
public static final int TAB_HEIGHT = 24;
private static final DrawableResource selectedTabImage = new DrawableBuilder(
"nei:textures/nei_tabbed_sprites.png",
0,
16,
24,
24).build();
private static final DrawableResource unselectedTabImage = new DrawableBuilder(
"nei:textures/nei_tabbed_sprites.png",
24,
16,
24,
24).build();
private boolean selected;
public GuiRecipeTab(IRecipeHandler handler, int x, int y) {
super();
this.x = x;
this.y = y;
this.w = UIRecipeTexture.TAB_UNSELECTED.getWidth();
this.h = UIRecipeTexture.TAB_UNSELECTED.getHeight();
this.w = TAB_WIDTH;
this.h = TAB_HEIGHT;
this.handler = handler;
this.handlerName = handler.getHandlerId();
this.selected = false;
@@ -68,20 +84,21 @@ public abstract class GuiRecipeTab extends Widget {
drawForeground(mouseX, mouseY);
}
private void drawBackground(int mouseX, int mouseY) {
final Drawable image = this.selected ? UIRecipeTexture.TAB_SELECTED : UIRecipeTexture.TAB_UNSELECTED;
public void drawBackground(int mouseX, int mouseY) {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor4f(1, 1, 1, 1);
image.draw(this.x, this.y, this.w, this.h);
final DrawableResource image = this.selected ? selectedTabImage : unselectedTabImage;
image.draw(this.x, this.y);
}
private void drawForeground(int mouseX, int mouseY) {
public void drawForeground(int mouseX, int mouseY) {
final int iconX = this.x + 4;
final int iconY = this.y + 4;
final FontRenderer fontRenderer = GuiDraw.fontRenderer;
final HandlerInfo handlerInfo = getHandlerInfo(this.handlerName, this.handlerID);
final Drawable icon = handlerInfo != null ? handlerInfo.getImage() : null;
final DrawableResource icon = handlerInfo != null ? handlerInfo.getImage() : null;
final ItemStack itemStack = handlerInfo != null ? handlerInfo.getItemStack() : null;
final int iconX = this.x + (this.w - 16) / 2;
final int iconY = this.y + this.h - 16 - 6;
if (icon != null) {
icon.draw(iconX + 1, iconY + 1);
@@ -94,17 +111,24 @@ public abstract class GuiRecipeTab extends Widget {
if (!isEnabled) GL11.glDisable(GL12.GL_RESCALE_NORMAL);
} else {
// Text fallback
final int color = this.selected ? ColorUtils.buttonLabelHover.getColor()
: ColorUtils.buttonLabelNormal.getColor();
String text = this.handler.getRecipeName();
if (text == null || text.length() == 0) {
if (text != null && text.length() > 0) {
if (text.length() > 2) {
text = text.substring(0, 2);
}
} else {
text = "??";
} else if (text.length() > 2) {
text = text.substring(0, 2);
}
GuiDraw.drawStringC(text, iconX + 8, iconY + 4, color);
int textCenterX = this.x + (int) (this.w / 2f);
int textCenterY = this.y + (int) (this.h / 2f) - 3;
int color = this.selected ? ColorUtils.buttonLabelHover.getColor()
: ColorUtils.buttonLabelNormal.getColor();
fontRenderer.drawStringWithShadow(
text,
textCenterX - (int) (fontRenderer.getStringWidth(text) / 2f),
textCenterY,
color);
GL11.glColor4f(1, 1, 1, 1);
}
}
@@ -2,23 +2,19 @@ package codechicken.nei.recipe;
import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.BooleanSupplier;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.Button;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.theme.UIWidgetTexture;
import codechicken.nei.NEIClientUtils;
public class GuiRecipeTabs {
private final List<GuiRecipeTab> tabs = new ArrayList<>();
private final List<Button> buttons = new ArrayList<>();
private final Rectangle area = new Rectangle();
private List<? extends IRecipeHandler> currenthandlers = Collections.emptyList();
private List<? extends IRecipeHandler> currenthandlers;
private int pageCount = 1;
private int pageNumber = 0;
@@ -26,78 +22,56 @@ public class GuiRecipeTabs {
private int numHandlers = 1;
private int recipetype;
private static class TabArrowButton extends Button {
private final Drawable icon;
private final BooleanSupplier action;
private TabArrowButton(Drawable icon, BooleanSupplier action) {
this.icon = icon;
this.action = action;
this.w = 8;
this.h = 20;
}
private final Button prevTab = new Button("<") {
@Override
public boolean onButtonPress(boolean rightClick) {
return !rightClick && this.action.getAsBoolean();
if (!rightClick) {
NEIClientUtils.playClickSound();
return previousPage();
} else return false;
}
};
private final Button nextTab = new Button(">") {
@Override
public void draw(int mouseX, int mouseY) {
UIWidgetTexture.BUTTON
.draw(this.x, this.y, this.w, this.h, this.icon, true, false, contains(mouseX, mouseY));
public boolean onButtonPress(boolean rightclick) {
if (!rightclick) {
NEIClientUtils.playClickSound();
return nextPage();
} else return false;
}
}
private final Button prevTab = new TabArrowButton(UIRecipeTexture.ICON_PREV, this::previousPage);
private final Button nextTab = new TabArrowButton(UIRecipeTexture.ICON_NEXT, this::nextPage);
};
public static int getTabWidth() {
return UIRecipeTexture.TAB_UNSELECTED.getWidth() - 1;
return GuiRecipeTab.TAB_WIDTH;
}
public static int getTabHeight() {
return UIRecipeTexture.TAB_UNSELECTED.getHeight();
return GuiRecipeTab.TAB_HEIGHT;
}
public void place(int navLeft, int navWidth, int guiTop) {
public void update(GuiRecipe<?> guiRecipe) {
final int tabWidth = getTabWidth();
final int tabHeight = getTabHeight();
final int perPage = (navWidth - 4) / tabWidth;
this.area.width = perPage * tabWidth;
this.area.height = tabHeight;
this.area.x = navLeft + (navWidth - this.area.width) / 2;
this.area.y = guiTop - tabHeight + 4;
this.prevTab.y = this.nextTab.y = guiTop - this.prevTab.h + 1;
this.prevTab.x = this.area.x - this.prevTab.w + 1;
this.nextTab.x = this.area.x + this.area.width - 1;
if (this.categoriesPerPage != perPage) {
this.categoriesPerPage = perPage;
rebuild();
} else {
refreshPage();
}
}
public void update(List<? extends IRecipeHandler> handlers, int recipetype) {
this.currenthandlers = handlers;
this.recipetype = recipetype;
rebuild();
}
private void rebuild() {
this.recipetype = guiRecipe.recipetype;
this.currenthandlers = guiRecipe.currenthandlers;
this.numHandlers = this.currenthandlers.size();
this.categoriesPerPage = (guiRecipe.xSize - 4) / tabWidth;
this.pageNumber = this.recipetype / Math.max(this.categoriesPerPage, 1);
this.pageCount = (int) Math.ceil((float) this.numHandlers / this.categoriesPerPage);
this.area.width = this.categoriesPerPage * tabWidth;
this.area.height = tabHeight;
this.area.x = guiRecipe.guiLeft + 4;
this.area.y = guiRecipe.guiTop - tabHeight + 3;
refreshPage();
refreshArrows();
updateArrows(tabHeight);
}
public void refreshPage() {
@@ -123,10 +97,17 @@ public class GuiRecipeTabs {
}
}
private void refreshArrows() {
private void updateArrows(int tabHeight) {
this.buttons.clear();
if (this.numHandlers > this.categoriesPerPage) {
this.prevTab.w = this.nextTab.w = 8;
this.prevTab.h = this.nextTab.h = tabHeight - 4;
this.prevTab.y = this.nextTab.y = this.area.y + 2;
this.prevTab.x = this.area.x - this.prevTab.w + 1;
this.nextTab.x = this.area.x + this.area.width - 1;
this.buttons.add(this.prevTab);
this.buttons.add(this.nextTab);
}
@@ -163,17 +144,14 @@ public class GuiRecipeTabs {
public void handleTooltip(int mousex, int mousey, List<String> tooltips) {
if (!NEIClientConfig.areJEIStyleTabsVisible()) return;
for (Button button : this.buttons) {
if (button.contains(mousex, mousey)) {
button.addTooltips(tooltips);
return;
}
}
for (GuiRecipeTab tab : this.tabs) {
if (tab.contains(mousex, mousey)) {
tab.addTooltips(tooltips);
return;
}
}
for (Button button : this.buttons) {
if (button.contains(mousex, mousey)) {
button.addTooltips(tooltips);
}
}
}
@@ -183,7 +161,7 @@ public class GuiRecipeTabs {
for (Button button : this.buttons) {
if (button.contains(x, y)) {
return button.handleClick(x, y, mouseButton);
return button.onButtonPress(mouseButton == 1);
}
}
@@ -36,9 +36,6 @@ public class HandlerInfo {
private boolean allowOverflowX = true;
private boolean allowOverflowY = false;
private int windowWidth = 0;
private boolean recipeSpacing = false;
private ItemStack itemStack = null;
private DrawableResource image = null;
@@ -192,22 +189,6 @@ public class HandlerInfo {
this.allowOverflowY = allowOverflowY;
}
public int getWindowWidth() {
return this.windowWidth;
}
public void setWindowWidth(int windowWidth) {
this.windowWidth = windowWidth;
}
public boolean isRecipeSpacing() {
return this.recipeSpacing;
}
public void setRecipeSpacing(boolean recipeSpacing) {
this.recipeSpacing = recipeSpacing;
}
public static class Builder {
private final HandlerInfo info;
@@ -315,16 +296,6 @@ public class HandlerInfo {
return this;
}
public Builder setWindowWidth(int windowWidth) {
this.info.windowWidth = windowWidth;
return this;
}
public Builder setRecipeSpacing(boolean recipeSpacing) {
this.info.recipeSpacing = recipeSpacing;
return this;
}
public HandlerInfo build() {
return this.info;
}
@@ -45,10 +45,6 @@ public interface IRecipeHandler {
return getRecipeName();
}
default int getRecipeWidth(int recipe) {
return 0;
}
default int getRecipeHeight(int recipe) {
return 0;
}
@@ -1,170 +0,0 @@
package codechicken.nei.recipe;
import java.util.List;
import java.util.function.BooleanSupplier;
import net.minecraft.client.gui.FontRenderer;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.Button;
import codechicken.nei.ColorUtils;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.Widget;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.theme.UIWidgetTexture;
class NavigationBar extends Widget {
protected class NavButton extends Button {
private final Drawable icon;
private final Runnable action;
private final BooleanSupplier isEnabled;
protected NavButton(Drawable icon, BooleanSupplier isEnabled, Runnable action) {
this.icon = icon;
this.action = action;
this.isEnabled = isEnabled;
this.w = BUTTON_SIZE;
this.h = BUTTON_SIZE;
}
@Override
public void draw(int mx, int my) {
final boolean enabled = this.isEnabled.getAsBoolean();
final boolean active = (this.state & 0x3) == 2;
UIWidgetTexture.BUTTON.draw(this.x, this.y, this.w, this.h, this.icon, enabled, active, contains(mx, my));
}
@Override
public boolean onButtonPress(boolean rightclick) {
if (rightclick) return false;
this.action.run();
return true;
}
}
protected static final int BUTTON_SIZE = 12;
protected static final int GAP = 2;
private final NavButton prev;
private final NavButton next;
protected boolean enabled = true;
protected String label = "";
protected int color = 0xffffff;
protected int hoverColor = 0xffffff;
protected int insetLeft;
protected Runnable labelAction;
public String labelTooltip;
private String croppedLabel;
private int croppedLabelWidth;
private String croppedLabelSource;
private int croppedLabelMaxWidth;
public NavigationBar(Runnable labelAction, Runnable onPrev, Runnable onNext) {
this.prev = new NavButton(UIRecipeTexture.ICON_PREV, () -> NavigationBar.this.enabled, onPrev);
this.next = new NavButton(UIRecipeTexture.ICON_NEXT, () -> NavigationBar.this.enabled, onNext);
this.labelAction = labelAction;
this.h = BUTTON_SIZE;
}
protected int plateX() {
return this.x + BUTTON_SIZE + GAP;
}
protected int plateWidth() {
return this.w - (BUTTON_SIZE + GAP) * 2;
}
public void place(int x, int y, int w) {
this.x = x;
this.y = y;
this.w = w;
this.prev.x = x;
this.prev.y = y;
this.next.x = x + w - BUTTON_SIZE;
this.next.y = y;
}
@Override
public void draw(int mx, int my) {
GuiDraw.drawRect(
plateX() + this.insetLeft,
this.y,
plateWidth() - this.insetLeft,
this.h,
ColorUtils.recipeTitleBG.getColor());
this.prev.draw(mx, my);
this.next.draw(mx, my);
if (!this.label.isEmpty()) {
final FontRenderer font = NEIClientUtils.mc().fontRenderer;
updateCroppedLabel(font);
font.drawStringWithShadow(
this.croppedLabel,
labelX(),
labelY(font),
isLabelHovered(mx, my) ? this.hoverColor : this.color);
}
}
private void updateCroppedLabel(FontRenderer font) {
final int maxWidth = plateWidth() - this.insetLeft;
if (!this.label.equals(this.croppedLabelSource) || maxWidth != this.croppedLabelMaxWidth) {
this.croppedLabel = NEIClientUtils.cropText(font, this.label, maxWidth - 2);
this.croppedLabelSource = this.label;
this.croppedLabelMaxWidth = maxWidth;
this.croppedLabelWidth = font.getStringWidth(this.croppedLabel);
}
}
private int labelX() {
return plateX() + this.insetLeft + (plateWidth() - this.insetLeft) / 2 - this.croppedLabelWidth / 2;
}
private int labelY(FontRenderer font) {
return this.y + (this.h - font.FONT_HEIGHT) / 2 + 1;
}
private boolean isLabelHovered(int mx, int my) {
if (this.labelAction == null || this.label.isEmpty()) return false;
final FontRenderer font = NEIClientUtils.mc().fontRenderer;
updateCroppedLabel(font);
final int textX = labelX();
final int textY = labelY(font);
return mx >= textX && mx < textX + this.croppedLabelWidth && my >= textY && my < textY + font.FONT_HEIGHT;
}
@Override
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
if (tooltip.isEmpty() && this.labelTooltip != null && isLabelHovered(mx, my)) {
tooltip.add(this.labelTooltip);
}
return tooltip;
}
@Override
public boolean handleClick(int mx, int my, int button) {
if (button == 0 && isLabelHovered(mx, my)) {
this.labelAction.run();
return true;
}
if (!this.enabled) return false;
if (this.prev.contains(mx, my)) return this.prev.handleClick(mx, my, button);
if (this.next.contains(mx, my)) return this.next.handleClick(mx, my, button);
return false;
}
}
@@ -487,11 +487,11 @@ public class Recipe {
stack = getMainResult(getResults(), RecipeIngredient::getItemStack).getItemStack();
}
long stackSize = 0;
int stackSize = 0;
for (RecipeIngredient result : this.results) {
if (result.contains(stack)) {
stackSize += StackInfo.getAmountLong(result.getItemStack());
stackSize += result.getAmount();
}
}
@@ -271,7 +271,7 @@ public class RecipeItemsTooltipLineHandler extends CompositeTooltipLineHandler {
}
if (screen instanceof GuiContainer container) {
return ItemStackAmount.of(container);
return AutoCraftingManager.getInventoryItems(container);
}
return new ItemStackAmount();
@@ -125,7 +125,7 @@ public class RecipeJsonWriter {
}
private static List<Integer> filteredRecipes(IRecipeHandler handler) {
return new SearchRecipeHandler<>(handler, GuiRecipe.getRecipeListFilter()).getFilteredRecipes();
return new SearchRecipeHandler<>(handler).getFilteredRecipes();
}
private void writeFile(File file, List<? extends IRecipeHandler> handlers,
@@ -11,100 +11,60 @@ import net.minecraft.item.ItemStack;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.Widget;
import codechicken.nei.recipe.widget.RecipeWidget;
import codechicken.nei.recipe.widget.ViewStates;
import codechicken.nei.scroll.ScrollContainer;
public class RecipePageManager {
private static final int RECIPE_GAP = 4;
private static final class Page {
private final List<Widget> widgets;
private final int width;
private final boolean overflowY;
private int top;
private int gap;
private Page(List<Widget> widgets, int width, boolean overflowY, int gap) {
this.widgets = widgets;
this.width = width;
this.overflowY = overflowY;
this.gap = gap;
}
}
private SearchRecipeHandler<?> handler;
private ScrollContainer container;
private HandlerInfo handlerInfo;
private int numRecipes = -1;
private int searchVersion = -1;
private int visibleHeight = -1;
private String cacheKey = "";
private int currentPageIndex = -1;
private final List<RecipeWidget> recipeWidgets = new ArrayList<>();
private final List<Page> pages = new ArrayList<>();
private final ViewStates viewStates;
private int maxRecipeWidth;
private boolean overflowY;
private final int recipeGap;
private List<List<Widget>> pageWidgets = new ArrayList<>();
public RecipePageManager(SearchRecipeHandler<?> handler, HandlerInfo handlerInfo, ScrollContainer container,
ViewStates viewStates) {
public RecipePageManager(SearchRecipeHandler<?> handler, HandlerInfo handlerInfo, ScrollContainer container) {
this.handler = handler;
this.handlerInfo = handlerInfo;
this.container = container;
this.viewStates = viewStates;
this.recipeGap = handlerInfo.isRecipeSpacing() ? RECIPE_GAP : 0;
rebuildWidgets();
rebuildPages();
}
public boolean rebuildPages() {
final boolean widgetsChanged = this.numRecipes != getNumRecipes()
|| this.searchVersion != this.handler.getSearchVersion();
final int visibleHeight = this.container.getVisibleHeight();
final String cacheKey = handlerInfo.getHandlerName() + ":"
+ getNumRecipes()
+ ":"
+ this.container.getVisibleHeight()
+ ":"
+ GuiRecipe.searchField.text();
if (!widgetsChanged && visibleHeight == this.visibleHeight) {
if (cacheKey.equals(this.cacheKey)) {
return false;
}
this.visibleHeight = visibleHeight;
this.cacheKey = cacheKey;
if (widgetsChanged) {
rebuildWidgets();
}
final List<RecipeWidget> pausedWidgets = getPausedWidgets();
this.pageWidgets.clear();
this.pages.clear();
this.overflowY = false;
final boolean allowOverflowY = this.handlerInfo.isAllowOverflowY();
final int handlerHeight = this.handlerInfo.getHeight() + this.handlerInfo.getYShift();
final boolean multipleWidgetsAllowed = !allowOverflowY && handlerInfo.isMultipleWidgetsAllowed();
final boolean infiniteScroll = !allowOverflowY
&& NEIClientConfig.getBooleanSetting("inventory.guirecipe.infiniteScroll");
buildPages();
buildSpreadGaps();
changePage(0);
return true;
}
private void rebuildWidgets() {
this.numRecipes = getNumRecipes();
this.searchVersion = this.handler.getSearchVersion();
this.recipeWidgets.clear();
for (List<Integer> group : groupRecipes()) {
this.recipeWidgets.add(
new RecipeWidget(this.handler.original, group, this.viewStates.get(this.handler.original, group)));
}
this.maxRecipeWidth = this.recipeWidgets.stream().mapToInt(widget -> widget.w).max()
.orElse(this.handlerInfo.getWidth());
}
private List<List<Integer>> groupRecipes() {
final int heightAvailable = this.container.getVisibleHeight();
final int width = Math.max(166, this.handlerInfo.getWidth());
final List<Integer> searchRecipes = this.handler.getFilteredRecipes();
final int numRecipes = searchRecipes.size();
final List<List<Integer>> groupedRecipes = new ArrayList<>();
final Map<Object, Integer> groupEndIndices = new HashMap<>();
List<Widget> widgets = new ArrayList<>();
int shiftY = 0;
for (int recipeIndex : searchRecipes) {
for (int i = 0; i < numRecipes; i++) {
final int recipeIndex = searchRecipes.get(i);
final Object groupId = this.handler.original.getRecipeGroupId(recipeIndex);
final int groupIndex = groupId != null
? groupEndIndices.computeIfAbsent(groupId, k -> groupedRecipes.size())
@@ -117,121 +77,42 @@ public class RecipePageManager {
groupedRecipes.get(groupIndex).add(recipeIndex);
}
return groupedRecipes;
}
for (int groupIndex = 0; groupIndex < groupedRecipes.size(); groupIndex++) {
final RecipeWidget widget = new RecipeWidget(this.handler.original, groupedRecipes.get(groupIndex));
private void buildPages() {
final boolean multipleWidgetsAllowed = isMultipleWidgetsAllowed();
final boolean infiniteScroll = isInfiniteScroll();
final int heightAvailable = this.container.getVisibleHeight();
List<Widget> widgets = new ArrayList<>();
int shiftY = 0;
// keep the pause of the rebuilt widgets
for (RecipeWidget paused : pausedWidgets) {
final int pausedIndex = paused.getRecipeHandlerRef().recipeIndex;
for (RecipeWidget widget : this.recipeWidgets) {
if (this.handlerInfo.isAllowOverflowY()) {
widget.setHeight(Math.min(widget.getContentHeight(), heightAvailable));
if (widget.containsRecipeIndex(pausedIndex)) {
widget.pinRecipe(pausedIndex, paused.getPinnedIngredients());
}
}
if (!widgets.isEmpty() && (!multipleWidgetsAllowed
|| !infiniteScroll && shiftY + this.recipeGap + widget.h > heightAvailable)) {
addPage(widgets);
widget.w = width;
if (allowOverflowY) {
widget.h = Math.min(handlerHeight, heightAvailable);
}
if (!widgets.isEmpty()
&& (!multipleWidgetsAllowed || !infiniteScroll && shiftY + widget.h > heightAvailable)) {
this.pageWidgets.add(widgets);
widgets = new ArrayList<>();
shiftY = 0;
}
if (!widgets.isEmpty()) {
shiftY += this.recipeGap;
}
widgets.add(widget);
shiftY += widget.h;
}
if (!widgets.isEmpty()) {
addPage(widgets);
}
}
private void addPage(List<Widget> widgets) {
final int pageWidth = widgets.stream().mapToInt(widget -> widget.w).max().orElse(0);
final int pageHeight = widgets.stream().mapToInt(widget -> widget.h).sum()
+ this.recipeGap * (widgets.size() - 1);
final boolean pageOverflowsY = pageHeight > this.container.getVisibleHeight();
this.overflowY |= pageOverflowsY;
this.pages.add(new Page(widgets, pageWidth, pageOverflowsY, this.recipeGap));
}
public boolean needsVerticalScroll() {
return this.overflowY;
}
private Page getCurrentPage() {
return this.currentPageIndex >= 0 && this.currentPageIndex < this.pages.size()
? this.pages.get(this.currentPageIndex)
: null;
}
public boolean currentPageNeedsVerticalScroll() {
final Page page = getCurrentPage();
return page != null && page.overflowY;
}
private void buildSpreadGaps() {
if (!isMultipleWidgetsAllowed() || isInfiniteScroll()
|| !NEIClientConfig.getBooleanSetting("inventory.guirecipe.evenRecipeSpacing")) {
return;
this.pageWidgets.add(widgets);
}
final int heightAvailable = this.container.getVisibleHeight();
int maxHeight = 0;
changePage(0);
for (Page page : this.pages) {
for (Widget widget : page.widgets) {
maxHeight = Math.max(maxHeight, widget.h);
}
}
final int slots = maxHeight > 0 ? (heightAvailable + this.recipeGap) / (maxHeight + this.recipeGap) : 0;
// a page that fits a single recipe has nothing to spread
if (slots <= 1) {
return;
}
for (int index = 0; index < this.pages.size(); index++) {
final Page page = this.pages.get(index);
int totalHeight = 0;
for (Widget widget : page.widgets) {
totalHeight += widget.h;
}
int spreadGap = (heightAvailable - totalHeight) / (page.widgets.size() + 1);
if (index == this.pages.size() - 1) {
final int fullPageGap;
if (index > 0) {
fullPageGap = this.pages.get(index - 1).top;
} else {
fullPageGap = (heightAvailable - slots * maxHeight) / (slots + 1);
}
spreadGap = Math.min(spreadGap, fullPageGap);
}
if (spreadGap >= this.recipeGap) {
page.top = spreadGap;
page.gap = spreadGap;
}
}
}
private boolean isInfiniteScroll() {
return !this.handlerInfo.isAllowOverflowY()
&& NEIClientConfig.getBooleanSetting("inventory.guirecipe.infiniteScroll");
return true;
}
public boolean isMultipleWidgetsAllowed() {
@@ -247,16 +128,7 @@ public class RecipePageManager {
}
public int getNumPages() {
return this.pages.size();
}
public int getMaxRecipeWidth() {
return this.maxRecipeWidth;
}
public int getCurrentPageWidth() {
final Page page = getCurrentPage();
return page != null ? page.width : 0;
return this.pageWidgets.size();
}
public void changePage(int delta) {
@@ -273,8 +145,8 @@ public class RecipePageManager {
public boolean gotoRecipeIndex(int recipeIndex) {
for (int page = 0; page < this.pages.size(); page++) {
for (Widget widget : this.pages.get(page).widgets) {
for (int page = 0; page < this.pageWidgets.size(); page++) {
for (Widget widget : this.pageWidgets.get(page)) {
if (widget instanceof RecipeWidget recipeWidget && recipeWidget.containsRecipeIndex(recipeIndex)) {
changePage(page - this.currentPageIndex);
return true;
@@ -285,10 +157,24 @@ public class RecipePageManager {
return false;
}
private List<RecipeWidget> getPausedWidgets() {
final List<RecipeWidget> paused = new ArrayList<>();
for (List<Widget> widgets : this.pageWidgets) {
for (Widget widget : widgets) {
if (widget instanceof RecipeWidget recipeWidget && recipeWidget.isPaused()) {
paused.add(recipeWidget);
}
}
}
return paused;
}
public boolean pinRecipe(int recipeIndex, List<ItemStack> ingredients) {
for (Page page : this.pages) {
for (Widget widget : page.widgets) {
for (List<Widget> widgets : this.pageWidgets) {
for (Widget widget : widgets) {
if (widget instanceof RecipeWidget recipeWidget && recipeWidget.containsRecipeIndex(recipeIndex)) {
return recipeWidget.pinRecipe(recipeIndex, ingredients);
}
@@ -299,35 +185,32 @@ public class RecipePageManager {
}
public List<Widget> getCurrentPageWidgets() {
if (this.pages.isEmpty()) {
if (this.pageWidgets.isEmpty()) {
return Collections.emptyList();
}
final Page page = this.pages.get(this.currentPageIndex);
final int placeWidth = Math.max(this.container.w, page.width);
int shiftY = page.top;
List<Widget> currentWidgets = this.pageWidgets.get(this.currentPageIndex);
int shiftY = 0;
for (Widget widget : page.widgets) {
for (Widget widget : currentWidgets) {
if (widget instanceof RecipeWidget recipeWidget) {
final int offsetX = (placeWidth - widget.w) / 2;
recipeWidget.setLocation(offsetX, shiftY, placeWidth - widget.w - offsetX);
recipeWidget.setLocation(2, shiftY);
}
shiftY += widget.h + page.gap;
shiftY += widget.h;
}
return page.widgets;
return currentWidgets;
}
public List<Integer> getRecipeIndices() {
if (this.pages.isEmpty()) {
if (this.pageWidgets.isEmpty()) {
return Collections.emptyList();
}
final List<Integer> recipeIndices = new ArrayList<>();
for (Widget widget : this.pages.get(this.currentPageIndex).widgets) {
for (Widget widget : this.pageWidgets.get(this.currentPageIndex)) {
if (widget instanceof RecipeWidget recipeWidget) {
recipeIndices.add(recipeWidget.getRecipeHandlerRef().recipeIndex);
}
@@ -1,327 +0,0 @@
package codechicken.nei.recipe;
import java.util.List;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.item.ItemStack;
import codechicken.lib.gui.GuiDraw;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.RecipeSearchField;
import codechicken.nei.RestartableTask;
import codechicken.nei.SearchField;
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
import codechicken.nei.SearchTokenParser.SearchMode;
import codechicken.nei.api.IRecipeFilter;
import codechicken.nei.api.ItemFilter;
import codechicken.nei.search.SearchExpressionUtils;
import codechicken.nei.theme.UIRecipeTexture;
class RecipeSearchBar extends NavigationBar {
private static final int FIELD_MARGIN = 40;
private final RestartableTask updateFilter = new RestartableTask("NEI Recipe Filtering") {
@Override
public void execute() {
if (!(NEIClientUtils.mc().currentScreen instanceof GuiRecipe<?>guiRecipe)) return;
final SearchRecipeHandler<?> searchHandler = guiRecipe.getSearchHandler();
if (searchHandler == null) return;
final IRecipeFilter filter = getRecipeFilter();
final List<Integer> found = filter != null ? searchHandler.getSearchResult(filter) : null;
if (interrupted() || filter != null && found == null) return;
searchHandler.setSearchIndices(found);
}
};
private final RecipeSearchField field = new RecipeSearchField("") {
@Override
protected boolean noResults() {
final GuiScreen currentScreen = NEIClientUtils.mc().currentScreen;
return !(currentScreen instanceof GuiRecipe<?>guiRecipe) || guiRecipe.getNumRecipes() > 0;
}
@Override
public void onTextChange(String oldText) {
if (!text().equals(oldText)) {
RecipeSearchBar.this.updateFilter.restart();
}
}
};
private final NavButton toggle = new NavButton(UIRecipeTexture.ICON_SEARCH, () -> true, this::toggleField) {
@Override
public void addTooltips(List<String> tooltip) {
tooltip.add(NEIClientUtils.translate("recipe.search.tooltip.name") + GuiDraw.TOOLTIP_LINESPACE);
if (NEIClientUtils.shiftKey()) {
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.input",
SearchExpressionUtils.HIGHLIGHTS.RECIPE + "<"));
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.output",
SearchExpressionUtils.HIGHLIGHTS.RECIPE + ">"));
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.text",
SearchExpressionUtils.HIGHLIGHTS.RECIPE + "~"));
final int patternMode = NEIClientConfig.getIntSetting("inventory.search.patternMode");
if (patternMode != 2) {
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.auxiliary",
SearchExpressionUtils.HIGHLIGHTS.RECIPE + "^"));
}
if (patternMode == 3) {
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.all",
SearchExpressionUtils.HIGHLIGHTS.RECIPE + "<&"));
}
for (ISearchParserProvider provider : SearchField.searchParser.getProviders()) {
if (provider.getSearchMode() == SearchMode.PREFIX) {
addPrefixTooltip(tooltip, provider);
}
}
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.exclude",
SearchExpressionUtils.HIGHLIGHTS.NEGATE + "-"));
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.exclude_recipe",
SearchExpressionUtils.HIGHLIGHTS.NEGATE + "!"));
tooltip.add(
NEIClientUtils
.translate("recipe.search.tooltip.or", SearchExpressionUtils.HIGHLIGHTS.OR.f + "|"));
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.exact",
SearchExpressionUtils.HIGHLIGHTS.QUOTED + "\"",
SearchExpressionUtils.HIGHLIGHTS.QUOTED + "\""));
if (patternMode == 1 || patternMode == 3) {
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.regex",
SearchExpressionUtils.HIGHLIGHTS.REGEX + "r/",
SearchExpressionUtils.HIGHLIGHTS.REGEX + "/"));
}
} else {
tooltip.add(NEIClientUtils.translate("recipe.search.tooltip.shift"));
}
}
private void addPrefixTooltip(List<String> tooltip, ISearchParserProvider provider) {
final char prefix = SearchField.searchParser.getRedefinedPrefix(provider.getPrefix());
final String modeName = NEIClientUtils.translate("recipe.search.tooltip.prefix." + provider.getName());
tooltip.add(
NEIClientUtils.translate(
"recipe.search.tooltip.prefix",
provider.getHighlightedColor() + String.valueOf(prefix),
modeName));
}
};
private boolean available = false;
private String pageInfo = "";
private String pageCounter = "";
private boolean pageInfoCropped;
private String pageLabel = "";
public RecipeSearchBar(Runnable onPrev, Runnable onNext) {
super(null, onPrev, onNext);
}
public void setPages(int current, int total) {
this.pageInfo = current + "/" + total;
this.pageLabel = NEIClientUtils.translate("recipe.page", current, total);
updateCounter();
updateLabel();
}
private void updateCounter() {
this.pageCounter = NEIClientUtils.cropText(GuiDraw.fontRenderer, this.pageInfo, FIELD_MARGIN - GAP);
this.pageInfoCropped = !this.pageCounter.equals(this.pageInfo);
}
private void updateLabel() {
this.label = this.field.isVisible() ? "" : this.pageLabel;
}
private void toggleField() {
if (this.field.isVisible()) {
this.field.setText("");
this.field.setFocus(false);
this.field.setVisible(false);
this.toggle.state = 0;
} else {
this.field.setVisible(true);
this.field.setFocus(true);
this.toggle.state = 2;
}
updateLabel();
}
public void setAvailable(boolean available) {
this.available = available;
this.insetLeft = available ? this.toggle.w + GAP : 0;
}
public void place(int x, int y, int w) {
super.place(x, y, w);
this.toggle.x = plateX();
this.toggle.y = y;
this.field.x = this.toggle.x + this.toggle.w + 1;
this.field.y = y - 1;
this.field.w = plateWidth() - this.toggle.w - FIELD_MARGIN;
this.field.h = 14;
updateCounter();
}
public ItemFilter getFilter() {
return this.field.getFilter();
}
public IRecipeFilter getRecipeFilter() {
return this.field.text().isEmpty() ? null : this.field.getRecipeFilter();
}
public RecipeSearchField getSearchField() {
return this.field;
}
public void updateFilter() {
this.updateFilter.restart();
}
public void reset() {
this.field.setText("");
this.field.setVisible(false);
this.toggle.state = 0;
updateLabel();
updateFilter();
}
public boolean overSearch(int px, int py) {
return this.available && this.toggle.contains(px, py) || this.field.isVisible() && this.field.contains(px, py);
}
@Override
public boolean contains(int px, int py) {
return super.contains(px, py) || overSearch(px, py);
}
@Override
public void draw(int mx, int my) {
super.draw(mx, my);
if (this.available) {
this.toggle.draw(mx, my);
}
if (this.field.isVisible()) {
this.field.draw(mx, my);
final FontRenderer font = GuiDraw.fontRenderer;
final int textY = this.y + (this.h - font.FONT_HEIGHT) / 2 + 1;
GuiDraw.drawStringC(this.pageCounter, this.field.x + this.field.w + FIELD_MARGIN / 2, textY, 0xffffff);
}
}
@Override
public boolean handleClick(int mx, int my, int button) {
if (this.available) {
if (this.toggle.contains(mx, my)) {
return this.toggle.handleClick(mx, my, button);
} else if (this.field.isVisible() && this.field.contains(mx, my)) {
return this.field.handleClick(mx, my, button);
}
this.field.onGuiClick(mx, my);
}
return super.handleClick(mx, my, button);
}
@Override
public boolean handleKeyPress(int keyID, char keyChar) {
return isFocused() && this.field.handleKeyPress(keyID, keyChar);
}
@Override
public boolean isFocused() {
return this.field.isVisible() && this.field.focused();
}
@Override
public void loseFocus() {
this.field.setFocus(false);
}
@Override
public void lastKeyTyped(int keyID, char keyChar) {
if (isFocused()) {
this.field.lastKeyTyped(keyID, keyChar);
}
}
@Override
public boolean onHotkeyPressed() {
return this.field.isVisible() && this.field.onHotkeyPressed();
}
@Override
public List<String> handleTooltip(int mx, int my, List<String> tooltip) {
if (this.available) {
tooltip = this.toggle.handleTooltip(mx, my, tooltip);
}
if (tooltip.isEmpty() && this.field.isVisible()
&& mx >= this.field.x + this.field.w
&& mx < plateX() + plateWidth()
&& my >= this.y
&& my < this.y + this.h
&& this.pageInfoCropped) {
tooltip.add(this.pageInfo);
}
return tooltip;
}
public boolean handleDragNDrop(int mx, int my, ItemStack draggedStack) {
if (this.field.isVisible() && this.field.contains(mx, my)) {
this.field.setText(SearchField.getEscapedSearchText(draggedStack));
return true;
}
return false;
}
}
@@ -8,17 +8,30 @@ import org.lwjgl.opengl.GL11;
import codechicken.lib.gui.GuiDraw;
import codechicken.lib.gui.GuiDraw.ITooltipLineHandler;
import codechicken.nei.ColorUtils;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.Recipe.RecipeId;
import codechicken.nei.recipe.widget.RecipeWidget;
import codechicken.nei.scroll.GuiHelper;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.util.ReadableNumberConverter;
public class RecipeTooltipLineHandler implements ITooltipLineHandler {
private static final int BG_PADDING = 5;
private static final int TRANSPARENCY_BORDER = 4;
private final DrawableResource BG_TEXTURE = new DrawableBuilder(
"nei:textures/gui/recipebg.png",
0,
0,
176 + TRANSPARENCY_BORDER * 2,
166 + TRANSPARENCY_BORDER * 2)
.setSlices(
BG_PADDING + TRANSPARENCY_BORDER,
BG_PADDING + TRANSPARENCY_BORDER,
BG_PADDING + TRANSPARENCY_BORDER,
BG_PADDING + TRANSPARENCY_BORDER)
.build();
protected long lastUpdate = System.currentTimeMillis();
protected String recipeName = "";
@@ -67,16 +80,12 @@ public class RecipeTooltipLineHandler implements ITooltipLineHandler {
}
if (this.widget != null) {
return new Dimension(getContentWidth() + BG_PADDING * 2, this.widget.h + BG_PADDING * 2 + 12);
return new Dimension(this.widget.w + BG_PADDING * 2, this.widget.h + BG_PADDING * 2 + 12);
}
return new Dimension(0, 0);
}
private int getContentWidth() {
return Math.max(this.widget.w, GuiDraw.getStringWidth(this.recipeName));
}
@Override
public void draw(int x, int y) {
if (this.widget == null) return;
@@ -97,24 +106,25 @@ public class RecipeTooltipLineHandler implements ITooltipLineHandler {
GuiContainerManager.enable2DRender();
GL11.glColor4f(1, 1, 1, 1);
UIRecipeTexture.WIDGET.draw(0, 0, size.width, size.height);
BG_TEXTURE.draw(
-TRANSPARENCY_BORDER,
-TRANSPARENCY_BORDER,
size.width + TRANSPARENCY_BORDER * 2,
size.height + TRANSPARENCY_BORDER * 2);
GL11.glEnable(GL11.GL_ALPHA_TEST);
final int titleColor = ColorUtils.recipeTitle.getColor();
GuiDraw.drawRect(BG_PADDING, BG_PADDING, size.width - BG_PADDING * 2, 12, ColorUtils.recipeTitleBG.getColor());
GuiDraw.drawStringC(this.recipeName, size.width / 2, BG_PADDING + 2, titleColor);
GuiDraw.drawRect(BG_PADDING, BG_PADDING, size.width - BG_PADDING * 2, 12, 0x30000000);
GuiDraw.drawStringC(this.recipeName, this.widget.w / 2, BG_PADDING + 2, 0xffffff);
if (this.multiplier > 0) {
GuiDraw.drawString(
"x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(this.multiplier),
BG_PADDING + 2,
BG_PADDING + 2,
titleColor);
0xffffff);
}
this.widget.x = BG_PADDING + (getContentWidth() - this.widget.w) / 2;
GuiHelper.useScissor(
this.widget.x,
this.widget.y,
@@ -3,7 +3,6 @@ package codechicken.nei.recipe;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.function.IntPredicate;
import java.util.stream.Collectors;
@@ -19,19 +18,18 @@ class SearchRecipeHandler<H extends IRecipeHandler> {
private List<Integer> filteredRecipes;
private volatile List<Integer> searchRecipes;
private List<Integer> searchRecipes;
private volatile int searchVersion;
public SearchRecipeHandler(H handler, IRecipeFilter filter) {
public SearchRecipeHandler(H handler) {
this.original = handler;
if (this.original.numRecipes() == 0) {
this.filteredRecipes = Collections.emptyList();
} else {
final Stream<Integer> items = IntStream.range(0, this.original.numRecipes()).boxed();
final IRecipeFilter filter = this.searchingAvailable() ? GuiRecipe.getRecipeListFilter() : null;
if (filter == null || !this.searchingAvailable()) {
if (filter == null) {
this.filteredRecipes = items.collect(Collectors.toList());
} else {
this.filteredRecipes = items.filter(recipe -> mathRecipe(this.original, recipe, filter))
@@ -66,43 +64,39 @@ class SearchRecipeHandler<H extends IRecipeHandler> {
public List<Integer> getSearchResult(IRecipeFilter filter) {
if (this.filteredRecipes.isEmpty() || !this.searchingAvailable()) {
if (filteredRecipes.isEmpty() || !this.searchingAvailable()) {
return null;
}
final List<Integer> positions = IntStream.range(0, this.filteredRecipes.size()).boxed()
.collect(Collectors.toList());
List<Integer> filtered = null;
final List<Integer> recipes = IntStream.range(0, filteredRecipes.size()).boxed().collect(Collectors.toList());
try {
return ItemList.forkJoinPool.submit(
() -> positions.parallelStream()
.filter(position -> mathRecipe(this.original, this.filteredRecipes.get(position), filter))
filtered = ItemList.forkJoinPool.submit(
() -> recipes.parallelStream()
.filter(recipe -> mathRecipe(this.original, filteredRecipes.get(recipe), filter))
.collect(Collectors.toList()))
.get();
filtered.sort((a, b) -> a - b);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
return null;
return filtered;
}
public void setSearchIndices(List<Integer> searchRecipes) {
if (Objects.equals(this.searchRecipes, searchRecipes)) return;
this.searchRecipes = searchRecipes;
this.searchVersion++;
}
public int getSearchVersion() {
return this.searchVersion;
}
public List<Integer> getFilteredRecipes() {
final List<Integer> search = this.searchRecipes;
if (search == null) {
if (this.searchRecipes == null) {
return this.filteredRecipes;
}
final List<Integer> search = this.searchRecipes;
final List<Integer> resolved = new ArrayList<>(search.size());
for (int idx : search) {
@@ -113,18 +107,21 @@ class SearchRecipeHandler<H extends IRecipeHandler> {
}
public int ref(int index) {
final List<Integer> search = this.searchRecipes;
if (search != null) {
index = search.get(index);
if (searchRecipes != null) {
index = searchRecipes.get(index);
}
return this.filteredRecipes.get(index);
return filteredRecipes.get(index);
}
public int numRecipes() {
final List<Integer> search = this.searchRecipes;
return search != null ? search.size() : this.filteredRecipes.size();
if (searchRecipes != null) {
return searchRecipes.size();
}
return filteredRecipes.size();
}
}
@@ -121,13 +121,9 @@ public class StackInfo {
}
public static int getAmount(ItemStack stack) {
return (int) Math.min(getAmountLong(stack), Integer.MAX_VALUE);
}
public static long getAmountLong(ItemStack stack) {
if (stack == null) return 0;
final NBTTagCompound nbTag = StackInfo.itemStackToNBT(stack);
return nbTag != null ? nbTag.getLong("Count") : 0;
return nbTag != null ? nbTag.getInteger("Count") : 0;
}
public static boolean equalItemAndNBT(ItemStack stackA, ItemStack stackB, boolean useNBT) {
@@ -27,6 +27,7 @@ import codechicken.nei.NEIClientUtils;
import codechicken.nei.bookmark.BookmarkItem;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.AutoCraftingManager;
import codechicken.nei.recipe.GuiRecipe;
import codechicken.nei.recipe.GuiRecipeTab;
import codechicken.nei.recipe.HandlerInfo;
@@ -136,7 +137,7 @@ public class RecipeChainTooltipLineHandler extends CompositeTooltipLineHandler {
final GuiContainer currentGui = NEIClientUtils.getGuiContainer();
if (this.lastShiftKey && currentGui != null && !(currentGui instanceof GuiRecipe<?>)) {
inventory.putAll(ItemStackAmount.of(currentGui));
inventory.putAll(AutoCraftingManager.getInventoryItems(currentGui));
}
if (!this.outputRecipes.isEmpty()) {
@@ -155,7 +156,7 @@ public class RecipeChainTooltipLineHandler extends CompositeTooltipLineHandler {
for (ItemStack stack : items) {
if (stack != null
&& NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, item.itemStack)) {
amount += StackInfo.getAmountLong(stack);
amount += StackInfo.getAmount(stack);
}
}
@@ -64,8 +64,6 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
public boolean showFavorites;
public boolean showOverlay;
public boolean showBadge;
public int windowWidth;
public boolean recipeSpacing;
private String csvLine;
@@ -82,8 +80,6 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
this.showFavorites = info.getShowFavoritesButton();
this.showOverlay = info.getShowOverlayButton();
this.showBadge = info.getShowBadge();
this.windowWidth = info.getWindowWidth();
this.recipeSpacing = info.isRecipeSpacing();
this.csvLine = toCsvLine();
}
@@ -96,8 +92,6 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
this.info.setShowFavoritesButton(this.showFavorites);
this.info.setShowOverlayButton(this.showOverlay);
this.info.setShowBadge(this.showBadge);
this.info.setWindowWidth(this.windowWidth);
this.info.setRecipeSpacing(this.recipeSpacing);
NEIClientConfig.handlerOrdering.put(this.handlerKey, this.order);
}
@@ -114,8 +108,6 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
this.showFavorites = intOrDefault(parts[8], this.showFavorites ? 1 : 0) == 1;
this.showOverlay = intOrDefault(parts[9], this.showOverlay ? 1 : 0) == 1;
this.showBadge = intOrDefault(parts[10], this.showBadge ? 1 : 0) == 1;
this.windowWidth = intOrDefault(parts[11], this.windowWidth);
this.recipeSpacing = intOrDefault(parts[12], this.recipeSpacing ? 1 : 0) == 1;
apply();
}
@@ -133,9 +125,7 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
String.valueOf(this.allowOverflowY ? 1 : 0),
String.valueOf(this.showFavorites ? 1 : 0),
String.valueOf(this.showOverlay ? 1 : 0),
String.valueOf(this.showBadge ? 1 : 0),
String.valueOf(this.windowWidth),
String.valueOf(this.recipeSpacing ? 1 : 0));
String.valueOf(this.showBadge ? 1 : 0));
}
public boolean isUnmodified() {
@@ -158,7 +148,7 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
private static final int LABEL_WIDTH = 50;
private static final String TOOLTIP_PREFIX = "debug.RecipeHandler.";
private static final String HEADER = "HandlerId,YShift,Height,Width,MultiWidgets,Order,AllowOverflowX,AllowOverflowY,ShowFavorites,ShowOverlay,ShowBadge,WindowWidth,RecipeSpacing";
private static final String HEADER = "HandlerId,YShift,Height,Width,MultiWidgets,Order,AllowOverflowX,AllowOverflowY,ShowFavorites,ShowOverlay,ShowBadge";
private final int[] COLORS = new int[] { 0x2200FF00, 0x22FF0000, 0x220000FF, 0x2200FFFF, 0x22FF00FF, 0x22FFFF00 };
public static DebugHandlerWidget instance = new DebugHandlerWidget();
@@ -227,11 +217,6 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
saveHandlerInfoPatch();
}, y);
y = addCheckboxWidget("RecipeSpacing", button -> {
record.recipeSpacing = button.value;
saveHandlerInfoPatch();
}, y);
final LabelWidget readonly = new LabelWidget(0xffffff, true);
readonly.y = y;
@@ -247,12 +232,7 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
y = addTextFieldWidget("Width", HandlerInfo.DEFAULT_WIDTH, (field, oldText) -> {
record.width = field.getInteger();
saveHandlerInfoPatch();
}, newValue -> newValue > 0, y);
y = addTextFieldWidget("WindowWidth", 0, (field, oldText) -> {
record.windowWidth = field.getInteger();
saveHandlerInfoPatch();
}, newValue -> newValue >= 0, y);
}, newValue -> newValue >= HandlerInfo.DEFAULT_WIDTH, y);
y = addCheckboxWidget("AllowOverflowX", button -> {
record.allowOverflowX = button.value;
@@ -494,8 +474,6 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
this.values.get("height").updateValue(String.valueOf(this.record.height));
this.values.get("height_readonly").updateValue(String.valueOf(this.record.height));
this.values.get("width").updateValue(String.valueOf(this.record.width));
this.values.get("windowwidth").updateValue(String.valueOf(this.record.windowWidth));
this.values.get("recipespacing").updateValue(String.valueOf(this.record.recipeSpacing));
this.values.get("multiwidgets").updateValue(String.valueOf(this.record.multiWidgets));
this.values.get("allowoverflowx").updateValue(String.valueOf(this.record.allowOverflowX));
@@ -767,8 +745,7 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
ClientHandler.loadSettingsFile("handlers.patch", lines -> {
final List<String> linesList = lines.collect(Collectors.toCollection(ArrayList::new));
// files saved before new columns were appended have a prefix of the current header
if (linesList.isEmpty() || linesList.get(0).isEmpty() || !HEADER.startsWith(linesList.get(0))) {
if (linesList.isEmpty() || !HEADER.equals(linesList.get(0))) {
return;
}
@@ -782,7 +759,7 @@ public class DebugHandlerWidget extends Widget implements IContainerTooltipHandl
key -> new HandlerInfoRecord(
key,
GuiRecipeTab.handlerMap.getOrDefault(key, GuiRecipeTab.DEFAULT_HANDLER_INFO)));
record.apply((line + ",null,null,null,null,null,null,null,null,null,null,null,null"));
record.apply((line + ",null,null,null,null,null,null,null,null,null,null"));
}
});
@@ -22,7 +22,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
protected static Class<?> itemFluidDisplay = null;
protected static Method getFluidFromDisplayStack = null;
private static Method getGTFluidAmount = null;
protected static Class<?> gtMetaGeneratedTool = null;
protected static Field playSound = null;
@@ -43,12 +42,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
"gregtech.common.items.GT_FluidDisplayItem");
getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class);
try {
getGTFluidAmount = gtUtility.getMethod("getFluidAmount", FluidStack.class);
} catch (NoSuchMethodException ignored) {
/* GregTech without long fluid stacks */
}
gtMetaGeneratedTool = ReflectionHelper.getClass(
loader,
"gregtech.api.items.MetaGeneratedTool",
@@ -59,18 +52,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
}
}
/** GregTech fluid stacks can hold more than {@link FluidStack#amount} does */
public static long getFluidAmount(FluidStack fluidStack) {
if (getGTFluidAmount != null) {
try {
return (long) getGTFluidAmount.invoke(null, fluidStack);
} catch (Exception ignored) {}
}
return fluidStack.amount;
}
@Override
public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) {
@@ -80,7 +61,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler {
if (fluidStack != null) {
final NBTTagCompound nbTag = new NBTTagCompound();
nbTag.setString(FluidDisplayStackStringifyHandler.NBT_FLUID_NAME, fluidStack.getFluid().getName());
nbTag.setLong("Count", saveStackSize ? getFluidAmount(fluidStack) : 144);
nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 144);
return nbTag;
}
}
@@ -387,7 +387,7 @@ public class RecipeGroup {
protected boolean isSameStack(ItemStack stackA, ItemStack stackB) {
return stackA == stackB || NEIServerUtils.areStacksSameType(stackA, stackB)
&& StackInfo.getAmountLong(stackA) == StackInfo.getAmountLong(stackB);
&& StackInfo.getAmount(stackA) == StackInfo.getAmount(stackB);
}
protected List<ItemStack> getFilteredPermutations(int member, Point slotKey) {
@@ -29,7 +29,8 @@ import codechicken.nei.PositionedStack;
import codechicken.nei.Widget;
import codechicken.nei.api.IGuiContainerOverlay;
import codechicken.nei.api.ShortcutInputHandler;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableBuilder;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler;
import codechicken.nei.recipe.Badge;
@@ -43,41 +44,39 @@ import codechicken.nei.recipe.IRecipeHandler;
import codechicken.nei.recipe.RecipeHandlerRef;
import codechicken.nei.recipe.StackInfo;
import codechicken.nei.recipe.debug.DebugHandlerWidget;
import codechicken.nei.theme.UIRecipeTexture;
import codechicken.nei.util.NEIMouseUtils;
public class RecipeWidget extends Widget {
protected static final int TICKS_PER_CYCLE = 20;
protected static final Drawable PAUSE_MARKER = UIRecipeTexture.ICON_PAUSE;
protected static final DrawableResource PAUSE_MARKER = new DrawableBuilder(
"nei:textures/pinned_pause.png",
0,
0,
8,
8).setTextureSize(8, 8).build();
protected static final int PAUSE_MARKER_OFFSET = 1;
protected static final int BUTTON_GAP = 2;
protected static final int BUTTON_SPACING = 2;
protected static final int BUTTON_BOTTOM_OFFSET = 6;
protected final RecipeGroup group;
protected final IRecipeHandler handler;
protected final HandlerInfo handlerInfo;
protected final Map<PositionedStack, List<Badge>> badgeCache = new WeakHashMap<>();
protected final Map<Integer, List<GuiRecipeButton>> buttonCache = new HashMap<>();
protected final Map<Integer, List<GuiRecipeButton>> layoutCache = new HashMap<>();
protected AcceptsFollowingTooltipLineHandler acceptsTooltip;
protected int recipeHeight = 0;
protected int spaceRight = 0;
protected final ViewState state;
protected int activeMember = 0;
// single state counter: member = allowed[cycle % size], permutation index = cycle / size
protected int cycle = 0;
protected int cycleticks = 0;
protected int lastcycle = -1;
protected int favoriteRevision = FavoriteRecipes.getRevision();
protected boolean showAsWidget = false;
protected boolean update = true;
protected boolean paused = false;
protected List<ItemStack> pinnedIngredients = null;
protected Map<Point, ItemStack> pinnedSlots = Collections.emptyMap();
public RecipeWidget(RecipeHandlerRef handlerRef) {
@@ -85,24 +84,14 @@ public class RecipeWidget extends Widget {
}
public RecipeWidget(IRecipeHandler handler, List<Integer> recipeIndices) {
this(handler, recipeIndices, null);
}
public RecipeWidget(IRecipeHandler handler, List<Integer> recipeIndices, ViewState state) {
this(new RecipeGroup(handler, recipeIndices), state);
this(new RecipeGroup(handler, recipeIndices));
}
public RecipeWidget(RecipeGroup group) {
this(group, null);
}
public RecipeWidget(RecipeGroup group, ViewState state) {
this.group = group;
this.handler = group.getHandler();
this.handlerInfo = group.getHandlerInfo();
this.state = state != null ? state : new ViewState();
update();
restore();
}
public RecipeHandlerRef getRecipeHandlerRef() {
@@ -117,81 +106,33 @@ public class RecipeWidget extends Widget {
return this.group.contains(recipeIndex);
}
// the state may come from a group with other members, then its cycle no longer fits
private void restore() {
final int member = this.group.indexOf(this.state.recipeIndex);
if (member < 0 || this.state.groupSize != this.group.size()) {
this.state.cycle = 0;
}
this.state.groupSize = this.group.size();
// a pause on a recipe hidden by the search stays in the state until the recipe is shown again
if (this.state.pausedRecipeIndex >= 0
&& pinRecipe(this.state.pausedRecipeIndex, this.state.pinnedIngredients)) {
return;
}
setActiveMember(Math.max(member, 0));
syncCycle();
}
public HandlerInfo getHandlerInfo() {
return this.handlerInfo;
}
public void setLocation(int x, int y, int spaceRight) {
public void setLocation(int x, int y) {
this.x = x;
this.y = y;
if (this.spaceRight != spaceRight) {
this.spaceRight = spaceRight;
relayoutButtons();
}
}
public void setHeight(int h) {
if (this.h != h) {
this.h = h;
relayoutButtons();
}
}
public void showAsWidget(boolean show) {
this.showAsWidget = show;
}
@Override
public boolean contains(int px, int py) {
return super.contains(px, py) || isOverButton(px, py);
}
private boolean isOverButton(int px, int py) {
for (GuiRecipeButton button : getRecipeButtonsIfInit()) {
if (button.contains(px - this.x, py - this.y)) {
return true;
}
}
return false;
}
public boolean isPaused() {
return this.paused;
}
public List<ItemStack> getPinnedIngredients() {
return this.state.pinnedIngredients;
return this.pinnedIngredients;
}
public void setPaused(boolean paused) {
final boolean wasPaused = this.paused;
this.paused = paused && this.group.canCycle();
this.state.pausedRecipeIndex = this.paused ? this.state.recipeIndex : -1;
if (!this.paused) {
this.state.pinnedIngredients = null;
this.pinnedIngredients = null;
this.pinnedSlots = Collections.emptyMap();
if (wasPaused) {
@@ -219,10 +160,9 @@ public class RecipeWidget extends Widget {
return false;
}
this.state.pinnedIngredients = ingredients;
this.pinnedIngredients = ingredients;
this.pinnedSlots = slots;
this.paused = true;
this.state.pausedRecipeIndex = recipeIndex;
setActiveMember(member);
updatePermutations();
@@ -279,39 +219,25 @@ public class RecipeWidget extends Widget {
@Override
public void update() {
final int prevW = this.w;
final int prevH = this.h;
int recipeWidth = 0;
this.recipeHeight = 0;
for (int member = 0; member < this.group.size(); member++) {
final int recipe = this.group.getRecipeIndex(member);
recipeWidth = Math.max(recipeWidth, this.handler.getRecipeWidth(recipe));
this.recipeHeight = Math.max(this.recipeHeight, this.handler.getRecipeHeight(recipe));
}
this.w = recipeWidth > 0 ? recipeWidth : this.handlerInfo.getWidth();
if (this.showAsWidget || !this.handlerInfo.isAllowOverflowY()) {
this.h = getContentHeight();
}
int maxHeight = 0;
if (this.w != prevW || this.h != prevH) {
relayoutButtons();
for (int member = 0; member < this.group.size(); member++) {
final int recipeHeight = this.handler.getRecipeHeight(this.group.getRecipeIndex(member));
if (recipeHeight > 0) {
maxHeight = Math.max(maxHeight, recipeHeight);
}
}
this.w = Math.max(166, this.handlerInfo.getWidth());
this.h = (maxHeight > 0 ? maxHeight : this.handlerInfo.getHeight()) + this.handlerInfo.getYShift();
}
this.update = true;
}
public int getContentHeight() {
return (this.recipeHeight > 0 ? this.recipeHeight : this.handlerInfo.getHeight())
+ this.handlerInfo.getYShift();
}
private boolean showFavoritesButton() {
return NEIClientConfig.favoritesEnabled() && this.handlerInfo.getShowFavoritesButton();
}
public List<GuiRecipeButton> getRecipeButtons() {
return this.buttonCache.computeIfAbsent(this.activeMember, this::createButtons);
}
@@ -326,55 +252,8 @@ public class RecipeWidget extends Widget {
return Collections.emptyList();
}
final List<GuiRecipeButton> buttons = initButtons(
RecipeHandlerRef.of(this.handler, this.group.getRecipeIndex(member)));
final List<GuiRecipeButton> unplaced = new ArrayList<>();
// NEI creates its buttons at (0, 0), so anything else was placed by a mod and keeps its position.
for (GuiRecipeButton button : buttons) {
if (button.xPosition == 0 && button.yPosition == 0) {
unplaced.add(button);
}
}
this.layoutCache.put(member, unplaced);
layoutButtons(unplaced);
return Collections.unmodifiableList(buttons);
}
private void relayoutButtons() {
for (List<GuiRecipeButton> buttons : this.layoutCache.values()) {
layoutButtons(buttons);
}
}
private void layoutButtons(List<GuiRecipeButton> buttons) {
final int top = this.handlerInfo.getYShift();
final int bottom = this.h - BUTTON_BOTTOM_OFFSET;
int columnX = 0;
int columnWidth = 0;
int y = bottom;
for (GuiRecipeButton button : buttons) {
if (y != bottom && y - button.height < top) {
columnX += columnWidth + BUTTON_SPACING;
columnWidth = 0;
y = bottom;
}
y -= button.height;
button.xPosition = columnX;
button.yPosition = y;
y -= BUTTON_SPACING;
columnWidth = Math.max(columnWidth, button.width);
}
final int left = this.w + Math.min(BUTTON_GAP, this.spaceRight - columnX - columnWidth);
for (GuiRecipeButton button : buttons) {
button.xPosition += left;
}
return Collections
.unmodifiableList(initButtons(RecipeHandlerRef.of(this.handler, this.group.getRecipeIndex(member))));
}
private List<GuiRecipeButton> initButtons(RecipeHandlerRef ref) {
@@ -410,17 +289,22 @@ public class RecipeWidget extends Widget {
private List<GuiRecipeButton> getDefaultButtons(RecipeHandlerRef ref) {
GuiContainer guiContainer = NEIClientUtils.getGuiContainer();
final List<GuiRecipeButton> buttons = new ArrayList<>();
final boolean showFavorites = NEIClientConfig.favoritesEnabled() && handlerInfo.getShowFavoritesButton();
final boolean showOverlay = handlerInfo.getShowOverlayButton();
final int x = Math.min(166, this.w) - GuiRecipeButton.BUTTON_WIDTH;
int y = this.h - GuiRecipeButton.BUTTON_HEIGHT - 6;
if (guiContainer instanceof IGuiContainerOverlay overlay) {
guiContainer = overlay.getFirstScreen();
}
if (this.handlerInfo.getShowOverlayButton()) {
buttons.add(new GuiOverlayButton(guiContainer, ref, 0, 0));
if (showOverlay) {
buttons.add(new GuiOverlayButton(guiContainer, ref, x, y));
y -= GuiRecipeButton.BUTTON_HEIGHT + 1;
}
if (showFavoritesButton()) {
buttons.add(new GuiFavoriteButton(ref, 0, 0));
if (showFavorites) {
buttons.add(new GuiFavoriteButton(ref, x, y));
}
return buttons;
@@ -434,10 +318,10 @@ public class RecipeWidget extends Widget {
this.update = false;
if (this.lastcycle == -1) {
this.lastcycle = this.state.cycleticks / TICKS_PER_CYCLE;
this.lastcycle = 0;
applyCycle();
} else if (tickCycle() && !isCycleFrozen(mouseX, mouseY)) {
this.state.cycle++;
this.cycle++;
applyCycle();
} else if (this.favoriteRevision != FavoriteRecipes.getRevision()) {
this.favoriteRevision = FavoriteRecipes.getRevision();
@@ -849,8 +733,8 @@ public class RecipeWidget extends Widget {
private boolean tickCycle() {
if ((this.state.cycleticks++ / TICKS_PER_CYCLE) != this.lastcycle) {
this.lastcycle = this.state.cycleticks / TICKS_PER_CYCLE;
if ((this.cycleticks++ / TICKS_PER_CYCLE) != this.lastcycle) {
this.lastcycle = this.cycleticks / TICKS_PER_CYCLE;
return true;
}
@@ -865,14 +749,15 @@ public class RecipeWidget extends Widget {
return NEIClientConfig.freezeCycleOnHover() && !this.showAsWidget
&& contains(mouseX, mouseY)
&& (getPositionedStackMouseOver(mouseX, mouseY) != null || isOverButton(mouseX, mouseY));
&& (getPositionedStackMouseOver(mouseX, mouseY) != null
|| forEachButtons(button -> button.contains(mouseX, mouseY) ? true : null, false));
}
private void applyCycle() {
if (!this.paused) {
final List<Integer> allowed = this.group.getAllowedMembers();
setActiveMember(allowed.get(this.state.cycle % allowed.size()));
setActiveMember(allowed.get(this.cycle % allowed.size()));
}
this.group.refresh(this.activeMember);
@@ -880,7 +765,7 @@ public class RecipeWidget extends Widget {
}
private int getPermutationIndex() {
return this.state.cycle / this.group.getAllowedMembers().size();
return this.cycle / this.group.getAllowedMembers().size();
}
// keep the permutation index, move the member part of the counter to the active member
@@ -889,7 +774,7 @@ public class RecipeWidget extends Widget {
final int allowedIndex = allowed.indexOf(this.activeMember);
if (allowedIndex >= 0) {
this.state.cycle = this.state.cycle / allowed.size() * allowed.size() + allowedIndex;
this.cycle = this.cycle / allowed.size() * allowed.size() + allowedIndex;
}
}
@@ -938,7 +823,6 @@ public class RecipeWidget extends Widget {
}
}
this.state.recipeIndex = this.group.getRecipeIndex(member);
}
private boolean containsStack(PositionedStack pStack, ItemStack stack) {
@@ -1,17 +0,0 @@
package codechicken.nei.recipe.widget;
import java.util.List;
import net.minecraft.item.ItemStack;
public final class ViewState {
public int recipeIndex = -1;
public int groupSize = 0;
// single state counter: member = allowed[cycle % size], permutation index = cycle / size
public int cycle = 0;
public int cycleticks = 0;
public int pausedRecipeIndex = -1;
public List<ItemStack> pinnedIngredients = null;
}
@@ -1,22 +0,0 @@
package codechicken.nei.recipe.widget;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import codechicken.nei.recipe.IRecipeHandler;
public final class ViewStates {
private final Map<Object, ViewState> groupStates = new HashMap<>();
private final Map<Integer, ViewState> recipeStates = new HashMap<>();
// a group keeps its state while a search hides some of its recipes, a search can't split or merge groups
public ViewState get(IRecipeHandler handler, List<Integer> group) {
final int firstRecipe = group.get(0);
final Object groupId = handler.getRecipeGroupId(firstRecipe);
return groupId != null ? this.groupStates.computeIfAbsent(groupId, k -> new ViewState())
: this.recipeStates.computeIfAbsent(firstRecipe, k -> new ViewState());
}
}
@@ -6,7 +6,7 @@ import org.lwjgl.opengl.GL11;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.theme.UIWidgetTexture;
public class ScrollBar {
@@ -52,8 +52,8 @@ public class ScrollBar {
private int trackPaddingTop = 0;
private int trackPaddingBottom = 0;
private Drawable thumbTexture;
private Drawable trackTexture;
private DrawableResource thumbTexture;
private DrawableResource trackTexture;
public static ScrollBar defaultScrollBar() {
return new ScrollBar();
@@ -72,7 +72,7 @@ public class ScrollBar {
/**
* Sets the size of the scrollbar without texture in the non-scrolling axis (width for vertical, height for
* horizontal).
*
*
* @param trackWidth
* @return
*/
@@ -117,12 +117,12 @@ public class ScrollBar {
return getTrackWidth();
}
public ScrollBar setThumbTexture(Drawable texture) {
public ScrollBar setThumbTexture(DrawableResource texture) {
this.thumbTexture = texture;
return this;
}
public ScrollBar setTrackTexture(Drawable texture) {
public ScrollBar setTrackTexture(DrawableResource texture) {
this.trackTexture = texture;
return this;
}
@@ -404,7 +404,7 @@ public class ScrollBar {
NEIClientUtils.drawRect(bounds.x, bounds.y, bounds.w, bounds.h, thumbColor);
}
private void drawTexture(Drawable texture, Rectangle4i bounds, boolean disabled, float opacity) {
private void drawTexture(DrawableResource texture, Rectangle4i bounds, boolean disabled, float opacity) {
final float c = disabled ? 0.65f : 1f;
GL11.glColor4f(c, c, c, opacity);
@@ -3,7 +3,6 @@ package codechicken.nei.scroll;
import java.awt.Point;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
@@ -81,16 +80,6 @@ public class ScrollContainer extends WidgetContainer {
getVisibleHeight());
}
@Override
public void setWidgets(List<Widget> widgets) {
for (Widget widget : widgets) {
this.relativePosition.remove(widget);
}
super.setWidgets(widgets);
}
@Override
public void clear() {
@@ -2,68 +2,43 @@ package codechicken.nei.theme;
import org.lwjgl.opengl.GL11;
import com.gtnewhorizon.gtnhlib.color.ColorResource;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableResource;
public final class ButtonSkin {
private final Drawable normal;
private final Drawable hover;
private final Drawable active;
private final Drawable disabled;
private final ColorResource foregroundNormal;
private final ColorResource foregroundHover;
private final ColorResource foregroundActive;
private final ColorResource foregroundDisabled;
public ButtonSkin(Drawable normal, Drawable hover, Drawable active, Drawable disabled,
ColorResource foregroundNormal, ColorResource foregroundHover, ColorResource foregroundActive,
ColorResource foregroundDisabled) {
private final DrawableResource normal;
private final DrawableResource hover;
private final DrawableResource active;
private final DrawableResource disabled;
public ButtonSkin(DrawableResource normal, DrawableResource hover, DrawableResource active,
DrawableResource disabled) {
this.normal = normal;
this.hover = hover;
this.active = active;
this.disabled = disabled;
this.foregroundNormal = foregroundNormal;
this.foregroundHover = foregroundHover;
this.foregroundActive = foregroundActive;
this.foregroundDisabled = foregroundDisabled;
}
public ButtonSkin withForeground(ColorResource normal, ColorResource hover, ColorResource active,
ColorResource disabled) {
return new ButtonSkin(this.normal, this.hover, this.active, this.disabled, normal, hover, active, disabled);
}
public Drawable background(boolean enabled, boolean active, boolean hovered) {
public DrawableResource background(boolean enabled, boolean active, boolean hovered) {
if (!enabled) return this.disabled;
if (active) return this.active;
return hovered ? this.hover : this.normal;
}
public int foreground(boolean enabled, boolean active, boolean hovered) {
if (!enabled) return this.foregroundDisabled.getColor();
if (active) return this.foregroundActive.getColor();
return hovered ? this.foregroundHover.getColor() : this.foregroundNormal.getColor();
}
public void draw(int x, int y, int w, int h, Drawable icon, boolean enabled, boolean active, boolean hovered) {
public void draw(int x, int y, int w, int h, DrawableResource icon, boolean enabled, boolean active,
boolean hovered) {
GL11.glColor4f(1, 1, 1, 1);
background(enabled, active, hovered).draw(x, y, w, h);
drawIcon(x, y, w, h, icon, enabled, active, hovered);
drawIcon(x, y, w, h, icon, enabled);
}
public void drawIcon(int x, int y, int w, int h, Drawable icon, boolean enabled, boolean active, boolean hovered) {
final int argb = foreground(enabled, active, hovered);
public static void drawIcon(int x, int y, int w, int h, DrawableResource icon, boolean enabled) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4ub((byte) (argb >> 16), (byte) (argb >> 8), (byte) argb, (byte) (argb >>> 24));
GL11.glColor4f(1, 1, 1, enabled ? 1 : 0.5f);
icon.draw(x + (w - icon.getWidth()) / 2, y + (h - icon.getHeight()) / 2);
GL11.glColor4f(1, 1, 1, 1);
GL11.glDisable(GL11.GL_BLEND);
GL11.glColor4f(1, 1, 1, 1);
}
}
@@ -1,44 +0,0 @@
package codechicken.nei.theme;
import codechicken.nei.drawable.Drawable;
public final class UIRecipeTexture {
public static final Drawable WINDOW = UISprite
.of("recipe/window", 176, 109, new int[] { 6, 6, 6, 6 }, new int[] { 5, 33, 5, 5 });
public static final Drawable WIDGET = UISprite
.of("recipe/widget", 176, 95, new int[] { 6, 6, 6, 6 }, new int[] { 5, 19, 5, 5 });
private static final Drawable[] TAB = UISprite.frames("recipe/tab", 24, 27, 2);
private static final Drawable[] NAV = UISprite.frames("recipe/icon_nav", 12, 12, 2);
private static final Drawable[] OVERLAY = UISprite.frames("recipe/icon_overlay", 12, 12, 2);
private static final Drawable[] ITEM_STATUS = UISprite.frames("recipe/item_status", 12, 12, 2);
public static final Drawable TAB_SELECTED = TAB[0];
public static final Drawable TAB_UNSELECTED = TAB[1];
private static final Drawable[] CATALYST = UISprite
.frames("recipe/catalyst_tab", 23, 28, 2, new int[] { 6, 6, 0, 6 }, new int[] { 5, 5, 5, 5 });
public static final Drawable CATALYST_TAB = CATALYST[0];
public static final Drawable CATALYST_TAB_JOINED = CATALYST[1];
public static final Drawable CATALYST_SLOT = UISprite
.of("recipe/catalyst_slot", 18, 18, UISprite.DEFAULT_SPACE, new int[] { 1, 1, 1, 1 });
public static final Drawable ICON_PREV = NAV[0];
public static final Drawable ICON_NEXT = NAV[1];
public static final Drawable ICON_SEARCH = UISprite.of("recipe/icon_search", 12, 12);
public static final Drawable ICON_PAUSE = UISprite.of("recipe/icon_pause", 12, 12);
public static final Drawable ICON_FAVORITE = UISprite.of("recipe/icon_favorite", 12, 12);
public static final Drawable ICON_OVERLAY = OVERLAY[0];
public static final Drawable ICON_OVERLAY_FILL = OVERLAY[1];
public static final Drawable ITEM_MISSING = ITEM_STATUS[0];
public static final Drawable ITEM_PRESENT = ITEM_STATUS[1];
private UIRecipeTexture() {}
}
@@ -2,7 +2,6 @@ package codechicken.nei.theme;
import net.minecraft.util.ResourceLocation;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableResource;
public final class UISprite {
@@ -11,24 +10,24 @@ public final class UISprite {
private UISprite() {}
public static Drawable of(String name, int w, int h, int[] margin, int[] slice) {
public static DrawableResource of(String name, int w, int h, int[] margin, int[] slice) {
return frames(name, w, h, 1, margin, slice)[0];
}
public static Drawable of(String name, int w, int h) {
public static DrawableResource of(String name, int w, int h) {
return of(name, w, h, DEFAULT_SPACE, DEFAULT_SPACE);
}
public static Drawable[] frames(String name, int w, int h, int count) {
public static DrawableResource[] frames(String name, int w, int h, int count) {
return frames(name, w, h, count, DEFAULT_SPACE, DEFAULT_SPACE);
}
// frames are stacked top to bottom and each includes the margin; {left, top, right, bottom}
public static Drawable[] frames(String name, int w, int h, int count, int[] margin, int[] slice) {
public static DrawableResource[] frames(String name, int w, int h, int count, int[] margin, int[] slice) {
final ResourceLocation texture = new ResourceLocation("nei", "textures/gui/" + name + ".png");
final int frameWidth = w + margin[0] + margin[2];
final int frameHeight = h + margin[1] + margin[3];
final Drawable[] frames = new Drawable[count];
final DrawableResource[] frames = new DrawableResource[count];
for (int i = 0; i < count; i++) {
frames[i] = new DrawableResource(
@@ -1,50 +1,31 @@
package codechicken.nei.theme;
import codechicken.nei.ColorUtils;
import codechicken.nei.drawable.Drawable;
import codechicken.nei.drawable.DrawableResource;
import codechicken.nei.scroll.ScrollBar;
import codechicken.nei.scroll.ScrollBar.ScrollType;
public final class UIWidgetTexture {
private static final Drawable[] BTN = UISprite
private static final DrawableResource[] BTN = UISprite
.frames("widgets/button", 12, 12, 4, UISprite.DEFAULT_SPACE, new int[] { 2, 2, 2, 3 });
public static final Drawable BTN_NORMAL = BTN[0];
public static final Drawable BTN_HOVER = BTN[1];
public static final Drawable BTN_ACTIVE = BTN[2];
public static final Drawable BTN_DISABLED = BTN[3];
public static final ButtonSkin BUTTON = new ButtonSkin(
BTN_NORMAL,
BTN_HOVER,
BTN_ACTIVE,
BTN_DISABLED,
ColorUtils.buttonIconNormal,
ColorUtils.buttonIconHover,
ColorUtils.buttonIconActive,
ColorUtils.buttonIconDisabled);
public static final ButtonSkin BUTTON_FAVORITE = BUTTON.withForeground(
ColorUtils.buttonIconFavoriteNormal,
ColorUtils.buttonIconFavoriteHover,
ColorUtils.buttonIconFavoriteActive,
ColorUtils.buttonIconFavoriteDisabled);
public static final ButtonSkin BUTTON_OVERLAY_ERROR = BUTTON.withForeground(
ColorUtils.buttonIconOverlayErrorNormal,
ColorUtils.buttonIconOverlayErrorHover,
ColorUtils.buttonIconOverlayErrorActive,
ColorUtils.buttonIconOverlayErrorDisabled);
public static final DrawableResource BTN_NORMAL = BTN[0];
public static final DrawableResource BTN_HOVER = BTN[1];
public static final DrawableResource BTN_ACTIVE = BTN[2];
public static final DrawableResource BTN_DISABLED = BTN[3];
public static final ButtonSkin BUTTON = new ButtonSkin(BTN_NORMAL, BTN_HOVER, BTN_ACTIVE, BTN_DISABLED);
private static final int[] THUMB_INSET = new int[] { 1, 1, 1, 1 };
// frame 0 is the track, frame 1 the thumb drawn inside a transparent THUMB_INSET border of the same frame size
public static final Drawable SCROLL_V_TRACK = UISprite
public static final DrawableResource SCROLL_V_TRACK = UISprite
.frames("widgets/scroll_v", 8, 11, 2, UISprite.DEFAULT_SPACE, new int[] { 1, 1, 1, 1 })[0];
public static final Drawable SCROLL_V_THUMB = UISprite
public static final DrawableResource SCROLL_V_THUMB = UISprite
.frames("widgets/scroll_v", 6, 9, 2, THUMB_INSET, new int[] { 1, 1, 1, 2 })[1];
public static final Drawable SCROLL_H_TRACK = UISprite
public static final DrawableResource SCROLL_H_TRACK = UISprite
.frames("widgets/scroll_h", 11, 8, 2, UISprite.DEFAULT_SPACE, new int[] { 1, 1, 1, 1 })[0];
public static final Drawable SCROLL_H_THUMB = UISprite
public static final DrawableResource SCROLL_H_THUMB = UISprite
.frames("widgets/scroll_h", 9, 6, 2, THUMB_INSET, new int[] { 1, 1, 2, 1 })[1];
public static final int SCROLL_TRACK_WIDTH = 8;
@@ -346,10 +346,10 @@ moze_intel.projecte.integration.NEI.NEIAlchBagHandler,ProjectE,ProjectE:item.pe_
de.katzenpapst.amunra.nei.recipehandler.ARCircuitFab,Pra's Galacticraft Mod,GalacticraftCore:tile.machine2:4,,GalacticraftAmunRa,TRUE,,,,,,,,,,,,
de.katzenpapst.amunra.nei.recipehandler.ARNasaWorkbenchShuttle,Pra's Galacticraft Mod,GalacticraftAmunRa:item.itemShuttle,,GalacticraftAmunRa,TRUE,,,130,168,16,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerFloatingFlowers,Botania,Botania:miniIsland,,Botania,TRUE,,,,,5,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerPetalApothecary,Botania,Botania:altar,,Botania,TRUE,,,102,166,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerRunicAltar,Botania,Botania:runeAltar,,Botania,TRUE,,,122,166,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerManaPool,Botania,Botania:pool,,Botania,TRUE,,,90,166,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerElvenTrade,Botania,Botania:alfheimPortal,,Botania,TRUE,,,90,166,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerPetalApothecary,Botania,Botania:altar,,Botania,TRUE,,,102,137,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerRunicAltar,Botania,Botania:runeAltar,,Botania,TRUE,,,122,137,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerManaPool,Botania,Botania:pool,,Botania,TRUE,,,90,137,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerElvenTrade,Botania,Botania:alfheimPortal,,Botania,TRUE,,,90,130,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerBrewery,Botania,Botania:brewery,,Botania,TRUE,,,,,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerPureDaisy,Botania,Botania:specialFlower,"{type:puredaisy}",Botania,TRUE,,,,,4,,,,,,,
vazkii.botania.client.integration.nei.recipe.RecipeHandlerLexicaBotania,Botania,Botania:lexicon,,Botania,TRUE,,,,,,,,,,,,
@@ -523,10 +523,10 @@ de.ellpeck.actuallyadditions.mod.nei.NEICompostRecipe,Actually Additions,Actuall
de.ellpeck.actuallyadditions.mod.nei.NEIReconstructorRecipe,Actually Additions,ActuallyAdditions:blockAtomicReconstructor,,ActuallyAdditions,TRUE,,,,,,,,,,,,
de.ellpeck.actuallyadditions.mod.nei.NEITreasureChestRecipe,Actually Additions,ActuallyAdditions:blockTreasureChest,,ActuallyAdditions,TRUE,,,,,,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerFloatingFlowers,Botania,Botania:miniIsland,,Botania,TRUE,,,,,5,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerPetalApothecary,Botania,Botania:altar,,Botania,TRUE,,,102,166,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerRunicAltar,Botania,Botania:runeAltar,,Botania,TRUE,,,122,166,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerManaPool,Botania,Botania:pool,,Botania,TRUE,,,90,166,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerElvenTrade,Botania,Botania:alfheimPortal,,Botania,TRUE,,,90,166,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerPetalApothecary,Botania,Botania:altar,,Botania,TRUE,,,102,137,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerRunicAltar,Botania,Botania:runeAltar,,Botania,TRUE,,,122,137,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerManaPool,Botania,Botania:pool,,Botania,TRUE,,,90,137,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerElvenTrade,Botania,Botania:alfheimPortal,,Botania,TRUE,,,90,130,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerBrewery,Botania,Botania:brewery,,Botania,TRUE,,,,,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerPureDaisy,Botania,Botania:specialFlower,"{type:puredaisy}",Botania,TRUE,,,,,4,,,,,,,
vazkii.botania.client.integration.nei.RecipeHandlerLexicaBotania,Botania,Botania:lexicon,,Botania,TRUE,,,,,,,,,,,,
1 handler modName itemName nbtInfo modId modRequired excludedModId yShift handlerHeight handlerWidth maxRecipesPerPage imageResource imageX imageY imageWidth imageHeight itemNotes useCustomScroll
346 de.katzenpapst.amunra.nei.recipehandler.ARCircuitFab Pra's Galacticraft Mod GalacticraftCore:tile.machine2:4 GalacticraftAmunRa TRUE
347 de.katzenpapst.amunra.nei.recipehandler.ARNasaWorkbenchShuttle Pra's Galacticraft Mod GalacticraftAmunRa:item.itemShuttle GalacticraftAmunRa TRUE 130 168 16
348 vazkii.botania.client.integration.nei.recipe.RecipeHandlerFloatingFlowers Botania Botania:miniIsland Botania TRUE 5
349 vazkii.botania.client.integration.nei.recipe.RecipeHandlerPetalApothecary Botania Botania:altar Botania TRUE 102 166 137 4
350 vazkii.botania.client.integration.nei.recipe.RecipeHandlerRunicAltar Botania Botania:runeAltar Botania TRUE 122 166 137 4
351 vazkii.botania.client.integration.nei.recipe.RecipeHandlerManaPool Botania Botania:pool Botania TRUE 90 166 137 4
352 vazkii.botania.client.integration.nei.recipe.RecipeHandlerElvenTrade Botania Botania:alfheimPortal Botania TRUE 90 166 130 4
353 vazkii.botania.client.integration.nei.recipe.RecipeHandlerBrewery Botania Botania:brewery Botania TRUE 4
354 vazkii.botania.client.integration.nei.recipe.RecipeHandlerPureDaisy Botania Botania:specialFlower {type:puredaisy} Botania TRUE 4
355 vazkii.botania.client.integration.nei.recipe.RecipeHandlerLexicaBotania Botania Botania:lexicon Botania TRUE
523 de.ellpeck.actuallyadditions.mod.nei.NEIReconstructorRecipe Actually Additions ActuallyAdditions:blockAtomicReconstructor ActuallyAdditions TRUE
524 de.ellpeck.actuallyadditions.mod.nei.NEITreasureChestRecipe Actually Additions ActuallyAdditions:blockTreasureChest ActuallyAdditions TRUE
525 vazkii.botania.client.integration.nei.RecipeHandlerFloatingFlowers Botania Botania:miniIsland Botania TRUE 5
526 vazkii.botania.client.integration.nei.RecipeHandlerPetalApothecary Botania Botania:altar Botania TRUE 102 166 137 4
527 vazkii.botania.client.integration.nei.RecipeHandlerRunicAltar Botania Botania:runeAltar Botania TRUE 122 166 137 4
528 vazkii.botania.client.integration.nei.RecipeHandlerManaPool Botania Botania:pool Botania TRUE 90 166 137 4
529 vazkii.botania.client.integration.nei.RecipeHandlerElvenTrade Botania Botania:alfheimPortal Botania TRUE 90 166 130 4
530 vazkii.botania.client.integration.nei.RecipeHandlerBrewery Botania Botania:brewery Botania TRUE 4
531 vazkii.botania.client.integration.nei.RecipeHandlerPureDaisy Botania Botania:specialFlower {type:puredaisy} Botania TRUE 4
532 vazkii.botania.client.integration.nei.RecipeHandlerLexicaBotania Botania Botania:lexicon Botania TRUE
@@ -343,9 +343,6 @@ nei.options.inventory.guirecipe.slotHighlightPresent.false=No
nei.options.inventory.guirecipe.infiniteScroll=Use Infinite Scroll
nei.options.inventory.guirecipe.infiniteScroll.true=Yes
nei.options.inventory.guirecipe.infiniteScroll.false=No
nei.options.inventory.guirecipe.evenRecipeSpacing=Spread Recipes Evenly
nei.options.inventory.guirecipe.evenRecipeSpacing.true=Yes
nei.options.inventory.guirecipe.evenRecipeSpacing.false=No
nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst=JEI Style Recipe Catalysts
nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.0=None
nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.1=Grid
@@ -363,8 +360,6 @@ nei.options.inventory.guirecipe.scrollPages.true=Enabled
nei.options.inventory.guirecipe.scrollPages.false=Disabled
nei.options.inventory.guirecipe.maxHeight=Max Height
nei.options.inventory.guirecipe.minWidth=Minimum Recipe Screen Width
nei.options.inventory.guirecipe.topMargin=Recipe Screen Top Margin
nei.options.inventory.showItemQuantityWidget=Show Item Quantity Widget
nei.options.inventory.showItemQuantityWidget.true=Yes
nei.options.inventory.showItemQuantityWidget.false=No
@@ -635,8 +630,6 @@ nei.debug.RecipeHandler.yShift=yShift
nei.debug.RecipeHandler.MultiWidgets=Multi Widgets
nei.debug.RecipeHandler.Height=Height
nei.debug.RecipeHandler.Width=Width
nei.debug.RecipeHandler.WindowWidth=Window Width
nei.debug.RecipeHandler.RecipeSpacing=Recipe Spacing
nei.debug.RecipeHandler.ShowFavorites=Show Favorites
nei.debug.RecipeHandler.ShowOverlay=Show Overlays
nei.debug.RecipeHandler.ShowBadge=Show Badge
@@ -213,8 +213,6 @@ nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.2=Скролл
nei.options.inventory.guirecipe.cycledIngredientsTooltip=Подсказка циклических ингредиентов
nei.options.inventory.guirecipe.cycledIngredientsTooltip.true=Показывать
nei.options.inventory.guirecipe.cycledIngredientsTooltip.false=Скрыть
nei.options.inventory.guirecipe.minWidth=Минимальная ширина окна рецептов
nei.options.inventory.guirecipe.topMargin=Верхний отступ окна рецептов
nei.options.inventory.showItemQuantityWidget=Показывать виджет количества предметов
nei.options.inventory.showItemQuantityWidget.true=Да
nei.options.inventory.showItemQuantityWidget.false=Нет
@@ -259,9 +257,6 @@ nei.options.inventory.guirecipe.shiftOverlayRecipe.false=Нет
nei.options.inventory.guirecipe.freezeCycleOnHover=Останавливать перелистывание рецепта при наведении на предмет или кнопку
nei.options.inventory.guirecipe.freezeCycleOnHover.true=Да
nei.options.inventory.guirecipe.freezeCycleOnHover.false=Нет
nei.options.inventory.guirecipe.evenRecipeSpacing=Равномерно распределять рецепты по высоте
nei.options.inventory.guirecipe.evenRecipeSpacing.true=Да
nei.options.inventory.guirecipe.evenRecipeSpacing.false=Нет
nei.options.inventory.widgetsenabled.true=NEI включен
nei.options.inventory.widgetsenabled.false=NEI выключен
nei.options.inventory.cheatmode.0=Режим рецептов
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 153 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 206 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 312 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 319 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 554 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 B