Skip to content

Commit 6a21335

Browse files
committed
UD-260205
1 parent 86286fe commit 6a21335

13 files changed

Lines changed: 232 additions & 45 deletions

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mae_version=1.0.2
2525
mod_id=mia
2626
mod_name=Memento In Abyss
2727
mod_license=MIT
28-
mod_version=0.1.0-alpha.16
28+
mod_version=0.1.0-alpha.17
2929
mod_group_id=com.altnoir.mia
3030
mod_authors=Altnoir, lonelyicer, zljtt, zhaijineet
3131
mod_description=Memento In Abyss.

src/main/java/com/altnoir/mia/MiaConfig.java

Lines changed: 48 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ public class MiaConfig {
88
private static final ModConfigSpec.Builder COMMON_BUILDER = new ModConfigSpec.Builder();
99
private static final ModConfigSpec.Builder SERVER_BUILDER = new ModConfigSpec.Builder();
1010

11+
public enum AbyssMobLevelIncreasingCurve {FROM_FAST_TO_SLOW, FROM_SLOW_TO_FAST}
12+
1113
public static int abyssRadius;
12-
public static int blazeReapExplosionCount;
13-
public static double blazeReapExplosionRadius;
1414

15+
// ==================== 诅咒配置 ====================
1516
public static boolean curse;
1617
public static boolean curseGod;
17-
public static int caveExplorerBeaconHorizontal;
18-
public static int caveExplorerBeaconVertical;
19-
public static boolean caveExplorerBeaconMaxVertical;
18+
19+
// ==================== 无尽锤配置 ===================
20+
public static int blazeReapExplosionCount;
21+
public static double blazeReapExplosionRadius;
2022

2123
// ==================== 钩爪配置 ====================
2224
public static double hookMaxDistance;
@@ -27,6 +29,15 @@ public class MiaConfig {
2729
public static double hookRetractDistance;
2830
public static double hookJumpBoost;
2931

32+
// ==================== 探窟者信标配置 ====================
33+
public static int caveExplorerBeaconHorizontal;
34+
public static int caveExplorerBeaconVertical;
35+
public static boolean caveExplorerBeaconMaxVertical;
36+
37+
// ==================== 深渊怪物等级配置 ====================
38+
public static boolean abyssMobLevelSwitch;
39+
public static AbyssMobLevelIncreasingCurve abyssMobLevelIncreasingCurve;
40+
3041
private static final ModConfigSpec.IntValue ABYSS_RADIUS = COMMON_BUILDER
3142
.comment("The radius of the Abyss (Default: 160) | 深渊半径 (默认值: 160)")
3243
.defineInRange("abyss_radius", 160, 64, 10000);
@@ -43,36 +54,33 @@ public class MiaConfig {
4354
/**
4455
* 钩爪相关的配置
4556
*/
46-
private static final ModConfigSpec.Builder HOOK = COMMON_BUILDER.push("hook")
47-
.comment("Hook Configuration | 钩爪配置");
48-
49-
private static final ModConfigSpec.DoubleValue HOOK_MAX_DISTANCE = HOOK
57+
private static final ModConfigSpec.DoubleValue HOOK_MAX_DISTANCE = COMMON_BUILDER
5058
.comment("Maximum hook distance in blocks (Default: 32.0) | 最大钩爪距离 (默认值: 32.0)")
51-
.defineInRange("hook_max_distance", 32.0, 1.0, 256.0);
59+
.defineInRange("hook.max_distance", 32.0, 1.0, 256.0);
5260

53-
private static final ModConfigSpec.DoubleValue HOOK_SHOOT_VELOCITY = HOOK
61+
private static final ModConfigSpec.DoubleValue HOOK_SHOOT_VELOCITY = COMMON_BUILDER
5462
.comment("Hook shoot velocity (Default: 4.0) | 钩爪射击速度 (默认值: 4.0)")
55-
.defineInRange("hook_shoot_velocity", 4.0, 0.5, 4.0);
63+
.defineInRange("hook.shoot_velocity", 4.0, 0.5, 4.0);
5664

57-
private static final ModConfigSpec.DoubleValue HOOK_PULL_VELOCITY = HOOK
65+
private static final ModConfigSpec.DoubleValue HOOK_PULL_VELOCITY = COMMON_BUILDER
5866
.comment("Base pull velocity (Default: 0.3) | 基础拉取速度 (默认值: 0.2)")
59-
.defineInRange("hook_pull_velocity", 0.2, 0.01, 2.0);
67+
.defineInRange("hook.pull_velocity", 0.2, 0.01, 2.0);
6068

61-
private static final ModConfigSpec.DoubleValue HOOK_STOP_DISTANCE = HOOK
69+
private static final ModConfigSpec.DoubleValue HOOK_STOP_DISTANCE = COMMON_BUILDER
6270
.comment("Distance at which the hook stops pulling the player (Default: 1.0) | 钩爪停止拉取距离 (默认值: 1.0)")
63-
.defineInRange("hook_stop_distance", 1.41421, 1.0, 10.0);
71+
.defineInRange("hook.stop_distance", 1.41421, 1.0, 10.0);
6472

65-
private static final ModConfigSpec.DoubleValue HOOK_RETRACT_VELOCITY = HOOK
73+
private static final ModConfigSpec.DoubleValue HOOK_RETRACT_VELOCITY = COMMON_BUILDER
6674
.comment("Hook retract velocity (Default: 0.75) | 钩爪收回速度 (默认值: 0.75)")
67-
.defineInRange("hook_retract_velocity", 0.75, 0.1, 5.0);
75+
.defineInRange("hook.retract_velocity", 0.75, 0.1, 5.0);
6876

69-
private static final ModConfigSpec.DoubleValue HOOK_RETRACT_DISTANCE = HOOK
77+
private static final ModConfigSpec.DoubleValue HOOK_RETRACT_DISTANCE = COMMON_BUILDER
7078
.comment("Retract distance in blocks (Default: 4.0) | 回收距离 (默认值: 4.0)")
71-
.defineInRange("hook_retract_distance", 4.0, 1.0, 16.0);
79+
.defineInRange("hook.retract_distance", 4.0, 1.0, 16.0);
7280

73-
private static final ModConfigSpec.DoubleValue HOOK_JUMP_BOOST = HOOK
81+
private static final ModConfigSpec.DoubleValue HOOK_JUMP_BOOST = COMMON_BUILDER
7482
.comment("Jump boost multiplier (Default: 1.25) | 跳跃增强倍数 (默认值: 1.25)")
75-
.defineInRange("hook_jump_boost", 1.25, 1.0, 3.0);
83+
.defineInRange("hook.jump_boost", 1.25, 1.0, 3.0);
7684

7785
/**
7886
* 诅咒相关的配置
@@ -87,18 +95,25 @@ public class MiaConfig {
8795
/**
8896
* 探窟者信标相关的配置
8997
*/
90-
private static final ModConfigSpec.Builder CAVE_EXPLORER = SERVER_BUILDER.push("cave_explorer_beacon")
91-
.comment("Cave Explorer Beacon Configuration | 探窟者信标配置");
92-
93-
private static final ModConfigSpec.IntValue CAVE_EXPLORER_BEACON_HORIZONTAL = CAVE_EXPLORER
98+
private static final ModConfigSpec.IntValue CAVE_EXPLORER_BEACON_HORIZONTAL = SERVER_BUILDER
9499
.comment("The horizontal range of the Cave Explorer Beacon, Beacon Level x (Default: 10) + 10 | 探窟者信标水平半径,信标等级 x (默认值: 10) + 10")
95-
.defineInRange("cave_explorer_beacon_horizontal", 10, 1, 1000);
96-
private static final ModConfigSpec.IntValue CAVE_EXPLORER_BEACON_VERTICAL = CAVE_EXPLORER
100+
.defineInRange("cave_explorer_beacon.horizontal", 10, 1, 1000);
101+
private static final ModConfigSpec.IntValue CAVE_EXPLORER_BEACON_VERTICAL = SERVER_BUILDER
97102
.comment("The vertical range of the Cave Explorer Beacon, Beacon Level x (Default: 5) + 5 | 探窟者信标垂直半径,信标等级 x (默认值: 5) + 5")
98-
.defineInRange("cave_explorer_beacon_vertical", 5, 1, 1000);
99-
private static final ModConfigSpec.BooleanValue CAVE_EXPLORER_BEACON_MAX_VERTICAL = CAVE_EXPLORER
103+
.defineInRange("cave_explorer_beacon.vertical", 5, 1, 1000);
104+
private static final ModConfigSpec.BooleanValue CAVE_EXPLORER_BEACON_MAX_VERTICAL = SERVER_BUILDER
100105
.comment("Whether to set the vertical range of the Cave Explorer Beacon to the world height (Default: false) | 是否把探窟者信标垂直半径设置为世界高度 (默认值: false)")
101-
.define("cave_explorer_beacon_max_vertical", false);
106+
.define("cave_explorer_beacon.max_vertical", false);
107+
108+
/**
109+
* 深渊怪物等级相关的配置
110+
*/
111+
private static final ModConfigSpec.BooleanValue ABYSS_MOB_LEVEL_SWITCH = SERVER_BUILDER
112+
.comment("Switch to enable the Abyss Mob Level (Default: true) | 开启深渊怪物等级 (默认值: true)")
113+
.define("abyss_mob_level.switch", true);
114+
private static final ModConfigSpec.EnumValue<AbyssMobLevelIncreasingCurve> ABYSS_MOB_LEVEL_INCREASING_CURVE = SERVER_BUILDER
115+
.comment("The increasing curve of the Abyss Mob Level (Default: FromSlowToFast) | 深渊怪物等级增长曲线 (默认值: FromSlowToFast)")
116+
.defineEnum("abyss_mob_level.increasing_curve", AbyssMobLevelIncreasingCurve.FROM_FAST_TO_SLOW);
102117

103118
public static final ModConfigSpec COMMON_SPEC = COMMON_BUILDER.build();
104119
public static final ModConfigSpec SERVER_SPEC = SERVER_BUILDER.build();
@@ -124,6 +139,8 @@ public static void onLoad(ModConfig config) {
124139
caveExplorerBeaconHorizontal = CAVE_EXPLORER_BEACON_HORIZONTAL.get();
125140
caveExplorerBeaconVertical = CAVE_EXPLORER_BEACON_VERTICAL.get();
126141
caveExplorerBeaconMaxVertical = CAVE_EXPLORER_BEACON_MAX_VERTICAL.get();
142+
abyssMobLevelSwitch = ABYSS_MOB_LEVEL_SWITCH.get();
143+
abyssMobLevelIncreasingCurve = ABYSS_MOB_LEVEL_INCREASING_CURVE.get();
127144
}
128145
}
129146
}

src/main/java/com/altnoir/mia/client/MIAClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ public static void addGameEventBus(IEventBus gameEventBus) {
3636
gameEventBus.addListener(MiaClientEvents::onRenderOverlay);
3737
gameEventBus.addListener(MiaClientEvents::onScreenInitPost);
3838
gameEventBus.addListener(MiaClientEvents::onTooltip);
39+
gameEventBus.addListener(MiaClientEvents::onRenderNameTag);
40+
//gameEventBus.addListener(MiaClientEvents::onCameraAngles);
3941
}
4042
}

src/main/java/com/altnoir/mia/client/MiaClientConfig.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ public enum DisconnectButtonState {DEFAULT, DISABLED, HIDDEN}
3232
"HIDDEN: Hide the disconnect button | 隐藏退出按钮")
3333
.defineEnum("disconnect_button_state", DisconnectButtonState.DEFAULT);
3434

35-
private static final ModConfigSpec.Builder HOOK = BUILDER.push("hook")
36-
.comment("Hook Configuration | 钩爪配置");
37-
public static final ModConfigSpec.BooleanValue AUTO_HOOK = HOOK
35+
public static final ModConfigSpec.BooleanValue AUTO_HOOK = BUILDER
3836
.comment("Enable auto hook | 启用自动回收")
39-
.define("auto_hook", false);
37+
.define("hook.auto", false);
4038

4139
public static final ModConfigSpec CLIENT_SPEC = BUILDER.build();
4240

src/main/java/com/altnoir/mia/client/MiaClientEvents.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.altnoir.mia.client;
22

3+
import com.altnoir.mia.MiaConfig;
34
import com.altnoir.mia.client.gui.screens.ArtifactSmithingTableScreen;
45
import com.altnoir.mia.client.gui.screens.inventory.tooltip.ClientArtifactBundleTooltip;
56
import com.altnoir.mia.client.handler.HookHandler;
67
import com.altnoir.mia.client.renderer.TheAbyssDimEffects;
78
import com.altnoir.mia.common.component.ArtifactBundleInventoryComponent;
89
import com.altnoir.mia.event.client.*;
10+
import com.altnoir.mia.event.common.AbyssMobEvent;
911
import com.altnoir.mia.init.MiaKeyBinding;
1012
import com.altnoir.mia.init.MiaMenus;
1113
import net.minecraft.client.Minecraft;
@@ -68,6 +70,20 @@ public static void onScreenInitPost(ScreenEvent.Init.Post event) {
6870
public static void onTooltip(ItemTooltipEvent event) {
6971
ClientTooltipEvent.onTooltip(event.getItemStack(), event.getToolTip());
7072
}
73+
74+
public static void onRenderNameTag(RenderNameTagEvent event) {
75+
if (!MiaConfig.abyssMobLevelSwitch) return;
76+
var result = AbyssMobEvent.onRenderMobLevel(event.getEntity());
77+
if (result != null) {
78+
event.setCanRender(result);
79+
}
80+
}
81+
82+
public static void onCameraAngles(ViewportEvent.ComputeCameraAngles event) {
83+
event.setYaw(-event.getYaw());
84+
event.setPitch(-event.getPitch());
85+
event.setRoll(event.getRoll() + 180.0F);
86+
}
7187
}
7288

7389

src/main/java/com/altnoir/mia/event/EventHandle.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ public static void addGameEventBus(IEventBus gameEventBus) {
2727
gameEventBus.addListener(MiaEvents::onLivingDeath);
2828
gameEventBus.addListener(MiaEvents::onBrewingRecipe);
2929
gameEventBus.addListener(MiaEvents::onRegisterCommands);
30+
gameEventBus.addListener(MiaEvents::onFinalizeSpawn);
31+
gameEventBus.addListener(MiaEvents::onLivingDrops);
3032
}
3133
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
package com.altnoir.mia.event.common;
2+
3+
import com.altnoir.mia.MiaConfig;
4+
import com.altnoir.mia.init.MiaAttachments;
5+
import com.altnoir.mia.worldgen.dimension.MiaDimensions;
6+
import net.minecraft.ChatFormatting;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.server.level.ServerLevel;
9+
import net.minecraft.world.damagesource.DamageSource;
10+
import net.minecraft.world.entity.*;
11+
import net.minecraft.world.entity.ai.attributes.Attributes;
12+
import net.minecraft.world.entity.animal.horse.Llama;
13+
import net.minecraft.world.entity.animal.horse.SkeletonHorse;
14+
import net.minecraft.world.entity.item.ItemEntity;
15+
import net.minecraft.world.entity.monster.Enemy;
16+
import net.minecraft.world.item.Items;
17+
import net.minecraft.world.level.ServerLevelAccessor;
18+
import net.neoforged.api.distmarker.Dist;
19+
import net.neoforged.api.distmarker.OnlyIn;
20+
import net.neoforged.neoforge.common.util.TriState;
21+
22+
import java.util.Collection;
23+
import java.util.Objects;
24+
import java.util.UUID;
25+
26+
public class AbyssMobEvent {
27+
private static final short CHUNK_RADIUS = 28;
28+
29+
public static void onCheckSpawn(Mob mob, ServerLevelAccessor level, MobSpawnType type) {
30+
if (!MiaConfig.abyssMobLevelSwitch) return;
31+
var pos = mob.blockPosition();
32+
33+
long chunkX = pos.getX() >> 4, chunkZ = pos.getZ() >> 4; // 等价于 / 16
34+
long distance = (long) chunkX * chunkX + chunkZ * chunkZ;
35+
36+
37+
if (distance <= CHUNK_RADIUS * CHUNK_RADIUS) return;
38+
double euclideanDistance = Math.sqrt(distance);
39+
40+
if (level instanceof ServerLevel serverLevel && serverLevel.dimension() == MiaDimensions.THE_ABYSS_LEVEL) {
41+
if (mob instanceof Enemy || mob instanceof Llama || mob instanceof SkeletonHorse) {
42+
double maxHealth = mob.getMaxHealth();
43+
44+
boolean reverse = MiaConfig.abyssMobLevelIncreasingCurve != MiaConfig.AbyssMobLevelIncreasingCurve.FROM_FAST_TO_SLOW;
45+
int mobLevel = calculateMobLevel(euclideanDistance, reverse);
46+
47+
if (mobLevel <= 0) return;
48+
49+
// 从半径28个区块开始计算
50+
maxHealth += mobLevel;
51+
maxHealth = Math.min(maxHealth, 2048.0);
52+
Objects.requireNonNull(mob.getAttribute(Attributes.MAX_HEALTH)).setBaseValue(maxHealth);
53+
mob.setHealth((float) maxHealth);
54+
55+
mob.setData(MiaAttachments.ABYSS_MOB_LEVEL.get(), mobLevel);
56+
mob.setCustomName(Component.literal("Lv: " + mobLevel).withStyle(ChatFormatting.GREEN));
57+
58+
if (serverLevel.getRandom().nextBoolean()) {
59+
createRidingSkeleton(serverLevel, mob);
60+
}
61+
}
62+
}
63+
}
64+
65+
public static void onLivingDrops(LivingEntity entity, Collection<ItemEntity> drops, DamageSource damageSource) {
66+
if (!MiaConfig.abyssMobLevelSwitch) return;
67+
if (entity.hasData(MiaAttachments.ABYSS_MOB_LEVEL.get())) {
68+
int mobLevel = entity.getData(MiaAttachments.ABYSS_MOB_LEVEL.get());
69+
var level = entity.level();
70+
71+
for (var item : drops) {
72+
var originalStack = item.getItem();
73+
int amount = originalStack.getCount() * mobLevel;
74+
75+
// 拆分物品堆叠,确保每个堆叠不超过最大限制
76+
while (amount > 0) {
77+
int stackSize = Math.min(amount, originalStack.getMaxStackSize());
78+
amount -= stackSize;
79+
80+
var newItemEntity = new ItemEntity(
81+
level,
82+
item.getX(), item.getY(), item.getZ(),
83+
originalStack.copyWithCount(stackSize)
84+
);
85+
level.addFreshEntity(newItemEntity);
86+
}
87+
}
88+
}
89+
}
90+
91+
@OnlyIn(Dist.CLIENT)
92+
public static TriState onRenderMobLevel(Entity entity) {
93+
if (entity instanceof Mob mob) {
94+
var name = mob.getCustomName();
95+
if (name != null && name.getString().startsWith("Lv")) {
96+
return TriState.TRUE;
97+
}
98+
}
99+
return null;
100+
}
101+
102+
private static int calculateMobLevel(double euclideanDistance, boolean reverse) {
103+
if (!reverse) {
104+
int level = (int) ((Math.sqrt(8 * (euclideanDistance - CHUNK_RADIUS)) - 1) / 2) + 1;
105+
return Math.min(level, 1000);
106+
} else {
107+
double remaining = (499501 + CHUNK_RADIUS) - euclideanDistance;
108+
if (remaining <= 0) return 1000;
109+
110+
int x = (int) ((Math.sqrt(8 * remaining) - 1) / 2) + 1;
111+
int level = 1000 - x;
112+
113+
return Math.max(0, Math.min(level, 1000));
114+
}
115+
}
116+
117+
private static void createRidingSkeleton(ServerLevel serverLevel, Mob mob) {
118+
EntityType<?>[] riderTypes = {EntityType.SKELETON, EntityType.BOGGED};
119+
var random = serverLevel.getRandom().nextInt(riderTypes.length);
120+
121+
EntityType<?> riders = riderTypes[random];
122+
var rider = riders.create(serverLevel);
123+
124+
if (rider != null) {
125+
rider.setUUID(UUID.randomUUID());
126+
rider.moveTo(mob.position());
127+
serverLevel.addFreshEntityWithPassengers(rider);
128+
129+
if (rider instanceof LivingEntity entity) {
130+
entity.setItemSlot(EquipmentSlot.MAINHAND, Items.BOW.getDefaultInstance());
131+
}
132+
rider.startRiding(mob);
133+
}
134+
}
135+
}

src/main/java/com/altnoir/mia/init/MiaAttachments.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.altnoir.mia.MIA;
44
import com.altnoir.mia.common.attachments.Curse;
5+
import com.mojang.serialization.Codec;
56
import net.neoforged.bus.api.IEventBus;
67
import net.neoforged.neoforge.attachment.AttachmentType;
78
import net.neoforged.neoforge.registries.DeferredRegister;
@@ -15,9 +16,12 @@ public class MiaAttachments {
1516
public static final Supplier<AttachmentType<Curse>> CURSE = ATTACHMENT_TYPES.register("curse",
1617
() -> AttachmentType.serializable(Curse::new).build());
1718

18-
// public static final DeferredHolder<AttachmentType<?>, AttachmentType<Boolean>> HOOK = ATTACHMENT_TYPES.register("hook",
19+
// public static final DeferredHolder<AttachmentType<?>, AttachmentType<Boolean>> HOOK = ATTACHMENT_TYPES.register("hook",
1920
// () -> AttachmentType.builder(() -> false).serialize(Codec.BOOL).build());
2021

22+
public static final Supplier<AttachmentType<Integer>> ABYSS_MOB_LEVEL = ATTACHMENT_TYPES.register("abyss_mob_level",
23+
() -> AttachmentType.builder(() -> 0).serialize(Codec.INT).build());
24+
2125
public static void register(IEventBus bus) {
2226
ATTACHMENT_TYPES.register(bus);
2327
}

0 commit comments

Comments
 (0)