跳到主要内容

36自定义船

代码

在entity包下新建一个船:

public class ModBoats {
public static final Identifier CHESTNUT_BOAT_ID = new Identifier(TutorialMod.MOD_ID, "chestnut_boat");
public static final Identifier CHESTNUT_CHEST_BOAT_ID = new Identifier(TutorialMod.MOD_ID, "chestnut_chest_boat");

public static final RegistryKey<TerraformBoatType> CHESTNUT_BOAT_KEY = TerraformBoatTypeRegistry.createKey(CHESTNUT_BOAT_ID);

public static void registerBoats() {
TerraformBoatType chestnutBoat = new TerraformBoatType.Builder()
.item(ModItems.CHESTNUT_BOAT)
.chestItem(ModItems.CHESTNUT_CHEST_BOAT)
.planks(ModBlocks.CHESTNUT_PLANKS.asItem())
.build();

Registry.register(TerraformBoatTypeRegistry.INSTANCE, CHESTNUT_BOAT_KEY, chestnutBoat);
}
}

注册到物品中:

public static final Item CHESTNUT_BOAT = TerraformBoatItemHelper.registerBoatItem(ModBoats.CHESTNUT_BOAT_ID, ModBoats.CHESTNUT_BOAT_KEY, false);
public static final Item CHESTNUT_CHEST_BOAT = TerraformBoatItemHelper.registerBoatItem(ModBoats.CHESTNUT_CHEST_BOAT_ID, ModBoats.CHESTNUT_BOAT_KEY, true);

添加到物品组:

entries.add(ModItems.CHESTNUT_BOAT);
entries.add(ModItems.CHESTNUT_CHEST_BOAT);

初始化加载TutorialMod:

ModBoats.registerBoats();

TutorialModClient:

TerraformBoatClientHelper.registerModelLayers(ModBoats.CHESTNUT_BOAT_ID, false);

数据生成ModModelProvider:

itemModelGenerator.register(ModItems.CHESTNUT_BOAT, Models.GENERATED);
itemModelGenerator.register(ModItems.CHESTNUT_CHEST_BOAT, Models.GENERATED);

##效果

image-20240825193126383