@@ -28,18 +28,21 @@ public static Map<ResourceLocation, List<ItemStack>> generateLootMap(ServerLevel
2828 Map <ResourceLocation , List <ItemStack >> lootMap = new HashMap <>();
2929 Set <ResourceLocation > allEntryIds = ServerFieldGuideManager .getInstance ().getAllEntryIds ();
3030
31+ Set <Object > uniqueEntries = new HashSet <>();
3132 for (ResourceLocation entryId : allEntryIds ) {
32- EntryResolutionHelper .resolveSingleEntry (entryId , null , null ).ifPresent (entry -> {
33- ResourceLocation tableId = null ;
34- if (entry instanceof EntityType <?> type ) tableId = type .getDefaultLootTable ();
35- else if (entry instanceof Block block ) tableId = block .getLootTable ();
36- else if (entry instanceof CompositeFieldGuideEntry composite ) {
37- Object display = composite .displayEntry ();
38- if (display instanceof EntityType <?> type ) tableId = type .getDefaultLootTable ();
39- else if (display instanceof Block block ) tableId = block .getLootTable ();
40- }
41- processEntry (level , entry , tableId , lootMap );
42- });
33+ EntryResolutionHelper .resolveSingleEntry (entryId , null , null ).ifPresent (uniqueEntries ::add );
34+ }
35+
36+ for (Object entry : uniqueEntries ) {
37+ ResourceLocation tableId = null ;
38+ if (entry instanceof EntityType <?> type ) tableId = type .getDefaultLootTable ();
39+ else if (entry instanceof Block block ) tableId = block .getLootTable ();
40+ else if (entry instanceof CompositeFieldGuideEntry composite ) {
41+ Object display = composite .displayEntry ();
42+ if (display instanceof EntityType <?> type ) tableId = type .getDefaultLootTable ();
43+ else if (display instanceof Block block ) tableId = block .getLootTable ();
44+ }
45+ processEntry (level , entry , tableId , lootMap );
4346 }
4447 return lootMap ;
4548 }
@@ -68,22 +71,51 @@ private static void processEntry(ServerLevel level, Object entry, ResourceLocati
6871 if (!formattedDrops .isEmpty ()) {
6972 ResourceLocation id = AutoPopulateRegistry .getEntryId (entry , true );
7073 if (id != null ) {
71- lootMap .computeIfAbsent (id , k -> new ArrayList <>()).addAll (formattedDrops );
74+ List <ItemStack > existing = lootMap .computeIfAbsent (id , k -> new ArrayList <>());
75+ for (ItemStack newStack : formattedDrops ) {
76+ boolean found = false ;
77+ for (ItemStack s : existing ) {
78+ if (ItemStack .isSameItemSameTags (s , newStack )) {
79+ CompoundTag existingTag = s .getOrCreateTag ();
80+ CompoundTag newTag = newStack .getOrCreateTag ();
81+
82+ float existingChance = existingTag .getFloat ("FieldGuideDropChance" );
83+ float newChance = newTag .getFloat ("FieldGuideDropChance" );
84+ existingTag .putFloat ("FieldGuideDropChance" , Math .min (100.0f , existingChance + newChance ));
85+
86+ int existingMin = existingTag .contains ("FieldGuideMin" ) ? existingTag .getInt ("FieldGuideMin" ) : 1 ;
87+ int newMin = newTag .contains ("FieldGuideMin" ) ? newTag .getInt ("FieldGuideMin" ) : 1 ;
88+ existingTag .putInt ("FieldGuideMin" , Math .min (existingMin , newMin ));
89+
90+ int existingMax = existingTag .contains ("FieldGuideMax" ) ? existingTag .getInt ("FieldGuideMax" ) : 1 ;
91+ int newMax = newTag .contains ("FieldGuideMax" ) ? newTag .getInt ("FieldGuideMax" ) : 1 ;
92+ existingTag .putInt ("FieldGuideMax" , Math .max (existingMax , newMax ));
93+
94+ found = true ;
95+ break ;
96+ }
97+ }
98+ if (!found ) {
99+ existing .add (newStack );
100+ }
101+ }
72102 }
73103 }
74104 }
75105
76106 private static boolean matchesTarget (Object entry , String targetStr ) {
77- ResourceLocation entryId = EntryResolver .getRawId (EntryResolver .getEntryId (entry ));
107+ Object coreEntry = entry instanceof CompositeFieldGuideEntry composite ? composite .displayEntry () : entry ;
108+ ResourceLocation entryId = EntryResolver .getRawId (EntryResolver .getEntryId (coreEntry ));
109+
78110 if (entryId == null ) return false ;
79111 if (targetStr .startsWith ("#" )) {
80112 try {
81113 ResourceLocation tagId = new ResourceLocation (targetStr .substring (1 ));
82- if (entry instanceof EntityType <?> type ) {
114+ if (coreEntry instanceof EntityType <?> type ) {
83115 return BuiltInRegistries .ENTITY_TYPE .getHolder (BuiltInRegistries .ENTITY_TYPE .getResourceKey (type ).get ()).get ().is (TagKey .create (Registries .ENTITY_TYPE , tagId ));
84- } else if (entry instanceof Block block ) {
116+ } else if (coreEntry instanceof Block block ) {
85117 return BuiltInRegistries .BLOCK .getHolder (BuiltInRegistries .BLOCK .getResourceKey (block ).get ()).get ().is (TagKey .create (Registries .BLOCK , tagId ));
86- } else if (entry instanceof Item item ) {
118+ } else if (coreEntry instanceof Item item ) {
87119 return BuiltInRegistries .ITEM .getHolder (BuiltInRegistries .ITEM .getResourceKey (item ).get ()).get ().is (TagKey .create (Registries .ITEM , tagId ));
88120 }
89121 } catch (Exception ignored ) {
0 commit comments