Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public boolean toggleNodeConnection(PastelNodeBlockEntity firstNode, PastelNodeB
// we have no network yet
// => Create one
if (firstNetwork.isEmpty() && secondNetwork.isEmpty()) {
ServerPastelNetwork newNetwork = createNetwork((ServerWorld) firstNode.getWorld(), firstNode.getNodeId());
ServerPastelNetwork newNetwork = createNetwork((ServerWorld) firstNode.getWorld(), UUID.randomUUID());
newNetwork.addNode(secondNode);
secondNode.setNetworkUUID(newNetwork.getUUID());
newNetwork.addNodeAndConnect(firstNode, secondNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public class PastelNodeBlockEntity extends BlockEntity implements FilterConfigur
protected Direction cachedDirection = null;

private final List<ItemVariant> filterItems;
private final HashSet<Item> filterHashset = new HashSet<>(10);
private int nbtCheckingFilterItems = 0;
float rotationTarget, crystalRotation, lastRotationTarget, heightTarget, crystalHeight, lastHeightTarget, alphaTarget, ringAlpha, lastAlphaTarget;
long creationStamp = -1, interpTicks, interpLength = -1, spinTicks;
private State state;
Expand Down Expand Up @@ -250,6 +252,7 @@ public void updateUpgrades() {

if (filterSlotRows < oldFilterSlotCount) {
for (int i = getDrawnSlots(); i < filterItems.size(); i++) {
filterHashset.remove(filterItems.get(i).getItem());
filterItems.set(i, ItemVariant.blank());
}
}
Expand Down Expand Up @@ -351,6 +354,11 @@ public void readNbt(NbtCompound nbt) {

if (this.getNodeType().usesFilters()) {
FilterConfigurable.readFilterNbt(nbt, this.filterItems);
this.filterHashset.clear();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check: do we need to reset nbtCheckingFilterItems here?

Copy link
Contributor Author

@Aquaeyes Aquaeyes Dec 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh good point, absolutely klsdgf

this.filterItems.forEach((itemVariant) -> {
this.filterHashset.add(itemVariant.getItem());
this.updateNbtCheckingCount(itemVariant, 1);
});
}
}

Expand Down Expand Up @@ -450,9 +458,21 @@ public List<ItemVariant> getItemFilters() {

@Override
public void setFilterItem(int slot, ItemVariant item) {
updateNbtCheckingCount(item, 1);
updateNbtCheckingCount(this.filterItems.get(slot), -1);
if(Collections.frequency(this.filterItems, item) == 1) { this.filterHashset.remove(this.filterItems.get(slot).getItem()); }
this.filterItems.set(slot, item);
this.filterHashset.add(item.getItem());
}


private void updateNbtCheckingCount(ItemVariant itemVariant, int change) {
if(!itemVariant.hasNbt()) { return; }
ItemStack stack = itemVariant.toStack();
if((stack.isIn(SpectrumItemTags.TAG_FILTERING_ITEMS) && stack.hasCustomName()) || LoreHelper.hasLore(stack)) {
this.nbtCheckingFilterItems += change;
}
}

public Predicate<ItemVariant> getTransferFilterTo(PastelNodeBlockEntity other) {
if (this.getNodeType().usesFilters() && !this.hasEmptyFilter()) {
if (other.getNodeType().usesFilters() && !other.hasEmptyFilter()) {
Expand All @@ -467,8 +487,11 @@ public Predicate<ItemVariant> getTransferFilterTo(PastelNodeBlockEntity other) {
return itemVariant -> true;
}
}

private boolean filter(ItemVariant variant) {
if(nbtCheckingFilterItems == 0) {
return filterHashset.contains(variant.getItem());
}

filter: for (ItemVariant filterItem : filterItems) {
if (filterItem.isBlank()) {
continue;
Expand Down Expand Up @@ -527,15 +550,15 @@ private boolean filter(ItemVariant variant) {

public boolean testNBTPredicates(String description, ItemStack stack, ItemVariant variant) {
var tested = variant.getNbt();
var cleanString = StringUtils.trim(description).toLowerCase();
var cleanString = StringUtils.trim(description);
var pieces = StringUtils.splitByWholeSeparator(cleanString, null);
var target = pieces[0];
var predicateString = StringUtils.remove(cleanString, target); // We don't want ambiguity when checking for keywords
var predicateString = StringUtils.remove(cleanString.toLowerCase(), target); // We don't want ambiguity when checking for keywords
var source = stack.getNbt(); //No need to check if it has nbt, to get here it already had to have some.
boolean nullSourceFilter = false;

// A few corrections for ease of use
if (StringUtils.equalsAnyIgnoreCase(target, "durability", "uses"))
if (StringUtils.equalsAnyIgnoreCase(target, "durability", "uses", "damage"))
target = ItemStack.DAMAGE_KEY;

if (StringUtils.equalsAnyIgnoreCase(target, "enchs", "enchants", "enchantment")) {
Expand Down Expand Up @@ -612,7 +635,7 @@ public boolean testNBTPredicates(String description, ItemStack stack, ItemVarian
}

switch (testedData.getType()) {
case NbtElement.NUMBER_TYPE: {
case NbtElement.NUMBER_TYPE: case NbtElement.INT_TYPE: {
var testedNum = ((AbstractNbtNumber) testedData).doubleValue();

// Special damage keywords - durability is weird and counts up as it decreases
Expand Down