diff --git a/src/main/java/net/neoforged/neoforge/client/model/generators/ItemModelProvider.java b/src/main/java/net/neoforged/neoforge/client/model/generators/ItemModelProvider.java index f4af7fdeaf..046ef31566 100644 --- a/src/main/java/net/neoforged/neoforge/client/model/generators/ItemModelProvider.java +++ b/src/main/java/net/neoforged/neoforge/client/model/generators/ItemModelProvider.java @@ -10,6 +10,7 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; +import net.minecraft.world.level.block.Block; import net.neoforged.neoforge.common.data.ExistingFileHelper; /** @@ -31,6 +32,33 @@ public ItemModelBuilder basicItem(ResourceLocation item) { .texture("layer0", ResourceLocation.fromNamespaceAndPath(item.getNamespace(), "item/" + item.getPath())); } + public ItemModelBuilder handheldItem(Item item) { + return handheldItem(Objects.requireNonNull(BuiltInRegistries.ITEM.getKey(item))); + } + + public ItemModelBuilder handheldItem(ResourceLocation item) { + return getBuilder(item.toString()) + .parent(new ModelFile.UncheckedModelFile("item/handheld")) + .texture("layer0", ResourceLocation.fromNamespaceAndPath(item.getNamespace(), "item/" + item.getPath())); + } + + public ItemModelBuilder spawnEggItem(Item item) { + return spawnEggItem(Objects.requireNonNull(BuiltInRegistries.ITEM.getKey(item))); + } + + public ItemModelBuilder spawnEggItem(ResourceLocation item) { + return getBuilder(item.toString()) + .parent(new ModelFile.UncheckedModelFile("item/template_spawn_egg")); + } + + public ItemModelBuilder simpleBlockItem(Block block) { + return simpleBlockItem(Objects.requireNonNull(BuiltInRegistries.BLOCK.getKey(block))); + } + + public ItemModelBuilder simpleBlockItem(ResourceLocation block) { + return withExistingParent(block.toString(), ResourceLocation.fromNamespaceAndPath(block.getNamespace(), "block/" + block.getPath())); + } + @Override public String getName() { return "Item Models: " + modid; diff --git a/tests/src/generated/resources/assets/minecraft/models/item/acacia_planks.json b/tests/src/generated/resources/assets/minecraft/models/item/acacia_planks.json new file mode 100644 index 0000000000..3c90abef53 --- /dev/null +++ b/tests/src/generated/resources/assets/minecraft/models/item/acacia_planks.json @@ -0,0 +1,3 @@ +{ + "parent": "minecraft:block/acacia_planks" +} \ No newline at end of file diff --git a/tests/src/generated/resources/assets/minecraft/models/item/sheep_spawn_egg.json b/tests/src/generated/resources/assets/minecraft/models/item/sheep_spawn_egg.json new file mode 100644 index 0000000000..d1aaa9d6ef --- /dev/null +++ b/tests/src/generated/resources/assets/minecraft/models/item/sheep_spawn_egg.json @@ -0,0 +1,3 @@ +{ + "parent": "minecraft:item/template_spawn_egg" +} \ No newline at end of file diff --git a/tests/src/generated/resources/assets/minecraft/models/item/wooden_sword.json b/tests/src/generated/resources/assets/minecraft/models/item/wooden_sword.json new file mode 100644 index 0000000000..4024a58a08 --- /dev/null +++ b/tests/src/generated/resources/assets/minecraft/models/item/wooden_sword.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:item/handheld", + "textures": { + "layer0": "minecraft:item/wooden_sword" + } +} \ No newline at end of file diff --git a/tests/src/main/java/net/neoforged/neoforge/oldtest/client/model/CustomItemDisplayContextTest.java b/tests/src/main/java/net/neoforged/neoforge/oldtest/client/model/CustomItemDisplayContextTest.java index 9c6ce94624..17f8a3cb3a 100644 --- a/tests/src/main/java/net/neoforged/neoforge/oldtest/client/model/CustomItemDisplayContextTest.java +++ b/tests/src/main/java/net/neoforged/neoforge/oldtest/client/model/CustomItemDisplayContextTest.java @@ -34,6 +34,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.HorizontalDirectionalBlock; import net.minecraft.world.level.block.RenderShape; @@ -167,6 +168,12 @@ protected void registerModels() { .translation(-2.25f, 1.5f, -0.25f).scale(0.48f) .end() .end(); + + handheldItem(Items.WOODEN_SWORD); + + spawnEggItem(Items.SHEEP_SPAWN_EGG); + + simpleBlockItem(Blocks.ACACIA_PLANKS); } }