Skip to content

Commit 30b05a1

Browse files
committed
Change ItemSinkModule fuzzyFlag property
1 parent f9f0f7b commit 30b05a1

File tree

2 files changed

+74
-57
lines changed

2 files changed

+74
-57
lines changed

common/logisticspipes/modules/ModuleItemSink.java

+71-48
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
import net.minecraft.entity.player.EntityPlayer;
1313
import net.minecraft.inventory.IInventory;
1414
import net.minecraft.item.ItemStack;
15+
import net.minecraft.nbt.NBTTagCompound;
1516

1617
import com.google.common.collect.ImmutableList;
18+
import org.jetbrains.annotations.NotNull;
1719

1820
import logisticspipes.gui.hud.modules.HUDItemSink;
1921
import logisticspipes.interfaces.IClientInformationProvider;
@@ -51,28 +53,29 @@
5153
import network.rs485.logisticspipes.module.SimpleFilter;
5254
import network.rs485.logisticspipes.property.BitSetProperty;
5355
import network.rs485.logisticspipes.property.BooleanProperty;
56+
import network.rs485.logisticspipes.property.IBitSet;
5457
import network.rs485.logisticspipes.property.InventoryProperty;
5558
import network.rs485.logisticspipes.property.Property;
59+
import network.rs485.logisticspipes.util.FuzzyFlag;
60+
import network.rs485.logisticspipes.util.FuzzyUtil;
5661

5762
@CCType(name = "ItemSink Module")
5863
public class ModuleItemSink extends LogisticsModule
59-
implements SimpleFilter, IClientInformationProvider, IHUDModuleHandler, IModuleWatchReciver,
60-
ISimpleInventoryEventHandler, IModuleInventoryReceive, Gui {
64+
implements SimpleFilter, IClientInformationProvider, IHUDModuleHandler, IModuleWatchReciver,
65+
ISimpleInventoryEventHandler, IModuleInventoryReceive, Gui {
6166

6267
public final InventoryProperty filterInventory = new InventoryProperty(
63-
new ItemIdentifierInventory(9, "Requested items", 1), "");
68+
new ItemIdentifierInventory(9, "Requested items", 1), "");
6469
public final BooleanProperty defaultRoute = new BooleanProperty(false, "defaultdestination");
65-
public final BitSetProperty ignoreData = new BitSetProperty(
66-
new BitSet(filterInventory.getSizeInventory()), "ignoreData");
67-
public final BitSetProperty ignoreNBT = new BitSetProperty(
68-
new BitSet(filterInventory.getSizeInventory()), "ignoreNBT");
70+
71+
public final BitSetProperty fuzzyFlags = new BitSetProperty(
72+
new BitSet(filterInventory.getSizeInventory() * 4), "fuzzyFlags");
6973

7074
private final List<Property<?>> properties = ImmutableList.<Property<?>>builder()
71-
.add(filterInventory)
72-
.add(defaultRoute)
73-
.add(ignoreData)
74-
.add(ignoreNBT)
75-
.build();
75+
.add(filterInventory)
76+
.add(defaultRoute)
77+
.add(fuzzyFlags)
78+
.build();
7679

7780
private final PlayerCollectionList localModeWatchers = new PlayerCollectionList();
7881
private final IHUDModuleRenderer HUD = new HUDItemSink(this);
@@ -116,39 +119,39 @@ public void setDefaultRoute(Boolean isDefaultRoute) {
116119
defaultRoute.setValue(isDefaultRoute);
117120
if (!localModeWatchers.isEmpty()) {
118121
MainProxy.sendToPlayerList(
119-
PacketHandler.getPacket(ItemSinkDefault.class).setFlag(isDefaultRoute).setModulePos(this),
120-
localModeWatchers);
122+
PacketHandler.getPacket(ItemSinkDefault.class).setFlag(isDefaultRoute).setModulePos(this),
123+
localModeWatchers);
121124
}
122125
}
123126

124127
@Override
125128
public void registerPosition(@Nonnull ModulePositionType slot, int positionInt) {
126129
super.registerPosition(slot, positionInt);
127130
_sinkReply = new SinkReply(FixedPriority.ItemSink, 0, true, false, 1, 0,
128-
new ChassiTargetInformation(getPositionInt()));
131+
new ChassiTargetInformation(getPositionInt()));
129132
_sinkReplyDefault = new SinkReply(FixedPriority.DefaultRoute, 0, true, true, 1, 0,
130-
new ChassiTargetInformation(getPositionInt()));
133+
new ChassiTargetInformation(getPositionInt()));
131134
}
132135

133136
public Stream<ItemIdentifier> getAdjacentInventoriesItems() {
134137
return Objects.requireNonNull(_service)
135-
.getAvailableAdjacent()
136-
.inventories()
137-
.stream()
138-
.map(LPNeighborTileEntityKt::getInventoryUtil)
139-
.filter(Objects::nonNull)
140-
.flatMap(invUtil -> invUtil.getItems().stream())
141-
.distinct();
138+
.getAvailableAdjacent()
139+
.inventories()
140+
.stream()
141+
.map(LPNeighborTileEntityKt::getInventoryUtil)
142+
.filter(Objects::nonNull)
143+
.flatMap(invUtil -> invUtil.getItems().stream())
144+
.distinct();
142145
}
143146

144147
@Override
145148
public SinkReply sinksItem(@Nonnull ItemStack stack, ItemIdentifier item, int bestPriority, int bestCustomPriority,
146-
boolean allowDefault, boolean includeInTransit, boolean forcePassive) {
149+
boolean allowDefault, boolean includeInTransit, boolean forcePassive) {
147150
if (defaultRoute.getValue() && !allowDefault) {
148151
return null;
149152
}
150153
if (bestPriority > _sinkReply.fixedPriority.ordinal() || (bestPriority == _sinkReply.fixedPriority.ordinal()
151-
&& bestCustomPriority >= _sinkReply.customPriority)) {
154+
&& bestCustomPriority >= _sinkReply.customPriority)) {
152155
return null;
153156
}
154157
final IPipeServiceProvider service = _service;
@@ -170,11 +173,12 @@ public SinkReply sinksItem(@Nonnull ItemStack stack, ItemIdentifier item, int be
170173
}
171174
ItemIdentifier ident1 = item;
172175
ItemIdentifier ident2 = filter.getValue1().getItem();
173-
if (ignoreData.get(filter.getValue2())) {
176+
IBitSet slotFlags = getSlotFuzzyFlags(filter.getValue2());
177+
if (FuzzyUtil.INSTANCE.get(slotFlags, FuzzyFlag.IGNORE_DAMAGE)) {
174178
ident1 = ident1.getIgnoringData();
175179
ident2 = ident2.getIgnoringData();
176180
}
177-
if (ignoreNBT.get(filter.getValue2())) {
181+
if (FuzzyUtil.INSTANCE.get(slotFlags, FuzzyFlag.IGNORE_NBT)) {
178182
ident1 = ident1.getIgnoringNBT();
179183
ident2 = ident2.getIgnoringNBT();
180184
}
@@ -188,8 +192,8 @@ public SinkReply sinksItem(@Nonnull ItemStack stack, ItemIdentifier item, int be
188192
}
189193
if (defaultRoute.getValue()) {
190194
if (bestPriority > _sinkReplyDefault.fixedPriority.ordinal() || (
191-
bestPriority == _sinkReplyDefault.fixedPriority.ordinal()
192-
&& bestCustomPriority >= _sinkReplyDefault.customPriority)) {
195+
bestPriority == _sinkReplyDefault.fixedPriority.ordinal()
196+
&& bestCustomPriority >= _sinkReplyDefault.customPriority)) {
193197
return null;
194198
}
195199
if (service.canUseEnergy(1)) {
@@ -228,9 +232,9 @@ public void stopHUDWatching() {
228232
public void startWatching(EntityPlayer player) {
229233
localModeWatchers.add(player);
230234
MainProxy.sendPacketToPlayer(PacketHandler.getPacket(ModuleInventory.class)
231-
.setIdentList(ItemIdentifierStack.getListFromInventory(filterInventory)).setModulePos(this), player);
235+
.setIdentList(ItemIdentifierStack.getListFromInventory(filterInventory)).setModulePos(this), player);
232236
MainProxy.sendPacketToPlayer(
233-
PacketHandler.getPacket(ItemSinkDefault.class).setFlag(defaultRoute.getValue()).setModulePos(this), player);
237+
PacketHandler.getPacket(ItemSinkDefault.class).setFlag(defaultRoute.getValue()).setModulePos(this), player);
234238
}
235239

236240
@Override
@@ -241,12 +245,12 @@ public void stopWatching(EntityPlayer player) {
241245
@Override
242246
public void InventoryChanged(IInventory inventory) {
243247
MainProxy.runOnServer(getWorld(), () -> () ->
244-
MainProxy.sendToPlayerList(
245-
PacketHandler.getPacket(ModuleInventory.class)
246-
.setIdentList(ItemIdentifierStack.getListFromInventory(inventory))
247-
.setModulePos(this),
248-
localModeWatchers
249-
)
248+
MainProxy.sendToPlayerList(
249+
PacketHandler.getPacket(ModuleInventory.class)
250+
.setIdentList(ItemIdentifierStack.getListFromInventory(inventory))
251+
.setModulePos(this),
252+
localModeWatchers
253+
)
250254
);
251255
}
252256

@@ -279,13 +283,14 @@ public void collectSpecificInterests(@Nonnull Collection<ItemIdentifier> itemidC
279283
continue;
280284
}
281285
ItemIdentifier ident = stack.getValue1().getItem();
282-
if (ignoreData.get(stack.getValue2())) {
286+
IBitSet slotFlags = getSlotFuzzyFlags(stack.getValue2());
287+
if (FuzzyUtil.INSTANCE.get(slotFlags, FuzzyFlag.IGNORE_DAMAGE)) {
283288
itemidCollection.add(ident.getIgnoringData());
284289
}
285-
if (ignoreNBT.get(stack.getValue2())) {
290+
if (FuzzyUtil.INSTANCE.get(slotFlags, FuzzyFlag.IGNORE_NBT)) {
286291
itemidCollection.add(ident.getIgnoringNBT());
287292
}
288-
if (ignoreData.get(stack.getValue2()) && ignoreNBT.get(stack.getValue2())) {
293+
if (FuzzyUtil.INSTANCE.get(slotFlags, FuzzyFlag.IGNORE_DAMAGE) && FuzzyUtil.INSTANCE.get(slotFlags, FuzzyFlag.IGNORE_NBT)) {
289294
itemidCollection.add(ident.getIgnoringData().getIgnoringNBT());
290295
}
291296
}
@@ -308,20 +313,15 @@ public boolean recievePassive() {
308313
return true;
309314
}
310315

311-
public void setIgnoreData(BitSet ignoreData) {
312-
this.ignoreData.replaceWith(ignoreData);
313-
}
314-
315-
public void setIgnoreNBT(BitSet ignoreNBT) {
316-
this.ignoreNBT.replaceWith(ignoreNBT);
316+
public void setFuzzyFlags(BitSet fuzzyFlags) {
317+
this.fuzzyFlags.replaceWith(fuzzyFlags);
317318
}
318319

319320
@Nonnull
320321
@Override
321322
public ModuleCoordinatesGuiProvider getPipeGuiProvider() {
322323
return NewGuiHandler.getGui(ItemSinkSlot.class).setDefaultRoute(defaultRoute.getValue())
323-
.setIgnoreData(ignoreData.copyValue()).setIgnoreNBT(ignoreNBT.copyValue())
324-
.setHasFuzzyUpgrade(getUpgradeManager().isFuzzyUpgrade());
324+
.setFuzzyFlags(fuzzyFlags.copyValue()).setHasFuzzyUpgrade(getUpgradeManager().isFuzzyUpgrade());
325325
}
326326

327327
@Nonnull
@@ -330,4 +330,27 @@ public ModuleInHandGuiProvider getInHandGuiProvider() {
330330
return NewGuiHandler.getGui(ItemSinkInHand.class);
331331
}
332332

333+
public IBitSet getSlotFuzzyFlags(int slotId) {
334+
final int startBit = slotId * 4;
335+
return fuzzyFlags.get(startBit, startBit + 3);
336+
}
337+
338+
@Override
339+
public void readFromNBT(@NotNull NBTTagCompound tag) {
340+
super.readFromNBT(tag);
341+
342+
// FIXME: remove after 1.12
343+
if (!tag.hasKey("fuzzyFlags") && tag.hasKey("ignoreData") && tag.hasKey("ignoreNBT")) {
344+
BitSet ignoreData = BitSet.valueOf(tag.getByteArray("ignoreData"));
345+
BitSet ignoreNBT = BitSet.valueOf(tag.getByteArray("ignoreNBT"));
346+
for (int i = 0; i < filterInventory.getSizeInventory(); i++) {
347+
if (i < ignoreData.size()) {
348+
fuzzyFlags.set(i * 4 + FuzzyFlag.IGNORE_DAMAGE.getBit(), ignoreData.get(i));
349+
}
350+
if (i < ignoreNBT.size()) {
351+
fuzzyFlags.set(i * 4 + FuzzyFlag.IGNORE_NBT.getBit(), ignoreNBT.get(i));
352+
}
353+
}
354+
}
355+
}
333356
}

common/logisticspipes/network/guis/module/inpipe/ItemSinkSlot.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ public class ItemSinkSlot extends ModuleCoordinatesGuiProvider {
3131

3232
@Getter
3333
@Setter
34-
private BitSet ignoreData;
35-
36-
@Getter
37-
@Setter
38-
private BitSet ignoreNBT;
34+
private BitSet fuzzyFlags;
3935

4036
public ItemSinkSlot(int id) {
4137
super(id);
@@ -46,17 +42,15 @@ public void writeData(LPDataOutput output) {
4642
super.writeData(output);
4743
output.writeBoolean(isDefaultRoute);
4844
output.writeBoolean(hasFuzzyUpgrade);
49-
output.writeBitSet(ignoreData);
50-
output.writeBitSet(ignoreNBT);
45+
output.writeBitSet(fuzzyFlags);
5146
}
5247

5348
@Override
5449
public void readData(LPDataInput input) {
5550
super.readData(input);
5651
isDefaultRoute = input.readBoolean();
5752
hasFuzzyUpgrade = input.readBoolean();
58-
ignoreData = input.readBitSet();
59-
ignoreNBT = input.readBitSet();
53+
fuzzyFlags = input.readBitSet();
6054
}
6155

6256
@Override

0 commit comments

Comments
 (0)