Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few new ItemModelProvider methods! #1542

Open
wants to merge 7 commits into
base: 1.21.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 item) {
return withExistingParent(item.toString(), ResourceLocation.fromNamespaceAndPath(item.getNamespace(), "block/" + item.getPath()));
}

@Override
public String getName() {
return "Item Models: " + modid;
Expand Down
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
Loading