12
12
import net .minecraft .entity .player .EntityPlayer ;
13
13
import net .minecraft .inventory .IInventory ;
14
14
import net .minecraft .item .ItemStack ;
15
+ import net .minecraft .nbt .NBTTagCompound ;
15
16
16
17
import com .google .common .collect .ImmutableList ;
18
+ import org .jetbrains .annotations .NotNull ;
17
19
18
20
import logisticspipes .gui .hud .modules .HUDItemSink ;
19
21
import logisticspipes .interfaces .IClientInformationProvider ;
51
53
import network .rs485 .logisticspipes .module .SimpleFilter ;
52
54
import network .rs485 .logisticspipes .property .BitSetProperty ;
53
55
import network .rs485 .logisticspipes .property .BooleanProperty ;
56
+ import network .rs485 .logisticspipes .property .IBitSet ;
54
57
import network .rs485 .logisticspipes .property .InventoryProperty ;
55
58
import network .rs485 .logisticspipes .property .Property ;
59
+ import network .rs485 .logisticspipes .util .FuzzyFlag ;
60
+ import network .rs485 .logisticspipes .util .FuzzyUtil ;
56
61
57
62
@ CCType (name = "ItemSink Module" )
58
63
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 {
61
66
62
67
public final InventoryProperty filterInventory = new InventoryProperty (
63
- new ItemIdentifierInventory (9 , "Requested items" , 1 ), "" );
68
+ new ItemIdentifierInventory (9 , "Requested items" , 1 ), "" );
64
69
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" );
69
73
70
74
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 ();
76
79
77
80
private final PlayerCollectionList localModeWatchers = new PlayerCollectionList ();
78
81
private final IHUDModuleRenderer HUD = new HUDItemSink (this );
@@ -116,39 +119,39 @@ public void setDefaultRoute(Boolean isDefaultRoute) {
116
119
defaultRoute .setValue (isDefaultRoute );
117
120
if (!localModeWatchers .isEmpty ()) {
118
121
MainProxy .sendToPlayerList (
119
- PacketHandler .getPacket (ItemSinkDefault .class ).setFlag (isDefaultRoute ).setModulePos (this ),
120
- localModeWatchers );
122
+ PacketHandler .getPacket (ItemSinkDefault .class ).setFlag (isDefaultRoute ).setModulePos (this ),
123
+ localModeWatchers );
121
124
}
122
125
}
123
126
124
127
@ Override
125
128
public void registerPosition (@ Nonnull ModulePositionType slot , int positionInt ) {
126
129
super .registerPosition (slot , positionInt );
127
130
_sinkReply = new SinkReply (FixedPriority .ItemSink , 0 , true , false , 1 , 0 ,
128
- new ChassiTargetInformation (getPositionInt ()));
131
+ new ChassiTargetInformation (getPositionInt ()));
129
132
_sinkReplyDefault = new SinkReply (FixedPriority .DefaultRoute , 0 , true , true , 1 , 0 ,
130
- new ChassiTargetInformation (getPositionInt ()));
133
+ new ChassiTargetInformation (getPositionInt ()));
131
134
}
132
135
133
136
public Stream <ItemIdentifier > getAdjacentInventoriesItems () {
134
137
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 ();
142
145
}
143
146
144
147
@ Override
145
148
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 ) {
147
150
if (defaultRoute .getValue () && !allowDefault ) {
148
151
return null ;
149
152
}
150
153
if (bestPriority > _sinkReply .fixedPriority .ordinal () || (bestPriority == _sinkReply .fixedPriority .ordinal ()
151
- && bestCustomPriority >= _sinkReply .customPriority )) {
154
+ && bestCustomPriority >= _sinkReply .customPriority )) {
152
155
return null ;
153
156
}
154
157
final IPipeServiceProvider service = _service ;
@@ -170,11 +173,12 @@ public SinkReply sinksItem(@Nonnull ItemStack stack, ItemIdentifier item, int be
170
173
}
171
174
ItemIdentifier ident1 = item ;
172
175
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 )) {
174
178
ident1 = ident1 .getIgnoringData ();
175
179
ident2 = ident2 .getIgnoringData ();
176
180
}
177
- if (ignoreNBT . get (filter . getValue2 () )) {
181
+ if (FuzzyUtil . INSTANCE . get (slotFlags , FuzzyFlag . IGNORE_NBT )) {
178
182
ident1 = ident1 .getIgnoringNBT ();
179
183
ident2 = ident2 .getIgnoringNBT ();
180
184
}
@@ -188,8 +192,8 @@ public SinkReply sinksItem(@Nonnull ItemStack stack, ItemIdentifier item, int be
188
192
}
189
193
if (defaultRoute .getValue ()) {
190
194
if (bestPriority > _sinkReplyDefault .fixedPriority .ordinal () || (
191
- bestPriority == _sinkReplyDefault .fixedPriority .ordinal ()
192
- && bestCustomPriority >= _sinkReplyDefault .customPriority )) {
195
+ bestPriority == _sinkReplyDefault .fixedPriority .ordinal ()
196
+ && bestCustomPriority >= _sinkReplyDefault .customPriority )) {
193
197
return null ;
194
198
}
195
199
if (service .canUseEnergy (1 )) {
@@ -228,9 +232,9 @@ public void stopHUDWatching() {
228
232
public void startWatching (EntityPlayer player ) {
229
233
localModeWatchers .add (player );
230
234
MainProxy .sendPacketToPlayer (PacketHandler .getPacket (ModuleInventory .class )
231
- .setIdentList (ItemIdentifierStack .getListFromInventory (filterInventory )).setModulePos (this ), player );
235
+ .setIdentList (ItemIdentifierStack .getListFromInventory (filterInventory )).setModulePos (this ), player );
232
236
MainProxy .sendPacketToPlayer (
233
- PacketHandler .getPacket (ItemSinkDefault .class ).setFlag (defaultRoute .getValue ()).setModulePos (this ), player );
237
+ PacketHandler .getPacket (ItemSinkDefault .class ).setFlag (defaultRoute .getValue ()).setModulePos (this ), player );
234
238
}
235
239
236
240
@ Override
@@ -241,12 +245,12 @@ public void stopWatching(EntityPlayer player) {
241
245
@ Override
242
246
public void InventoryChanged (IInventory inventory ) {
243
247
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
+ )
250
254
);
251
255
}
252
256
@@ -279,13 +283,14 @@ public void collectSpecificInterests(@Nonnull Collection<ItemIdentifier> itemidC
279
283
continue ;
280
284
}
281
285
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 )) {
283
288
itemidCollection .add (ident .getIgnoringData ());
284
289
}
285
- if (ignoreNBT . get (stack . getValue2 () )) {
290
+ if (FuzzyUtil . INSTANCE . get (slotFlags , FuzzyFlag . IGNORE_NBT )) {
286
291
itemidCollection .add (ident .getIgnoringNBT ());
287
292
}
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 )) {
289
294
itemidCollection .add (ident .getIgnoringData ().getIgnoringNBT ());
290
295
}
291
296
}
@@ -308,20 +313,15 @@ public boolean recievePassive() {
308
313
return true ;
309
314
}
310
315
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 );
317
318
}
318
319
319
320
@ Nonnull
320
321
@ Override
321
322
public ModuleCoordinatesGuiProvider getPipeGuiProvider () {
322
323
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 ());
325
325
}
326
326
327
327
@ Nonnull
@@ -330,4 +330,27 @@ public ModuleInHandGuiProvider getInHandGuiProvider() {
330
330
return NewGuiHandler .getGui (ItemSinkInHand .class );
331
331
}
332
332
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
+ }
333
356
}
0 commit comments