mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-10-25 20:32:20 +00:00
Merge branch 'master' into caedis/autocraft-throttle
This commit is contained in:
5 files changed
+65
-21
No files matched your search
@@ -27,7 +27,7 @@ import codechicken.nei.commands.CommandUntranslator;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import codechicken.nei.guihook.IContainerSlotClickHandler;
|
||||
import codechicken.nei.recipe.GuiRecipe;
|
||||
import codechicken.nei.util.EmptyContainer;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -252,7 +252,7 @@ public class NEIController implements IContainerSlotClickHandler, IContainerInpu
|
||||
|
||||
// slot in GuiRecipe does not contain actual stack
|
||||
// and scroll should be handled by GuiRecipe, not here
|
||||
if (gui instanceof GuiRecipe) return false;
|
||||
if (gui.inventorySlots instanceof EmptyContainer) return false;
|
||||
|
||||
Point mousePos = getMousePosition();
|
||||
Slot mouseover = manager.window.getSlotAtPosition(mousePos.x, mousePos.y);
|
||||
|
||||
@@ -625,7 +625,7 @@ public class GuiContainerManager {
|
||||
tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE);
|
||||
}
|
||||
|
||||
} else if (!tooltip.isEmpty()) {
|
||||
} else if (!tooltip.isEmpty() && !tooltip.get(0).startsWith(GuiDraw.TOOLTIP_HANDLER)) {
|
||||
tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE);
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ import codechicken.nei.scroll.ScrollBar;
|
||||
import codechicken.nei.scroll.ScrollBar.OverflowType;
|
||||
import codechicken.nei.scroll.ScrollBar.ScrollPlace;
|
||||
import codechicken.nei.scroll.ScrollContainer;
|
||||
import codechicken.nei.util.EmptyContainer;
|
||||
import codechicken.nei.util.SlotInaccessible;
|
||||
|
||||
public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer implements IGuiContainerOverlay,
|
||||
@@ -181,7 +182,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
private boolean isHeightHackApplied = false;
|
||||
|
||||
protected GuiRecipe(GuiScreen prevgui) {
|
||||
super(new ContainerRecipe());
|
||||
super(new EmptyContainer());
|
||||
this.recipeTabs = new GuiRecipeTabs() {
|
||||
|
||||
@Override
|
||||
@@ -191,7 +192,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
};
|
||||
this.recipeCatalyst = new GuiRecipeCatalyst();
|
||||
this.slotcontainer = (ContainerRecipe) this.inventorySlots;
|
||||
this.slotcontainer = (EmptyContainer) this.inventorySlots;
|
||||
|
||||
this.prevGui = prevgui;
|
||||
this.firstGuiGeneral = prevgui;
|
||||
@@ -526,7 +527,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
@Override
|
||||
public Slot getSlotAtPosition(int mousex, int mousey) {
|
||||
final Widget activeWidget = this.container.getWidgetUnderMouse(mousex, mousey);
|
||||
final ContainerRecipe slotcontainer = (ContainerRecipe) inventorySlots;
|
||||
final EmptyContainer slotcontainer = (EmptyContainer) inventorySlots;
|
||||
slotcontainer.setActiveStack(null);
|
||||
|
||||
if (activeWidget instanceof NEIRecipeWidget recipeWidget) {
|
||||
@@ -1033,7 +1034,7 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
private GuiOverlayButton[] overlayButtons = new GuiOverlayButton[0];
|
||||
|
||||
@Deprecated
|
||||
public ContainerRecipe slotcontainer;
|
||||
public EmptyContainer slotcontainer;
|
||||
|
||||
@Deprecated
|
||||
public List<GuiButton> getOverlayButtons() {
|
||||
|
||||
@@ -25,6 +25,34 @@ import codechicken.nei.recipe.StackInfo;
|
||||
|
||||
public class RecipeChainMath {
|
||||
|
||||
public interface ChainVisitor {
|
||||
|
||||
void enterRecipe(RecipeId recipeId, long multiplier);
|
||||
|
||||
void addIngredient(BookmarkItem ingrItem, long requestedAmount);
|
||||
|
||||
void addIngredientFresh(BookmarkItem ingrItem, long freshAmount);
|
||||
|
||||
void leaveRecipe();
|
||||
|
||||
}
|
||||
|
||||
private static class EmptyChainVisitor implements ChainVisitor {
|
||||
|
||||
@Override
|
||||
public void enterRecipe(RecipeId recipeId, long multiplier) {}
|
||||
|
||||
@Override
|
||||
public void addIngredient(BookmarkItem ingrItem, long requestedAmount) {}
|
||||
|
||||
@Override
|
||||
public void addIngredientFresh(BookmarkItem ingrItem, long freshAmount) {}
|
||||
|
||||
@Override
|
||||
public void leaveRecipe() {}
|
||||
|
||||
}
|
||||
|
||||
private static class ContainerItemResult {
|
||||
|
||||
public ItemStack stack;
|
||||
@@ -38,6 +66,8 @@ public class RecipeChainMath {
|
||||
}
|
||||
}
|
||||
|
||||
private static final ChainVisitor EMPTY_CHAIN_VISITOR = new EmptyChainVisitor();
|
||||
|
||||
private static final ItemStack ROOT_ITEM = new ItemStack(Blocks.fire);
|
||||
private static final RecipeId ROOT_RECIPE_ID = RecipeId
|
||||
.of(ROOT_ITEM, "recipe-autocrafting", Collections.emptyList());
|
||||
@@ -298,6 +328,10 @@ public class RecipeChainMath {
|
||||
}
|
||||
|
||||
public RecipeChainMath refresh() {
|
||||
return refresh(EMPTY_CHAIN_VISITOR);
|
||||
}
|
||||
|
||||
public RecipeChainMath refresh(ChainVisitor visitor) {
|
||||
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
|
||||
StackInfo.pauseItemDamageSound(true);
|
||||
|
||||
@@ -321,7 +355,7 @@ public class RecipeChainMath {
|
||||
}
|
||||
|
||||
this.preferredItems.put(prefItem, prefItem);
|
||||
calculateSuitableRecipe(prefItem, prefAmount, new ArrayList<>());
|
||||
calculateSuitableRecipe(prefItem, prefAmount, new ArrayList<>(), visitor);
|
||||
this.preferredItems.remove(prefItem);
|
||||
}
|
||||
}
|
||||
@@ -338,9 +372,12 @@ public class RecipeChainMath {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void calculateSuitableRecipe(BookmarkItem ingrItem, long ingrAmount, List<RecipeId> visited) {
|
||||
private void calculateSuitableRecipe(BookmarkItem ingrItem, long ingrAmount, List<RecipeId> visited,
|
||||
ChainVisitor visitor) {
|
||||
final BookmarkItem prefItem = this.preferredItems.get(ingrItem);
|
||||
|
||||
visitor.addIngredient(prefItem != null ? prefItem : ingrItem, ingrAmount);
|
||||
|
||||
// calculate existing containers
|
||||
if (ingrAmount > 0) {
|
||||
for (ItemStack stack : ingrItem.permutations.values()) {
|
||||
@@ -358,7 +395,7 @@ public class RecipeChainMath {
|
||||
if (ingrAmount > 0) {
|
||||
for (BookmarkItem item : this.initialItems) {
|
||||
if (item.containsItems(ingrItem)
|
||||
&& (ingrAmount = addRequiredAmount(item, ingrAmount, item.getAmount())) == 0) {
|
||||
&& (ingrAmount = addRequiredAmount(item, ingrAmount, item.getAmount(), visitor)) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -366,33 +403,37 @@ public class RecipeChainMath {
|
||||
|
||||
// shift amount
|
||||
if (prefItem == null) {
|
||||
addRequiredAmount(ingrItem, ingrAmount, Long.MAX_VALUE);
|
||||
addRequiredAmount(ingrItem, ingrAmount, Long.MAX_VALUE, visitor);
|
||||
} else if (visited.contains(prefItem.recipeId)) {
|
||||
addRequiredAmount(prefItem, ingrAmount, Long.MAX_VALUE);
|
||||
addRequiredAmount(prefItem, ingrAmount, Long.MAX_VALUE, visitor);
|
||||
} else {
|
||||
addRequiredAmount(prefItem, ingrAmount, Long.MAX_VALUE);
|
||||
addRequiredAmount(prefItem, ingrAmount, Long.MAX_VALUE, visitor);
|
||||
final long multiplier = Math
|
||||
.max(0, prefItem.getMultiplierFromAmount(this.requiredAmount.get(prefItem)) - prefItem.multiplier);
|
||||
|
||||
if (multiplier > 0) {
|
||||
addShift(prefItem.recipeId, multiplier);
|
||||
visited.add(prefItem.recipeId);
|
||||
prepareIngredients(prefItem.recipeId, multiplier, visited);
|
||||
prepareIngredients(prefItem.recipeId, multiplier, visited, visitor);
|
||||
visited.remove(prefItem.recipeId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void prepareIngredients(RecipeId recipeId, long multiplier, List<RecipeId> visited) {
|
||||
private void prepareIngredients(RecipeId recipeId, long multiplier, List<RecipeId> visited, ChainVisitor visitor) {
|
||||
visitor.enterRecipe(recipeId, multiplier);
|
||||
|
||||
for (BookmarkItem item : this.recipeIngredients) {
|
||||
if (!item.emptyFactor() && recipeId.equals(item.recipeId)) {
|
||||
calculateSuitableRecipe(item, item.getAmount(multiplier), visited);
|
||||
calculateSuitableRecipe(item, item.getAmount(multiplier), visited, visitor);
|
||||
}
|
||||
}
|
||||
|
||||
visitor.leaveRecipe();
|
||||
}
|
||||
|
||||
private long addRequiredAmount(BookmarkItem prefItem, long ingrAmount, long maxAmount) {
|
||||
private long addRequiredAmount(BookmarkItem prefItem, long ingrAmount, long maxAmount, ChainVisitor visitor) {
|
||||
long shiftAmount = this.requiredAmount.getOrDefault(prefItem, 0L);
|
||||
|
||||
if (hasContainerItem(prefItem.itemStack)) {
|
||||
@@ -411,8 +452,9 @@ public class RecipeChainMath {
|
||||
final ContainerItemResult result = getToolsContainerItems(itemStack, steps);
|
||||
|
||||
if (result.stack == null) {
|
||||
multiplier = steps / (steps - result.leftSteps);
|
||||
steps = steps % (steps - result.leftSteps);
|
||||
final long stepsPerReplacement = steps - result.leftSteps;
|
||||
multiplier = Math.min(steps / stepsPerReplacement, maxAmount - shiftAmount);
|
||||
steps -= multiplier * stepsPerReplacement;
|
||||
} else {
|
||||
steps = result.leftSteps;
|
||||
}
|
||||
@@ -448,6 +490,7 @@ public class RecipeChainMath {
|
||||
ingrAmount -= initAmount;
|
||||
}
|
||||
|
||||
visitor.addIngredientFresh(prefItem, shiftAmount - this.requiredAmount.getOrDefault(prefItem, 0L));
|
||||
this.requiredAmount.put(prefItem, shiftAmount);
|
||||
|
||||
return ingrAmount;
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package codechicken.nei.recipe;
|
||||
package codechicken.nei.util;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -8,7 +8,7 @@ import net.minecraft.item.ItemStack;
|
||||
import codechicken.nei.PositionedStack;
|
||||
import codechicken.nei.api.ShortcutInputHandler;
|
||||
|
||||
public class ContainerRecipe extends Container {
|
||||
public class EmptyContainer extends Container {
|
||||
|
||||
private ItemStack activeStack = null;
|
||||
|
||||
Reference in new issue
Block a user