尝试为我所在的服务器制作一个小型个人模组,使用 MC Forge 1.20.1。我们想要定制床模型。除了一些事情之外,我几乎一切都在工作。由于某种原因,我无法弄清楚如何降低旋转块的放置位置。到目前为止,我的所有代码看起来都是正确的,我有一个类来检查块位置、块状态和项目等。该块将放置得很好,直到我尝试添加块状态然后变成紫色和黑色错误块。
查看文档我尝试更改类的调用方式以及块注册表的方式。我已经多次更改块状态,并且块状态只是类似
{
"variants": {
"": {
"model": "tutorial_testing:block/hope_bed"
}
}
}
床就可以出现,但一旦我尝试放入类似的东西:
{
"variants": {
"facing = north": {
"model": "tutorial_testing:block/hope_bed"},
"facing = east": {
"model": "tutorial_testing:block/hope_bed",
"y": 90
},
"facing = south": {
"model": "tutorial_testing:block/hope_bed",
"y": 180
},
"facing = west": {
"model": "tutorial_testing:block/hope_bed",
"y": 270
}
}
}
该块变成紫色和黑色纹理块。我知道这与它找不到纹理有关,但我一生都无法弄清楚为什么。
编辑以添加更多代码,抱歉
区块注册表:
import io.github.magikpups.testing.TestingMod;
import io.github.magikpups.testing.block.advhopebed;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
public class BlockRegistry {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS,
TestingMod.MOD_ID);
public static final RegistryObject<Block> HOPE_BED = BLOCKS.register(
"hope_bed", () -> new advhopebed(Block.Properties.copy(Blocks.BAMBOO_PLANKS)
.mapColor(MapColor.COLOR_LIGHT_GREEN)
.strength(5.0f)
.sound(SoundType.BAMBOO_WOOD)
.noLootTable()
.dynamicShape()
));
}
班级建议:
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
public class advhopebed extends HorizontalDirectionalBlock {
public static final DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;
public advhopebed(Properties properties) {
super(properties);
}
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(FACING);
}
}
编辑:找到问题所在,我不应该为“face=north”添加空格。只是想我把它放在这里以防其他人遇到问题:>
想通了。代码应该是这样的。
{
"variants": {
"facing=north": {
"model": "tutorial_testing:block/hope_bed"},
"facing=east": {
"model": "tutorial_testing:block/hope_bed",
"y": 90
},
"facing=south": {
"model": "tutorial_testing:block/hope_bed",
"y": 180
},
"facing=west": {
"model": "tutorial_testing:block/hope_bed",
"y": 270
}
}
}