Compare commits

..

5 Commits

Author SHA1 Message Date
PrototypeTrousers f13d7f351d fix container items breaking not being taken into account during simulation properly
optimize crafting with container items by checking IF WE HAVE ANY of before LOOKING UP IF THE RECIPE MATCHES with the item we DONT HAVE
2023-07-03 15:30:05 -03:00
PrototypeTrousers 086ddd5a67 shady optimization 2023-06-29 15:21:33 -03:00
PrototypeTrousers acb1d00197 attempt to separate itens used simulation (threaded) from the main 2023-06-29 12:53:32 -03:00
PrototypeTrousers 4aaa3f8929 make container itens not arrive too late or early instead precisely when
they are meant to
2023-06-29 12:51:04 -03:00
PrototypeTrousers cba89b0323 fix damageable container items not being returned immediately for simulation 2023-06-27 11:47:23 -03:00
5 changed files with 118 additions and 148 deletions
@@ -319,6 +319,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
this.searchField.setText(memoryText); this.searchField.setText(memoryText);
this.searchField.selectAll(); this.searchField.selectAll();
this.repo.setSearchString(memoryText); this.repo.setSearchString(memoryText);
this.repo.updateView();
this.setScrollBar(); this.setScrollBar();
} }
@@ -380,6 +381,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) { if (btn == 1 && this.searchField.isMouseIn(xCoord, yCoord)) {
this.searchField.setText(""); this.searchField.setText("");
this.repo.setSearchString(""); this.repo.setSearchString("");
this.repo.updateView();
this.setScrollBar(); this.setScrollBar();
} }
@@ -474,6 +476,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
if (this.searchField.textboxKeyTyped(character, key)) { if (this.searchField.textboxKeyTyped(character, key)) {
this.repo.setSearchString(this.searchField.getText()); this.repo.setSearchString(this.searchField.getText());
this.repo.updateView();
this.setScrollBar(); this.setScrollBar();
// tell forge the key event is handled and should not be sent out // tell forge the key event is handled and should not be sent out
this.keyHandled = mouseInGui; this.keyHandled = mouseInGui;
+61 -115
View File
@@ -37,7 +37,7 @@ import net.minecraft.item.ItemStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@@ -45,7 +45,7 @@ import java.util.regex.Pattern;
public class ItemRepo { public class ItemRepo {
private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList(); private final IItemList<IAEItemStack> list = AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList();
private List<IAEItemStack> view = new ArrayList<>(); private final ArrayList<IAEItemStack> view = new ArrayList<>();
private final IScrollSource src; private final IScrollSource src;
private final ISortSource sortSrc; private final ISortSource sortSrc;
@@ -56,16 +56,6 @@ public class ItemRepo {
private String innerSearch = ""; private String innerSearch = "";
private boolean hasPower; private boolean hasPower;
private Enum lastView;
private Enum lastSearchMode;
private Enum lastSortBy;
private Enum lastSortDir;
private String lastSearch = "";
private boolean resort = true;
private boolean changed = false;
public ItemRepo(final IScrollSource src, final ISortSource sortSrc) { public ItemRepo(final IScrollSource src, final ISortSource sortSrc) {
this.src = src; this.src = src;
this.sortSrc = sortSrc; this.sortSrc = sortSrc;
@@ -93,8 +83,6 @@ public class ItemRepo {
} else { } else {
this.list.add(is); this.list.add(is);
} }
changed = true;
} }
public long getItemCount(final IAEItemStack is) { public long getItemCount(final IAEItemStack is) {
@@ -108,84 +96,18 @@ public class ItemRepo {
} }
public void updateView() { public void updateView() {
this.view.clear();
this.view.ensureCapacity(this.list.size());
final Enum viewMode = this.sortSrc.getSortDisplay(); final Enum viewMode = this.sortSrc.getSortDisplay();
if (lastView != viewMode) {
resort = true;
lastView = viewMode;
}
final Enum searchMode = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE); final Enum searchMode = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_MODE);
if (lastSearchMode != searchMode) { final boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE;
resort = true;
lastSearchMode = searchMode;
}
if (searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP) { if (searchMode == SearchBoxMode.JEI_AUTOSEARCH || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH || searchMode == SearchBoxMode.JEI_AUTOSEARCH_KEEP || searchMode == SearchBoxMode.JEI_MANUAL_SEARCH_KEEP) {
this.updateJEI(this.searchString); this.updateJEI(this.searchString);
} }
if (!lastSearch.equals(searchString)) {
resort = true;
lastSearch = searchString;
}
final Enum sortBy = this.sortSrc.getSortBy();
final Enum sortDir = this.sortSrc.getSortDir();
if (lastSortBy != sortBy) {
resort = true;
lastSortBy = sortBy;
}
if (lastSortDir != sortDir) {
resort = true;
lastSortDir = sortDir;
}
if (changed || resort) {
changed = false;
resort = false;
view = new ArrayList<>();
ItemSorters.setDirection((appeng.api.config.SortDir) sortDir);
ItemSorters.init();
Comparator<IAEItemStack> c = getComparator(sortBy);
for (IAEItemStack is : this.list) {
addIAE(is, viewMode);
}
view.sort(c);
}
}
private static Comparator<IAEItemStack> getComparator(Enum sortBy) {
Comparator<IAEItemStack> c;
if (sortBy == SortOrder.MOD) {
c = ItemSorters.CONFIG_BASED_SORT_BY_MOD;
} else if (sortBy == SortOrder.AMOUNT) {
c = ItemSorters.CONFIG_BASED_SORT_BY_SIZE;
} else if (sortBy == SortOrder.INVTWEAKS) {
if (InventoryBogoSortModule.isLoaded()) {
c = InventoryBogoSortModule.COMPARATOR;
} else {
c = ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS;
}
} else {
c = ItemSorters.CONFIG_BASED_SORT_BY_NAME;
}
return c;
}
private void addIAE(IAEItemStack is, Enum viewMode) {
final boolean needsZeroCopy = viewMode == ViewItems.CRAFTABLE;
final boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO; final boolean terminalSearchToolTips = AEConfig.instance().getConfigManager().getSetting(Settings.SEARCH_TOOLTIPS) != YesNo.NO;
boolean searchMod = false; boolean searchMod = false;
@@ -207,52 +129,76 @@ public class ItemRepo {
} }
} }
if (this.myPartitionList != null) { boolean notDone = false;
if (!this.myPartitionList.isListed(is)) { for (IAEItemStack is : this.list) {
return; if (this.myPartitionList != null) {
if (!this.myPartitionList.isListed(is)) {
continue;
}
} }
}
if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) { if (viewMode == ViewItems.CRAFTABLE && !is.isCraftable()) {
return; continue;
} }
if (viewMode == ViewItems.STORED && is.getStackSize() == 0) { if (viewMode == ViewItems.STORED && is.getStackSize() == 0) {
return; continue;
} }
final String dspName = (searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is)).toLowerCase(); final String dspName = (searchMod ? Platform.getModId(is) : Platform.getItemDisplayName(is)).toLowerCase();
boolean foundMatchingItemStack = true; boolean foundMatchingItemStack = true;
for (String term : innerSearch.split(" ")) { for (String term : innerSearch.split(" ")) {
if (term.length() > 1 && (term.startsWith("-") || term.startsWith("!"))) { if (term.length() > 1 && (term.startsWith("-") || term.startsWith("!"))) {
term = term.substring(1); term = term.substring(1);
if (dspName.contains(term)) { if (dspName.contains(term)) {
foundMatchingItemStack = false;
break;
}
} else if (!dspName.contains(term)) {
foundMatchingItemStack = false; foundMatchingItemStack = false;
break; break;
} }
} else if (!dspName.contains(term)) {
foundMatchingItemStack = false;
break;
} }
}
if (terminalSearchToolTips && !foundMatchingItemStack) { if (terminalSearchToolTips && !foundMatchingItemStack) {
final List<String> tooltip = Platform.getTooltip(is); final List<String> tooltip = Platform.getTooltip(is);
for (final String line : tooltip) { for (final String line : tooltip) {
if (m.matcher(line).find()) { if (m.matcher(line).find()) {
foundMatchingItemStack = true; foundMatchingItemStack = true;
break; break;
}
} }
} }
if (foundMatchingItemStack) {
if (needsZeroCopy) {
is = is.copy();
is.setStackSize(0);
}
this.view.add(is);
}
} }
if (foundMatchingItemStack) { final Enum SortBy = this.sortSrc.getSortBy();
if (needsZeroCopy) { final Enum SortDir = this.sortSrc.getSortDir();
is = is.copy();
is.setStackSize(0); ItemSorters.setDirection((appeng.api.config.SortDir) SortDir);
ItemSorters.init();
if (SortBy == SortOrder.MOD) {
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_MOD);
} else if (SortBy == SortOrder.AMOUNT) {
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_SIZE);
} else if (SortBy == SortOrder.INVTWEAKS) {
if (InventoryBogoSortModule.isLoaded()) {
Collections.sort(this.view, InventoryBogoSortModule.COMPARATOR);
} else {
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_INV_TWEAKS);
} }
this.view.add(is); } else {
Collections.sort(this.view, ItemSorters.CONFIG_BASED_SORT_BY_NAME);
} }
} }
@@ -32,13 +32,14 @@ import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketInformPlayer; import appeng.core.sync.packets.PacketInformPlayer;
import appeng.me.cluster.implementations.CraftingCPUCluster; import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.Platform; import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.fml.common.Optional;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.LinkedList;
import java.util.List; import java.util.List;
public class CraftingTreeNode { public class CraftingTreeNode {
@@ -111,14 +112,16 @@ public class CraftingTreeNode {
this.what.setStackSize(l); this.what.setStackSize(l);
if (this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable()) { if (this.getSlot() >= 0 && this.parent != null && this.parent.details.isCraftable()) {
Collection<IAEItemStack> itemList = new ArrayList<>(); LinkedList<IAEItemStack> itemList = new LinkedList<>();
boolean damageableItem = this.what.getItem().isDamageable() || Platform.isGTDamageableItem(this.what.getItem()); boolean damageableItem = this.what.getItem().isDamageable() || Platform.isGTDamageableItem(this.what.getItem());
if (this.parent.details.canSubstitute()) { if (this.parent.details.canSubstitute()) {
for (IAEItemStack subs : this.parent.details.getSubstituteInputs(this.slot)) { for (IAEItemStack subs : this.parent.details.getSubstituteInputs(this.slot)) {
if (damageableItem) { if (damageableItem) {
itemList.addAll(inventoryList.findFuzzy(subs, FuzzyMode.IGNORE_ALL)); for (IAEItemStack i : inventoryList.findFuzzy(subs, FuzzyMode.IGNORE_ALL)) {
itemList.add(i);
}
} }
subs = inventoryList.findPrecise(subs); subs = inventoryList.findPrecise(subs);
if (subs != null) { if (subs != null) {
@@ -127,7 +130,9 @@ public class CraftingTreeNode {
} }
} else { } else {
if (damageableItem) { if (damageableItem) {
itemList.addAll(inventoryList.findFuzzy(this.what, FuzzyMode.IGNORE_ALL)); for (IAEItemStack i : inventoryList.findFuzzy(this.what, FuzzyMode.IGNORE_ALL)) {
itemList.add(i);
}
} else { } else {
final IAEItemStack item = inventoryList.findPrecise(this.what); final IAEItemStack item = inventoryList.findPrecise(this.what);
if (item != null) { if (item != null) {
@@ -137,13 +142,25 @@ public class CraftingTreeNode {
} }
for (IAEItemStack fuzz : itemList) { for (IAEItemStack fuzz : itemList) {
if (this.parent.details.isValidItemForSlot(this.getSlot(), fuzz.copy().getCachedItemStack(1), this.world)) { if (fuzz.getStackSize() == 0) {
continue;
}
if (this.parent.details.isValidItemForSlot(this.getSlot(), fuzz.getDefinition(), this.world)) {
fuzz = fuzz.copy(); fuzz = fuzz.copy();
fuzz.setStackSize(l); fuzz.setStackSize(l);
final IAEItemStack available = inv.extractItems(fuzz, Actionable.MODULATE, src); final IAEItemStack available = inv.extractItems(fuzz, Actionable.MODULATE, src);
if (available != null) { if (available != null) {
if (available.getItem().hasContainerItem(available.getDefinition())) {
final ItemStack is2 = Platform.getContainerItem(available.createItemStack());
final IAEItemStack o = AEItemStack.fromItemStack(is2);
if (o != null) {
this.parent.addContainers(o);
}
}
if (!this.exhausted) { if (!this.exhausted) {
final IAEItemStack is = this.job.checkUse(available); final IAEItemStack is = this.job.checkUse(available);
@@ -197,6 +214,16 @@ public class CraftingTreeNode {
final IAEItemStack available = inv.extractItems(madeWhat, Actionable.MODULATE, src); final IAEItemStack available = inv.extractItems(madeWhat, Actionable.MODULATE, src);
if (available != null) { if (available != null) {
if (parent != null && available.getItem().hasContainerItem(available.getDefinition())) {
final ItemStack is2 = Platform.getContainerItem(available.createItemStack());
final IAEItemStack o = AEItemStack.fromItemStack(is2);
if (o != null) {
this.parent.addContainers(o);
}
}
this.bytes += available.getStackSize(); this.bytes += available.getStackSize();
l -= available.getStackSize(); l -= available.getStackSize();
@@ -240,6 +267,14 @@ public class CraftingTreeNode {
if (job.isSimulation()) { if (job.isSimulation()) {
this.bytes += l; this.bytes += l;
if (parent != null && this.what.getItem().hasContainerItem(this.what.getDefinition())) {
final ItemStack is2 = Platform.getContainerItem(this.what.copy().setStackSize(1).createItemStack());
final IAEItemStack o = AEItemStack.fromItemStack(is2);
if (o != null) {
this.parent.addContainers(o);
}
}
this.missing += l; this.missing += l;
final IAEItemStack rv = this.what.copy(); final IAEItemStack rv = this.what.copy();
rv.setStackSize(l); rv.setStackSize(l);
@@ -27,15 +27,11 @@ import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.me.cluster.implementations.CraftingCPUCluster; import appeng.me.cluster.implementations.CraftingCPUCluster;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableCollection;
import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; import it.unimi.dsi.fastutil.objects.Object2LongArrayMap;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -50,6 +46,7 @@ public class CraftingTreeProcess {
boolean possible = true; boolean possible = true;
private long crafts = 0; private long crafts = 0;
private long bytes = 0; private long bytes = 0;
private ArrayList<IAEItemStack> containers;
public CraftingTreeProcess(final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth) { public CraftingTreeProcess(final ICraftingGrid cc, final CraftingJob job, final ICraftingPatternDetails details, final CraftingTreeNode craftingTreeNode, final int depth) {
this.parent = craftingTreeNode; this.parent = craftingTreeNode;
@@ -198,32 +195,18 @@ public class CraftingTreeProcess {
void request(final MECraftingInventory inv, final long amountOfTimes, final IActionSource src) throws CraftBranchFailure, InterruptedException { void request(final MECraftingInventory inv, final long amountOfTimes, final IActionSource src) throws CraftBranchFailure, InterruptedException {
addProcess(); addProcess();
this.job.handlePausing(); this.job.handlePausing();
List<IAEItemStack> containerItems = null;
// request and remove inputs... // request and remove inputs...
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) { for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
final IAEItemStack stack = entry.getKey().request(inv, entry.getValue() * amountOfTimes, src); final IAEItemStack stack = entry.getKey().request(inv, entry.getValue() * amountOfTimes, src);
if (this.details.isCraftable() && stack.getItem().hasContainerItem(stack.getDefinition())) {
final ItemStack is = Platform.getContainerItem(stack.createItemStack());
final IAEItemStack o = AEItemStack.fromItemStack(is);
if (o != null) {
if (containerItems == null) {
containerItems = new ArrayList<>();
}
this.bytes++;
o.setCachedItemStack(is);
containerItems.add(o);
}
}
} }
if (containerItems != null) { if (this.containers != null) {
for (IAEItemStack i : containerItems) { for (IAEItemStack iae : containers) {
inv.injectItems(i, Actionable.MODULATE, src); inv.injectItems(iae, Actionable.MODULATE, src);
} }
containers = null;
} }
// assume its possible. // assume its possible.
// add crafting results.. // add crafting results..
@@ -235,6 +218,13 @@ public class CraftingTreeProcess {
this.crafts += amountOfTimes; this.crafts += amountOfTimes;
} }
public void addContainers(IAEItemStack container) {
if (this.containers == null) {
this.containers = new ArrayList<>();
}
this.containers.add(container);
}
void dive(final CraftingJob job) { void dive(final CraftingJob job) {
job.addTask(this.getAmountCrafted(this.parent.getStack(1)), this.crafts, this.details, this.depth); job.addTask(this.getAmountCrafted(this.parent.getStack(1)), this.crafts, this.details, this.depth);
for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) { for (final Entry<CraftingTreeNode, Long> entry : this.nodes.object2LongEntrySet()) {
@@ -74,13 +74,11 @@ public class MultiCraftingTracker {
public boolean handleCrafting(final int x, final long itemToCraft, final IAEItemStack ais, final InventoryAdaptor d, final World w, final IGrid g, final ICraftingGrid cg, final IActionSource mySrc) { public boolean handleCrafting(final int x, final long itemToCraft, final IAEItemStack ais, final InventoryAdaptor d, final World w, final IGrid g, final ICraftingGrid cg, final IActionSource mySrc) {
if (ais != null) { if (ais != null) {
ItemStack inputStack = ais.getCachedItemStack(ais.getStackSize()); ItemStack inputStack = ais.createItemStack();
ItemStack remaining = d.simulateAdd(inputStack); ItemStack remaining = d.simulateAdd(inputStack);
if (remaining.isEmpty()) { if (remaining.isEmpty()) {
ais.setCachedItemStack(inputStack);
final Future<ICraftingJob> craftingJob = this.getJob(x); final Future<ICraftingJob> craftingJob = this.getJob(x);
if (this.getLink(x) != null) { if (this.getLink(x) != null) {
@@ -117,8 +115,6 @@ public class MultiCraftingTracker {
this.setJob(x, cg.beginCraftingJob(w, g, mySrc, aisC, null)); this.setJob(x, cg.beginCraftingJob(w, g, mySrc, aisC, null));
} }
} }
} else {
ais.setCachedItemStack(remaining);
} }
} }
return false; return false;