-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update resource pack api, now with a way to create typed item asset d…
…efinitions on the fly, update to pre3
- Loading branch information
Showing
87 changed files
with
1,576 additions
and
339 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,5 @@ jobs: | |
git config --global user.name Docs deploy | ||
git config --global user.email [email protected] | ||
mike set-default latest | ||
mike deploy --push --update-aliases 0.10.x latest | ||
mike deploy --push --update-aliases 0.11.x latest | ||
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
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
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
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
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,37 @@ | ||
archivesBaseName = "polymer-resource-pack-extras" | ||
version = rootProject.mod_version + "+" + rootProject.minecraft_version | ||
group = rootProject.maven_group | ||
|
||
sourceSets { | ||
testmod { | ||
compileClasspath += main.compileClasspath | ||
runtimeClasspath += main.runtimeClasspath | ||
} | ||
} | ||
|
||
loom { | ||
|
||
} | ||
|
||
dependencies { | ||
modCompileOnly "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_version}" | ||
|
||
api (project(path: ':polymer-common', configuration: 'namedElements')) | ||
api (project(path: ':polymer-resource-pack', configuration: 'namedElements')) | ||
} | ||
|
||
afterEvaluate { | ||
// Disable the gen sources task on sub projects | ||
genSourcesWithFernFlower.enabled = true | ||
genSourcesWithCfr.enabled = false | ||
} | ||
|
||
processResources { | ||
inputs.property "version", project.version | ||
inputs.property "minecraft_version_supported", rootProject.minecraft_version_supported | ||
|
||
filesMatching("fabric.mod.json") { | ||
expand "version": project.version | ||
expand "minecraft_version_supported": rootProject.minecraft_version_supported | ||
} | ||
} |
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 @@ | ||
project.name = 'polymer-resource-pack-extras' |
150 changes: 150 additions & 0 deletions
150
...-pack-extras/src/main/java/eu/pb4/polymer/resourcepack/extras/api/ResourcePackExtras.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,150 @@ | ||
package eu.pb4.polymer.resourcepack.extras.api; | ||
|
||
import eu.pb4.polymer.resourcepack.api.AssetPaths; | ||
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils; | ||
import eu.pb4.polymer.resourcepack.api.ResourcePackBuilder; | ||
import eu.pb4.polymer.resourcepack.api.ResourcePackCreator; | ||
import eu.pb4.polymer.resourcepack.extras.api.format.item.ItemAsset; | ||
import eu.pb4.polymer.resourcepack.extras.api.format.item.model.BasicItemModel; | ||
import eu.pb4.polymer.resourcepack.extras.api.format.item.tint.CustomModelDataTintSource; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
import java.util.*; | ||
import java.util.function.BiFunction; | ||
|
||
/** | ||
* Utilities allowing simple creation of resource pack | ||
*/ | ||
public final class ResourcePackExtras { | ||
private static final ResourcePackExtras MAIN = new ResourcePackExtras(PolymerResourcePackUtils.getInstance()); | ||
private final Map<Identifier, BiFunction<Identifier, ResourcePackBuilder, @Nullable ItemAsset>> bridgedModels = new HashMap<>(); | ||
|
||
ResourcePackExtras(ResourcePackCreator creator) { | ||
creator.afterInitialCreationEvent.register(this::setup); | ||
} | ||
|
||
public static ResourcePackExtras forDefault() { | ||
return MAIN; | ||
} | ||
|
||
public static ResourcePackExtras of(ResourcePackCreator creator) { | ||
if (PolymerResourcePackUtils.getInstance() == creator) { | ||
return MAIN; | ||
} | ||
return new ResourcePackExtras(creator); | ||
} | ||
|
||
public static ResourcePackExtras of(ResourcePackCreator creator, ResourcePackExtras source) { | ||
if (PolymerResourcePackUtils.getInstance() == creator) { | ||
throw new IllegalArgumentException("Passed creator matches PolymerResourcePackUtils.getInstance(), so you can't copy settings from other sources to it!"); | ||
} | ||
|
||
var extras = new ResourcePackExtras(creator); | ||
extras.bridgedModels.putAll(source.bridgedModels); | ||
return extras; | ||
} | ||
|
||
public static Identifier bridgeModelNoItem(Identifier model) { | ||
if (model.getPath().startsWith("item/")) { | ||
return model.withPath(model.getPath().substring("item/".length())); | ||
} | ||
|
||
return bridgeModel(model); | ||
} | ||
|
||
public static Identifier bridgeModel(Identifier model) { | ||
return model.withPrefixedPath("-/"); | ||
} | ||
|
||
/** | ||
* Adds a bridge, allowing you to access any model from selected folder as `namespace:-/modelpath`. | ||
* | ||
* @param modelFolderId Model folder to bridge. For example "mod:block" will bridge all models from "assets/mod/models/block" | ||
* @return Success of addition. | ||
*/ | ||
public boolean addBridgedModelsFolder(Identifier modelFolderId) { | ||
return addBridgedModelsFolder(modelFolderId, | ||
(identifier, resourcePackBuilder) -> new ItemAsset(new BasicItemModel(identifier), ItemAsset.Properties.DEFAULT) | ||
); | ||
} | ||
|
||
public boolean addBridgedModelsFolderWithColor(Identifier modelFolderId) { | ||
return addBridgedModelsFolder(modelFolderId, | ||
(identifier, resourcePackBuilder) -> new ItemAsset(new BasicItemModel(identifier, | ||
List.of( | ||
new CustomModelDataTintSource(0, 0xFFFFFF), | ||
new CustomModelDataTintSource(1, 0xFFFFFF), | ||
new CustomModelDataTintSource(2, 0xFFFFFF), | ||
new CustomModelDataTintSource(3, 0xFFFFFF)) | ||
), ItemAsset.Properties.DEFAULT) | ||
); | ||
} | ||
|
||
public boolean addBridgedModelsFolder(Identifier modelFolderId, BiFunction<Identifier, ResourcePackBuilder, @Nullable ItemAsset> bridgeBuilder) { | ||
this.bridgedModels.put(modelFolderId.getPath().endsWith("/") ? modelFolderId.withPath(x -> x.substring(0, x.length() - 1)) : modelFolderId, bridgeBuilder); | ||
return true; | ||
} | ||
|
||
public boolean addBridgedModelsFolder(Identifier... modelFolderId) { | ||
var b = true; | ||
for (var model : modelFolderId) { | ||
b &= addBridgedModelsFolder(model); | ||
} | ||
return b; | ||
} | ||
|
||
public boolean addBridgedModelsFolder(Collection<Identifier> modelFolderId) { | ||
var b = true; | ||
for (var model : modelFolderId) { | ||
b &= addBridgedModelsFolder(model); | ||
} | ||
return b; | ||
} | ||
|
||
public boolean addBridgedModelsFolder(Collection<Identifier> modelFolderId, BiFunction<Identifier, ResourcePackBuilder, @Nullable ItemAsset> bridgeBuilder) { | ||
var b = true; | ||
for (var model : modelFolderId) { | ||
b &= addBridgedModelsFolder(model, bridgeBuilder); | ||
} | ||
return b; | ||
} | ||
|
||
|
||
private void setup(ResourcePackBuilder builder) { | ||
if (!this.bridgedModels.isEmpty()) { | ||
builder.addPreFinishTask((b) -> { | ||
b.forEachFile((path, out) -> { | ||
if (!path.startsWith("assets/")) { | ||
return; | ||
} | ||
path = path.substring("assets/".length()); | ||
|
||
for (var x : this.bridgedModels.entrySet()) { | ||
var key = x.getKey(); | ||
var y = key.getNamespace() + "/models/" + key.getPath() + "/"; | ||
if (path.startsWith(y)) { | ||
if (!path.endsWith(".json")) { | ||
return; | ||
} | ||
path = path.substring(key.getNamespace().length() + "/models/".length(), path.length() - ".json".length()); | ||
|
||
var assetPath = AssetPaths.itemAsset(key.withPath("-/" + path)); | ||
|
||
if (b.getData(assetPath) != null) { | ||
return; | ||
} | ||
|
||
var asset = x.getValue().apply(key.withPath(path), b); | ||
if (asset != null) { | ||
b.addData(assetPath, asset.toJson().getBytes(StandardCharsets.UTF_8)); | ||
} | ||
return; | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.