mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-19 20:00:00 +00:00
Various CPU and RAM improvements (#1015)
Co-authored-by: Martin Robertz <[email protected]>
This commit is contained in:
1 parent
866b796411
commit
3f38e6f39b
9 files changed
+236
-54
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ItemsGridTest {
|
||||
|
||||
@Test
|
||||
void synchronizesOverlapAndCaptureRefresh() {
|
||||
TestGrid grid = new TestGrid();
|
||||
ItemsGrid.ScreenCapture capture = mock(ItemsGrid.ScreenCapture.class);
|
||||
grid.screenCapture = capture;
|
||||
|
||||
grid.setGridSize(1, 2, 18, 18);
|
||||
grid.setGridSize(1, 2, 18, 18);
|
||||
verify(capture, times(1)).refreshBuffer();
|
||||
|
||||
when(capture.needRefresh(1)).thenReturn(false, true);
|
||||
grid.refresh(null);
|
||||
grid.refresh(null);
|
||||
assertEquals(1, grid.overlapRefreshes);
|
||||
}
|
||||
|
||||
private static final class TestGrid extends ItemsGrid<ItemsGrid.ItemsGridSlot, ItemsGrid.MouseContext> {
|
||||
|
||||
private int overlapRefreshes;
|
||||
|
||||
@Override
|
||||
protected int getGridRenderingCacheMode() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateGuiOverlapSlots(GuiContainer gui) {
|
||||
overlapRefreshes++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemsGrid.ItemsGridSlot> getMask() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemsGrid.MouseContext getMouseContext(int mousex, int mousey) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package codechicken.nei;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import net.minecraft.client.renderer.InventoryEffectRenderer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class NEIPotionGuiHandlerTest {
|
||||
|
||||
@Test
|
||||
void preservesGapsBetweenPotionBoxes() {
|
||||
assertTrue(NEIPotionGuiHandler.intersectsPotionEffects(131, 1, 100, 2, 33));
|
||||
assertFalse(NEIPotionGuiHandler.intersectsPotionEffects(132, 1, 100, 2, 33));
|
||||
}
|
||||
|
||||
@Test
|
||||
void skipsConfigLookupOutsidePotionColumn() {
|
||||
InventoryEffectRenderer gui = mock(InventoryEffectRenderer.class);
|
||||
gui.guiLeft = 200;
|
||||
|
||||
assertFalse(new NEIPotionGuiHandler().hideItemPanelSlot(gui, 216, 100, 1, 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package codechicken.nei.api;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import codechicken.lib.vec.Rectangle4i;
|
||||
|
||||
public class GuiInfoTest {
|
||||
|
||||
@Test
|
||||
void checksProvidedHandlerSnapshot() {
|
||||
GuiContainer gui = mock(GuiContainer.class);
|
||||
INEIGuiHandler handler = mock(INEIGuiHandler.class);
|
||||
when(handler.hideItemPanelSlot(gui, 1, 2, 3, 4)).thenReturn(true);
|
||||
|
||||
assertTrue(GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(1, 2, 3, 4), new INEIGuiHandler[] { handler }));
|
||||
}
|
||||
|
||||
@Test
|
||||
void buttonEdgeContactDoesNotOverlap() {
|
||||
GuiContainer gui = mock(GuiContainer.class);
|
||||
gui.buttonList = Collections.singletonList(new GuiButton(0, 10, 10, 10, 10, ""));
|
||||
|
||||
assertTrue(GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(19, 19, 1, 1), new INEIGuiHandler[0]));
|
||||
assertFalse(GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(20, 10, 1, 1), new INEIGuiHandler[0]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package codechicken.nei.guihook;
|
||||
|
||||
import static org.mockito.Mockito.mockStatic;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.mockito.MockedStatic;
|
||||
|
||||
public class GuiContainerManagerTest {
|
||||
|
||||
@Test
|
||||
void matrixStackLoggingSupportsNestedContexts() {
|
||||
try (MockedStatic<GL11> gl = mockStatic(GL11.class)) {
|
||||
GuiContainerManager.enableMatrixStackLogging();
|
||||
GuiContainerManager.enableMatrixStackLogging();
|
||||
GuiContainerManager.disableMatrixStackLogging();
|
||||
|
||||
gl.verify(() -> GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT));
|
||||
gl.verify(GL11::glPopAttrib, times(0));
|
||||
|
||||
GuiContainerManager.disableMatrixStackLogging();
|
||||
gl.verify(GL11::glPopAttrib);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user