Skip to content

Commit 5b5cb7b

Browse files
committed
Initial pass at rewriting module containers and the module system to more properly interface with the immutable nature of data components
1 parent 9496be1 commit 5b5cb7b

File tree

75 files changed

+2271
-1883
lines changed

Some content is hidden

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

75 files changed

+2271
-1883
lines changed

src/api/java/mekanism/api/NBTConstants.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ private NBTConstants() {
5454
public static final String SCALE_ALT_2 = "scale2";
5555
public static final String SCALE_ALT_3 = "scale3";
5656
public static final String SOUND_SCALE = "soundScale";
57+
/**
58+
* @since 10.6.0
59+
*/
60+
public static final String VALUE = "value";
5761
public static final String VALVE = "valve";
5862
public static final String VOLUME = "volume";
5963

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package mekanism.api.gear;
2+
3+
import mekanism.api.annotations.NothingNullByDefault;
4+
import net.minecraft.world.item.enchantment.Enchantment;
5+
6+
/**
7+
* Abstract implementation to make creating custom modules that provide a specific enchantment when installed easier, while also properly "hiding" the fact that there is
8+
* an enchantment applied. This does not provide any easy way to make the enchantment use energy or other resources, and is probably only useful for enchantments that
9+
* have a lot of hardcoded checks so reproducing functionality would be extremely hard if even possible.
10+
* <p>
11+
* Instances of this should be returned via the {@link ModuleData}.
12+
*
13+
* @since 10.6.0
14+
*/
15+
@NothingNullByDefault//TODO - 1.20.5: Update docs on this
16+
public interface EnchantmentAwareModule<MODULE extends EnchantmentAwareModule<MODULE>> extends ICustomModule<MODULE> {
17+
18+
/**
19+
* Gets the enchantment that this module provides when enabled.
20+
*
21+
* @return The enchantment that this module provides.
22+
*/
23+
Enchantment enchantment();
24+
25+
//TODO - 1.20.5: Docs
26+
default int getLevelFor(IModule<MODULE> module) {
27+
return module.isEnabled() ? module.getInstalledCount() : 0;
28+
}
29+
}

src/api/java/mekanism/api/gear/EnchantmentBasedModule.java

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

src/api/java/mekanism/api/gear/ICustomModule.java

Lines changed: 60 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.function.Consumer;
55
import mekanism.api.annotations.NothingNullByDefault;
66
import mekanism.api.functions.FloatSupplier;
7-
import mekanism.api.gear.config.ModuleConfigItemCreator;
87
import mekanism.api.math.FloatingLongSupplier;
98
import mekanism.api.radial.RadialData;
109
import mekanism.api.radial.mode.IRadialMode;
@@ -29,57 +28,55 @@
2928
@NothingNullByDefault
3029
public interface ICustomModule<MODULE extends ICustomModule<MODULE>> {
3130

32-
/**
33-
* Called when initializing a new module instance and the backing custom module. This can be used to create module config items that will show up in the ModuleTweaker
34-
* and can be used to control various settings of this module.
35-
*
36-
* @param module Module instance.
37-
* @param configItemCreator Helper to create module config items.
38-
*/
39-
default void init(IModule<MODULE> module, ModuleConfigItemCreator configItemCreator) {
40-
}
41-
4231
/**
4332
* Called each tick on the server side when installed in a MekaSuit and set to enabled.
4433
*
45-
* @param module Module instance.
46-
* @param player Player wearing the MekaSuit.
34+
* @param module Module instance.
35+
* @param moduleContainer The container this module is part of.
36+
* @param stack The stack this module is installed on.
37+
* @param player Player wearing the MekaSuit.
4738
*/
48-
default void tickServer(IModule<MODULE> module, Player player) {
39+
default void tickServer(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, Player player) {
4940
}
5041

5142
/**
5243
* Called each tick on the client side when installed in a MekaSuit and set to enabled.
5344
*
54-
* @param module Module instance.
55-
* @param player Player wearing the MekaSuit.
45+
* @param module Module instance.
46+
* @param moduleContainer The container this module is part of.
47+
* @param stack The stack this module is installed on.
48+
* @param player Player wearing the MekaSuit.
5649
*/
57-
default void tickClient(IModule<MODULE> module, Player player) {
50+
default void tickClient(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, Player player) {
5851
}
5952

6053
/**
6154
* Called to collect any HUD strings that should be displayed. This will only be called if {@link ModuleData#rendersHUD()} is {@code true}.
6255
*
63-
* @param module Module instance.
64-
* @param player Player using the Meka-Tool or wearing the MekaSuit. In general this will be the client player, but is passed to make sidedness safer and
65-
* easier.
66-
* @param hudStringAdder Accepts and adds HUD strings.
56+
* @param module Module instance.
57+
* @param moduleContainer The container this module is part of.
58+
* @param stack The stack this module is installed on.odule is installed on.
59+
* @param player Player using the Meka-Tool or wearing the MekaSuit. In general this will be the client player, but is passed to make sidedness safer and
60+
* easier.
61+
* @param hudStringAdder Accepts and adds HUD strings.
6762
*/
68-
default void addHUDStrings(IModule<MODULE> module, Player player, Consumer<Component> hudStringAdder) {
63+
default void addHUDStrings(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, Player player, Consumer<Component> hudStringAdder) {
6964
}
7065

7166
/**
7267
* Called to collect any HUD elements that should be displayed when the MekaSuit is rendering the HUD. This will only be called if {@link ModuleData#rendersHUD()} is
7368
* {@code true}.
7469
*
7570
* @param module Module instance.
71+
* @param moduleContainer The container this module is part of.
72+
* @param stack The stack this module is installed on.
7673
* @param player Player using the Meka-Tool or wearing the MekaSuit. In general this will be the client player, but is passed to make sidedness safer and
7774
* easier.
7875
* @param hudElementAdder Accepts and adds HUD elements.
7976
*
8077
* @apiNote See {@link IModuleHelper} for various helpers to create HUD elements.
8178
*/
82-
default void addHUDElements(IModule<MODULE> module, Player player, Consumer<IHUDElement> hudElementAdder) {
79+
default void addHUDElements(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, Player player, Consumer<IHUDElement> hudElementAdder) {
8380
}
8481

8582
/**
@@ -131,13 +128,14 @@ default Component getModeScrollComponent(IModule<MODULE> module, ItemStack stack
131128
*
132129
* @param module Module instance.
133130
* @param player The player who made the mode change.
131+
* @param moduleContainer The container this module is part of.
134132
* @param stack The stack to change the mode of.
135133
* @param shift The amount to shift the mode by, may be negative for indicating the mode should decrease.
136134
* @param displayChangeMessage {@code true} if a message should be displayed when the mode changes
137135
*
138136
* @see #canChangeModeWhenDisabled(IModule)
139137
*/
140-
default void changeMode(IModule<MODULE> module, Player player, ItemStack stack, int shift, boolean displayChangeMessage) {
138+
default void changeMode(IModule<MODULE> module, Player player, IModuleContainer moduleContainer, ItemStack stack, int shift, boolean displayChangeMessage) {
141139
}
142140

143141
/**
@@ -177,52 +175,49 @@ default <MODE extends IRadialMode> MODE getMode(IModule<MODULE> module, ItemStac
177175
* Called by the Meka-Tool to attempt to set the mode of the module for the given radial data. This will only be called if {@link ModuleData#handlesModeChange()} is
178176
* {@code true}, but may be called when this module does not support or handle the given radial type, so the radial type should be validated.
179177
*
180-
* @param module Module instance.
181-
* @param player The player who is attempting to set the mode.
182-
* @param stack The stack to set the mode of.
183-
* @param radialData Radial data of the mode being set.
184-
* @param mode Mode to attempt to set if this module can handle modes of this type.
185-
* @param <MODE> Radial Mode.
178+
* @param <MODE> Radial Mode.
179+
* @param module Module instance.
180+
* @param player The player who is attempting to set the mode.
181+
* @param moduleContainer The container this module is part of.
182+
* @param stack The stack this module is installed on.
183+
* @param radialData Radial data of the mode being set.
184+
* @param mode Mode to attempt to set if this module can handle modes of this type.
186185
*
187186
* @return {@code true} if this module was able to handle the given radial data.
188187
*
189188
* @see #canChangeRadialModeWhenDisabled(IModule)
190189
* @since 10.3.2
191190
*/
192-
default <MODE extends IRadialMode> boolean setMode(IModule<MODULE> module, Player player, ItemStack stack, RadialData<MODE> radialData, MODE mode) {
191+
default <MODE extends IRadialMode> boolean setMode(IModule<MODULE> module, Player player, IModuleContainer moduleContainer, ItemStack stack, RadialData<MODE> radialData, MODE mode) {
193192
return false;
194193
}
195194

196195
/**
197196
* Called when this module is added to an item.
198197
*
199-
* @param module Module instance.
200-
* @param first {@code true} if it is the first module of this type installed.
198+
* @param module Module instance.
199+
* @param moduleContainer The container this module is part of.
200+
* @param stack The stack this module is installed on.
201+
* @param first {@code true} if it is the first module of this type installed.
201202
*
202203
* @apiNote This method may be called when more than one module is added at once, so it is important to get the installed count from the module rather than assume it
203204
* just went up by one.
204205
*/
205-
default void onAdded(IModule<MODULE> module, boolean first) {
206+
default void onAdded(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, boolean first) {
206207
}
207208

208209
/**
209210
* Called when this module is removed from an item.
210211
*
211-
* @param module Module instance.
212-
* @param last {@code true} if it was the last module of this type installed.
212+
* @param module Module instance.
213+
* @param moduleContainer The container this module is part of.
214+
* @param stack The stack this module is installed on.
215+
* @param wasLast {@code true} if it was the last module of this type installed.
213216
*
214-
* @apiNote This method may be called when more than one module is removed at once, so it is important to get the installed count from the module rather than assume it
215-
* just down up by one.
217+
* @apiNote This method may be called when more than one module is removed at once, so it is important to get the installed count from the module rather than assume
218+
* it just down up by one.
216219
*/
217-
default void onRemoved(IModule<MODULE> module, boolean last) {
218-
}
219-
220-
/**
221-
* Called when the enabled state of this module changes.
222-
*
223-
* @param module Module instance.
224-
*/
225-
default void onEnabledStateChange(IModule<MODULE> module) {
220+
default void onRemoved(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, boolean wasLast) {
226221
}
227222

228223
/**
@@ -253,37 +248,43 @@ default InteractionResult onItemUse(IModule<MODULE> module, UseOnContext context
253248
/**
254249
* Called to check if this module allows the Meka-Tool to perform a specific {@link ToolAction}.
255250
*
256-
* @param module Module instance.
257-
* @param action Tool action to check.
251+
* @param module Module instance.
252+
* @param moduleContainer The container this module is part of.
253+
* @param stack The stack this module is installed on.
254+
* @param action Tool action to check.
258255
*/
259-
default boolean canPerformAction(IModule<MODULE> module, ToolAction action) {
256+
default boolean canPerformAction(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, ToolAction action) {
260257
return false;
261258
}
262259

263260
/**
264261
* Called when the Meka-Tool is used on an entity to allow modules to implement custom interact behavior.
265262
*
266-
* @param module Module instance.
267-
* @param player Player using the Meka-Tool.
268-
* @param entity Entity type being interacted with.
269-
* @param hand Hand used.
263+
* @param module Module instance.
264+
* @param player Player using the Meka-Tool.
265+
* @param entity Entity type being interacted with.
266+
* @param hand Hand used.
267+
* @param moduleContainer The container this module is part of.
268+
* @param stack Stack the module is installed on and is being used to interact with an entity.
270269
*
271270
* @return Result type or {@link InteractionResult#PASS} to pass.
272271
*/
273-
default InteractionResult onInteract(IModule<MODULE> module, Player player, LivingEntity entity, InteractionHand hand) {
272+
default InteractionResult onInteract(IModule<MODULE> module, Player player, LivingEntity entity, InteractionHand hand, IModuleContainer moduleContainer, ItemStack stack) {
274273
return InteractionResult.PASS;
275274
}
276275

277276
/**
278277
* Called on enabled modules when the Meka-Tool or MekaSuit is "dispensed" from a dispenser. The MekaSuit will prioritize performing the vanilla armor dispense
279278
* behavior of equipping on entities before checking if any of the modules have a custom behavior.
280279
*
281-
* @param module Module instance.
282-
* @param source Dispenser source information.
280+
* @param module Module instance.
281+
* @param moduleContainer The container this module is part of.
282+
* @param stack The stack this module is installed on.
283+
* @param source Dispenser source information.
283284
*
284285
* @return The {@link ModuleDispenseResult} defining how this dispenser should behave.
285286
*/
286-
default ModuleDispenseResult onDispense(IModule<MODULE> module, BlockSource source) {
287+
default ModuleDispenseResult onDispense(IModule<MODULE> module, IModuleContainer moduleContainer, ItemStack stack, BlockSource source) {
287288
return ModuleDispenseResult.DEFAULT;
288289
}
289290

@@ -304,7 +305,7 @@ record ModuleDamageAbsorbInfo(@NotNull FloatSupplier absorptionRatio, @NotNull F
304305
}
305306

306307
/**
307-
* Represents the different result states of {@link ICustomModule#onDispense(IModule, BlockSource)}.
308+
* Represents the different result states of {@link ICustomModule#onDispense(IModule, IModuleContainer, ItemStack, BlockSource)}.
308309
*/
309310
enum ModuleDispenseResult {
310311
/**

0 commit comments

Comments
 (0)