Skip to content

Commit

Permalink
Add a few new ItemModelProvider methods! (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZestyBlaze authored Oct 10, 2024
1 parent b88c1e1 commit f869db5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "minecraft:block/acacia_planks"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "minecraft:item/template_spawn_egg"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/handheld",
"textures": {
"layer0": "minecraft:item/wooden_sword"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit f869db5

Please sign in to comment.