Skip to content

Commit d42e668

Browse files
committed
Working configuration logic.
1 parent ed02852 commit d42e668

File tree

11 files changed

+108
-35
lines changed

11 files changed

+108
-35
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# MC Trade Post
2-
=======
1+
# MC Trade Post
32

43
## Description
54

@@ -41,7 +40,7 @@ These frames should be mounted in empty (air) blocks tagged with the "display_sh
4140
This mod can best be described as a "pre-alpha" state. It functionality may change rapidly and without warning.
4241

4342
### Roadmap (Roughly Prioritized)
44-
43+
External configurability
4544
Interface for spending earned income.
4645
- Unlock subsequent levels of the merchant building
4746
- Summon traders

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod_name=MC Trade Post
3232
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
3333
mod_license=All Rights Reserved
3434
# The mod version. See https://semver.org/
35-
mod_version=0.0.4
35+
mod_version=0.1.0
3636
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
3737
# This should match the base package used for the mod sources.
3838
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

src/main/java/com/deathfrog/mctradepost/Config.java

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.deathfrog.mctradepost;
2+
3+
import java.io.ObjectInputFilter.Config;
4+
import java.lang.reflect.Field;
5+
6+
import net.neoforged.bus.api.SubscribeEvent;
7+
import net.neoforged.fml.ModContainer;
8+
import net.neoforged.fml.common.EventBusSubscriber;
9+
import net.neoforged.fml.config.ModConfig;
10+
import net.neoforged.fml.event.config.ModConfigEvent;
11+
import net.neoforged.neoforge.common.ModConfigSpec;
12+
import net.neoforged.neoforge.common.ModConfigSpec.ConfigValue;
13+
import net.neoforged.neoforge.common.ModConfigSpec.IntValue;
14+
15+
16+
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
17+
// Demonstrates how to use Neo's config APIs
18+
@EventBusSubscriber(modid = MCTradePostMod.MODID, bus = EventBusSubscriber.Bus.MOD)
19+
public class MCTPConfig
20+
{
21+
public static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
22+
public static final ModConfigSpec SPEC;
23+
24+
public static final ConfigValue<Integer> marketplaceLevel3;
25+
26+
static {
27+
BUILDER.push("marketplace");
28+
29+
marketplaceLevel3 = BUILDER
30+
.comment("How much does unlocking the level 3 marketplace cost?")
31+
.define("marketplaceLevel3", 500);
32+
33+
BUILDER.pop();
34+
35+
SPEC = BUILDER.build(); // Last
36+
37+
// TODO: Eliminate once testing is complete.
38+
MCTradePostMod.LOGGER.info("Static initialization of MCTPConfig complete.");
39+
}
40+
41+
42+
private static void setupConfiguration(final ModConfigEvent sourceEvent)
43+
{
44+
// No-op
45+
}
46+
47+
@SubscribeEvent
48+
static void onLoad(final ModConfigEvent.Loading event)
49+
{
50+
MCTradePostMod.LOGGER.info("Loading config");
51+
setupConfiguration(event);
52+
}
53+
54+
@SubscribeEvent
55+
static void onReload(final ModConfigEvent.Reloading event)
56+
{
57+
MCTradePostMod.LOGGER.info("Reloading config");
58+
setupConfiguration(event);
59+
}
60+
61+
/**
62+
* Register the config with the given mod container.
63+
* @param modContainer The mod container to register the config with.
64+
*/
65+
public static void register(ModContainer modContainer) {
66+
MCTradePostMod.LOGGER.info("Registering MCTPConfig to handle configurations.");
67+
modContainer.registerConfig(ModConfig.Type.COMMON, SPEC, "mctradepost-common.toml");
68+
}
69+
}

src/main/java/com/deathfrog/mctradepost/MCTradePostMod.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
4242
import net.neoforged.neoforge.client.event.EntityRenderersEvent;
4343
import net.neoforged.neoforge.client.event.RegisterItemDecorationsEvent;
44+
import net.neoforged.neoforge.client.gui.ConfigurationScreen;
45+
import net.neoforged.neoforge.client.gui.IConfigScreenFactory;
46+
import net.neoforged.neoforge.common.ModConfigSpec;
4447
import net.neoforged.neoforge.common.NeoForge;
4548
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent;
4649
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
@@ -348,7 +351,7 @@ public class MCTradePostMod
348351
public static final DeferredItem<AdvancedClipboardItem> ADVANCED_CLIPBOARD = ITEMS.register("advanced_clipboard",
349352
() -> new AdvancedClipboardItem(new Item.Properties().stacksTo(1)));
350353

351-
// TODO: Get the block hut registered with the JEI.
354+
352355
public static MCTPBaseBlockHut blockHutMarketplace;
353356

354357
// Create a Deferred Register to hold CreativeModeTabs which will all be registered under the "examplemod" namespace
@@ -400,7 +403,12 @@ public MCTradePostMod(IEventBus modEventBus, ModContainer modContainer)
400403
modEventBus.addListener(this::onLoadComplete);
401404

402405
// Register our mod's ModConfigSpec so that FML can create and load the config file for us
403-
modContainer.registerConfig(ModConfig.Type.COMMON, Config.SPEC);
406+
// TODO: Once working, refactor into server/client/common pattern.
407+
MCTPConfig.register(modContainer);
408+
409+
// This will use NeoForge's ConfigurationScreen to display this mod's configs
410+
modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new);
411+
404412
ModJobsInitializer.DEFERRED_REGISTER.register(modEventBus);
405413
TileEntityInitializer.BLOCK_ENTITIES.register(modEventBus);
406414
ModBuildingsInitializer.DEFERRED_REGISTER.register(modEventBus);
@@ -424,7 +432,6 @@ private void addCreative(BuildCreativeModeTabContentsEvent event)
424432
event.accept(MCTradePostMod.ADVANCED_CLIPBOARD.get());
425433
}
426434

427-
// TODO: Test Marketplace from creative mode tab and JEI
428435
if (event.getTabKey() == CreativeModeTabs.FUNCTIONAL_BLOCKS) {
429436
event.accept(MCTradePostMod.blockHutMarketplace);
430437
}

src/main/java/com/deathfrog/mctradepost/core/colony/jobs/buildings/modules/ItemValueRegistry.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ public static void generateValues()
6464

6565
startTracking = false;
6666
}
67+
68+
MCTradePostMod.LOGGER.info("Finished configuring theItemValueRegistry.");
6769
}
6870

6971
/**

src/main/java/com/deathfrog/mctradepost/core/colony/jobs/buildings/modules/MCTPBuildingModules.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class MCTPBuildingModules
5656
"econ_module", BuildingEconModule::new,
5757
() -> EconModuleView::new);
5858

59-
// TODO: Repair the setting label (possibly requiring a custom gui XML, which in turn requires a custom view and window class).
59+
// TODO: TEST: Repair the setting label
6060
// TODO: The settings window will also be where spend takes place.
6161
public static final BuildingEntry.ModuleProducer<SettingsModule,SettingsModuleView> ECON_SETTINGS =
6262
new BuildingEntry.ModuleProducer<>("marketplace_settings",

src/main/java/com/deathfrog/mctradepost/core/colony/jobs/buildings/workerbuildings/BuildingMarketplace.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import org.jetbrains.annotations.NotNull;
2929

30+
import com.deathfrog.mctradepost.MCTPConfig;
3031
import com.deathfrog.mctradepost.MCTradePostMod;
3132
import com.google.common.collect.ImmutableList;
3233

src/main/java/com/deathfrog/mctradepost/gui/AdvancedWindowClipBoard.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.minecolonies.api.colony.requestsystem.token.IToken;
1313
import com.minecolonies.core.client.gui.AbstractWindowRequestTree;
1414
import com.minecolonies.core.network.messages.server.colony.UpdateRequestStateMessage;
15+
import com.deathfrog.mctradepost.MCTPConfig;
1516
import com.deathfrog.mctradepost.MCTradePostMod;
1617
import com.google.common.collect.ImmutableList;
1718
import net.minecraft.client.Minecraft;
@@ -75,6 +76,18 @@ private void togglePlayerOnly()
7576
{
7677
this.playerOnly = !this.playerOnly;
7778
MCTradePostMod.LOGGER.info("Player Only filter set to: " + this.playerOnly);
79+
80+
try{
81+
// TODO: Remove when testing complete.
82+
if (MCTPConfig.SPEC.isLoaded()) {
83+
MCTradePostMod.LOGGER.info("Confirmed SPEC is loaded.");
84+
MCTradePostMod.LOGGER.info("Configured value for marketplaceLevel3 is: ", MCTPConfig.marketplaceLevel3.get());
85+
} else {
86+
MCTradePostMod.LOGGER.info("SPEC is not loaded.");
87+
}
88+
} catch (Exception e) {
89+
MCTradePostMod.LOGGER.error("Error getting config value for itemCost", e);
90+
}
7891
}
7992

8093
/**

src/main/java/com/deathfrog/mctradepost/network/ItemValueReigstry.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)