11package com .glisco .numismaticoverhaul ;
22
3- import com .glisco .numismaticoverhaul .block .NumismaticOverhaulBlocks ;
4- import com .glisco .numismaticoverhaul .block .PiggyBankScreenHandler ;
5- import com .glisco .numismaticoverhaul .block .ShopScreenHandler ;
3+ import com .glisco .numismaticoverhaul .block .*;
64import com .glisco .numismaticoverhaul .currency .MoneyBagLootEntry ;
75import com .glisco .numismaticoverhaul .item .*;
8- import com .glisco .numismaticoverhaul .network .RequestPurseActionC2SPacket ;
9- import com .glisco .numismaticoverhaul .network .ShopScreenHandlerRequestC2SPacket ;
10- import com .glisco .numismaticoverhaul .network .UpdateShopScreenS2CPacket ;
6+ import com .glisco .numismaticoverhaul .network .*;
117import com .glisco .numismaticoverhaul .villagers .data .VillagerTradesResourceListener ;
128import com .glisco .numismaticoverhaul .villagers .json .VillagerTradesHandler ;
139import io .wispforest .owo .itemgroup .Icon ;
2925import net .minecraft .block .Block ;
3026import net .minecraft .component .ComponentType ;
3127import net .minecraft .entity .EntityType ;
32- import net .minecraft .loot .*;
28+ import net .minecraft .loot .LootPool ;
29+ import net .minecraft .loot .LootTables ;
3330import net .minecraft .loot .condition .RandomChanceLootCondition ;
3431import net .minecraft .loot .entry .LootPoolEntryType ;
3532import net .minecraft .particle .BlockStateParticleEffect ;
3633import net .minecraft .particle .ParticleTypes ;
37- import net .minecraft .registry .Registries ;
38- import net .minecraft .registry .Registry ;
39- import net .minecraft .registry .RegistryKeys ;
34+ import net .minecraft .registry .*;
4035import net .minecraft .registry .tag .TagKey ;
4136import net .minecraft .resource .ResourceType ;
4237import net .minecraft .resource .featuretoggle .FeatureFlags ;
4338import net .minecraft .screen .ScreenHandlerType ;
39+ import net .minecraft .server .MinecraftServer ;
4440import net .minecraft .sound .SoundEvent ;
4541import net .minecraft .util .Identifier ;
4642import net .minecraft .util .math .BlockPos ;
4743import net .minecraft .world .GameRules ;
4844import org .apache .logging .log4j .LogManager ;
4945import org .apache .logging .log4j .Logger ;
46+ import java .util .HashMap ;
47+ import java .util .Map ;
5048
5149public class NumismaticOverhaul implements ModInitializer {
5250
@@ -59,8 +57,8 @@ public class NumismaticOverhaul implements ModInitializer {
5957 ClientParticles .setParticleCount (6 * data );
6058 ClientParticles .randomizeVelocity (2 );
6159 ClientParticles .spawnCenteredOnBlock (
62- new BlockStateParticleEffect (ParticleTypes .BLOCK , NumismaticOverhaulBlocks .PIGGY_BANK .getDefaultState ()),
63- world , new BlockPos ((int ) pos .x , (int ) pos .y , (int ) pos .z ), .75
60+ new BlockStateParticleEffect (ParticleTypes .BLOCK , NumismaticOverhaulBlocks .PIGGY_BANK .getDefaultState ()),
61+ world , new BlockPos ((int ) pos .x , (int ) pos .y , (int ) pos .z ), .75
6462 );
6563 });
6664
@@ -74,27 +72,31 @@ world, new BlockPos((int) pos.x, (int) pos.y, (int) pos.z), .75
7472 public static final TagKey <Block > VERY_HEAVY_BLOCKS = TagKey .of (RegistryKeys .BLOCK , id ("very_heavy_blocks" ));
7573
7674 public static final GameRules .Key <GameRules .IntRule > MONEY_DROP_PERCENTAGE
77- = GameRuleRegistry .register ("moneyDropPercentage" , GameRules .Category .PLAYER , GameRuleFactory .createIntRule (10 , 0 , 100 ));
75+ = GameRuleRegistry .register ("moneyDropPercentage" , GameRules .Category .PLAYER , GameRuleFactory .createIntRule (10 , 0 , 100 ));
7876
7977 public static final GameRules .Key <GameRules .IntRule > MONEY_MOB_DROP_VARIANCE
8078 = GameRuleRegistry .register ("moneyMobDropVariancePercentage" , GameRules .Category .MOBS , GameRuleFactory .createIntRule (50 , 0 , 100 ));
8179
8280 public static final ComponentType <MoneyBagComponent > MONEY_BAG_COMPONENT = MoneyBagComponent .register ();
8381
8482 public static final OwoItemGroup NUMISMATIC_GROUP = OwoItemGroup .builder (
85- NumismaticOverhaul .id ("main" ),
86- () -> Icon .of (MoneyBagItem .fromRawValue (100 )))
87- .initializer (group -> {
88- group .addButton (ItemGroupButton .modrinth (group , "https://modrinth.com/mod/numismatic-overhaul" ));
89- group .addButton (ItemGroupButton .curseforge (group , "https://www.curseforge.com/minecraft/mc-mods/numismatic-overhaul" ));
90- group .addButton (ItemGroupButton .github (group , "https://github.com/wisp-forest/numismatic-overhaul" ));
91- group .addButton (ItemGroupButton .discord (group , "https://discord.gg/xrwHKktV2d" ));
92- }).build ();
83+ NumismaticOverhaul .id ("main" ),
84+ () -> Icon .of (MoneyBagItem .fromRawValue (100 )))
85+ .initializer (group -> {
86+ group .addButton (ItemGroupButton .modrinth (group , "https://modrinth.com/mod/numismatic-overhaul" ));
87+ group .addButton (ItemGroupButton .curseforge (group , "https://www.curseforge.com/minecraft/mc-mods/numismatic-overhaul" ));
88+ group .addButton (ItemGroupButton .github (group , "https://github.com/wisp-forest/numismatic-overhaul" ));
89+ group .addButton (ItemGroupButton .discord (group , "https://discord.gg/xrwHKktV2d" ));
90+ }).build ();
91+
92+ public static final Map <EntityType <?>, Integer > MOBS_IN_BOURGEOISIE = new HashMap <>();
9393
9494 public static final com .glisco .numismaticoverhaul .NumismaticOverhaulConfig CONFIG = com .glisco .numismaticoverhaul .NumismaticOverhaulConfig .createAndLoad ();
9595
9696 @ Override
9797 public void onInitialize () {
98+ // this type of code truly feels like DH code
99+ ServerLifecycleEvents .SERVER_STARTED .register (NumismaticOverhaul ::loadMobDropConfig );
98100
99101 FieldRegistrationHandler .register (NumismaticOverhaulItems .class , MOD_ID , false );
100102 FieldRegistrationHandler .register (NumismaticOverhaulBlocks .class , MOD_ID , false );
@@ -117,27 +119,28 @@ public void onInitialize() {
117119
118120 ServerLifecycleEvents .END_DATA_PACK_RELOAD .register ((server , serverResourceManager , success ) -> {
119121 VillagerTradesHandler .broadcastErrors (server );
122+ CONFIG .subscribeToMobsToBaseValues (NumismaticOverhaul ::reloadMobDropConfig );
120123 });
121124
122125 NUMISMATIC_GROUP .initialize ();
123126
124127 if (CONFIG .generateCurrencyInChests ()) {
125128 LootOps .injectItem (NumismaticOverhaulItems .GOLD_COIN , .01f , LootTables .STRONGHOLD_LIBRARY_CHEST .getValue (), LootTables .BASTION_TREASURE_CHEST .getValue (), LootTables .STRONGHOLD_CORRIDOR_CHEST .getValue (),
126- LootTables .PILLAGER_OUTPOST_CHEST .getValue (), LootTables .BURIED_TREASURE_CHEST .getValue (), LootTables .SIMPLE_DUNGEON_CHEST .getValue (), LootTables .ABANDONED_MINESHAFT_CHEST .getValue ());
129+ LootTables .PILLAGER_OUTPOST_CHEST .getValue (), LootTables .BURIED_TREASURE_CHEST .getValue (), LootTables .SIMPLE_DUNGEON_CHEST .getValue (), LootTables .ABANDONED_MINESHAFT_CHEST .getValue ());
127130
128131 LootTableEvents .MODIFY .register ((key , tableBuilder , source , registries ) -> {
129132 if (anyMatch (key .getValue (), LootTables .DESERT_PYRAMID_CHEST .getValue ())) {
130133 tableBuilder .pool (LootPool .builder ().with (MoneyBagLootEntry .builder (CONFIG .lootOptions .desertMinLoot (), CONFIG .lootOptions .desertMaxLoot ()))
131- .conditionally (RandomChanceLootCondition .builder (0.45f )));
134+ .conditionally (RandomChanceLootCondition .builder (0.45f )));
132135 } else if (anyMatch (key .getValue (), LootTables .SIMPLE_DUNGEON_CHEST .getValue (), LootTables .ABANDONED_MINESHAFT_CHEST .getValue ())) {
133136 tableBuilder .pool (LootPool .builder ().with (MoneyBagLootEntry .builder (CONFIG .lootOptions .dungeonMinLoot (), CONFIG .lootOptions .dungeonMaxLoot ()))
134- .conditionally (RandomChanceLootCondition .builder (0.75f )));
137+ .conditionally (RandomChanceLootCondition .builder (0.75f )));
135138 } else if (anyMatch (key .getValue (), LootTables .BASTION_TREASURE_CHEST .getValue (), LootTables .STRONGHOLD_CORRIDOR_CHEST .getValue (), LootTables .PILLAGER_OUTPOST_CHEST .getValue (), LootTables .BURIED_TREASURE_CHEST .getValue ())) {
136139 tableBuilder .pool (LootPool .builder ().with (MoneyBagLootEntry .builder (CONFIG .lootOptions .structureMinLoot (), CONFIG .lootOptions .structureMaxLoot ()))
137- .conditionally (RandomChanceLootCondition .builder (0.75f )));
140+ .conditionally (RandomChanceLootCondition .builder (0.75f )));
138141 } else if (anyMatch (key .getValue (), LootTables .STRONGHOLD_LIBRARY_CHEST .getValue ())) {
139142 tableBuilder .pool (LootPool .builder ().with (MoneyBagLootEntry .builder (CONFIG .lootOptions .strongholdLibraryMinLoot (), CONFIG .lootOptions .strongholdLibraryMaxLoot ()))
140- .conditionally (RandomChanceLootCondition .builder (0.85f )));
143+ .conditionally (RandomChanceLootCondition .builder (0.85f )));
141144 }
142145 });
143146 }
@@ -153,4 +156,25 @@ private static boolean anyMatch(Identifier target, Identifier... comparisons) {
153156 public static Identifier id (String path ) {
154157 return Identifier .of (MOD_ID , path );
155158 }
159+
160+ private static void loadMobDropConfig (MinecraftServer ignored ) {
161+ CONFIG .mobsToBaseValues ().forEach ((s , baseValue ) -> {
162+ if (s .startsWith ("#" )) {
163+ Registries .ENTITY_TYPE .getEntryList (TagKey .of (RegistryKeys .ENTITY_TYPE , Identifier .of (s .split ("#" )[1 ]))).ifPresent (registryEntries -> {
164+ registryEntries .forEach (entityTypeRegistryEntry -> MOBS_IN_BOURGEOISIE .put (entityTypeRegistryEntry .value (), baseValue ));
165+ });
166+ } else {
167+ var entityOpt = Registries .ENTITY_TYPE .getOrEmpty (Identifier .of (s ));
168+ entityOpt .ifPresentOrElse (entityType -> MOBS_IN_BOURGEOISIE .put (entityType , baseValue ), () -> {
169+ LOGGER .error ("[Numismatic Overhaul] Could not find entity type or entity type tag '{}' for mob drops" , s );
170+ });
171+ }
172+ });
173+ }
174+
175+ private static void reloadMobDropConfig (Map <String , Integer > ignored ) {
176+ MOBS_IN_BOURGEOISIE .clear ();
177+ CONFIG .load ();
178+ loadMobDropConfig (null );
179+ }
156180}
0 commit comments