Skip to content

Commit efbcbf8

Browse files
committed
Functional marketplace upgrades.
1 parent a8a7244 commit efbcbf8

File tree

17 files changed

+147
-10
lines changed

17 files changed

+147
-10
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import net.neoforged.bus.api.SubscribeEvent;
44
import net.neoforged.fml.common.EventBusSubscriber;
55
import net.neoforged.fml.event.config.ModConfigEvent;
6+
import net.neoforged.neoforge.common.ModConfigSpec;
67

78
// An example config class. This is not required, but it's a good idea to have one to keep your config organized.
89
// Demonstrates how to use Neo's config APIs
910
@EventBusSubscriber(modid = MCTradePostMod.MODID, bus = EventBusSubscriber.Bus.MOD)
1011
public class Config
1112
{
13+
private static final ModConfigSpec.Builder BUILDER = new ModConfigSpec.Builder();
14+
static final ModConfigSpec SPEC = BUILDER.build();
1215

1316
@SubscribeEvent
1417
static void onLoad(final ModConfigEvent event)

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.slf4j.Logger;
44

5+
import com.deathfrog.mctradepost.api.sounds.ModSoundEvents;
56
import com.deathfrog.mctradepost.apiimp.initializer.ModBuildingsInitializer;
67
import com.deathfrog.mctradepost.apiimp.initializer.ModJobsInitializer;
78
import com.deathfrog.mctradepost.apiimp.initializer.ModModelTypeInitializer;
@@ -76,22 +77,24 @@ public class MCTradePostMod
7677
public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID);
7778

7879
// Creates a new Block with the id "examplemod:example_block", combining the namespace and path
79-
public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
80+
// public static final DeferredBlock<Block> EXAMPLE_BLOCK = BLOCKS.registerSimpleBlock("example_block", BlockBehaviour.Properties.of().mapColor(MapColor.STONE));
81+
8082
// Creates a new BlockItem with the id "examplemod:example_block", combining the namespace and path
81-
public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK);
83+
// public static final DeferredItem<BlockItem> EXAMPLE_BLOCK_ITEM = ITEMS.registerSimpleBlockItem("example_block", EXAMPLE_BLOCK);
8284

8385
// Creates a new food item with the id "examplemod:example_id", nutrition 1 and saturation 2
84-
public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item", new Item.Properties().food(new FoodProperties.Builder()
85-
.alwaysEdible().nutrition(1).saturationModifier(2f).build()));
86+
// public static final DeferredItem<Item> EXAMPLE_ITEM = ITEMS.registerSimpleItem("example_item", new Item.Properties().food(new FoodProperties.Builder().alwaysEdible().nutrition(1).saturationModifier(2f).build()));
8687

8788
// Creates a creative tab with the id "examplemod:example_tab" for the example item, that is placed after the combat tab
89+
/*
8890
public static final DeferredHolder<CreativeModeTab, CreativeModeTab> EXAMPLE_TAB = CREATIVE_MODE_TABS.register("example_tab", () -> CreativeModeTab.builder()
8991
.title(Component.translatable("itemGroup.examplemod")) //The language key for the title of your CreativeModeTab
9092
.withTabsBefore(CreativeModeTabs.COMBAT)
9193
.icon(() -> EXAMPLE_ITEM.get().getDefaultInstance())
9294
.displayItems((parameters, output) -> {
9395
output.accept(EXAMPLE_ITEM.get()); // Add the example item to the tab. For your own tabs, this method is preferred over the event
9496
}).build());
97+
*/
9598

9699
// The constructor for the mod class is the first code that is run when your mod is loaded.
97100
// FML will recognize some parameter types like IEventBus or ModContainer and pass them in automatically.
@@ -123,6 +126,7 @@ public MCTradePostMod(IEventBus modEventBus, ModContainer modContainer)
123126
ModJobsInitializer.DEFERRED_REGISTER.register(modEventBus);
124127
TileEntityInitializer.BLOCK_ENTITIES.register(modEventBus);
125128
ModBuildingsInitializer.DEFERRED_REGISTER.register(modEventBus);
129+
ModSoundEvents.SOUND_EVENTS.register(modEventBus);
126130
}
127131

128132
private void commonSetup(final FMLCommonSetupEvent event)
@@ -136,11 +140,11 @@ private void commonSetup(final FMLCommonSetupEvent event)
136140
private void addCreative(BuildCreativeModeTabContentsEvent event)
137141
{
138142
if (event.getTabKey() == CreativeModeTabs.BUILDING_BLOCKS) {
139-
event.accept(EXAMPLE_BLOCK_ITEM);
143+
// event.accept(EXAMPLE_BLOCK_ITEM);
140144
}
141145

142146
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
143-
event.accept(EXAMPLE_ITEM.get());
147+
// event.accept(EXAMPLE_ITEM.get());
144148
event.accept(MCTradePostMod.ADVANCED_CLIPBOARD.get());
145149
}
146150
}

src/main/java/com/deathfrog/mctradepost/api/colony/buildings/jobs/MCTPModJobs.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.deathfrog.mctradepost.api.colony.buildings.jobs;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import com.deathfrog.mctradepost.MCTradePostMod;
46
import com.minecolonies.api.colony.jobs.registry.JobEntry;
57
import net.minecraft.resources.ResourceLocation;
@@ -18,5 +20,13 @@ private MCTPModJobs()
1820
{
1921
throw new IllegalStateException("Tried to initialize: ModJobs but this is a Utility class.");
2022
}
23+
24+
public static List<ResourceLocation> getJobs()
25+
{
26+
List<ResourceLocation> jobs = new ArrayList<>() { };
27+
jobs.add(SHOPKEEPER_ID);
28+
29+
return jobs;
30+
}
2131
}
2232

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package com.deathfrog.mctradepost.api.sounds;
2+
3+
import com.deathfrog.mctradepost.MCTradePostMod;
4+
import com.deathfrog.mctradepost.api.colony.buildings.jobs.MCTPModJobs;
5+
import com.minecolonies.api.sounds.EventType;
6+
import com.minecolonies.api.util.Tuple;
7+
import net.minecraft.core.registries.Registries;
8+
import net.minecraft.resources.ResourceLocation;
9+
import net.minecraft.sounds.SoundEvent;
10+
import net.neoforged.neoforge.registries.DeferredRegister;
11+
import java.util.*;
12+
13+
/**
14+
* Registering of sound events for our colony.
15+
*/
16+
public final class ModSoundEvents
17+
{
18+
/**
19+
* Citizen sound prefix.
20+
*/
21+
public static final String CITIZEN_SOUND_EVENT_PREFIX = "citizen.";
22+
23+
public static final DeferredRegister<SoundEvent> SOUND_EVENTS = DeferredRegister.create(Registries.SOUND_EVENT, MCTradePostMod.MODID);
24+
25+
/**
26+
* Map of sound events.
27+
*/
28+
public static Map<String, Map<EventType, List<Tuple<SoundEvent, SoundEvent>>>> CITIZEN_SOUND_EVENTS = new HashMap<>();
29+
30+
/**
31+
* Private constructor to hide the implicit public one.
32+
*/
33+
private ModSoundEvents()
34+
{
35+
/*
36+
* Intentionally left empty.
37+
*/
38+
}
39+
40+
/**
41+
* Register the {@link SoundEvent}s.
42+
*
43+
* @param registry the registry to register at.
44+
*/
45+
static
46+
{
47+
final List<ResourceLocation> mainTypes = new ArrayList<>(MCTPModJobs.getJobs());
48+
49+
for (final ResourceLocation job : mainTypes)
50+
{
51+
final Map<EventType, List<Tuple<SoundEvent, SoundEvent>>> map = new HashMap<>();
52+
for (final EventType event : EventType.values())
53+
{
54+
final List<Tuple<SoundEvent, SoundEvent>> individualSounds = new ArrayList<>();
55+
for (int i = 1; i <= 4; i++)
56+
{
57+
final SoundEvent maleSoundEvent =
58+
ModSoundEvents.getSoundID(CITIZEN_SOUND_EVENT_PREFIX + job.getPath() + ".male" + i + "." + event.getId());
59+
final SoundEvent femaleSoundEvent =
60+
ModSoundEvents.getSoundID(CITIZEN_SOUND_EVENT_PREFIX + job.getPath() + ".female" + i + "." + event.getId());
61+
62+
SOUND_EVENTS.register(maleSoundEvent.getLocation().getPath(), () -> maleSoundEvent);
63+
SOUND_EVENTS.register(femaleSoundEvent.getLocation().getPath(), () -> femaleSoundEvent);
64+
individualSounds.add(new Tuple<>(maleSoundEvent, femaleSoundEvent));
65+
}
66+
map.put(event, individualSounds);
67+
}
68+
CITIZEN_SOUND_EVENTS.put(job.getPath(), map);
69+
}
70+
71+
final Map<EventType, List<Tuple<SoundEvent, SoundEvent>>> map = new HashMap<>();
72+
for (final EventType event : EventType.values())
73+
{
74+
final List<Tuple<SoundEvent, SoundEvent>> individualSounds = new ArrayList<>();
75+
for (int i = 1; i <= 2; i++)
76+
{
77+
final SoundEvent maleSoundEvent =
78+
ModSoundEvents.getSoundID(CITIZEN_SOUND_EVENT_PREFIX + "child.male" + i + "." + event.getId());
79+
final SoundEvent femaleSoundEvent =
80+
ModSoundEvents.getSoundID(CITIZEN_SOUND_EVENT_PREFIX + "child.female" + i + "." + event.getId());
81+
82+
individualSounds.add(new Tuple<>(maleSoundEvent, femaleSoundEvent));
83+
individualSounds.add(new Tuple<>(maleSoundEvent, femaleSoundEvent));
84+
}
85+
map.put(event, individualSounds);
86+
}
87+
CITIZEN_SOUND_EVENTS.put("child", map);
88+
89+
}
90+
91+
/**
92+
* Register a {@link SoundEvent}.
93+
*
94+
* @param soundName The SoundEvent's name without the minecolonies prefix
95+
* @return The SoundEvent
96+
*/
97+
public static SoundEvent getSoundID(final String soundName)
98+
{
99+
return SoundEvent.createVariableRangeEvent(ResourceLocation.parse(MCTradePostMod.MODID + ":" + soundName));
100+
}
101+
}

src/main/java/com/deathfrog/mctradepost/apiimp/initializer/ModModelTypeInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private ModModelTypeInitializer()
1616
}
1717

1818
// TODO: Design shopkeeper textures and models
19-
19+
// TODO: Set up and record shopkeeper sounds. Investigate ModSoundEvents.
2020

2121
public static void init(final EntityRendererProvider.Context context)
2222
{

src/main/java/com/deathfrog/mctradepost/core/blocks/huts/MCTPBaseBlockHut.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,17 @@ public void onBlockPlacedByBuildTool(
7777
if (tileEntity != null) {
7878
MCTradePostMod.LOGGER.info("Placing hut of type {}", tileEntity.getClass().getName());
7979
} else {
80-
MCTradePostMod.LOGGER.info("Attempting to place a null tile entity.");
80+
MCTradePostMod.LOGGER.info("Attempting to place a null tile entity.");
8181
}
8282

8383
if (tileEntity instanceof final MCTPTileEntityColonyBuilding hut)
8484
{
85+
MCTradePostMod.LOGGER.info("Rotation mirror: {}; pack name: {}; blueprint path: {}", rotMir, style, blueprintPath);
8586
hut.setRotationMirror(rotMir);
8687
hut.setPackName(style);
8788
hut.setBlueprintPath(blueprintPath);
89+
} else {
90+
MCTradePostMod.LOGGER.info("Wrong instance to place a tile entity of type {}", tileEntity.getClass().getName());
8891
}
8992

9093
setPlacedBy(worldIn, pos, state, placer, stack);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public BuildingMarketplace(@NotNull IColony colony, BlockPos pos) {
4646
* Description string of the building.
4747
*/
4848
// TODO: Consistency between building (MARKETPLACE) and job (SHOPKEEPER)
49-
// TODO: Upgrading the building throws an exception - possibly due to schematics not implemented as a data pack.
49+
// TODO: Worker has no face...
5050
private static final String SHOPKEEPER = "shopkeeper";
5151

5252

@@ -66,13 +66,14 @@ public int getMaxBuildingLevel()
6666
@Override
6767
public void registerBlockPosition(@NotNull final BlockState block, @NotNull final BlockPos pos, @NotNull final Level world)
6868
{
69+
// MCTradePostMod.LOGGER.info("Registering Block Position: " + block + " at " + pos);
6970
super.registerBlockPosition(block, pos, world);
7071
}
7172

7273
@Override
7374
public void deserializeNBT(@NotNull final HolderLookup.Provider provider, final CompoundTag compound)
7475
{
75-
76+
super.deserializeNBT(provider, compound);
7677
}
7778

7879
@Override
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": 1,
3+
"pack-format": 1,
4+
"desc": "Trade Post structures.",
5+
"authors":
6+
[
7+
"Ayar", "Alysar"
8+
],
9+
"mods":
10+
[
11+
"structurize", "mctradepost"
12+
],
13+
"name": "Economic",
14+
"icon": "tradepost.png"
15+
}
214 KB
Loading

0 commit comments

Comments
 (0)