Skip to content

Commit 517e29b

Browse files
authored
Fix #608: Add KubeJS event to register energy/fluid/item hatches (#1097)
1 parent c4b7f93 commit 517e29b

File tree

8 files changed

+124
-5
lines changed

8 files changed

+124
-5
lines changed

docs/ADDING_CABLE_TIERS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@ MIRegistrationEvents.registerCableTiers(event => {
3333

3434
To register a corresponding cable with the [material system](ADDING_MATERIALS.md),
3535
use `.cable("iv")` on a material builder.
36+
37+
To register corresponding energy input and output hatches,
38+
see the page on [adding hatches](ADDING_HATCHES.md).

docs/ADDING_HATCHES.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Adding hatches
2+
To add new energy, fluid, or item hatches, use the `MIRegistrationEvents.registerHatches` startup event.
3+
4+
## Energy
5+
Use the `energy` registration method to register energy input and output hatches for the given cable tier.
6+
For example:
7+
```js
8+
MIMachineEvents.registerHatches(event => {
9+
// Takes the internal name for the cable tier.
10+
event.energy("iv");
11+
});
12+
```
13+
14+
The default generated model for energy hatches will use the casing corresponding to the cable tier.
15+
16+
See also [Adding cable tiers](ADDING_CABLE_TIERS.md) for more information on how to add a cable tier.
17+
18+
## Fluid
19+
Use the `fluid` registration method to register fluid input and output hatches.
20+
These hatches are not necessarily bound to a cable or progression tier.
21+
22+
Here is an example:
23+
```js
24+
MIMachineEvents.registerHatches(event => {
25+
event.fluid(
26+
// English name for the hatch tier. " Fluid Input/Output Hatch" will be added by MI.
27+
"Huge",
28+
// Internal name for the tier.
29+
// In this cases, the block IDs of the hatches will be huge_fluid_input_hatch and huge_fluid_output_hatch.
30+
"huge",
31+
// Machine casing for the model of the hatch.
32+
"superconductor",
33+
// Number of buckets that the hatch can hold.
34+
1000,
35+
);
36+
});
37+
```
38+
39+
## Item
40+
Use the `item` registration method to register item input and output hatches.
41+
These hatches are not necessarily bound to a cable or progression tier.
42+
43+
Here is an example:
44+
```js
45+
MIMachineEvents.registerHatches(event => {
46+
event.item(
47+
// English name for the hatch tier. " Item Input/Output Hatch" will be added by MI.
48+
"Huge",
49+
// Internal name for the tier.
50+
// In this cases, the block IDs of the hatches will be huge_item_input_hatch and huge_item_output_hatch.
51+
"huge",
52+
// Machine casing for the model of the hatch.
53+
"superconductor",
54+
// Number of slot rows and columns for the hatch slots:
55+
3, 7, // 3 rows and 7 columns here
56+
// Starting position of the slot grid:
57+
10, 18, // the first slot will be at (10, 18) inside the GUI
58+
);
59+
});
60+
```

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ Here are some examples to get you started:
5252
Refer to the page that interests you:
5353
- [Cable tiers](ADDING_CABLE_TIERS.md)
5454
- [Fluids](ADDING_FLUIDS.md)
55+
- [Hatches](ADDING_HATCHES.md)
5556
- [Machines](ADDING_MACHINES.md)
5657
- [Materials](ADDING_MATERIALS.md)
5758
- [Nuclear reactor components](ADDING_NUCLEAR_COMPONENTS.md)

src/main/java/aztech/modern_industrialization/compat/kubejs/KubeJSProxy.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public void fireRegisterMachineCasingsEvent() {
5656
public void fireRegisterMachinesEvent() {
5757
}
5858

59+
public void fireRegisterHatchesEvent() {
60+
}
61+
5962
public void fireRegisterUpgradesEvent() {
6063
}
6164

src/main/java/aztech/modern_industrialization/compat/kubejs/LoadedKubeJSProxy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public void fireRegisterMachinesEvent() {
6969
MIMachineKubeJSEvents.REGISTER_MACHINES.post(new RegisterMachinesEventJS());
7070
}
7171

72+
@Override
73+
public void fireRegisterHatchesEvent() {
74+
MIMachineKubeJSEvents.REGISTER_HATCHES.post(new RegisterHatchesEventJS());
75+
}
76+
7277
@Override
7378
public void fireAddMultiblockSlotsEvent(String category, SlotPositions.Builder itemInputs, SlotPositions.Builder itemOutputs,
7479
SlotPositions.Builder fluidInputs, SlotPositions.Builder fluidOutputs) {

src/main/java/aztech/modern_industrialization/compat/kubejs/machine/MIMachineKubeJSEvents.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public interface MIMachineKubeJSEvents {
3434
EventHandler REGISTER_RECIPE_TYPES = EVENT_GROUP.startup("registerRecipeTypes", () -> RegisterRecipeTypesEventJS.class);
3535
EventHandler REGISTER_CASINGS = EVENT_GROUP.startup("registerCasings", () -> RegisterCasingsEventJS.class);
3636
EventHandler REGISTER_MACHINES = EVENT_GROUP.startup("registerMachines", () -> RegisterMachinesEventJS.class);
37+
EventHandler REGISTER_HATCHES = EVENT_GROUP.startup("registerHatches", () -> RegisterHatchesEventJS.class);
3738
TargetedEventHandler<String> ADD_MULTIBLOCK_SLOTS = EVENT_GROUP.startup("addMultiblockSlots", () -> AddMultiblockSlotsEventJS.class)
3839
.requiredTarget(EventTargetType.STRING);
3940
EventHandler ADD_EBF_TIERS = EVENT_GROUP.startup("addEbfTiers", () -> AddEbfTiersEventJS.class);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2020 Azercoco & Technici4n
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
package aztech.modern_industrialization.compat.kubejs.machine;
25+
26+
import aztech.modern_industrialization.api.energy.CableTier;
27+
import aztech.modern_industrialization.machines.init.MultiblockHatches;
28+
import aztech.modern_industrialization.machines.models.MachineCasings;
29+
import dev.latvian.mods.kubejs.event.KubeEvent;
30+
31+
public class RegisterHatchesEventJS implements KubeEvent {
32+
public void energy(String cableTier) {
33+
MultiblockHatches.registerEnergyHatches(CableTier.getTier(cableTier));
34+
}
35+
36+
public void fluid(String englishPrefix, String prefix, String casing, int bucketCapacity) {
37+
MultiblockHatches.registerFluidHatches(englishPrefix, prefix, MachineCasings.get(casing), bucketCapacity);
38+
}
39+
40+
public void item(String englishPrefix, String prefix, String casing, int rows, int columns, int xStart, int yStart) {
41+
MultiblockHatches.registerItemHatches(englishPrefix, prefix, MachineCasings.get(casing), rows, columns, xStart, yStart);
42+
}
43+
}

src/main/java/aztech/modern_industrialization/machines/init/MultiblockHatches.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
package aztech.modern_industrialization.machines.init;
2525

2626
import aztech.modern_industrialization.api.energy.CableTier;
27+
import aztech.modern_industrialization.compat.kubejs.KubeJSProxy;
2728
import aztech.modern_industrialization.inventory.ConfigurableFluidStack;
2829
import aztech.modern_industrialization.inventory.ConfigurableItemStack;
2930
import aztech.modern_industrialization.inventory.MIInventory;
@@ -72,9 +73,11 @@ public static void init() {
7273

7374
MachineRegistrationHelper.registerMachine("Large Tank Hatch", "large_tank_hatch", LargeTankHatch::new, LargeTankHatch::registerFluidApi);
7475
MachineRegistrationHelper.addMachineModel("large_tank_hatch", "hatch_fluid", MachineCasings.STEEL, false, false, true, false);
76+
77+
KubeJSProxy.instance.fireRegisterHatchesEvent();
7578
}
7679

77-
private static void registerItemHatches(
80+
public static void registerItemHatches(
7881
String englishPrefix, String prefix, MachineCasing casing, int rows, int columns, int xStart, int yStart) {
7982
for (int iter = 0; iter < 2; ++iter) {
8083
boolean input = iter == 0;
@@ -97,10 +100,10 @@ private static void registerItemHatches(
97100
}
98101
}
99102

100-
public static final int FLUID_HATCH_SLOT_X = 80;
101-
public static final int FLUID_HATCH_SLOT_Y = 40;
103+
private static final int FLUID_HATCH_SLOT_X = 80;
104+
private static final int FLUID_HATCH_SLOT_Y = 40;
102105

103-
private static void registerFluidHatches(String englishPrefix, String prefix, MachineCasing casing, int bucketCapacity) {
106+
public static void registerFluidHatches(String englishPrefix, String prefix, MachineCasing casing, int bucketCapacity) {
104107
for (int iter = 0; iter < 2; ++iter) {
105108
boolean input = iter == 0;
106109
String machine = prefix + "_fluid_" + (input ? "input" : "output") + "_hatch";
@@ -117,7 +120,7 @@ private static void registerFluidHatches(String englishPrefix, String prefix, Ma
117120
}
118121
}
119122

120-
private static void registerEnergyHatches(CableTier tier) {
123+
public static void registerEnergyHatches(CableTier tier) {
121124
for (int iter = 0; iter < 2; ++iter) {
122125
boolean input = iter == 0;
123126
String machine = tier.name + "_energy_" + (input ? "input" : "output") + "_hatch";

0 commit comments

Comments
 (0)