|
14 | 14 | import com.evandev.fieldguide.util.EntryResolver; |
15 | 15 | import net.minecraft.client.resources.language.I18n; |
16 | 16 | import net.minecraft.core.registries.BuiltInRegistries; |
| 17 | +import net.minecraft.nbt.CompoundTag; |
17 | 18 | import net.minecraft.network.chat.Component; |
18 | 19 | import net.minecraft.resources.ResourceLocation; |
19 | 20 | import net.minecraft.server.packs.resources.ResourceManager; |
@@ -178,7 +179,6 @@ public void updateCategoriesFromServer(List<Category> categories) { |
178 | 179 | resolveAllEntries(); |
179 | 180 | } |
180 | 181 |
|
181 | | - |
182 | 182 | public void updateLootCache(Map<ResourceLocation, List<ItemStack>> lootCache) { |
183 | 183 | this.dropCache.clear(); |
184 | 184 |
|
@@ -261,9 +261,26 @@ private void loadVisuals(ResourceManager mgr, String folder, BiConsumer<Resource |
261 | 261 | private void resolveAllEntries() { |
262 | 262 | resolvedCategoryEntries.clear(); |
263 | 263 | ModConfig config = ModConfig.get(); |
| 264 | + Set<Object> allCompositeComponents = new HashSet<>(); |
| 265 | + |
264 | 266 | syncedCategories.values().forEach(category -> { |
265 | | - resolvedCategoryEntries.put(category.getId(), EntryResolver.resolveCategoryEntries(category, config)); |
| 267 | + List<Object> entries = EntryResolver.resolveCategoryEntries(category, config); |
| 268 | + for (Object entry : entries) { |
| 269 | + if (entry instanceof CompositeFieldGuideEntry composite) { |
| 270 | + if (composite.components() != null) { |
| 271 | + allCompositeComponents.addAll(composite.components()); |
| 272 | + } |
| 273 | + if (composite.displayEntry() != null) { |
| 274 | + allCompositeComponents.add(composite.displayEntry()); |
| 275 | + } |
| 276 | + } |
| 277 | + } |
| 278 | + resolvedCategoryEntries.put(category.getId(), entries); |
266 | 279 | }); |
| 280 | + |
| 281 | + for (List<Object> entries : resolvedCategoryEntries.values()) { |
| 282 | + entries.removeIf(entry -> !(entry instanceof CompositeFieldGuideEntry) && allCompositeComponents.contains(entry)); |
| 283 | + } |
267 | 284 | } |
268 | 285 |
|
269 | 286 | public List<Object> getEntriesForCategory(Category category) { |
@@ -291,25 +308,45 @@ public List<Object> searchEntries(String query) { |
291 | 308 | } |
292 | 309 |
|
293 | 310 | public List<ItemStack> getDrops(Object entry) { |
294 | | - List<ItemStack> rawDrops; |
| 311 | + List<ItemStack> rawDrops = new ArrayList<>(); |
295 | 312 | if (entry instanceof CompositeFieldGuideEntry composite) { |
296 | | - rawDrops = new ArrayList<>(dropCache.getOrDefault(composite.displayEntry(), Collections.emptyList())); |
297 | | - for (Object comp : composite.components()) { |
| 313 | + Set<Object> uniqueComponents = new HashSet<>(); |
| 314 | + if (composite.displayEntry() != null) uniqueComponents.add(composite.displayEntry()); |
| 315 | + if (composite.components() != null) uniqueComponents.addAll(composite.components()); |
| 316 | + for (Object comp : uniqueComponents) { |
298 | 317 | rawDrops.addAll(dropCache.getOrDefault(comp, Collections.emptyList())); |
299 | 318 | } |
300 | 319 | } else { |
301 | | - rawDrops = dropCache.getOrDefault(entry, Collections.emptyList()); |
| 320 | + rawDrops.addAll(dropCache.getOrDefault(entry, Collections.emptyList())); |
302 | 321 | } |
303 | 322 |
|
304 | 323 | List<ItemStack> distinct = new ArrayList<>(); |
305 | 324 | for (ItemStack stack : rawDrops) { |
306 | | - if (distinct.stream().noneMatch(s -> ItemStack.isSameItemSameTags(s, stack))) { |
| 325 | + if (distinct.stream().noneMatch(s -> isSameLootItem(s, stack))) { |
307 | 326 | distinct.add(stack); |
308 | 327 | } |
309 | 328 | } |
310 | 329 | return distinct; |
311 | 330 | } |
312 | 331 |
|
| 332 | + private boolean isSameLootItem(ItemStack a, ItemStack b) { |
| 333 | + if (!ItemStack.isSameItem(a, b)) return false; |
| 334 | + if (a.getTag() == b.getTag()) return true; |
| 335 | + if (a.getTag() == null || b.getTag() == null) return false; |
| 336 | + |
| 337 | + CompoundTag tagA = a.getTag().copy(); |
| 338 | + tagA.remove("FieldGuideDropChance"); |
| 339 | + tagA.remove("FieldGuideMin"); |
| 340 | + tagA.remove("FieldGuideMax"); |
| 341 | + |
| 342 | + CompoundTag tagB = b.getTag().copy(); |
| 343 | + tagB.remove("FieldGuideDropChance"); |
| 344 | + tagB.remove("FieldGuideMin"); |
| 345 | + tagB.remove("FieldGuideMax"); |
| 346 | + |
| 347 | + return tagA.equals(tagB); |
| 348 | + } |
| 349 | + |
313 | 350 | public void onClientTick(net.minecraft.client.Minecraft minecraft) { |
314 | 351 | FieldGuideScanner.getInstance().onClientTick(minecraft); |
315 | 352 | } |
|
0 commit comments