====== 아이템 추가 ====== ==== 소개 ==== 아이템을 추가하는 것은 모딩에 있어서 가장 첫 번째 단계입니다. 당신은 ''Item'' 오브젝트를 추가하고, 등록하고, 텍스쳐를 추가할 것입니다. 아이템의 추가적인 기능을 위해서는 커스텀 아이템 클래스를 만들어야만 할 것입니다. 모든 튜토리얼에서는 ''tutorial'' NameSpace를 사용할 것입니다. 다른 Mod ID를 사용하고 싶으시다면, 해당 부분을 수정하셔도 됩니다. ==== 아이템 등록 ==== 먼저, 아이템의 인스턴스를 생성합니다. 해당 인스턴스는 Initializer 클래스의 맨 윗 부분에 저장합니다. ''Item.Settings'' (또는 ''FabricFirst'') 가 인스턴스 생성자이며, 인벤토리 분류나 내구성, 한칸에 쌓일 수 있는 개수 등의 아이템 정보를 설정할 수 있습니다. public class ExampleMod implements ModInitializer { // 우리의 첫 번째 아이템의 인스턴스 public static final Item FABRIC_ITEM = new Item(new FabricItemSettings().group(ItemGroup.MISC)); [...] } 새로운 내용을 등록할 때는 바닐라 등록 시스템(레지스트리)을 사용할 것입니다. 기본적인 문법은 ''Registry#register(Registry Type, Identifier, Content)'' 입니다. Type은 기본적으로 ''Registry'' 클래스에 있으며, Identifier는 내용물을 설정합니다. Content는 당신이 추가하고자 하는 아이템의 인스턴스입니다. 이 함수는 Initialization 진행 중 언제든지 호출될 수 있습니다. public class ExampleMod implements ModInitializer { // 우리의 첫 번째 아이템의 인스턴스 public static final Item FABRIC_ITEM = new Item(new FabricItemSettings().group(ItemGroup.MISC)); @Override public void onInitialize() { Registry.register(Registry.ITEM, new Identifier("tutorial", "fabric_item"), FABRIC_ITEM); } } 자, 이제 첫 번째 아이템이 Minecraft에 추가되었습니다. ''runClient'' Gralde task를 실행하여 살펴보세요. {{:tutorial:2019-02-17_16.50.44.png?400|}} ==== 아이템 텍스쳐 추가 ==== 텍스쳐를 추가하기 위해서는 아이템 모델 .json 파일과 텍스쳐 이미지가 필요합니다. 이것들은 resource 폴더에 저장될 것이며, 경로는: 아이템 모델: .../resources/assets/tutorial/models/item/fabric_item.json 아이템 텍스쳐: .../resources/assets/tutorial/textures/item/fabric_item.png 기본 예시 텍스쳐는 [[https://i.imgur.com/CqLSMEQ.png|여기]]에서 찾으실 수 있습니다.. 아마도 첫 번째 단계에서 아이템이 성공적으로 추가되었을 때, 게임에서 다음과 같이 텍스쳐를 찾을 수 없다는 오류를 내뱉었을 것입니다: [Server-Worker-1/WARN]: Unable to load model: 'tutorial:fabric_item#inventory' referenced from: tutorial:fabric_item#inventory: java.io.FileNotFoundException: tutorial:models/item/fabric_item.json It conveniently tells you exactly where it expects your asset[s] to be found-- when in doubt, check the log. 가장 기본적인 아이템 모델 형식: { "parent": "item/generated", "textures": { "layer0": "tutorial:item/fabric_item" } } Parent는 손에서 어떻게 아이템이 렌더링되는지를 정할 수 있으며, 이는 블럭 아이템과 같은 경우에서 유용하게 쓰일 수 있습니다. "item/handheld"로 설정하면 텍스쳐의 좌측 하단 부분을 손이 들게 됩니다. textures/layer0은 이미지 파일의 경로입니다. 최종적으로 텍스쳐가 적용된 아이템: {{:tutorial:item_texture.png?400|}} ==== 아이템 클래스 생성 ==== 아이템에 대해 추가적인 기능을 넣기 위해서는, 아이템 클래스를 생성하여야 합니다. 기본적인 클래스 생성자는 Item.Settings 오브젝트를 필요로 합니다. public class FabricItem extends Item { public FabricItem(Settings settings) { super(settings); } } 아이템을 사용하면 소리가 나는 예시입니다: public class FabricItem extends Item { public FabricItem(Settings settings) { super(settings); } @Override public TypedActionResult use(World world, PlayerEntity playerEntity, Hand hand) { playerEntity.playSound(SoundEvents.BLOCK_WOOL_BREAK, 1.0F, 1.0F); return TypedActionResult.success(playerEntity.getStackInHand(hand)); } } 원래의 Item 오브젝트를 새로 만든 아이템 클래스로 바꿔주세요: public class ExampleMod implements ModInitializer { // an instance of our new item public static final FabricItem FABRIC_ITEM = new FabricItem(new FabricItemSettings().group(ItemGroup.MISC)); [...] } 여기까지 잘 따라왔다면, 아이템을 사용하였을 때 소리가 들릴 것입니다. ==== 아이템이 한칸에 쌓일 수 있는 개수를 조절하고 싶으면? ==== 여기서 우리는 쌓일 수 있는 개수를 조절하기 위해서 ''FabricItemSettings'' 안에 있는 ''maxCount(int size)''를 사용할 것입니다. 만약 해당 아이템의 내구도가 존재한다면 이를 조정할 수 없으며, 게임에서는 RuntimeException 오류가 나올 것입니다. public class ExampleMod implements ModInitializer { // An instance of our new item, where the maximum stack size is 16 public static final FabricItem FABRIC_ITEM = new FabricItem(new FabricItemSettings().group(ItemGroup.MISC).maxCount(16)); [...] } ==== 다음 단계 ==== [[tutorial:itemgroup|자신만의 ItemGroup에 아이템 추가하기 (영문)]].