1
1
package com .mcmoddev .golems ;
2
2
3
- import com .mcmoddev .golems .container .GolemContainer ;
4
- import net .minecraft .ResourceLocationException ;
5
3
import net .minecraft .resources .ResourceLocation ;
6
4
import net .minecraftforge .common .ForgeConfigSpec ;
7
5
8
6
import java .time .LocalDateTime ;
9
7
import java .time .Month ;
10
- import java .util .ArrayList ;
11
8
import java .util .List ;
12
- import java .util .Optional ;
13
9
14
10
public final class EGConfig {
15
11
@@ -22,11 +18,21 @@ public final class EGConfig {
22
18
private final ForgeConfigSpec .IntValue VILLAGER_GOLEM_SPAWN_CHANCE ;
23
19
private final ForgeConfigSpec .ConfigValue <List <? extends String >> VILLAGER_GOLEM_SPAWN_LIST ;
24
20
private static final String [] defaultVillagerGolemSpawns = {
25
- "golems:bookshelf" , "golems:clay" , "golems:coal" , "golems:crafting" ,
26
- "golems:glass" , "golems:glowstone" , "golems:hay" , "golems:leaves" ,
27
- "golems:log" , "golems:melon" , "golems:moss" , "golems:mushroom" , "golems:obsidian" ,
28
- "golems:quartz" , "golems:red_sandstone" , "golems:sandstone" ,
29
- "golems:terracotta" , "golems:wool"
21
+ new ResourceLocation (ExtraGolems .MODID , "bookshelf" ).toString (),
22
+ new ResourceLocation (ExtraGolems .MODID , "clay" ).toString (),
23
+ new ResourceLocation (ExtraGolems .MODID , "coal" ).toString (),
24
+ new ResourceLocation (ExtraGolems .MODID , "crafting" ).toString (),
25
+ new ResourceLocation (ExtraGolems .MODID , "glass" ).toString (),
26
+ new ResourceLocation (ExtraGolems .MODID , "glowstone" ).toString (),
27
+ new ResourceLocation (ExtraGolems .MODID , "hay" ).toString (),
28
+ new ResourceLocation (ExtraGolems .MODID , "leaves" ).toString (),
29
+ new ResourceLocation (ExtraGolems .MODID , "log" ).toString (),
30
+ new ResourceLocation (ExtraGolems .MODID , "melon" ).toString (),
31
+ new ResourceLocation (ExtraGolems .MODID , "moss" ).toString (),
32
+ new ResourceLocation (ExtraGolems .MODID , "mushroom" ).toString (),
33
+ new ResourceLocation (ExtraGolems .MODID , "obsidian" ).toString (),
34
+ new ResourceLocation (ExtraGolems .MODID , "terracotta" ).toString (),
35
+ new ResourceLocation (ExtraGolems .MODID , "wool" ).toString ()
30
36
};
31
37
32
38
private boolean aprilFirst ;
@@ -44,23 +50,23 @@ public final class EGConfig {
44
50
public EGConfig (final ForgeConfigSpec .Builder builder ) {
45
51
// Global values
46
52
builder .push ("general" );
47
- this . BEDROCK_GOLEM_CREATIVE_ONLY = builder .comment ("When true, only players in creative mode can use a Bedrock Golem spawn item" )
53
+ BEDROCK_GOLEM_CREATIVE_ONLY = builder .comment ("When true, only players in creative mode can use a Bedrock Golem spawn item" )
48
54
.define ("bedrock_golem_creative_only" , true );
49
- this . PUMPKIN_BUILDS_GOLEMS = builder .comment ("When true, pumpkins can be used to build this mod's golems" )
55
+ PUMPKIN_BUILDS_GOLEMS = builder .comment ("When true, pumpkins can be used to build this mod's golems" )
50
56
.define ("pumpkin_builds_golems" , false );
51
- this . ENABLE_FRIENDLY_FIRE = builder .comment ("When enabled, attacking a player-built entity will make it attack you" )
57
+ ENABLE_FRIENDLY_FIRE = builder .comment ("When enabled, attacking a player-built entity will make it attack you" )
52
58
.define ("friendly_fire" , true );
53
- this . ENABLE_USE_SPELL_ITEM = builder
59
+ ENABLE_USE_SPELL_ITEM = builder
54
60
.comment ("When enabled, players can use the spell item on a carved pumpkin to convert it to a golem head in-world" )
55
61
.define ("use_spell" , true );
56
- this . ENABLE_HOLIDAYS = builder .comment ("Super secret special days" )
62
+ ENABLE_HOLIDAYS = builder .comment ("Super secret special days" )
57
63
.define ("holidays" , true );
58
- this . VILLAGER_GOLEM_SPAWN_CHANCE = builder .comment ("Percent chance for a villager to summon an Extra Golems entity" )
64
+ VILLAGER_GOLEM_SPAWN_CHANCE = builder .comment ("Percent chance for a villager to summon an Extra Golems entity" )
59
65
.defineInRange ("villager_summon_chance" , 60 , 0 , 100 );
60
- this . ENABLE_HEAL_GOLEMS = builder .comment ("When enabled, giving blocks and items to golems can restore health" )
66
+ ENABLE_HEAL_GOLEMS = builder .comment ("When enabled, giving blocks and items to golems can restore health" )
61
67
.define ("heal_golems" , true );
62
- this . VILLAGER_GOLEM_SPAWN_LIST = builder .comment ("Golems that can be summoned by villagers" , "(Duplicate entries increase chances)" )
63
- .defineList ("villager_summon_golems" , List .of (defaultVillagerGolemSpawns ), o -> o instanceof String );
68
+ VILLAGER_GOLEM_SPAWN_LIST = builder .comment ("Golems that can be summoned by villagers" , "(Duplicate entries increase chances)" )
69
+ .defineList ("villager_summon_golems" , List .of (defaultVillagerGolemSpawns ), o -> o instanceof String s && ResourceLocation . tryParse ( s ) != null );
64
70
65
71
builder .pop ();
66
72
}
@@ -114,25 +120,6 @@ public void bake() {
114
120
enableHolidays = ENABLE_HOLIDAYS .get ();
115
121
enableHealGolems = ENABLE_HEAL_GOLEMS .get ();
116
122
villagerGolemSpawnChance = VILLAGER_GOLEM_SPAWN_CHANCE .get ();
117
- villagerGolemSpawnList = loadVillagerGolemList (VILLAGER_GOLEM_SPAWN_LIST .get ());
118
- }
119
-
120
-
121
- private static List <ResourceLocation > loadVillagerGolemList (List <? extends String > config ) {
122
- final List <ResourceLocation > list = new ArrayList <>();
123
- // load all villager golem candidates from config
124
- for (final String s : config ) {
125
- // parse each entry as resource location with error-catching
126
- if (s != null && !s .isEmpty ()) {
127
- try {
128
- ResourceLocation golemId = ResourceLocation .tryParse (s );
129
- final Optional <GolemContainer > container = ExtraGolems .GOLEM_CONTAINERS .get (golemId );
130
- container .ifPresent (c -> list .add (new ResourceLocation (s )));
131
- } catch (ResourceLocationException e ) {
132
- ExtraGolems .LOGGER .error ("Invalid golem ID in config file for villager_summon_golems: \" " + s + "\" " );
133
- }
134
- }
135
- }
136
- return list ;
123
+ villagerGolemSpawnList = VILLAGER_GOLEM_SPAWN_LIST .get ().stream ().map (ResourceLocation ::tryParse ).toList ();
137
124
}
138
125
}
0 commit comments