1
1
package org .violetmoon .zeta ;
2
2
3
- import java .util .function .Supplier ;
4
-
5
- import com .google .common .base .Stopwatch ;
6
- import net .minecraft .core .BlockPos ;
7
- import net .minecraft .world .InteractionHand ;
8
- import net .minecraft .world .entity .player .Player ;
9
- import net .minecraft .world .phys .BlockHitResult ;
3
+ import net .minecraft .resources .ResourceLocation ;
10
4
import org .apache .logging .log4j .Logger ;
11
5
import org .jetbrains .annotations .Nullable ;
12
6
import org .violetmoon .zeta .advancement .AdvancementModifierRegistry ;
23
17
import org .violetmoon .zeta .module .ZetaCategory ;
24
18
import org .violetmoon .zeta .module .ZetaModuleManager ;
25
19
import org .violetmoon .zeta .network .ZetaNetworkHandler ;
26
- import org .violetmoon .zeta .registry .BrewingRegistry ;
27
- import org .violetmoon .zeta .registry .CraftingExtensionsRegistry ;
28
- import org .violetmoon .zeta .registry .DyeablesRegistry ;
29
- import org .violetmoon .zeta .registry .PottedPlantRegistry ;
30
- import org .violetmoon .zeta .registry .RenderLayerRegistry ;
31
- import org .violetmoon .zeta .registry .VariantRegistry ;
32
- import org .violetmoon .zeta .registry .ZetaRegistry ;
33
- import org .violetmoon .zeta .util .NameChanger ;
34
- import org .violetmoon .zeta .util .RaytracingUtil ;
35
- import org .violetmoon .zeta .util .RegistryUtil ;
36
- import org .violetmoon .zeta .util .ZetaCommonProxy ;
37
- import org .violetmoon .zeta .util .ZetaSide ;
20
+ import org .violetmoon .zeta .registry .*;
21
+ import org .violetmoon .zeta .util .*;
38
22
import org .violetmoon .zeta .util .handler .FuelHandler ;
23
+ import org .violetmoon .zeta .util .handler .LoaderSpecificEventsHandler ;
39
24
import org .violetmoon .zeta .util .zetalist .IZeta ;
40
25
import org .violetmoon .zeta .util .zetalist .ZetaList ;
41
26
import org .violetmoon .zeta .world .EntitySpawnHandler ;
42
27
28
+ import java .util .List ;
29
+ import java .util .function .Supplier ;
30
+
43
31
/**
44
32
* do not touch forge OR quark from this package, it will later be split off
45
33
*/
46
34
public abstract class Zeta implements IZeta {
47
35
48
- public Zeta (String modid , Logger log , ZetaSide side , boolean isProduction ) {
36
+ public Zeta (String modid , Logger log , ZetaSide side , boolean isProduction , Object configPojo ,
37
+ ModuleFinder finder , List <ZetaCategory > categories , int networkProtocol ) {
49
38
this .log = log ;
50
39
51
40
this .modid = modid ;
52
41
this .side = side ;
53
- this .isProduction = isProduction ; //TODO: either have all these constants or static helpers here or in Utils. Not both
42
+ this .isProduction = isProduction ;
54
43
this .proxy = createProxy (side );
55
44
56
45
this .modules = createModuleManager ();
@@ -71,15 +60,51 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
71
60
this .fuel = createFuelHandler ();
72
61
73
62
this .entitySpawn = createEntitySpawnHandler ();
63
+ this .loaderSpecificEvents = createLoaderEventsHandler ();
74
64
75
- Stopwatch stopwatch = Stopwatch .createStarted ();
76
65
this .loadBus = this .createLoadBus ();
77
66
this .playBus = this .createPlayBus ();
78
- long elapsed = stopwatch .stop ().elapsed ().toMillis ();
67
+
68
+ this .network = createNetworkHandler (networkProtocol );
69
+ this .creativeTabs = this .createCreativeTabHandler ();
70
+
71
+
72
+ //manage subscriptions
73
+ this .loadBus .subscribe (craftingExtensions )
74
+ .subscribe (dyeables )
75
+ .subscribe (brewingRegistry )
76
+ .subscribe (fuel )
77
+ .subscribe (entitySpawn )
78
+ .subscribe (creativeTabs )
79
+ .subscribe (configPojo ).subscribe (configPojo .getClass ());
80
+
81
+ this .playBus .subscribe (fuel )
82
+ .subscribe (advancementModifierRegistry )
83
+ .subscribe (configPojo ).subscribe (configPojo .getClass ());
84
+
85
+ //load modules
86
+
87
+ //things need to happen in order:
88
+ // - load modules
89
+ // - load config
90
+ // - fire config bindings (on reload) so we can set up module enabled stuff inside the modules
91
+ // - subscribe module to bus
92
+ // - fire initial config loaded event
93
+ this .modules .initialize (finder , categories );
94
+
95
+ this .configManager = new ConfigManager (this , configPojo , this ::createConfigInternals );
96
+ // set initial state for modules based off configs
97
+ this .configManager .onReload ();
98
+ // hooks modules up to the now available configs which will immediately be queried to see which module is enabled
99
+ this .modules .setupBusSubscriptions ();
100
+ // fire the initial config loaded event which will trigger events for each mod
101
+ this .configManager .onZetaReady ();
79
102
80
103
ZetaList .INSTANCE .register (this );
104
+
81
105
}
82
106
107
+
83
108
//core
84
109
public final Logger log ;
85
110
public final String modid ;
@@ -92,8 +117,7 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
92
117
public final ZetaCommonProxy proxy ;
93
118
94
119
//registry
95
- //TODO: make private
96
- @ Deprecated (forRemoval = true )
120
+ //we handle registration
97
121
public final ZetaRegistry registry ;
98
122
public final RegistryUtil registryUtil = new RegistryUtil (this ); //TODO: !!Delete this, only needed cause there's no way to get early registry names.
99
123
public final RenderLayerRegistry renderLayerRegistry ;
@@ -113,44 +137,19 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
113
137
public final RaytracingUtil raytracingUtil ;
114
138
public final NameChanger nameChanger ;
115
139
public final FuelHandler fuel ;
140
+ public final LoaderSpecificEventsHandler loaderSpecificEvents ;
116
141
117
- //config (which isn't set in the constructor b/c module loading has to happen first)
118
- public ConfigManager configManager ;
119
- public IZetaConfigInternals configInternals ;
120
-
121
- //network (which isn't set in the constructor b/c it has a user-specified protocol version TODO this isnt good api design, imo)
122
- public ZetaNetworkHandler network ;
123
-
142
+ public final ConfigManager configManager ;
143
+ public final ZetaNetworkHandler network ;
144
+ public final CreativeTabHandler creativeTabs ;
124
145
// worldgen
125
- public EntitySpawnHandler entitySpawn ;
126
-
127
- protected abstract ZetaEventBus <IZetaPlayEvent > createPlayBus ();
128
-
129
- protected abstract ZetaEventBus <IZetaLoadEvent > createLoadBus ();
130
-
131
- /**
132
- * @param categories List of module categories in this mod, if null, will not load Modules but still load general config
133
- * @param finder Module finder instance to locate the modules this Zeta will load, if null, will not load Modules but still load general config
134
- * @param rootPojo General config object root
135
- */
136
- // call this in mod init otherwise zeta won't do much
137
- public final void loadModules (@ Nullable Iterable <ZetaCategory > categories , @ Nullable ModuleFinder finder , Object rootPojo ) {
138
- if (categories != null && finder != null ) {
139
- modules .initCategories (categories );
140
- modules .load (finder );
141
- }
146
+ public final EntitySpawnHandler entitySpawn ;
142
147
143
- //The reason why there's a circular dependency between configManager and configInternals:
144
- // - ConfigManager determines the shape and layout of the config file
145
- // - The platform-specific configInternals loads the actual values, from the platform-specfic config file
146
- // - Only then can ConfigManager do the initial config load
147
-
148
- this .configManager = new ConfigManager (this , rootPojo );
149
- this .configInternals = makeConfigInternals (configManager .getRootConfig ());
150
- asZeta ().log .info ("Doing super early config setup for {}" , asZeta ().modid );
151
- this .configManager .onReload ();
152
-
153
- this .modules .doFinalize ();
148
+ public ResourceLocation makeId (String name ) {
149
+ //You know how `new ResourceLocation(String)` prepends "minecraft" if there's no prefix?
150
+ //This method is like that, except it prepends *your* modid
151
+ if (name .indexOf (':' ) == -1 ) return new ResourceLocation (this .modid , name );
152
+ else return new ResourceLocation (name );
154
153
}
155
154
156
155
// modloader services
@@ -166,83 +165,81 @@ public <T> T modIntegration(String compatWith, Supplier<Supplier<T>> yes, Suppli
166
165
}
167
166
}
168
167
169
- // proxy
170
- public ZetaCommonProxy createProxy (ZetaSide effectiveSide ) {
168
+ public abstract boolean hasCompletedRegistration ();
169
+
170
+ // proxy madness
171
+ protected ZetaCommonProxy createProxy (ZetaSide effectiveSide ) {
171
172
try {
172
- if (effectiveSide == ZetaSide .CLIENT )
173
- return (ZetaCommonProxy ) Class .forName ("org.violetmoon.zeta.client.ZetaClientProxy" )
174
- .getConstructor (Zeta .class ).newInstance (this );
173
+ if (effectiveSide == ZetaSide .CLIENT )
174
+ return (ZetaCommonProxy ) Class .forName ("org.violetmoon.zeta.client.ZetaClientProxy" )
175
+ .getConstructor (Zeta .class ).newInstance (this );
175
176
else return new ZetaCommonProxy (this );
176
177
} catch (Exception e ) {
177
178
throw new RuntimeException ("Failed to construct proxy" , e );
178
179
}
179
180
}
180
181
182
+ // Inheritance loader specific stuff
183
+
184
+ protected abstract ZetaEventBus <IZetaPlayEvent > createPlayBus ();
185
+
186
+ protected abstract ZetaEventBus <IZetaLoadEvent > createLoadBus ();
187
+
181
188
// config
182
- public abstract IZetaConfigInternals makeConfigInternals (SectionDefinition rootSection );
189
+ protected abstract IZetaConfigInternals createConfigInternals (SectionDefinition rootSection );
183
190
184
191
// general xplat stuff
185
- public ZetaModuleManager createModuleManager () {
186
- return new ZetaModuleManager (this );
187
- }
188
192
189
- public abstract ZetaRegistry createRegistry ();
193
+ protected abstract ZetaRegistry createRegistry ();
190
194
191
- public RenderLayerRegistry createRenderLayerRegistry () {
192
- return new RenderLayerRegistry ();
193
- }
195
+ protected abstract CraftingExtensionsRegistry createCraftingExtensionsRegistry ();
194
196
195
- public abstract CraftingExtensionsRegistry createCraftingExtensionsRegistry ();
197
+ protected abstract BrewingRegistry createBrewingRegistry ();
196
198
197
- public DyeablesRegistry createDyeablesRegistry () {
198
- return new DyeablesRegistry ();
199
- }
199
+ protected abstract PottedPlantRegistry createPottedPlantRegistry ();
200
200
201
- public abstract BrewingRegistry createBrewingRegistry ();
201
+ protected abstract ZetaCapabilityManager createCapabilityManager ();
202
202
203
- public AdvancementModifierRegistry createAdvancementModifierRegistry () {
204
- return new AdvancementModifierRegistry (this );
205
- }
203
+ protected abstract ItemExtensionFactory createItemExtensionFactory ();
206
204
207
- public abstract PottedPlantRegistry createPottedPlantRegistry ();
205
+ protected abstract RaytracingUtil createRaytracingUtil ();
208
206
209
- public abstract ZetaCapabilityManager createCapabilityManager ( );
207
+ protected abstract ZetaNetworkHandler createNetworkHandler ( int protocolVersion );
210
208
211
- public BlockExtensionFactory createBlockExtensionFactory () {
212
- return BlockExtensionFactory .DEFAULT ;
209
+ protected abstract LoaderSpecificEventsHandler createLoaderEventsHandler ();
210
+
211
+ protected abstract CreativeTabHandler createCreativeTabHandler ();
212
+
213
+ protected ZetaModuleManager createModuleManager () {
214
+ return new ZetaModuleManager (this );
213
215
}
214
216
215
- public abstract ItemExtensionFactory createItemExtensionFactory ();
217
+ protected AdvancementModifierRegistry createAdvancementModifierRegistry () {
218
+ return new AdvancementModifierRegistry (this );
219
+ }
216
220
217
- public abstract RaytracingUtil createRaytracingUtil ();
221
+ protected DyeablesRegistry createDyeablesRegistry () {
222
+ return new DyeablesRegistry (this );
223
+ }
218
224
219
- public NameChanger createNameChanger () {
225
+ protected BlockExtensionFactory createBlockExtensionFactory () {
226
+ return BlockExtensionFactory .DEFAULT ;
227
+ }
228
+
229
+ protected NameChanger createNameChanger () {
220
230
return new NameChanger ();
221
231
}
222
232
223
- public FuelHandler createFuelHandler () {
233
+ protected FuelHandler createFuelHandler () {
224
234
return new FuelHandler (this );
225
235
}
226
236
227
- public EntitySpawnHandler createEntitySpawnHandler () {
237
+ protected EntitySpawnHandler createEntitySpawnHandler () {
228
238
return new EntitySpawnHandler (this );
229
239
}
230
240
231
- public abstract ZetaNetworkHandler createNetworkHandler (int protocolVersion );
232
-
233
- // ummmmmm why is this here??
234
- public abstract boolean fireRightClickBlock (Player player , InteractionHand hand , BlockPos pos , BlockHitResult bhr );
235
-
236
- // Let's Jump
237
- public void start (){
238
- loadBus .subscribe (craftingExtensions )
239
- .subscribe (dyeables )
240
- .subscribe (brewingRegistry )
241
- .subscribe (fuel )
242
- .subscribe (entitySpawn );
243
-
244
- playBus .subscribe (fuel )
245
- .subscribe (advancementModifierRegistry );
241
+ protected RenderLayerRegistry createRenderLayerRegistry () {
242
+ return new RenderLayerRegistry ();
246
243
}
247
244
248
245
@ Override
0 commit comments