mirror of
https://github.com/Ellpeck/PrettyPipes.git
synced 2024-12-23 15:39:23 +01:00
backport 8ead508776
This commit is contained in:
parent
db58a7b105
commit
9ff65e3b06
3 changed files with 24 additions and 7 deletions
|
@ -38,8 +38,7 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
super(size);
|
super(size);
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.pipe = pipe;
|
this.pipe = pipe;
|
||||||
if (stack.hasTag())
|
this.load();
|
||||||
this.deserializeNBT(stack.getTag().getCompound("filter"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Slot> getSlots(int x, int y) {
|
public List<Slot> getSlots(int x, int y) {
|
||||||
|
@ -70,12 +69,13 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
return buttons;
|
return buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onButtonPacket(int id) {
|
public void onButtonPacket(IFilteredContainer menu, int id) {
|
||||||
if (id == 0 && this.canModifyWhitelist) {
|
if (id == 0 && this.canModifyWhitelist) {
|
||||||
this.isWhitelist = !this.isWhitelist;
|
this.isWhitelist = !this.isWhitelist;
|
||||||
this.modified = true;
|
this.modified = true;
|
||||||
this.save();
|
this.save();
|
||||||
} else if (id == 1 && this.canPopulateFromInventories) {
|
} else if (id == 1 && this.canPopulateFromInventories) {
|
||||||
|
boolean changed = false;
|
||||||
// populate filter from inventories
|
// populate filter from inventories
|
||||||
List<ItemFilter> filters = this.pipe.getFilters();
|
List<ItemFilter> filters = this.pipe.getFilters();
|
||||||
for (Direction direction : Direction.values()) {
|
for (Direction direction : Direction.values()) {
|
||||||
|
@ -91,12 +91,15 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
// try inserting into ourselves and any filter increase modifiers
|
// try inserting into ourselves and any filter increase modifiers
|
||||||
for (ItemFilter filter : filters) {
|
for (ItemFilter filter : filters) {
|
||||||
if (ItemHandlerHelper.insertItem(filter, copy, false).isEmpty()) {
|
if (ItemHandlerHelper.insertItem(filter, copy, false).isEmpty()) {
|
||||||
|
changed = true;
|
||||||
filter.save();
|
filter.save();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (changed)
|
||||||
|
menu.onFilterPopulated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,6 +129,11 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
if (this.stack.hasTag())
|
||||||
|
this.deserializeNBT(this.stack.getTag().getCompound("filter"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundNBT serializeNBT() {
|
public CompoundNBT serializeNBT() {
|
||||||
CompoundNBT nbt = super.serializeNBT();
|
CompoundNBT nbt = super.serializeNBT();
|
||||||
|
@ -154,6 +162,10 @@ public class ItemFilter extends ItemStackHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IFilteredContainer {
|
public interface IFilteredContainer {
|
||||||
|
|
||||||
ItemFilter getFilter();
|
ItemFilter getFilter();
|
||||||
|
|
||||||
|
default void onFilterPopulated() {}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package de.ellpeck.prettypipes.packets;
|
||||||
|
|
||||||
import de.ellpeck.prettypipes.Utility;
|
import de.ellpeck.prettypipes.Utility;
|
||||||
import de.ellpeck.prettypipes.items.IModule;
|
import de.ellpeck.prettypipes.items.IModule;
|
||||||
import de.ellpeck.prettypipes.misc.ItemFilter;
|
|
||||||
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
import de.ellpeck.prettypipes.misc.ItemFilter.IFilteredContainer;
|
||||||
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
import de.ellpeck.prettypipes.pipe.PipeTileEntity;
|
||||||
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
import de.ellpeck.prettypipes.pipe.containers.AbstractPipeContainer;
|
||||||
|
@ -100,9 +99,8 @@ public class PacketButton {
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
FILTER_CHANGE((pos, data, player) -> {
|
FILTER_CHANGE((pos, data, player) -> {
|
||||||
IFilteredContainer container = (IFilteredContainer) player.openContainer;
|
if (player.openContainer instanceof IFilteredContainer)
|
||||||
ItemFilter filter = container.getFilter();
|
((IFilteredContainer) player.openContainer).getFilter().onButtonPacket((IFilteredContainer) player.openContainer, data[0]);
|
||||||
filter.onButtonPacket(data[0]);
|
|
||||||
}),
|
}),
|
||||||
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
STACK_SIZE_MODULE_BUTTON((pos, data, player) -> {
|
||||||
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.openContainer;
|
AbstractPipeContainer<?> container = (AbstractPipeContainer<?>) player.openContainer;
|
||||||
|
|
|
@ -35,4 +35,11 @@ public class FilterModuleContainer extends AbstractPipeContainer<FilterModuleIte
|
||||||
public ItemFilter getFilter() {
|
public ItemFilter getFilter() {
|
||||||
return this.filter;
|
return this.filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFilterPopulated() {
|
||||||
|
// reload the filter so that it displays correctly on the client
|
||||||
|
this.filter.load();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue