-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow setting custom properties onto model templates
Allow setting render types for model templates
- Loading branch information
1 parent
b4230f1
commit 611832a
Showing
7 changed files
with
79 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/net/neoforged/neoforge/common/data/vanilla/ModelTemplateWithCustomData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.common.data.vanilla; | ||
|
||
import com.google.gson.JsonObject; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import net.minecraft.data.models.model.ModelTemplate; | ||
import net.minecraft.data.models.model.TextureSlot; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.neoforged.neoforge.common.data.ExistingFileHelper; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ModelTemplateWithCustomData extends ModelTemplate { | ||
@Nullable | ||
private ResourceLocation renderType; | ||
|
||
public ModelTemplateWithCustomData(Optional<ResourceLocation> parent, Optional<String> pathSuffix, TextureSlot... requiredSlots) { | ||
super(parent, pathSuffix, requiredSlots); | ||
} | ||
|
||
public ModelTemplateWithCustomData(ModelTemplate template) { | ||
this(template.model, template.suffix, template.requiredSlots.toArray(TextureSlot[]::new)); | ||
} | ||
|
||
@Override | ||
public ModelTemplate withRenderType(ResourceLocation renderType) { | ||
this.renderType = renderType; | ||
return this; | ||
} | ||
|
||
@Override | ||
public JsonObject createBaseTemplate(ResourceLocation modelPath, Map<TextureSlot, ResourceLocation> textureMap, @Nullable ExistingFileHelper fileHelper) { | ||
var json = super.createBaseTemplate(modelPath, textureMap, fileHelper); | ||
|
||
if (renderType != null) { | ||
json.addProperty("render_type", renderType.toString()); | ||
} | ||
|
||
return json; | ||
} | ||
|
||
@Override | ||
public JsonObject createBaseTemplate(ResourceLocation modelPath, Map<TextureSlot, ResourceLocation> textureMap) { | ||
return createBaseTemplate(modelPath, textureMap, null); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/net/neoforged/neoforge/common/data/vanilla/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
@FieldsAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
package net.neoforged.neoforge.common.data.vanilla; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
import net.minecraft.FieldsAreNonnullByDefault; | ||
import net.minecraft.MethodsReturnNonnullByDefault; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...d/resources/assets/neotests_test_model_generators/models/item/vanilla_model_gen_item.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters