소스 검색

Fix tags in favorites, fix #349

Signed-off-by: shedaniel <daniel@shedaniel.me>
shedaniel 5 년 전
부모
커밋
222a297a85
3개의 변경된 파일34개의 추가작업 그리고 20개의 파일을 삭제
  1. 7 7
      gradle.properties
  2. 1 1
      src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java
  3. 26 12
      src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java

+ 7 - 7
gradle.properties

@@ -1,14 +1,14 @@
 org.gradle.jvmargs=-Xmx3G
-mod_version=4.4.2
-supported_version=1.16-pre1/2
-minecraft_version=1.16-pre2
-yarn_version=1.16-pre2+build.2+legacy.20w09a+build.8
+mod_version=4.4.3
+supported_version=1.16-pre3
+minecraft_version=1.16-pre3
+yarn_version=1.16-pre3+build.1+legacy.20w09a+build.8
 fabricloader_version=0.8.7+build.201
 cloth_events_version=2.2.0-unstable
-cloth_config_version=4.5.0-unstable
-modmenu_version=1.11.8+build.13
+cloth_config_version=4.5.2
+modmenu_version=1.12.0+build.14
 fabric_api=0.11.7+build.356-1.16
-autoconfig1u=3.0.1-unstable
+autoconfig1u=3.2.1-unstable
 api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u
 api_exculde=
 #api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations,net.fabricmc.fabric-api:fabric-

+ 1 - 1
src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java

@@ -376,7 +376,7 @@ public class EntryWidget extends Slot {
                 entry.setAmount(127);
                 if (keyCode.matchesKey(int_1, int_2)) {
                     if (reverseFavoritesAction())
-                        ConfigObject.getInstance().getFavorites().remove(entry);
+                        ConfigObject.getInstance().getFavorites().removeIf(entry::equalsIgnoreAmount);
                     else if (!CollectionUtils.anyMatchEqualsEntryIgnoreAmount(ConfigObject.getInstance().getFavorites(), entry))
                         ConfigObject.getInstance().getFavorites().add(entry);
                     ConfigManager.getInstance().saveConfig();

+ 26 - 12
src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java

@@ -41,6 +41,7 @@ import net.minecraft.client.util.math.MatrixStack;
 import net.minecraft.item.Item;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
 import net.minecraft.nbt.Tag;
 import net.minecraft.text.LiteralText;
 import net.minecraft.text.Text;
@@ -167,10 +168,10 @@ public class ItemEntryStack extends AbstractEntryStack implements OptimalEntrySt
         ItemStack otherStack = stack.getItemStack();
         CompoundTag o1 = itemStack.getTag();
         CompoundTag o2 = otherStack.getTag();
-        return o1 == o2 || ((o1 != null && o2 != null) && equals(o1, o2));
+        return o1 == o2 || ((o1 != null && o2 != null) && equalsTagWithoutCount(o1, o2));
     }
     
-    public boolean equals(CompoundTag o1, CompoundTag o2) {
+    private boolean equalsTagWithoutCount(CompoundTag o1, CompoundTag o2) {
         int o1Size = 0;
         int o2Size = 0;
         for (String key : o1.getKeys()) {
@@ -194,16 +195,8 @@ public class ItemEntryStack extends AbstractEntryStack implements OptimalEntrySt
                     continue;
                 Tag value = o1.get(key);
                 Tag otherValue = o2.get(key);
-                if (value == null) {
-                    if (!(otherValue == null && o2.contains(key)))
-                        return false;
-                } else if (value instanceof CompoundTag && otherValue instanceof CompoundTag) {
-                    if (!(value == otherValue || (value != null && otherValue != null) && equals((CompoundTag) value, (CompoundTag) otherValue)))
-                        return false;
-                } else {
-                    if (!value.asString().equals(otherValue.asString()))
-                        return false;
-                }
+                if (!equalsTag(value, otherValue))
+                    return false;
             }
         } catch (ClassCastException | NullPointerException unused) {
             return false;
@@ -212,6 +205,27 @@ public class ItemEntryStack extends AbstractEntryStack implements OptimalEntrySt
         return true;
     }
     
+    private boolean equalsTag(Tag tag, Tag otherTag) {
+        if (tag == null || otherTag == null) {
+            return tag == otherTag;
+        }
+        if (tag instanceof ListTag && otherTag instanceof ListTag)
+            return equalsList((ListTag) tag, (ListTag) otherTag);
+        return tag.equals(otherTag);
+    }
+    
+    private boolean equalsList(ListTag listTag, ListTag otherListTag) {
+        if (listTag.size() != otherListTag.size())
+            return false;
+        for (int i = 0; i < listTag.size(); i++) {
+            Tag value = listTag.get(i);
+            Tag otherValue = otherListTag.get(i);
+            if (!equalsTag(value, otherValue))
+                return false;
+        }
+        return true;
+    }
+    
     @Override
     public boolean equalsIgnoreTags(EntryStack stack) {
         Boolean ifFluid = compareIfFluid(stack, 1);