Skip to content

Commit 2a24196

Browse files
authored
feat: Add Touhou Little Maid experience lantern compatibility (#385)
- Experience Lantern can now drain experience from nearby TLM maids - Works both when placed and when on contraptions - Added config option 'experienceLanternDrainMaidExperience' to toggle this feature - TLM is an optional soft dependency (mod works without it)
1 parent 29e81cd commit 2a24196

File tree

9 files changed

+194
-0
lines changed

9 files changed

+194
-0
lines changed

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ dependencies {
102102

103103
compileOnly("top.theillusivec4.curios:curios-neoforge:${curios_version}+${curios_minecraft_version}:api")
104104
localRuntime("top.theillusivec4.curios:curios-neoforge:${curios_version}+${curios_minecraft_version}")
105+
106+
// Touhou Little Maid integration (optional)
107+
compileOnly("curse.maven:touhou-little-maid-355044:${tlm_file_id}")
105108
}
106109

107110
var generateModMetadata = tasks.register("generateModMetadata", ProcessResources) {

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,5 @@ jei_minecraft_version = 1.21.1
3232
jei_version = 19.21.2.313
3333
curios_minecraft_version = 1.21.1
3434
curios_version = 9.2.2
35+
# Touhou Little Maid (optional)
36+
tlm_file_id = 7307724

src/main/java/plus/dragons/createenchantmentindustry/common/fluids/lantern/ExperienceLanternBlockEntity.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import plus.dragons.createenchantmentindustry.common.fluids.experience.ExperienceHelper;
4545
import plus.dragons.createenchantmentindustry.common.registry.CEIFluids;
4646
import plus.dragons.createenchantmentindustry.config.CEIConfig;
47+
import plus.dragons.createenchantmentindustry.integration.tlm.TLMCompat;
4748

4849
public class ExperienceLanternBlockEntity extends SmartBlockEntity implements IHaveGoggleInformation {
4950
protected FluidTankBehaviour tank;
@@ -129,6 +130,19 @@ protected void drainExp() {
129130
}
130131
}
131132
}
133+
// Drain experience from Touhou Little Maid's maids if the mod is loaded
134+
if (TLMCompat.isLoaded() && CEIConfig.fluids().experienceLanternDrainMaidExperience.get()) {
135+
drainMaidExp();
136+
}
137+
}
138+
139+
/**
140+
* Drain experience from nearby Touhou Little Maid's maids.
141+
* This method is only called when TLM mod is loaded.
142+
*/
143+
protected void drainMaidExp() {
144+
plus.dragons.createenchantmentindustry.integration.tlm.MaidExperienceHandler
145+
.drainMaidExperience(level, effectiveAABB, tank.getPrimaryHandler());
132146
}
133147

134148
protected void pullExp() {

src/main/java/plus/dragons/createenchantmentindustry/common/fluids/lantern/ExperienceLanternMovementBehaviour.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import plus.dragons.createenchantmentindustry.common.fluids.experience.ExperienceHelper;
3535
import plus.dragons.createenchantmentindustry.common.registry.CEIFluids;
3636
import plus.dragons.createenchantmentindustry.config.CEIConfig;
37+
import plus.dragons.createenchantmentindustry.integration.tlm.TLMCompat;
3738

3839
public class ExperienceLanternMovementBehaviour implements MovementBehaviour {
3940
@Override
@@ -106,6 +107,11 @@ protected void drainExp(Level level, AABB effectiveAABB, MountedFluidStorageWrap
106107
}
107108
}
108109
}
110+
// Drain experience from Touhou Little Maid's maids if the mod is loaded
111+
if (TLMCompat.isLoaded() && CEIConfig.fluids().experienceLanternDrainMaidExperience.get()) {
112+
plus.dragons.createenchantmentindustry.integration.tlm.MaidExperienceHandler
113+
.drainMaidExperience(level, effectiveAABB, tank);
114+
}
109115
}
110116

111117
protected void pullExp(Level level, AABB effectiveAABB, Vec3 position) {

src/main/java/plus/dragons/createenchantmentindustry/config/CEIFluidsConfig.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ public class CEIFluidsConfig extends ConfigBase {
9393
public final ConfigFloat experienceLanternPullForceMultiplier = f(.075f, 0.0f, .5f,
9494
"experienceLanternPullForceMultiplier",
9595
Comments.experienceLanternPullForceMultiplier);
96+
public final ConfigBool experienceLanternDrainMaidExperience = b(true,
97+
"experienceLanternDrainMaidExperience",
98+
Comments.experienceLanternDrainMaidExperience);
9699
public final ConfigInt mechanicalGrindstoneFluidCapacity = i(1000, 5000,
97100
"mechanicalGrindstoneFluidCapacity",
98101
Comments.mechanicalGrindstoneFluidCapacity,
@@ -126,6 +129,7 @@ static class Comments {
126129
static final String experienceLanternPullToggle = "Whether the Experience Lantern will pull in experience orbs from nearby.";
127130
static final String experienceLanternPullRadius = "The range at which experience orbs will be pulled into the lantern.";
128131
static final String experienceLanternPullForceMultiplier = "Modifier for the amount of force with which to pull the experience orbs.";
132+
static final String experienceLanternDrainMaidExperience = "Whether the Experience Lantern will drain experience from nearby Touhou Little Maid's maids (requires TLM mod).";
129133
static final String mechanicalGrindstoneFluidCapacity = "The amount of liquid a Grindstone Drain can hold (mB).";
130134
}
131135
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright (C) 2025 DragonsPlus
3+
* SPDX-License-Identifier: LGPL-3.0-or-later
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package plus.dragons.createenchantmentindustry.integration.tlm;
20+
21+
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
22+
import java.util.List;
23+
import java.util.concurrent.atomic.AtomicInteger;
24+
import net.minecraft.world.level.Level;
25+
import net.minecraft.world.phys.AABB;
26+
import net.neoforged.neoforge.fluids.FluidStack;
27+
import net.neoforged.neoforge.fluids.capability.IFluidHandler;
28+
import plus.dragons.createenchantmentindustry.common.registry.CEIFluids;
29+
import plus.dragons.createenchantmentindustry.config.CEIConfig;
30+
31+
/**
32+
* Handler for draining experience from Touhou Little Maid's EntityMaid.
33+
* This class is only loaded when TLM is present.
34+
*/
35+
public class MaidExperienceHandler {
36+
/**
37+
* Drain experience from nearby maids and fill into the fluid handler.
38+
*
39+
* @param level the world level
40+
* @param effectiveAABB the area to search for maids
41+
* @param fluidHandler the fluid handler to fill experience into
42+
* @return the total amount of experience drained
43+
*/
44+
public static int drainMaidExperience(Level level, AABB effectiveAABB, IFluidHandler fluidHandler) {
45+
var rate = CEIConfig.fluids().experienceLanternDrainRate.get();
46+
List<EntityMaid> maids = level.getEntitiesOfClass(EntityMaid.class, effectiveAABB,
47+
maid -> maid.isAlive() && maid.getExperience() > 0);
48+
49+
if (maids.isEmpty()) {
50+
return 0;
51+
}
52+
53+
AtomicInteger totalDrained = new AtomicInteger();
54+
55+
// Calculate the total experience we can drain
56+
AtomicInteger sum = new AtomicInteger();
57+
maids.forEach(maid -> {
58+
var maidExp = maid.getExperience();
59+
if (maidExp >= rate) {
60+
sum.addAndGet(rate);
61+
} else if (maidExp > 0) {
62+
sum.addAndGet(maidExp);
63+
}
64+
});
65+
66+
if (sum.get() == 0) {
67+
return 0;
68+
}
69+
70+
// Try to insert the experience fluid
71+
var inserted = fluidHandler.fill(new FluidStack(CEIFluids.EXPERIENCE, sum.get()), IFluidHandler.FluidAction.EXECUTE);
72+
73+
if (inserted > 0) {
74+
// Distribute the drain across maids
75+
int remaining = inserted;
76+
for (var maid : maids) {
77+
if (remaining <= 0) break;
78+
79+
var maidExp = maid.getExperience();
80+
int toDrain;
81+
82+
if (remaining >= rate) {
83+
toDrain = Math.min(maidExp, rate);
84+
} else {
85+
toDrain = Math.min(maidExp, remaining);
86+
}
87+
88+
if (toDrain > 0) {
89+
maid.setExperience(maidExp - toDrain);
90+
remaining -= toDrain;
91+
totalDrained.addAndGet(toDrain);
92+
}
93+
}
94+
}
95+
96+
return totalDrained.get();
97+
}
98+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (C) 2025 DragonsPlus
3+
* SPDX-License-Identifier: LGPL-3.0-or-later
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package plus.dragons.createenchantmentindustry.integration.tlm;
20+
21+
import net.neoforged.fml.ModList;
22+
23+
/**
24+
* Compatibility utility class for Touhou Little Maid mod.
25+
*/
26+
public class TLMCompat {
27+
public static final String MOD_ID = "touhou_little_maid";
28+
private static Boolean loaded = null;
29+
30+
/**
31+
* Check if Touhou Little Maid mod is loaded.
32+
*
33+
* @return true if TLM is present
34+
*/
35+
public static boolean isLoaded() {
36+
if (loaded == null) {
37+
loaded = ModList.get().isLoaded(MOD_ID);
38+
}
39+
return loaded;
40+
}
41+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2025 DragonsPlus
3+
* SPDX-License-Identifier: LGPL-3.0-or-later
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
* You should have received a copy of the GNU General Public License
13+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
*/
15+
16+
/**
17+
* Integration with Touhou Little Maid mod.
18+
*/
19+
package plus.dragons.createenchantmentindustry.integration.tlm;

src/main/templates/META-INF/neoforge.mods.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ issueTrackerURL="${mod_github}/issues"
5151
versionRange="${create_dragons_plus_version_range}"
5252
ordering="NONE"
5353
side="BOTH"
54+
55+
[[dependencies.${mod_id}]]
56+
modId="touhou_little_maid"
57+
type="optional"
58+
versionRange="[1.2.0,)"
59+
ordering="AFTER"
60+
side="BOTH"

0 commit comments

Comments
 (0)