This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getting ready for initial release (0.1.0)!
- Loading branch information
1 parent
8a1cc78
commit c539afa
Showing
20 changed files
with
252 additions
and
401 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 |
---|---|---|
@@ -1,34 +1,27 @@ | ||
# Quilt Template Mod w/ `gradle.properties` Dependency Declaration | ||
## Glowstick: Emissive Textures via JSON, for Quilt Loader + Quilted Fabric API (1.19.2+) | ||
Glowstick is a mod that adds a simplistic emissive/'glowing' textures feature to vanilla's generated item textures (nearly all items that use a set of texture layers). | ||
|
||
A template mod for the Quilt Toolchain, based on the official template. | ||
Currently (as of 0.1.0), *only item models are supported*, and armor overlay support is planned for the near future. | ||
|
||
You can use this as a template for your own mods! | ||
Tested to be compatible with [Chime](https://github.com/emilyploszaj/chime)'s item predicate extensions. | ||
|
||
([And, you can find the official template here.](https://github.com/QuiltMC/quilt-template-mod)) | ||
### How to use Glowstick: | ||
|
||
## Usage | ||
In the main json object for an item model, add an array object with the name `"emissive_texures"`, and put the *texture ids* (not the layer names themselves!) for which you want the emissive effect to apply to within. | ||
|
||
In order to use this mod as a template: | ||
Example: (at `assets/minecraft/models/item/stick.json`) | ||
``` | ||
{ | ||
"parent": "minecraft:item/handheld", | ||
"textures": { | ||
"layer0": "testpack:item/glowstick", | ||
"layer1": "testpack:item/glowstick2" | ||
}, | ||
"emissive_textures": [ | ||
"testpack:item/glowstick2" | ||
] | ||
} | ||
``` | ||
### License: | ||
Glowstick is licensed under the *Mozilla Public License, Version 2.0* (see the LICENSE file and the licensing header!) | ||
|
||
1. Create a new repository from this template with `Use this template` | ||
2. Clone the recently-created repo on your PC | ||
3. Make the necessary changes in order to make it yours: | ||
- Update `gradle.properties` as is necessary: | ||
- Since this template declares dependency versions in `gradle.properties`, refer to the instructions in the comments on said file to update them. | ||
- Also, update `gradle.properties` in order to use your Maven group and mod ID: | ||
- If you don't know which Maven group to use, and you are planning to host the mod's source code on GitHub, use `io.github.<Your_Username_Here>` | ||
- Update `quilt.mod.json` in order to reflect your mod's metadata: | ||
- If you are planning to include (jar-in-jar) a mod, don't forget to declare its dependency on it! | ||
- The icon provided here is a placeholder one. If you aren't able to replace it yet, you can delete it and remove the "icon" property | ||
- Create a LICENSE file for this mod! If you don't know which license to use, check out [here](https://choosealicense.com/): | ||
- If you use `LICENSE.md`, don't forget to update the buildscript in order to use that file name! | ||
- In `quilt.mod.json`, don't forget to put the license's [SPDX identifier](https://spdx.org/licenses/) under the `"license"` property in `"metadata"`. | ||
- The GPLv3 and AGPLv3 are not valid mod licenses, so you can use almost any license except for those. | ||
- Update the Java sub-directory structure, so that it reflects your Maven group | ||
4. The mod is now ready to be worked on! | ||
|
||
## License | ||
|
||
This template is licensed under the [Creative Common Zero v1.0 license](./LICENSE-TEMPLATE.md). | ||
|
||
Mods created with this template are not automatically licensed under the CC0, and are not required to give any kind of credit back to QuiltMC (nor CoconaOfTheStars) for this template. |
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,17 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
package cocona20xx.glowstick; | ||
|
||
import net.minecraft.client.render.model.BakedQuad; | ||
|
||
public interface BakedQuadAccessor { | ||
int getModifier(); | ||
void setModifier(int newMod); | ||
|
||
void storeActual(BakedQuad toStore); | ||
|
||
BakedQuad getActual(); | ||
} |
123 changes: 123 additions & 0 deletions
123
src/main/java/cocona20xx/glowstick/EmissiveDataReloader.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,123 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
package cocona20xx.glowstick; | ||
|
||
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.Lists; | ||
import com.google.gson.*; | ||
import net.minecraft.resource.Resource; | ||
import net.minecraft.resource.ResourceManager; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.quiltmc.qsl.resource.loader.api.reloader.SimpleSynchronousResourceReloader; | ||
|
||
import java.io.BufferedReader; | ||
import java.util.*; | ||
import java.util.regex.Pattern; | ||
|
||
public class EmissiveDataReloader implements SimpleSynchronousResourceReloader { | ||
private static final ArrayListMultimap<Identifier, Identifier> EMISSIVE_MAP = ArrayListMultimap.create(); | ||
private static final Gson GSON = new Gson(); | ||
private static final String[] PARENT_BLACKLIST = {"template_banner", "template_bed", "template_shulker_box", "template_skull", "template_spawn_egg", "trident_in_hand", "spyglass_in_hand", "block"}; | ||
private static final ArrayList<String> BLACKLIST_LIST = Lists.newArrayList(PARENT_BLACKLIST); | ||
public static final Identifier RELOADER_ID = new Identifier(GlowstickModClient.MOD_ID, "emissive"); | ||
public static final String ET_MEMBER_NAME = "emissive_textures"; | ||
private static final String[] flags = {"layer0", "layer1", "layer2", "layer3", "layer4"}; | ||
|
||
@Override | ||
public void reload(ResourceManager manager) { | ||
GlowstickModClient.LOGGER.info("Starting Emissive Load..."); | ||
EMISSIVE_MAP.clear(); | ||
for(Identifier modelId : manager.findResources("models/item", path -> path.toString().endsWith(".json")).keySet()){ | ||
try { | ||
for(Resource r : manager.getAllResources(modelId)){ | ||
try (BufferedReader reader = r.openBufferedReader()){ | ||
JsonObject mainObject = GSON.fromJson(reader, JsonObject.class); | ||
if(mainObject.has(ET_MEMBER_NAME)){ | ||
if(!BLACKLIST_LIST.contains(mainObject.get("parent").getAsString())){ | ||
JsonArray etArrayJson = mainObject.getAsJsonArray(ET_MEMBER_NAME); | ||
int etLen = etArrayJson.size(); | ||
for (int i = 0; i < etLen; i++) { | ||
JsonPrimitive current = etArrayJson.get(i).getAsJsonPrimitive(); | ||
if(current.isString()){ | ||
//emissive texture strings are not checked against the model as overrides can refer to other models, and this (should) hopefully let those textures also work? needs testing ofc (TODO) | ||
Identifier sanitizedModelId = sanitizeValidId(modelId); | ||
Identifier sanitizedTextureId = convertIdStringToSanitized(current.getAsString()); | ||
putResult(sanitizedTextureId, sanitizedModelId); | ||
} else { | ||
throw new Exception("Emissive Textures array on item model " + modelId.toString() + " contains non-string value at index " + i +",skipping."); | ||
} | ||
} | ||
} | ||
} | ||
} catch (Exception e){ | ||
GlowstickModClient.LOGGER.warn("Error occurred when trying to parse emissive data: " + e); | ||
} | ||
} | ||
} catch (Exception e){ | ||
GlowstickModClient.LOGGER.warn("IO Error when trying to parse emissive data: " + e); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public @NotNull Identifier getQuiltId() { | ||
return RELOADER_ID; | ||
} | ||
|
||
private static void putResult(Identifier sanitizedTexId, Identifier sanitizedModelId){ | ||
EMISSIVE_MAP.put(sanitizedTexId, sanitizedModelId); | ||
} | ||
|
||
public static boolean checkValidity(Identifier sanitizedTexId, Identifier sanitizedModelId){ | ||
//you are valid! the model id, however, might not be | ||
boolean validity = false; | ||
List<Identifier> models = EMISSIVE_MAP.get(sanitizedTexId); | ||
for (Identifier model : models) { | ||
if (model.equals(sanitizedModelId)) { | ||
validity = true; | ||
break; | ||
} | ||
} | ||
return validity; | ||
} | ||
|
||
public static Identifier sanitizeValidId(Identifier toSanitize){ | ||
String path = toSanitize.getPath(); | ||
if(path.contains("#")){ | ||
path = path.split(Pattern.quote("#"))[0]; | ||
} | ||
path = removeLastIfValid(path, ".json"); | ||
path = removeLastIfValid(path, ".png"); | ||
path = removeFirstIfValid(path, "models/"); | ||
path = removeFirstIfValid(path, "textures/"); | ||
path = removeFirstIfValid(path, "item"); | ||
return new Identifier(toSanitize.getNamespace(), path); | ||
} | ||
|
||
public static Identifier convertIdStringToSanitized(String idString){ | ||
if(idString.contains(":")){ | ||
//id has defined namespace | ||
String[] s = idString.split(Pattern.quote(":")); | ||
return sanitizeValidId(new Identifier(s[0], s[1])); | ||
} else { | ||
//implicit minecraft namespace | ||
return sanitizeValidId(new Identifier("minecraft", idString)); | ||
} | ||
} | ||
|
||
private static String removeLastIfValid(String current, String last){ | ||
if(current.endsWith(last)){ | ||
int l = current.lastIndexOf(last); | ||
return current.substring(0, l); | ||
} else return current; | ||
} | ||
private static String removeFirstIfValid(String current, String first){ | ||
if(current.startsWith(first)){ | ||
return current.replaceFirst(Pattern.quote(first), ""); | ||
} else return current; | ||
} | ||
} |
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
11 changes: 8 additions & 3 deletions
11
...xx/retribution/mixins/BakedQuadMixin.java → ...20xx/glowstick/mixins/BakedQuadMixin.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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/cocona20xx/glowstick/mixins/JsonUnbakedModelMixin.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,40 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
package cocona20xx.glowstick.mixins; | ||
|
||
import cocona20xx.glowstick.GlowstickModClient; | ||
import cocona20xx.glowstick.EmissiveDataReloader; | ||
import cocona20xx.glowstick.BakedQuadAccessor; | ||
import net.minecraft.client.render.model.BakedQuad; | ||
import net.minecraft.client.render.model.ModelBakeSettings; | ||
import net.minecraft.client.render.model.json.JsonUnbakedModel; | ||
import net.minecraft.client.render.model.json.ModelElement; | ||
import net.minecraft.client.render.model.json.ModelElementFace; | ||
import net.minecraft.client.texture.Sprite; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.Direction; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(JsonUnbakedModel.class) | ||
public class JsonUnbakedModelMixin{ | ||
|
||
@Inject(method = "createQuad", at = @At("RETURN"), cancellable = true) | ||
private static void createQuadInjector(ModelElement element, ModelElementFace elementFace, Sprite sprite, Direction side, ModelBakeSettings settings, Identifier id, CallbackInfoReturnable<BakedQuad> cir){ | ||
BakedQuad initReturn = cir.getReturnValue(); | ||
if(sprite.getId().toString().contains("test")){ | ||
boolean useless = true; | ||
} | ||
if(EmissiveDataReloader.checkValidity(EmissiveDataReloader.sanitizeValidId(sprite.getId()), EmissiveDataReloader.sanitizeValidId(id))){ | ||
BakedQuadAccessor bakedQuadAccessor = (BakedQuadAccessor)initReturn; | ||
bakedQuadAccessor.storeActual(initReturn); | ||
bakedQuadAccessor.setModifier(GlowstickModClient.EMISSIVE_MODIFIER); | ||
cir.setReturnValue(bakedQuadAccessor.getActual()); | ||
} | ||
} | ||
} |
Oops, something went wrong.