Fix interface terminal spamming update packets due to matching the wrong name.

This commit is contained in:
Sebastian Hartte
2020-06-18 21:32:03 +02:00
parent c6af3d9a70
commit 749742a8aa
3 changed files with 34 additions and 38 deletions
@@ -24,7 +24,6 @@ import com.google.common.collect.HashMultimap;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.container.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
@@ -46,9 +45,6 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
private static final int LINES_ON_PAGE = 6;
// TODO: copied from GuiMEMonitorable. It looks not changed, maybe unneeded?
private final int offsetX = 9;
private final HashMap<Long, ClientDCInternalInv> byId = new HashMap<>();
private final HashMultimap<String, ClientDCInternalInv> byName = HashMultimap.create();
private final ArrayList<String> names = new ArrayList<>();
@@ -76,8 +72,7 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
this.getScrollBar().setHeight(106);
this.getScrollBar().setTop(18);
this.searchField = new MEGuiTextField(this.font, this.guiLeft + Math.max(104, this.offsetX), this.guiTop + 4,
65, 12);
this.searchField = new MEGuiTextField(this.font, this.guiLeft + 104, this.guiTop + 4, 65, 12);
this.searchField.setEnableBackgroundDrawing(false);
this.searchField.setMaxStringLength(25);
this.searchField.setTextColor(0xFFFFFF);
@@ -92,12 +87,7 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
final int ex = this.getScrollBar().getCurrentScroll();
final Iterator<Slot> o = this.container.inventorySlots.iterator();
while (o.hasNext()) {
if (o.next() instanceof SlotDisconnected) {
o.remove();
}
}
this.container.inventorySlots.removeIf(slot -> slot instanceof SlotDisconnected);
int offset = 17;
for (int x = 0; x < LINES_ON_PAGE && ex + x < this.lines.size(); x++) {
@@ -186,8 +176,8 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
try {
final long id = Long.parseLong(key.substring(1), Character.MAX_RADIX);
final CompoundNBT invData = in.getCompound(key);
final ClientDCInternalInv current = this.getById(id, invData.getLong("sortBy"),
invData.getString("un"));
ITextComponent un = ITextComponent.Serializer.fromJson(invData.getString("un"));
final ClientDCInternalInv current = this.getById(id, invData.getLong("sortBy"), un);
for (int x = 0; x < current.getInventory().getSlots(); x++) {
final String which = Integer.toString(x);
@@ -243,8 +233,8 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
}
// if found, filter skipped or machine name matching the search term, add it
if (found || entry.getName().toLowerCase().contains(searchFilterLowerCase)) {
this.byName.put(entry.getName(), entry);
if (found || entry.getSearchName().contains(searchFilterLowerCase)) {
this.byName.put(entry.getFormattedName(), entry);
cachedSearch.add(entry);
} else {
cachedSearch.remove(entry);
@@ -262,8 +252,7 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
for (final String n : this.names) {
this.lines.add(n);
final ArrayList<ClientDCInternalInv> clientInventories = new ArrayList<>();
clientInventories.addAll(this.byName.get(n));
List<ClientDCInternalInv> clientInventories = new ArrayList<>(this.byName.get(n));
Collections.sort(clientInventories);
this.lines.addAll(clientInventories);
@@ -337,11 +326,11 @@ public class GuiInterfaceTerminal extends AEBaseGui<ContainerInterfaceTerminal>
return this.names.size() + this.byId.size();
}
private ClientDCInternalInv getById(final long id, final long sortBy, final String string) {
private ClientDCInternalInv getById(final long id, final long sortBy, final ITextComponent name) {
ClientDCInternalInv o = this.byId.get(id);
if (o == null) {
this.byId.put(id, o = new ClientDCInternalInv(9, id, sortBy, string));
this.byId.put(id, o = new ClientDCInternalInv(9, id, sortBy, name));
this.refreshList = true;
}
@@ -20,31 +20,33 @@ package appeng.client.me;
import javax.annotation.Nonnull;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.text.ITextComponent;
import appeng.tile.inventory.AppEngInternalInventory;
public class ClientDCInternalInv implements Comparable<ClientDCInternalInv> {
private final String unlocalizedName;
private final String searchName;
private final String formattedName;
private final AppEngInternalInventory inventory;
private final long id;
private final long sortBy;
public ClientDCInternalInv(final int size, final long id, final long sortBy, final String unlocalizedName) {
public ClientDCInternalInv(final int size, final long id, final long sortBy, final ITextComponent name) {
this.inventory = new AppEngInternalInventory(null, size);
this.unlocalizedName = unlocalizedName;
this.searchName = name.getString().toLowerCase();
this.formattedName = name.getFormattedText();
this.id = id;
this.sortBy = sortBy;
}
public String getName() {
final String s = I18n.format(this.unlocalizedName + ".name");
if (s.equals(this.unlocalizedName + ".name")) {
return I18n.format(this.unlocalizedName);
}
return s;
public String getSearchName() {
return searchName;
}
public String getFormattedName() {
return formattedName;
}
@Override
@@ -59,4 +61,8 @@ public class ClientDCInternalInv implements Comparable<ClientDCInternalInv> {
public long getId() {
return this.id;
}
public boolean matchesSearch(String searchFilterLowerCase) {
return this.searchName.contains(searchFilterLowerCase);
}
}