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