Skip to content

Commit

Permalink
Merge remote-tracking branch 'michaeldoylecs/feature-shift-pause' int…
Browse files Browse the repository at this point in the history
…o dev
  • Loading branch information
Dream-Master committed Jan 12, 2025
2 parents 9f20656 + 48bb05c commit 51874d4
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,18 @@ public void onGuiClosed() {
memoryText = this.searchField.getText();
}

@Override
public void handleKeyboardInput() {
super.handleKeyboardInput();

// Pause the terminal when holding shift
this.repo.setPaused(hasShiftDown());
}

private boolean hasShiftDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
}

public void bindTextureBack(final String file) {
final ResourceLocation loc = new ResourceLocation(FluidCraft.MODID, "textures/" + file);
this.mc.getTextureManager().bindTexture(loc);
Expand Down
102 changes: 60 additions & 42 deletions src/main/java/com/glodblock/github/client/me/EssentiaRepo.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.glodblock.github.client.me;

import java.util.Iterator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

import com.glodblock.github.common.item.ItemFluidDrop;
import com.glodblock.github.crossmod.thaumcraft.AspectUtil;
Expand All @@ -15,7 +15,6 @@
import appeng.api.config.Settings;
import appeng.api.config.SortOrder;
import appeng.api.config.ViewItems;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.client.gui.widgets.IScrollSource;
import appeng.client.gui.widgets.ISortSource;
Expand All @@ -30,12 +29,61 @@ public EssentiaRepo(final IScrollSource src, final ISortSource sortSrc) {
@SuppressWarnings("deprecation")
@Override
public void updateView() {
this.view.clear();
this.dsp.clear();
if (this.paused) {
// Update existing view with new data
for (int i = 0; i < this.view.size(); i++) {
IAEItemStack entry = this.view.get(i);
IAEItemStack serverEntry = this.list.findPrecise(entry);
if (serverEntry == null) {
entry.setStackSize(0);
} else {
this.view.set(i, serverEntry);
}
}

this.view.ensureCapacity(this.list.size());
// Append newly added item stacks to the end of the view
Set<IAEItemStack> viewSet = new HashSet<>(this.view);
ArrayList<IAEItemStack> entriesToAdd = new ArrayList<>();
for (IAEItemStack serverEntry : this.list) {
if (!viewSet.contains(serverEntry)) {
entriesToAdd.add(serverEntry);
}
}
addEntriesToView(entriesToAdd);
} else {
this.view.clear();
this.view.ensureCapacity(this.list.size());
addEntriesToView(this.list);
}

// Do not sort if paused
if (!this.paused) {
final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}
}

// Update the display
this.dsp.clear();
this.dsp.ensureCapacity(this.list.size());
for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
}

private void addEntriesToView(Iterable<IAEItemStack> entries) {
final Enum<?> viewMode = this.sortSrc.getSortDisplay();
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) {
Expand All @@ -59,7 +107,11 @@ public void updateView() {
}
}

for (IAEItemStack is : this.list) {
for (IAEItemStack is : entries) {
if (!AspectUtil.isEssentiaGas(ItemFluidDrop.getAeFluidStack(is))) {
continue;
}

if (this.myPartitionList != null) {
if (!this.myPartitionList.isListed(is)) {
continue;
Expand Down Expand Up @@ -88,40 +140,6 @@ public void updateView() {
this.view.add(is);
}
}

final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}

for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
Iterator<IAEItemStack> it1 = this.view.iterator();
while (it1.hasNext()) {
IAEFluidStack fluid = ItemFluidDrop.getAeFluidStack(it1.next());
if (!AspectUtil.isEssentiaGas(fluid)) {
it1.remove();
}
}
Iterator<ItemStack> it2 = this.dsp.iterator();
while (it2.hasNext()) {
FluidStack fluid = ItemFluidDrop.getFluidStack(it2.next());
if (!AspectUtil.isEssentiaGas(fluid)) {
it2.remove();
}
}
}

}
96 changes: 72 additions & 24 deletions src/main/java/com/glodblock/github/client/me/FluidRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -52,6 +54,7 @@ public class FluidRepo implements IDisplayRepo {

protected String searchString = "";
protected IPartitionList<IAEItemStack> myPartitionList;
protected boolean paused = false;
private String NEIWord = null;
private boolean hasPower;

Expand Down Expand Up @@ -100,12 +103,60 @@ public void setViewCell(final ItemStack[] list) {
@SuppressWarnings("deprecation")
@Override
public void updateView() {
this.view.clear();
this.dsp.clear();
if (this.paused) {
// Update existing view with new data
for (int i = 0; i < this.view.size(); i++) {
IAEItemStack entry = this.view.get(i);
IAEItemStack serverEntry = this.list.findPrecise(entry);
if (serverEntry == null) {
entry.setStackSize(0);
} else {
this.view.set(i, serverEntry);
}
}

// Append newly added item stacks to the end of the view
Set<IAEItemStack> viewSet = new HashSet<>(this.view);
ArrayList<IAEItemStack> entriesToAdd = new ArrayList<>();
for (IAEItemStack serverEntry : this.list) {
if (!viewSet.contains(serverEntry)) {
entriesToAdd.add(serverEntry);
}
}
addEntriesToView(entriesToAdd);
} else {
this.view.clear();
this.view.ensureCapacity(this.list.size());
addEntriesToView(this.list);
}

// Do not sort if paused
if (!paused) {
final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

this.view.ensureCapacity(this.list.size());
if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}
}

this.dsp.clear();
this.dsp.ensureCapacity(this.list.size());
for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
}

private void addEntriesToView(Iterable<IAEItemStack> entries) {
final Enum<?> viewMode = this.sortSrc.getSortDisplay();
final Enum<?> searchMode = AEConfig.instance.settings.getSetting(Settings.SEARCH_MODE);
if (searchMode == SearchBoxMode.NEI_AUTOSEARCH || searchMode == SearchBoxMode.NEI_MANUAL_SEARCH) {
Expand All @@ -131,7 +182,7 @@ public void updateView() {
}
}

for (IAEItemStack is : this.list) {
for (IAEItemStack is : entries) {
if (this.myPartitionList != null) {
if (!this.myPartitionList.isListed(is)) {
continue;
Expand Down Expand Up @@ -168,26 +219,6 @@ public void updateView() {
}
}
}

final Enum<?> SortBy = this.sortSrc.getSortBy();
final Enum<?> SortDir = this.sortSrc.getSortDir();

FluidSorters.setDirection((appeng.api.config.SortDir) SortDir);
FluidSorters.init();

if (SortBy == SortOrder.MOD) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} else {
this.view.sort(FluidSorters.CONFIG_BASED_SORT_BY_NAME);
}

for (final IAEItemStack is : this.view) {
this.dsp.add(is.getItemStack());
}
}

protected void updateNEI(final String filter) {
Expand Down Expand Up @@ -245,4 +276,21 @@ public String getSearchString() {
public void setSearchString(@Nonnull final String searchString) {
this.searchString = searchString;
}

@Override
public boolean isPaused() {
return this.paused;
}

@Override
public void setPaused(boolean paused) {
if (this.paused != paused) {
this.paused = paused;

// Update view when un-paused
if (!paused) {
updateView();
}
}
}
}

0 comments on commit 51874d4

Please sign in to comment.