Skip to content

Commit 131f15b

Browse files
committed
mega refactors
1 parent 5b159e4 commit 131f15b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1343
-1371
lines changed

src/main/java/org/violetmoon/zeta/Zeta.java

+102-105
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
package org.violetmoon.zeta;
22

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;
104
import org.apache.logging.log4j.Logger;
115
import org.jetbrains.annotations.Nullable;
126
import org.violetmoon.zeta.advancement.AdvancementModifierRegistry;
@@ -23,34 +17,29 @@
2317
import org.violetmoon.zeta.module.ZetaCategory;
2418
import org.violetmoon.zeta.module.ZetaModuleManager;
2519
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.*;
3822
import org.violetmoon.zeta.util.handler.FuelHandler;
23+
import org.violetmoon.zeta.util.handler.LoaderSpecificEventsHandler;
3924
import org.violetmoon.zeta.util.zetalist.IZeta;
4025
import org.violetmoon.zeta.util.zetalist.ZetaList;
4126
import org.violetmoon.zeta.world.EntitySpawnHandler;
4227

28+
import java.util.List;
29+
import java.util.function.Supplier;
30+
4331
/**
4432
* do not touch forge OR quark from this package, it will later be split off
4533
*/
4634
public abstract class Zeta implements IZeta {
4735

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) {
4938
this.log = log;
5039

5140
this.modid = modid;
5241
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;
5443
this.proxy = createProxy(side);
5544

5645
this.modules = createModuleManager();
@@ -71,15 +60,51 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
7160
this.fuel = createFuelHandler();
7261

7362
this.entitySpawn = createEntitySpawnHandler();
63+
this.loaderSpecificEvents = createLoaderEventsHandler();
7464

75-
Stopwatch stopwatch = Stopwatch.createStarted();
7665
this.loadBus = this.createLoadBus();
7766
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();
79102

80103
ZetaList.INSTANCE.register(this);
104+
81105
}
82106

107+
83108
//core
84109
public final Logger log;
85110
public final String modid;
@@ -92,8 +117,7 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
92117
public final ZetaCommonProxy proxy;
93118

94119
//registry
95-
//TODO: make private
96-
@Deprecated(forRemoval = true)
120+
//we handle registration
97121
public final ZetaRegistry registry;
98122
public final RegistryUtil registryUtil = new RegistryUtil(this); //TODO: !!Delete this, only needed cause there's no way to get early registry names.
99123
public final RenderLayerRegistry renderLayerRegistry;
@@ -113,44 +137,19 @@ public Zeta(String modid, Logger log, ZetaSide side, boolean isProduction) {
113137
public final RaytracingUtil raytracingUtil;
114138
public final NameChanger nameChanger;
115139
public final FuelHandler fuel;
140+
public final LoaderSpecificEventsHandler loaderSpecificEvents;
116141

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;
124145
// 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;
142147

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);
154153
}
155154

156155
// modloader services
@@ -166,83 +165,81 @@ public <T> T modIntegration(String compatWith, Supplier<Supplier<T>> yes, Suppli
166165
}
167166
}
168167

169-
// proxy
170-
public ZetaCommonProxy createProxy(ZetaSide effectiveSide) {
168+
public abstract boolean hasCompletedRegistration();
169+
170+
// proxy madness
171+
protected ZetaCommonProxy createProxy(ZetaSide effectiveSide) {
171172
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);
175176
else return new ZetaCommonProxy(this);
176177
} catch (Exception e) {
177178
throw new RuntimeException("Failed to construct proxy", e);
178179
}
179180
}
180181

182+
// Inheritance loader specific stuff
183+
184+
protected abstract ZetaEventBus<IZetaPlayEvent> createPlayBus();
185+
186+
protected abstract ZetaEventBus<IZetaLoadEvent> createLoadBus();
187+
181188
// config
182-
public abstract IZetaConfigInternals makeConfigInternals(SectionDefinition rootSection);
189+
protected abstract IZetaConfigInternals createConfigInternals(SectionDefinition rootSection);
183190

184191
// general xplat stuff
185-
public ZetaModuleManager createModuleManager() {
186-
return new ZetaModuleManager(this);
187-
}
188192

189-
public abstract ZetaRegistry createRegistry();
193+
protected abstract ZetaRegistry createRegistry();
190194

191-
public RenderLayerRegistry createRenderLayerRegistry() {
192-
return new RenderLayerRegistry();
193-
}
195+
protected abstract CraftingExtensionsRegistry createCraftingExtensionsRegistry();
194196

195-
public abstract CraftingExtensionsRegistry createCraftingExtensionsRegistry();
197+
protected abstract BrewingRegistry createBrewingRegistry();
196198

197-
public DyeablesRegistry createDyeablesRegistry() {
198-
return new DyeablesRegistry();
199-
}
199+
protected abstract PottedPlantRegistry createPottedPlantRegistry();
200200

201-
public abstract BrewingRegistry createBrewingRegistry();
201+
protected abstract ZetaCapabilityManager createCapabilityManager();
202202

203-
public AdvancementModifierRegistry createAdvancementModifierRegistry() {
204-
return new AdvancementModifierRegistry(this);
205-
}
203+
protected abstract ItemExtensionFactory createItemExtensionFactory();
206204

207-
public abstract PottedPlantRegistry createPottedPlantRegistry();
205+
protected abstract RaytracingUtil createRaytracingUtil();
208206

209-
public abstract ZetaCapabilityManager createCapabilityManager();
207+
protected abstract ZetaNetworkHandler createNetworkHandler(int protocolVersion);
210208

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);
213215
}
214216

215-
public abstract ItemExtensionFactory createItemExtensionFactory();
217+
protected AdvancementModifierRegistry createAdvancementModifierRegistry() {
218+
return new AdvancementModifierRegistry(this);
219+
}
216220

217-
public abstract RaytracingUtil createRaytracingUtil();
221+
protected DyeablesRegistry createDyeablesRegistry() {
222+
return new DyeablesRegistry(this);
223+
}
218224

219-
public NameChanger createNameChanger() {
225+
protected BlockExtensionFactory createBlockExtensionFactory() {
226+
return BlockExtensionFactory.DEFAULT;
227+
}
228+
229+
protected NameChanger createNameChanger() {
220230
return new NameChanger();
221231
}
222232

223-
public FuelHandler createFuelHandler() {
233+
protected FuelHandler createFuelHandler() {
224234
return new FuelHandler(this);
225235
}
226236

227-
public EntitySpawnHandler createEntitySpawnHandler() {
237+
protected EntitySpawnHandler createEntitySpawnHandler() {
228238
return new EntitySpawnHandler(this);
229239
}
230240

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();
246243
}
247244

248245
@Override

src/main/java/org/violetmoon/zeta/advancement/AdvancementModifierRegistry.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
import org.violetmoon.zeta.advancement.modifier.WaxModifier;
1818
import org.violetmoon.zeta.api.IAdvancementModifier;
1919
import org.violetmoon.zeta.api.IAdvancementModifierDelegate;
20-
import org.violetmoon.zeta.client.event.play.ZScreen;
21-
import org.violetmoon.zeta.event.bus.LoadEvent;
2220
import org.violetmoon.zeta.event.bus.PlayEvent;
2321
import org.violetmoon.zeta.event.load.ZAddReloadListener;
2422
import org.violetmoon.zeta.event.load.ZGatherAdvancementModifiers;
@@ -53,7 +51,7 @@ public AdvancementModifierRegistry(Zeta zeta) {
5351
}
5452

5553
public ManualTrigger registerManualTrigger(String resloc) {
56-
ResourceLocation id = zeta.registry.newResourceLocation(resloc);
54+
ResourceLocation id = zeta.makeId(resloc);
5755
ManualTrigger trigger = new ManualTrigger(id);
5856
CriteriaTriggers.register(trigger);
5957
return trigger;

0 commit comments

Comments
 (0)