only save filter data of modified filters

Closes #26
This commit is contained in:
Ell 2020-09-02 22:06:44 +02:00
parent f5443becf8
commit b20d15c05a

View file

@ -33,6 +33,7 @@ public class ItemFilter extends ItemStackHandler {
public boolean canPopulateFromInventories;
public boolean canModifyWhitelist = true;
private boolean modified;
public ItemFilter(int size, ItemStack stack, PipeTileEntity pipe) {
super(size);
@ -73,6 +74,7 @@ public class ItemFilter extends ItemStackHandler {
public void onButtonPacket(int id) {
if (id == 0 && this.canModifyWhitelist) {
this.isWhitelist = !this.isWhitelist;
this.modified = true;
} else if (id == 1 && this.canPopulateFromInventories) {
// populate filter from inventories
for (Direction direction : Direction.values()) {
@ -88,6 +90,7 @@ public class ItemFilter extends ItemStackHandler {
ItemHandlerHelper.insertItem(this, copy, false);
}
}
this.modified = true;
}
this.save();
}
@ -117,7 +120,10 @@ public class ItemFilter extends ItemStackHandler {
}
public void save() {
this.stack.getOrCreateTag().put("filter", this.serializeNBT());
if (this.modified) {
this.stack.getOrCreateTag().put("filter", this.serializeNBT());
this.modified = false;
}
}
@Override
@ -133,6 +139,11 @@ public class ItemFilter extends ItemStackHandler {
this.isWhitelist = nbt.getBoolean("whitelist");
}
@Override
protected void onContentsChanged(int slot) {
this.modified = true;
}
public interface IFilteredContainer {
ItemFilter getFilter();
}