Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,64 +1,140 @@
{
"variants": {
"facing=east,overload=false,powered=false": {
"facing=east,overload=false,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"y": 90
},
"facing=east,overload=false,powered=true": {
"facing=east,overload=false,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"x": 180,
"y": 270
},
"facing=east,overload=false,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"y": 90
},
"facing=east,overload=true,powered=false": {
"facing=east,overload=false,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"x": 180,
"y": 270
},
"facing=east,overload=true,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"y": 90
},
"facing=east,overload=true,powered=true": {
"facing=east,overload=true,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180,
"y": 270
},
"facing=east,overload=true,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"y": 90
},
"facing=north,overload=false,powered=false": {
"facing=east,overload=true,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180,
"y": 270
},
"facing=north,overload=false,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom"
},
"facing=north,overload=false,powered=true": {
"facing=north,overload=false,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"x": 180,
"y": 180
},
"facing=north,overload=false,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_off"
},
"facing=north,overload=true,powered=false": {
"facing=north,overload=false,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"x": 180,
"y": 180
},
"facing=north,overload=true,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload"
},
"facing=north,overload=true,powered=true": {
"facing=north,overload=true,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180,
"y": 180
},
"facing=north,overload=true,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload"
},
"facing=south,overload=false,powered=false": {
"facing=north,overload=true,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180,
"y": 180
},
"facing=south,overload=false,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"y": 180
},
"facing=south,overload=false,powered=true": {
"facing=south,overload=false,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"x": 180
},
"facing=south,overload=false,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"y": 180
},
"facing=south,overload=true,powered=false": {
"facing=south,overload=false,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"x": 180
},
"facing=south,overload=true,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"y": 180
},
"facing=south,overload=true,powered=true": {
"facing=south,overload=true,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180
},
"facing=south,overload=true,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"y": 180
},
"facing=west,overload=false,powered=false": {
"facing=south,overload=true,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180
},
"facing=west,overload=false,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"y": 270
},
"facing=west,overload=false,powered=true": {
"facing=west,overload=false,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom",
"x": 180,
"y": 90
},
"facing=west,overload=false,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"y": 270
},
"facing=west,overload=true,powered=false": {
"facing=west,overload=false,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_off",
"x": 180,
"y": 90
},
"facing=west,overload=true,powered=false,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"y": 270
},
"facing=west,overload=true,powered=true": {
"facing=west,overload=true,powered=false,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180,
"y": 90
},
"facing=west,overload=true,powered=true,upside_down=false": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"y": 270
},
"facing=west,overload=true,powered=true,upside_down=true": {
"model": "anvilcraft:block/smart_block_placer_bottom_overload",
"x": 180,
"y": 90
}
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
{
"variants": {
"facing=east": {
"facing=east,upside_down=false": {
"model": "anvilcraft:block/structure_scanner",
"y": 90
},
"facing=north": {
"facing=east,upside_down=true": {
"model": "anvilcraft:block/structure_scanner",
"x": 180,
"y": 270
},
"facing=north,upside_down=false": {
"model": "anvilcraft:block/structure_scanner"
},
"facing=south": {
"facing=north,upside_down=true": {
"model": "anvilcraft:block/structure_scanner",
"x": 180,
"y": 180
},
"facing=south,upside_down=false": {
"model": "anvilcraft:block/structure_scanner",
"y": 180
},
"facing=west": {
"facing=south,upside_down=true": {
"model": "anvilcraft:block/structure_scanner",
"x": 180
},
"facing=west,upside_down=false": {
"model": "anvilcraft:block/structure_scanner",
"y": 270
},
"facing=west,upside_down=true": {
"model": "anvilcraft:block/structure_scanner",
"x": 180,
"y": 90
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,13 @@ public void loadAdditional(ValueInput input) {
}

public void loadAdditional(CompoundTag tag, HolderLookup.Provider ignored) {
this.loadFromTag(tag);
// 旧路径也从CompoundTag加载物品栏(向后兼容)
// 先加载物品栏,确保 tryLoadStructure 能正确访问到磁盘物品
// 否则 loadFromTag 中加载的 cachedStructure 会被 tryLoadStructure 误判清空
loadItemsFromTag(tag, this.diskInventory);
this.lastDiskItem = this.diskInventory.getItem(0).copy();
loadItemsFromTag(tag, this.bookInventory);
loadItemsFromTag(tag, this.outputBookInventory);
this.loadFromTag(tag);
}

private void loadFromTag(CompoundTag tag) {
Expand All @@ -351,10 +352,12 @@ private void loadFromTag(CompoundTag tag) {
this.loadedStructure = this.loadStructureData(tag.getCompoundOrEmpty("cachedStructure"));
this.loadedStructureName = tag.getStringOr("cachedStructureName", "");
if (tag.contains("cachedStructureUuid")) {
this.loadedStructureUuid = UUIDUtil.CODEC.parse(NbtOps.INSTANCE, tag.getCompoundOrEmpty("cachedStructureUuid"))
.result().orElse(null);
this.loadedStructureUuid = UUIDUtil.CODEC.parse(
NbtOps.INSTANCE, tag.getCompoundOrEmpty("cachedStructureUuid")
).result().orElse(null);
}
this.hasStructureDisk = true;
this.hasInvalidStructure = false;
}

// NBT加载后尝试从磁盘更新结构(如果有磁盘的话)
Expand Down Expand Up @@ -1277,13 +1280,22 @@ private void prepareBlueprintModeHeldBlock(Level level, BlockPos pos) {
// 可堆叠方块:检查容器中是否有足够的数量
int availableCount = this.countBlockItemInContainer(level, pos, requiredBlock);
if (availableCount < stackCount) {
// 数量不足,跳过
// 数量不足,停止模式下不前扫
if (!this.isSkipMissingMode) {
this.currentHeldBlock = ItemStack.EMPTY;
return;
}
continue;
}
} else {
// 普通方块:检查是否有物品
ItemStack blockItem = this.peekSpecificBlockItemFromContainer(level, pos, requiredBlock);
if (blockItem.isEmpty()) {
// 停止模式下不前扫
if (!this.isSkipMissingMode) {
this.currentHeldBlock = ItemStack.EMPTY;
return;
}
continue;
}
this.currentHeldBlock = blockItem.copy();
Expand Down Expand Up @@ -1340,6 +1352,12 @@ private void prepareBlueprintModeHeldBlock(Level level, BlockPos pos) {
return;
}
}

// 停止模式:源方块与当前位置不匹配时,不前扫
if (!this.isSkipMissingMode) {
this.currentHeldBlock = ItemStack.EMPTY;
return;
}
}
}

Expand Down Expand Up @@ -3889,6 +3907,20 @@ public void applySyncDataFromMenu(CompoundTag tag) {
this.isPickupMode = tag.getBooleanOr("isPickupMode", false);
this.isSkipMissingMode = tag.getBooleanOr("isSkipMissingMode", false);
this.loadLayerPositions(tag);

// 同步结构缓存数据(菜单打开包中包含 cachedStructure),
// 用于客户端预览蓝图和结构信息
if (tag.contains("cachedStructure")) {
this.loadedStructure = this.loadStructureData(tag.getCompoundOrEmpty("cachedStructure"));
this.loadedStructureName = tag.getStringOr("cachedStructureName", "");
if (tag.contains("cachedStructureUuid")) {
this.loadedStructureUuid = UUIDUtil.CODEC.parse(
NbtOps.INSTANCE, tag.getCompoundOrEmpty("cachedStructureUuid")
).result().orElse(null);
}
this.hasStructureDisk = true;
this.hasInvalidStructure = false;
}
}

void loadLayerPositions(CompoundTag tag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public class SmartBlockPlacerBlock extends BetterBaseEntityBlock implements IHam
private static final VoxelShape SHAPE_EAST = ShapeUtil.rotate(Direction.Axis.Y, 270, SHAPE_NORTH);

// 倒挂状态:使用 Axis.X 旋转 180 度实现 Y 轴翻转
private static final VoxelShape SHAPE_NORTH_UPSIDE = ShapeUtil.rotate(Direction.Axis.X, 180, SHAPE_NORTH);
private static final VoxelShape SHAPE_NORTH_UPSIDE = ShapeUtil.rotate(Direction.Axis.X, 180, SHAPE_SOUTH);
private static final VoxelShape SHAPE_WEST_UPSIDE = ShapeUtil.rotate(Direction.Axis.X, 180, SHAPE_WEST);
private static final VoxelShape SHAPE_SOUTH_UPSIDE = ShapeUtil.rotate(Direction.Axis.X, 180, SHAPE_SOUTH);
private static final VoxelShape SHAPE_SOUTH_UPSIDE = ShapeUtil.rotate(Direction.Axis.X, 180, SHAPE_NORTH);
private static final VoxelShape SHAPE_EAST_UPSIDE = ShapeUtil.rotate(Direction.Axis.X, 180, SHAPE_EAST);

public SmartBlockPlacerBlock(Properties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.state.BlockState;
import net.neoforged.neoforge.client.network.ClientPacketDistributor;
import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -950,15 +951,22 @@ private LevelLike buildPreviewLevelLike() {
int placerY = upsideDown ? 4 : 0;
previewLevelLike.setBlockState(
new BlockPos(2, placerY - 2, 7),
blockState.getBlock().defaultBlockState()
.setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)
.setValue(SmartBlockPlacerBlock.UPSIDE_DOWN, upsideDown)
blockState.setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)
);

var rotatedData = SmartBlockPlacerBlockEntity.rotateStructureDataStatic(structure);
int sizeX = structure.diskData.sizeX();
int sizeZ = structure.diskData.sizeZ();
for (var bp : rotatedData.blocks) {
int renderY = bp.y();
previewLevelLike.setBlockState(new BlockPos(bp.x(), renderY - 2, bp.z() + 1), bp.state());
int renderX = upsideDown ? (sizeX - 1 - bp.x()) : bp.x();
int renderZ = upsideDown ? (sizeZ - bp.z()) : (bp.z() + 1);
int renderY = upsideDown ? (2 - bp.y()) : (bp.y() - 2);
BlockState state = bp.state();
if (upsideDown) {
state = state.rotate(Rotation.CLOCKWISE_180);
state = SmartBlockPlacerBlockEntity.flipHalfPropertyStatic(state);
}
previewLevelLike.setBlockState(new BlockPos(renderX, renderY, renderZ), state);
}
} else {
// 普通模式:显示 UI 中的选区模式(不读取世界方块)
Expand All @@ -970,9 +978,7 @@ private LevelLike buildPreviewLevelLike() {
int placerY = upsideDown ? 4 : 0;
previewLevelLike.setBlockState(
new BlockPos(2, placerY - 2, 7),
blockState.getBlock().defaultBlockState()
.setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)
.setValue(SmartBlockPlacerBlock.UPSIDE_DOWN, upsideDown)
blockState.setValue(HorizontalDirectionalBlock.FACING, Direction.NORTH)
);

for (Map.Entry<Integer, Set<Integer>> entry : this.layerPositions.entrySet()) {
Expand Down
Loading
Loading