Skip to content

Commit 20d34d6

Browse files
authored
Merge pull request #15 from box3lab/dev_coolfish
Dev coolfish
2 parents 10842d8 + a83d8ec commit 20d34d6

20 files changed

Lines changed: 422 additions & 22 deletions

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# 神奇代码岛方块MC模组
1+
# Box3Blocks(神岛材质包)-- Minecraft Mod
22

33
![Modrinth Downloads](https://img.shields.io/modrinth/dt/iG3hRUix?logo=modrinth)
44
![CurseForge Downloads](https://img.shields.io/curseforge/dt/1456138?logo=curseforge)
55

66
[简体中文](README.md) | [English](README_en.md)
77

8-
导入神奇代码岛的384个方块到我的世界,让你在MC中也能使用熟悉的方块进行创作,还支持将神奇代码岛中的建筑结构完整迁移到Minecraft世界中,保持原汁原味的建造风格。
8+
导入神奇代码岛的384个方块到我的世界,让你在MC中也能使用熟悉的方块进行创作,还支持将神奇代码岛中的建筑/模型结构完整迁移到Minecraft世界中,保持原汁原味的建造风格。
99

1010
## 📦 安装要求
1111

@@ -47,6 +47,14 @@
4747
- `/box3import <fileName> <ignoreBarrier> <useVanillaWater>`
4848
`useVanillaWater = true` 时,所有流体统一替换为 MC 原版水方块。
4949

50+
### 🧩 导入神奇代码岛的模型物品
51+
52+
- **资源文件导入**:支持从 `minecraft/resourcepacks/` 目录文件导入资源包。
53+
- **资源包加载模型**:将模型放入资源包即可自动注册到创造模式。
54+
- **模型物品标签页**`Box3:模型` 标签页用于管理模型物品。
55+
- **模型销毁器**:右键模型可删除(道具名:模型销毁器)。
56+
- **生成模型资源包**:访问 https://box3lab.com/mc-resource-pack 获取适用于本模组的资源包文件。
57+
5058
### 🔍 屏障可见性切换
5159

5260
- **屏障可见性切换 `/box3barrier`**

README_en.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Box3 Blocks Minecraft Mod
1+
# Box3Blocks(神岛材质包)-- Minecraft Mod
22

33
![Modrinth Downloads](https://img.shields.io/modrinth/dt/iG3hRUix?logo=modrinth)
44
![CurseForge Downloads](https://img.shields.io/curseforge/dt/1456138?logo=curseforge)
@@ -49,6 +49,14 @@ You can also migrate structures from Box3 directly into your Minecraft world, pr
4949
- `/box3import <fileName> <ignoreBarrier> <useVanillaWater>`
5050
When `useVanillaWater = true`, all fluids are replaced with vanilla Minecraft water blocks.
5151

52+
### 🧩 Importing Box3 Model Items
53+
54+
- **Resource file import**: Supports importing resource packs from the `minecraft/resourcepacks/` directory.
55+
- **Resource pack model loading**: Put models into a resource pack to auto-register them in Creative.
56+
- **Model creative tab**: `Box3:Models` tab for model items.
57+
- **Model Destroyer**: Right-click a model to delete it (item name: Model Destroyer).
58+
- **Generate model resource pack**: Visit https://box3lab.com/mc-resource-pack to get a pack compatible with this mod.
59+
5260
### 🔍 Barrier Visibility Toggle
5361

5462
- **Barrier visibility command `/box3barrier`**:
@@ -68,7 +76,7 @@ This project is licensed under the [Apache License 2.0](LICENSE).
6876

6977
## 🙏 Acknowledgements
7078

71-
- Blocks provided by Box3 (Magic Code Island), and the mod developed by Box3 Lab
79+
- Blocks provided by Box3, and the mod developed by Box3Lab
7280
- FabricMC team for the Fabric mod loader
7381

7482
## Star History

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ loader_version=0.18.4
1212
loom_version=1.15-SNAPSHOT
1313

1414
# Mod Properties
15-
mod_version=1.2.0
15+
mod_version=1.3.0
1616
maven_group=com.box3lab
1717
archives_base_name=box3mod
1818

src/client/java/com/box3lab/Box3ModClient.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
public class Box3ModClient implements ClientModInitializer {
1616
@Override
1717
public void onInitializeClient() {
18-
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
18+
19+
//
1920
for (var entry : ModBlocks.VOXEL_BLOCKS.entrySet()) {
2021
String registryName = entry.getKey();
2122
Block block = entry.getValue();
2223

23-
String texturePart = registryName.startsWith("voxel_") ? registryName.substring("voxel_".length()) : registryName;
24+
String texturePart = registryName.startsWith("voxel_") ? registryName.substring("voxel_".length())
25+
: registryName;
2426
Integer id = BlockIndexUtil.getIdByName(texturePart);
2527
if (id != null && !BlockIndexUtil.isSolid(id)) {
2628
BlockRenderLayerMap.putBlock(block, ChunkSectionLayer.TRANSLUCENT);
@@ -32,8 +34,7 @@ public void onInitializeClient() {
3234
FluidRenderHandlerRegistry.INSTANCE.register(
3335
info.still,
3436
info.flowing,
35-
new VoxelFluidRenderHandler(stillTex, flowTex, info.tint, info.fluidExtinction)
36-
);
37+
new VoxelFluidRenderHandler(stillTex, flowTex, info.tint, info.fluidExtinction));
3738
}
3839
}
3940
}

src/client/java/com/box3lab/client/VoxelFluidRenderHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
public class VoxelFluidRenderHandler extends SimpleFluidRenderHandler {
1010
private final double fluidExtinction;
1111

12-
public VoxelFluidRenderHandler(Identifier stillTexture, Identifier flowingTexture, int tint, double fluidExtinction) {
12+
public VoxelFluidRenderHandler(Identifier stillTexture, Identifier flowingTexture, int tint,
13+
double fluidExtinction) {
1314
super(stillTexture, flowingTexture, tint);
1415
this.fluidExtinction = fluidExtinction;
1516
}
1617

1718
@Override
1819
public int getFluidColor(BlockAndTintGetter view, BlockPos pos, FluidState state) {
1920
int baseColor = super.getFluidColor(view, pos, state);
20-
// Apply extinction by reducing alpha (higher extinction = more transparent)
2121
int alpha = (int) (255 * (1.0 - Math.min(1.0, Math.max(0.0, fluidExtinction))));
2222
return (baseColor & 0x00FFFFFF) | ((alpha & 0xFF) << 24);
2323
}

src/client/java/com/box3lab/mixin/client/ExampleClientMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
public class ExampleClientMixin {
1111
@Inject(at = @At("HEAD"), method = "run")
1212
private void init(CallbackInfo info) {
13-
// This code is injected into the start of Minecraft.run()V
13+
1414
}
1515
}

src/main/java/com/box3lab/Box3Mod.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.box3lab.command.ModCommands;
44
import com.box3lab.register.ModBlocks;
55
import com.box3lab.register.ModFluids;
6+
import com.box3lab.register.ModItems;
67

78
import net.fabricmc.api.ModInitializer;
89

@@ -24,8 +25,9 @@ public void onInitialize() {
2425
// Proceed with mild caution.
2526
ModFluids.initialize();
2627
ModBlocks.initialize();
28+
ModItems.initialize();
2729
ModCommands.register();
2830

2931
// LOGGER.info("Hello Fabric world!");
3032
}
31-
}
33+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.box3lab.item;
2+
3+
import java.util.List;
4+
5+
import net.minecraft.server.level.ServerLevel;
6+
import net.minecraft.world.InteractionResult;
7+
import net.minecraft.world.entity.Display;
8+
import net.minecraft.world.entity.player.Player;
9+
import net.minecraft.world.item.Item;
10+
import net.minecraft.world.item.context.UseOnContext;
11+
import net.minecraft.world.level.Level;
12+
import net.minecraft.world.phys.AABB;
13+
import net.minecraft.world.phys.Vec3;
14+
15+
public class ModelDestroyerItem extends Item {
16+
private static final double RANGE = 10.0;
17+
18+
public ModelDestroyerItem(Properties properties) {
19+
super(properties);
20+
}
21+
22+
@Override
23+
public InteractionResult useOn(UseOnContext context) {
24+
Level level = context.getLevel();
25+
if (!(level instanceof ServerLevel serverLevel)) {
26+
return InteractionResult.SUCCESS;
27+
}
28+
29+
Player player = context.getPlayer();
30+
if (player == null) {
31+
return InteractionResult.PASS;
32+
}
33+
34+
boolean deleted = deleteTarget(serverLevel, player);
35+
return deleted ? InteractionResult.SUCCESS : InteractionResult.PASS;
36+
}
37+
38+
private static boolean deleteTarget(ServerLevel level, Player player) {
39+
Display.ItemDisplay target = findDisplay(level, player, RANGE);
40+
if (target == null) {
41+
return false;
42+
}
43+
target.discard();
44+
return true;
45+
}
46+
47+
private static Display.ItemDisplay findDisplay(ServerLevel level, Player player, double range) {
48+
Vec3 start = player.getEyePosition(1.0f);
49+
Vec3 look = player.getViewVector(1.0f);
50+
Vec3 end = start.add(look.scale(range));
51+
AABB searchBox = player.getBoundingBox().expandTowards(look.scale(range)).inflate(1.5);
52+
53+
List<Display.ItemDisplay> displays = level.getEntitiesOfClass(Display.ItemDisplay.class, searchBox);
54+
Display.ItemDisplay closest = null;
55+
double bestDist = range * range;
56+
57+
for (Display.ItemDisplay display : displays) {
58+
AABB box = display.getBoundingBox().inflate(0.8);
59+
var hit = box.clip(start, end);
60+
if (hit.isEmpty()) {
61+
continue;
62+
}
63+
double dist = start.distanceToSqr(hit.get());
64+
if (dist < bestDist) {
65+
bestDist = dist;
66+
closest = display;
67+
}
68+
}
69+
70+
return closest;
71+
}
72+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.box3lab.item;
2+
3+
import net.minecraft.core.BlockPos;
4+
import net.minecraft.server.level.ServerLevel;
5+
import net.minecraft.world.InteractionResult;
6+
import net.minecraft.world.entity.Display;
7+
import net.minecraft.world.entity.EntitySpawnReason;
8+
import net.minecraft.world.entity.EntityType;
9+
import net.minecraft.world.entity.player.Player;
10+
import net.minecraft.world.item.Item;
11+
import net.minecraft.world.item.ItemStack;
12+
import net.minecraft.world.item.context.UseOnContext;
13+
import net.minecraft.world.level.Level;
14+
import net.minecraft.world.phys.Vec3;
15+
16+
public class ModelDisplayItem extends Item {
17+
public ModelDisplayItem(Properties properties) {
18+
super(properties);
19+
}
20+
21+
@Override
22+
public InteractionResult useOn(UseOnContext context) {
23+
Level level = context.getLevel();
24+
if (!(level instanceof ServerLevel serverLevel)) {
25+
return InteractionResult.SUCCESS;
26+
}
27+
28+
Display.ItemDisplay display = EntityType.ITEM_DISPLAY.create(serverLevel, EntitySpawnReason.SPAWN_ITEM_USE);
29+
if (display == null) {
30+
return InteractionResult.FAIL;
31+
}
32+
33+
BlockPos placePos = context.getClickedPos().relative(context.getClickedFace());
34+
Vec3 pos = Vec3.atCenterOf(placePos);
35+
display.setPos(pos.x, pos.y, pos.z);
36+
37+
Player player = context.getPlayer();
38+
if (player != null) {
39+
display.setYRot(player.getYRot());
40+
}
41+
42+
ItemStack displayStack = context.getItemInHand().copyWithCount(1);
43+
display.getSlot(0).set(displayStack);
44+
45+
display.setNoGravity(true);
46+
serverLevel.addFreshEntity(display);
47+
48+
if (player == null || !player.getAbilities().instabuild) {
49+
context.getItemInHand().shrink(1);
50+
}
51+
52+
return InteractionResult.SUCCESS;
53+
}
54+
}

src/main/java/com/box3lab/mixin/ExampleMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
public class ExampleMixin {
1111
@Inject(at = @At("HEAD"), method = "loadLevel")
1212
private void init(CallbackInfo info) {
13-
// This code is injected into the start of MinecraftServer.loadLevel()V
13+
1414
}
1515
}

0 commit comments

Comments
 (0)