Skip to content

Commit 160ed58

Browse files
committed
UD-260309
1 parent 0a9cd7a commit 160ed58

23 files changed

Lines changed: 110 additions & 67 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ flywheel_version=1.0.4
2727
mod_id=mia
2828
mod_name=Memento In Abyss
2929
mod_license=MIT
30-
mod_version=0.1.0-alpha.23
30+
mod_version=0.1.0-alpha.25
3131
mod_group_id=com.altnoir.mia
3232
mod_authors=Altnoir, lonelyicer, zljtt, zhaijineet
3333
mod_description=Memento In Abyss.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/handheld",
3+
"textures": {
4+
"layer0": "mia:item/blaze_reap"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/handheld",
3+
"textures": {
4+
"layer0": "mia:item/debug_attribute_tool"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/generated",
3+
"textures": {
4+
"layer0": "mia:item/peace_phobia"
5+
}
6+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,16 @@ public class MiaItemGroups {
204204
output.accept(MiaItems.HEALTH_JUNKIE);
205205
output.accept(MiaItems.ARTIFACT_HASTE);
206206
output.accept(MiaItems.HOOK);
207-
output.accept(MiaItems.DEBUG_ATTRIBUTE_TOOL);
208207

209208
// Weapons
210209
output.accept(MiaItems.GROW_SWORD);
211210
output.accept(MiaItems.BLAZE_REAP);
212211

213212
// Misc
214213
output.accept(MiaItems.PEACE_PHOBIA);
214+
215+
// DEV
216+
output.accept(MiaItems.DEBUG_ATTRIBUTE_TOOL);
215217
}).build()
216218
);
217219

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.altnoir.mia.client.gui.screens.inventory.tooltip.ClientArtifactBundleTooltip;
66
import com.altnoir.mia.client.handler.HookHandler;
77
import com.altnoir.mia.client.renderer.TheAbyssDimEffects;
8+
import com.altnoir.mia.client.renderer.TheAbyssFogRenderer;
89
import com.altnoir.mia.common.component.ArtifactBundleInventoryComponent;
910
import com.altnoir.mia.compat.Mods;
1011
import com.altnoir.mia.compat.ponder.MiaPonder;
@@ -56,6 +57,9 @@ public static void registerKeyBindings(RegisterKeyMappingsEvent event) {
5657
// 游戏事件-持续事件
5758
public static void onClientTick(ClientTickEvent.Post event) {
5859
final Minecraft MC = Minecraft.getInstance();
60+
if (MC.level == null && MC.player == null) {
61+
TheAbyssFogRenderer.clearCache();
62+
}
5963
if (MC.level == null || MC.player == null) return;
6064

6165
KeyArrowEvent.onClientTick();

src/main/java/com/altnoir/mia/client/renderer/TheAbyssFogRenderer.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,27 @@
1414

1515
import java.util.HashMap;
1616
import java.util.Iterator;
17+
import java.util.LinkedHashMap;
1718
import java.util.Map;
1819

1920
public class TheAbyssFogRenderer {
20-
private static final Map<Long, Float> FOG_DENSITY_CACHE = new HashMap<>();
21-
21+
// 使用 LinkedHashMap 实现 LRU 缓存,自动移除最旧的条目
22+
private static final Map<Long, Float> FOG_DENSITY_CACHE = new LinkedHashMap<Long, Float>(256, 0.75f, true) {
23+
@Override
24+
protected boolean removeEldestEntry(Map.Entry<Long, Float> eldest) {
25+
return size() > 1024; // 增加缓存大小以减少频繁清理
26+
}
27+
};
2228
// 过渡控制变量
2329
private static final int TRANSITION_RANGE = 16; // 过渡范围
2430
private static float lastFogStart = 0;
2531
private static float lastFogEnd = 192;
2632
private static long lastUpdateTime = 0;
2733

2834
// 性能保护变量
29-
private static int samplesThisFrame = 0;
30-
private static long lastFrameTime = 0;
31-
private static final int MAX_SAMPLES_PER_FRAME = 8;
35+
private static final ThreadLocal<Integer> samplesThisFrame = ThreadLocal.withInitial(() -> 0);
36+
private static final ThreadLocal<Long> lastFrameTime = ThreadLocal.withInitial(() -> 0L);
37+
private static final int MAX_SAMPLES_PER_FRAME = 16;
3238

3339
public static boolean renderFog(Camera camera, FogRenderer.FogMode fogMode, float farPlaneDistance, float partialTick) {
3440
var player = camera.getEntity();
@@ -140,13 +146,15 @@ private static float getSmoothedBiomeFactor(Level level, double x, double y, dou
140146
private static float calculateBiomeBlendFactor(Level level, double x, double y, double z) {
141147
// 性能保护:每帧重置采样计数器
142148
long currentTime = System.currentTimeMillis();
143-
if (currentTime != lastFrameTime) {
144-
samplesThisFrame = 0;
145-
lastFrameTime = currentTime;
149+
if (currentTime != lastFrameTime.get()) {
150+
samplesThisFrame.set(0);
151+
lastFrameTime.set(currentTime);
146152
}
147-
// 如果超过每帧最大采样次数,返回默认值
148-
if (samplesThisFrame >= MAX_SAMPLES_PER_FRAME) {
149-
return 0.5f; // 默认值
153+
// 如果超过每帧最大采样次数,返回基于位置的默认值,而不是固定的0.5
154+
if (samplesThisFrame.get() >= MAX_SAMPLES_PER_FRAME) {
155+
// 基于位置计算一个伪随机但稳定的值,避免所有位置都返回相同值
156+
long seed = (long) (x * 3129871) ^ (long) (z * 116129781L) ^ (long) y;
157+
return 0.3f + (Math.abs(seed % 40) / 100.0f);
150158
}
151159

152160
// 将世界坐标转换为区块坐标
@@ -161,7 +169,7 @@ private static float calculateBiomeBlendFactor(Level level, double x, double y,
161169
if (FOG_DENSITY_CACHE.containsKey(key)) {
162170
return FOG_DENSITY_CACHE.get(key);
163171
}
164-
samplesThisFrame++; // 增加采样计数
172+
samplesThisFrame.set(samplesThisFrame.get() + 1); // 增加采样计数
165173

166174
// 采样3x3区块段
167175
int biomeFogCount = 0;
@@ -195,4 +203,9 @@ private static float calculateBiomeBlendFactor(Level level, double x, double y,
195203

196204
return blendFactor;
197205
}
206+
207+
// 提供一个方法来清除缓存,可在游戏退出时调用
208+
public static void clearCache() {
209+
FOG_DENSITY_CACHE.clear();
210+
}
198211
}

src/main/java/com/altnoir/mia/common/block/PedestalBlock.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@
2828
import net.minecraft.world.level.material.Fluids;
2929
import net.minecraft.world.phys.BlockHitResult;
3030
import net.minecraft.world.phys.shapes.CollisionContext;
31+
import net.minecraft.world.phys.shapes.Shapes;
3132
import net.minecraft.world.phys.shapes.VoxelShape;
3233
import org.jetbrains.annotations.Nullable;
3334

3435
public class PedestalBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
3536
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
36-
public static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 16, 15);
37+
public static final VoxelShape SHAPE = Shapes.or(
38+
Block.box(4.0, 6.0, 4.0, 12.0, 9.0, 12.0),
39+
Block.box(5, 2, 5, 11, 6, 11),
40+
Block.box(2, 0, 2, 14, 2, 14)
41+
);
3742
public static final MapCodec<PedestalBlock> CODEC = simpleCodec(PedestalBlock::new);
3843

3944
public PedestalBlock(Properties properties) {
@@ -102,7 +107,7 @@ protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Lev
102107
level.playSound(player, pos, SoundEvents.ITEM_PICKUP, SoundSource.BLOCKS, 0.5F, 1.0F);
103108
return ItemInteractionResult.SUCCESS;
104109
}
105-
if (blockEntity.tryInsertItem(stack.copy(), false)){
110+
if (blockEntity.tryInsertItem(stack.copy(), false)) {
106111
stack.setCount(0);
107112
level.playSound(player, pos, SoundEvents.ITEM_FRAME_ADD_ITEM, SoundSource.BLOCKS, 0.5F, 1.0F);
108113
return ItemInteractionResult.SUCCESS;

src/main/java/com/altnoir/mia/common/block/entity/renderer/PedestalRenderer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void render(PedestalBlockEntity blockEntity, float partialTick, PoseStack
3232
var yOffset = (float) Math.sin(time * 0.1F) * 0.05F;
3333

3434
poseStack.pushPose();
35-
poseStack.translate(0.5F, 1.05F + yOffset, 0.5F);
35+
poseStack.translate(0.5F, 0.875F + yOffset, 0.5F);
3636
poseStack.scale(0.5F, 0.5F, 0.5F);
3737

3838
var inputAngle = time * 4 % 360;
@@ -53,7 +53,7 @@ public void render(PedestalBlockEntity blockEntity, float partialTick, PoseStack
5353
int count = nonEmptyStacks.size();
5454
if (count == 0) return;
5555

56-
var radius = 0.35F;
56+
var radius = 0.45F;
5757
var yBase = 0.3F;
5858
var rotationSpeed = 2F;
5959

src/main/java/com/altnoir/mia/common/item/DebugAttributeTool.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,9 @@ private double getBaseAttributeValue(Player player, Holder<Attribute> attribute)
7777
}
7878
return 0.0;
7979
}
80+
81+
@Override
82+
public boolean isFoil(ItemStack stack) {
83+
return true;
84+
}
8085
}

0 commit comments

Comments
 (0)