mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-21 04:32:27 +00:00
Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cced6fa21b | ||
|
|
30eec77a20 | ||
|
|
75e480f0c7 | ||
|
|
6ae40a1b36 | ||
|
|
540caeaae3 | ||
|
|
502a688a75 | ||
|
|
cbaef9cee0 | ||
|
|
a40289ca65 | ||
|
|
9ce2aa40bb |
No files matched your search
@@ -30,7 +30,14 @@ public class InfiniteStackSizeHandler implements IInfiniteItemHandler {
|
||||
|
||||
@Override
|
||||
public void replenishInfiniteStack(InventoryPlayer inv, int slotNo) {
|
||||
inv.getStackInSlot(slotNo).stackSize = 111;
|
||||
ItemStack stack = inv.getStackInSlot(slotNo);
|
||||
stack.stackSize = 111;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); i++) {
|
||||
if (i == slotNo) continue;
|
||||
|
||||
if (NEIServerUtils.areStacksSameType(stack, inv.getStackInSlot(i))) inv.setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,13 +4,13 @@ import static codechicken.lib.gui.GuiDraw.getMousePosition;
|
||||
import static codechicken.nei.NEIClientConfig.canCheatItem;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.client.gui.inventory.GuiContainerCreative;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.ClientCommandHandler;
|
||||
|
||||
@@ -77,38 +77,29 @@ public class NEIController implements IContainerSlotClickHandler, IContainerInpu
|
||||
public static void updateUnlimitedItems(InventoryPlayer inventory) {
|
||||
if (!NEIClientConfig.canPerformAction("item") || !NEIClientConfig.hasSMPCounterPart()) return;
|
||||
|
||||
int size = inventory.getSizeInventory();
|
||||
for (int i = 0; i < size; i++) {
|
||||
LinkedList<ItemStack> beforeStacks = new LinkedList<>();
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
beforeStacks.add(NEIServerUtils.copyStack(inventory.getStackInSlot(i)));
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
if (stack == null) continue;
|
||||
|
||||
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers) {
|
||||
if (!handler.canHandleItem(stack) || !handler.isItemInfinite(stack)) continue;
|
||||
for (IInfiniteItemHandler handler : ItemInfo.infiniteHandlers)
|
||||
if (handler.canHandleItem(stack) && handler.isItemInfinite(stack))
|
||||
handler.replenishInfiniteStack(inventory, i);
|
||||
}
|
||||
|
||||
long beforeSize = packStackSize(stack.stackSize, stack.getItemDamage());
|
||||
handler.replenishInfiniteStack(inventory, i);
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack newstack = inventory.getStackInSlot(i);
|
||||
|
||||
ItemStack newstack = inventory.getStackInSlot(i);
|
||||
if (!sameStack(stack, beforeSize, newstack)) {
|
||||
NEIClientUtils.setSlotContents(i, newstack, false); // sends via SMP handler ;)
|
||||
stack.stackSize = (int) (beforeSize >> 32);
|
||||
stack.setItemDamage((int) beforeSize);
|
||||
inventory.setInventorySlotContents(i, stack); // restore in case of SMP fail
|
||||
}
|
||||
if (!NEIServerUtils.areStacksIdentical(beforeStacks.get(i), newstack)) {
|
||||
inventory.setInventorySlotContents(i, beforeStacks.get(i)); // restore in case of SMP fail
|
||||
NEIClientUtils.setSlotContents(i, newstack, false); // sends via SMP handler ;)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static long packStackSize(int stackSize, int itemDamage) {
|
||||
return ((long) stackSize << 32) | (itemDamage & 0xFFFFFFFFL);
|
||||
}
|
||||
|
||||
private static boolean sameStack(ItemStack before, long beforeSize, ItemStack stack) {
|
||||
if (stack == null) return before == null;
|
||||
return before != null && Item.getIdFromItem(before.getItem()) == Item.getIdFromItem(stack.getItem())
|
||||
&& beforeSize == packStackSize(stack.stackSize, stack.getItemDamage());
|
||||
}
|
||||
|
||||
public static void processCreativeCycling(InventoryPlayer inventory) {
|
||||
if (NEIClientConfig.invCreativeMode() && NEIClientUtils.controlKey()) {
|
||||
if (selectedItem != inventory.currentItem) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
import codechicken.lib.gui.GuiDraw;
|
||||
import codechicken.nei.ItemList.NothingItemFilter;
|
||||
import codechicken.nei.SearchTokenParser.ISearchParserProvider;
|
||||
import codechicken.nei.SearchTokenParser.SearchMode;
|
||||
import codechicken.nei.api.IRecipeFilter;
|
||||
import codechicken.nei.api.IRecipeFilter.IRecipeFilterProvider;
|
||||
import codechicken.nei.api.ItemFilter;
|
||||
@@ -84,8 +85,8 @@ public class SearchField extends TextField implements ItemFilterProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.fromInt(NEIClientConfig.getIntSetting("inventory.search." + this.name + "SearchMode"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,13 +59,7 @@ public class SearchTokenParser {
|
||||
|
||||
public EnumChatFormatting getHighlightedColor();
|
||||
|
||||
default SearchMode getSearchMode() {
|
||||
return SearchMode.fromInt(NEIClientConfig.getIntSetting("inventory.search." + getName() + "SearchMode"));
|
||||
}
|
||||
|
||||
default String getName() {
|
||||
return String.valueOf(getPrefix());
|
||||
}
|
||||
public SearchMode getSearchMode();
|
||||
}
|
||||
|
||||
private static class ProvidersCache {
|
||||
|
||||
@@ -399,8 +399,8 @@ public class SubsetWidget extends Button implements ItemFilterProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "subsets";
|
||||
public SearchMode getSearchMode() {
|
||||
return SearchMode.fromInt(NEIClientConfig.getIntSetting("inventory.search.subsetsSearchMode"));
|
||||
}
|
||||
|
||||
private boolean matches(String name, String searchText, Pattern pattern) {
|
||||
|
||||
@@ -77,13 +77,10 @@ import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier;
|
||||
*/
|
||||
public class ItemInfo {
|
||||
|
||||
public enum Layout {
|
||||
|
||||
public static enum Layout {
|
||||
HEADER,
|
||||
BODY,
|
||||
FOOTER;
|
||||
|
||||
public static final Layout[] VALUES = values();
|
||||
FOOTER
|
||||
}
|
||||
|
||||
public static final ArrayListMultimap<Layout, IHighlightHandler> highlightHandlers = ArrayListMultimap.create();
|
||||
@@ -475,7 +472,7 @@ public class ItemInfo {
|
||||
MovingObjectPosition mop) {
|
||||
List<String> retString = new ArrayList<>();
|
||||
|
||||
for (ItemInfo.Layout layout : Layout.VALUES)
|
||||
for (ItemInfo.Layout layout : ItemInfo.Layout.values())
|
||||
for (IHighlightHandler handler : ItemInfo.highlightHandlers.get(layout))
|
||||
retString = handler.handleTextData(itemStack, world, player, mop, retString, layout);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ public class AutoCraftingManager {
|
||||
final List<BookmarkItem> initialItems = prepareInitialItems(math, getInventoryItems(guiContainer));
|
||||
boolean processed = false;
|
||||
boolean changed = false;
|
||||
final CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
|
||||
StackInfo.pauseItemDamageSound(true);
|
||||
|
||||
@@ -48,9 +49,19 @@ public class AutoCraftingManager {
|
||||
if (handler != null && handler.canCraft(guiContainer)) {
|
||||
long multiplier = entry.getValue();
|
||||
|
||||
while (multiplier > 0 && !interrupted(guiContainer)
|
||||
&& handler.craft(guiContainer, (int) Math.min(64, multiplier))) {
|
||||
multiplier -= 64;
|
||||
while (multiplier > 0 && !interrupted(guiContainer)) {
|
||||
final CraftRampThrottle.Tick tick = throttle.next(entry.getKey());
|
||||
sleepInterruptibly(tick.delayMs, guiContainer);
|
||||
if (interrupted(guiContainer)) break;
|
||||
|
||||
boolean crafted = false;
|
||||
for (int i = 0; i < tick.crafts && multiplier > 0 && !interrupted(guiContainer); i++) {
|
||||
if (!handler.craft(guiContainer, 1)) break;
|
||||
multiplier -= 1;
|
||||
crafted = true;
|
||||
}
|
||||
|
||||
if (!crafted) break; // output couldn't be taken (e.g. inventory full)
|
||||
}
|
||||
|
||||
craft = multiplier != entry.getValue();
|
||||
@@ -86,6 +97,19 @@ public class AutoCraftingManager {
|
||||
return interrupted() || guiContainer != NEIClientUtils.getGuiContainer();
|
||||
}
|
||||
|
||||
private void sleepInterruptibly(long delayMs, GuiContainer guiContainer) {
|
||||
long remaining = delayMs;
|
||||
while (remaining > 0 && !interrupted(guiContainer)) {
|
||||
final long chunk = Math.min(20L, remaining);
|
||||
try {
|
||||
Thread.sleep(chunk);
|
||||
} catch (InterruptedException ignored) {
|
||||
return;
|
||||
}
|
||||
remaining -= chunk;
|
||||
}
|
||||
}
|
||||
|
||||
private List<BookmarkItem> prepareInitialItems(RecipeChainMath math, ItemStackAmount inventory) {
|
||||
final List<BookmarkItem> initialItems = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
|
||||
/**
|
||||
* Per-craft delay ramp for auto-crafting. Crafting a recipe repeatedly speeds up (delay decays geometrically toward a
|
||||
* floor). Momentum is global: switching to a different recipe reduces speed by a penalty but does not reset it, so
|
||||
* going back to a recipe resumes with most of its momentum. At floor (max) speed crafts are batched. Pure logic; does
|
||||
* not sleep.
|
||||
*/
|
||||
public class CraftRampThrottle {
|
||||
|
||||
public static final long START_DELAY_MS = 300L; // delay before the 1st craft
|
||||
public static final long FLOOR_DELAY_MS = 100L; // fastest allowed (cap)
|
||||
public static final double DECAY = 0.88D; // per-craft speedup
|
||||
public static final double SWITCH_PENALTY = 2.0D; // momentum lost on recipe change
|
||||
public static final int BULK_CRAFTS = 4; // crafts per tick once maxed out
|
||||
|
||||
/** Delay to wait before a craft, and how many crafts that tick covers. */
|
||||
public static final class Tick {
|
||||
|
||||
public final long delayMs;
|
||||
public final int crafts;
|
||||
|
||||
Tick(long delayMs, int crafts) {
|
||||
this.delayMs = delayMs;
|
||||
this.crafts = crafts;
|
||||
}
|
||||
}
|
||||
|
||||
private RecipeId current;
|
||||
private long delayMs = START_DELAY_MS;
|
||||
|
||||
/** Next tick for {@code id}: decays on repeat, slows (but keeps momentum) on a recipe change. */
|
||||
public Tick next(RecipeId id) {
|
||||
if (!Objects.equals(id, this.current)) {
|
||||
if (this.current != null) {
|
||||
this.delayMs = Math.min(START_DELAY_MS, Math.round(this.delayMs * SWITCH_PENALTY));
|
||||
}
|
||||
this.current = id;
|
||||
}
|
||||
|
||||
final long delay = this.delayMs;
|
||||
this.delayMs = Math.max(FLOOR_DELAY_MS, Math.round(delay * DECAY));
|
||||
return new Tick(delay, delay <= FLOOR_DELAY_MS ? BULK_CRAFTS : 1);
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,12 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
|
||||
if (craftingSlot.getHasStack() && craftingSlot.canTakeStack(firstGui.mc.thePlayer)) {
|
||||
FastTransferManager.clickSlot(firstGui, craftingSlot.slotNumber, 0, 1);
|
||||
|
||||
// Output still present means it wasn't taken (e.g. inventory full); stop.
|
||||
if (craftingSlot.getHasStack()) {
|
||||
break;
|
||||
}
|
||||
|
||||
craft = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ import codechicken.nei.PositionedStack;
|
||||
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.VisiblityData;
|
||||
import codechicken.nei.Widget;
|
||||
import codechicken.nei.api.IGuiContainerOverlay;
|
||||
@@ -56,7 +54,6 @@ 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.search.SearchExpressionUtils;
|
||||
import codechicken.nei.util.EmptyContainer;
|
||||
import codechicken.nei.util.SlotInaccessible;
|
||||
|
||||
@@ -176,59 +173,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
return true;
|
||||
}
|
||||
|
||||
@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 + ">"));
|
||||
|
||||
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 + "\""));
|
||||
} 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));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -816,10 +760,6 @@ public abstract class GuiRecipe<H extends IRecipeHandler> extends GuiContainer i
|
||||
|
||||
this.recipeTabs.handleTooltip(mousex, mousey, currenttip);
|
||||
|
||||
if (this.handler != null && this.handler.searchingAvailable()) {
|
||||
currenttip = GuiRecipe.toggleSearch.handleTooltip(mousex, mousey, currenttip);
|
||||
}
|
||||
|
||||
if (currenttip.isEmpty() && isHandlerTitleHovered(mousex, mousey)) {
|
||||
currenttip.add(NEIClientUtils.translate("recipe.tab.view_all.tooltip"));
|
||||
}
|
||||
|
||||
@@ -252,20 +252,13 @@ public class ItemUntranslator {
|
||||
return this.processedNames.computeIfAbsent(guidKey, stackKey -> {
|
||||
String displayName = this.secondNames.get(stackKey);
|
||||
|
||||
try {
|
||||
|
||||
if (displayName == null) {
|
||||
final String guid = findBestGUIDForLookup(stack);
|
||||
displayName = this.secondNames
|
||||
.computeIfAbsent(guid == null ? stackKey : guid, g -> getFallbackDisplayName(stack));
|
||||
}
|
||||
|
||||
return displayName.equals(stripFormatting(stack.getDisplayName())) ? "" : displayName;
|
||||
} catch (Throwable e) {
|
||||
NEIClientConfig.logger.warn("Failed to get display name for itemstack {}", stack, e);
|
||||
if (displayName == null) {
|
||||
final String guid = findBestGUIDForLookup(stack);
|
||||
displayName = this.secondNames
|
||||
.computeIfAbsent(guid == null ? stackKey : guid, g -> getFallbackDisplayName(stack));
|
||||
}
|
||||
|
||||
return displayName != null ? displayName : "";
|
||||
return displayName.equals(stripFormatting(stack.getDisplayName())) ? "" : displayName;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -571,24 +571,6 @@ nei.debug.RecipeHandler.reset=Reset
|
||||
nei.recipe.page=Page %s/%s
|
||||
nei.recipe.tooltip=Recipes
|
||||
nei.recipe.tab.view_all.tooltip=View all categories
|
||||
nei.recipe.search.tooltip.name=Filter Syntax
|
||||
nei.recipe.search.tooltip.shift=§7Hold §6Shift§7 for more info
|
||||
nei.recipe.search.tooltip.input=%s§ftext§8 - §7search in inputs
|
||||
nei.recipe.search.tooltip.output=%s§ftext§8 - §7search in outputs
|
||||
nei.recipe.search.tooltip.prefix=%stext§8 - §7%s
|
||||
|
||||
nei.recipe.search.tooltip.prefix.modName=search by mod
|
||||
nei.recipe.search.tooltip.prefix.tooltip=search by tooltip
|
||||
nei.recipe.search.tooltip.prefix.oreDict=search by ore dict
|
||||
nei.recipe.search.tooltip.prefix.identifier=search by resource ID
|
||||
nei.recipe.search.tooltip.prefix.subsets=search by subsets
|
||||
nei.recipe.search.tooltip.prefix.chemicalFormula=search by chemical formula
|
||||
|
||||
nei.recipe.search.tooltip.exclude=%s§ftext§8 - §7exclude items with text
|
||||
nei.recipe.search.tooltip.exclude_recipe=%s§ftext§8 - §7exclude recipes with text
|
||||
nei.recipe.search.tooltip.or=§fa%s§fb§8 - §7match a or b
|
||||
nei.recipe.search.tooltip.exact=%s§ftext%s§8 - §7match exact phrase
|
||||
|
||||
nei.recipe.shaped=Shaped Crafting
|
||||
nei.recipe.shapeless=Shapeless Crafting
|
||||
nei.recipe.furnace=Smelting
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package codechicken.nei.recipe;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import codechicken.nei.recipe.CraftRampThrottle.Tick;
|
||||
import codechicken.nei.recipe.Recipe.RecipeId;
|
||||
|
||||
class CraftRampThrottleTest {
|
||||
|
||||
private static Tick rampToFloor(CraftRampThrottle throttle, RecipeId id) {
|
||||
Tick tick = null;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
tick = throttle.next(id);
|
||||
}
|
||||
return tick;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("first craft of a recipe uses the start delay and is single")
|
||||
void firstCraftUsesStartDelay() {
|
||||
CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
RecipeId id = mock(RecipeId.class);
|
||||
|
||||
Tick tick = throttle.next(id);
|
||||
assertEquals(CraftRampThrottle.START_DELAY_MS, tick.delayMs);
|
||||
assertEquals(1, tick.crafts);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("same recipe decays monotonically and clamps at floor")
|
||||
void rampDecaysToFloor() {
|
||||
CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
RecipeId id = mock(RecipeId.class);
|
||||
|
||||
long prev = Long.MAX_VALUE;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
long delay = throttle.next(id).delayMs;
|
||||
assertTrue(delay <= prev, "delay should not increase while ramping");
|
||||
assertTrue(delay >= CraftRampThrottle.FLOOR_DELAY_MS, "delay should not drop below floor");
|
||||
prev = delay;
|
||||
}
|
||||
|
||||
assertEquals(CraftRampThrottle.FLOOR_DELAY_MS, rampToFloor(throttle, id).delayMs);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("at floor speed, crafts happen in bulk")
|
||||
void bulkAtFloorSpeed() {
|
||||
CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
RecipeId id = mock(RecipeId.class);
|
||||
|
||||
Tick tick = rampToFloor(throttle, id);
|
||||
assertEquals(CraftRampThrottle.FLOOR_DELAY_MS, tick.delayMs);
|
||||
assertEquals(CraftRampThrottle.BULK_CRAFTS, tick.crafts);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("crafts stay single while still ramping")
|
||||
void singleWhileRamping() {
|
||||
CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
RecipeId id = mock(RecipeId.class);
|
||||
|
||||
assertEquals(1, throttle.next(id).crafts);
|
||||
assertEquals(1, throttle.next(id).crafts);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("recipe change reduces momentum but does not fully reset")
|
||||
void recipeChangeReducesMomentum() {
|
||||
CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
RecipeId a = mock(RecipeId.class);
|
||||
RecipeId b = mock(RecipeId.class);
|
||||
|
||||
// Ramp A to full speed (floor).
|
||||
assertEquals(CraftRampThrottle.FLOOR_DELAY_MS, rampToFloor(throttle, a).delayMs);
|
||||
|
||||
// Switching to B slows down, but keeps momentum: slower than floor, faster than a cold start.
|
||||
long afterSwitch = throttle.next(b).delayMs;
|
||||
assertTrue(afterSwitch > CraftRampThrottle.FLOOR_DELAY_MS, "switch should reduce momentum");
|
||||
assertTrue(afterSwitch < CraftRampThrottle.START_DELAY_MS, "switch should not fully reset");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user