Skip to content

Commit

Permalink
4th type - Quilt
Browse files Browse the repository at this point in the history
  • Loading branch information
PanSzelescik committed Feb 18, 2024
1 parent 62cf3c0 commit 7b74d6f
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ jobs:
with:
name: NeoForge
path: neoforged/build/libs/
- name: Publish Quilt
uses: actions/upload-artifact@v3
with:
name: Quilt
path: quilt/build/libs/
35 changes: 35 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,41 @@ jobs:
loaders: |
fabric
modrinth-game-versions: |
>=1.19.3
curseforge-game-versions: |
>=1.19.3
java: |
18
17
retry-attempts: 2
retry-delay: 10000
fail-mode: fail
- name: Publish Quilt to CurseForge and Modrinth
uses: Kir-Antipov/mc-publish@v3.3
with:
modrinth-id: 4sQDl6he
modrinth-featured: true
modrinth-unfeature-mode: intersection
modrinth-token: ${{ secrets.MODRINTH_TOKEN }}

curseforge-id: 658780
curseforge-token: ${{ secrets.CURSEFORGE_API_KEY }}

files: |
quilt/build/libs/!(*-@(dev|dev-shadow|sources|javadoc)).jar
quilt/build/libs/*-@(dev|dev-shadow|sources|javadoc).jar
name: ""
version-type: release

dependencies: |
qsl(required){modrinth:qsl}{curseforge:634179}
jei(optional){modrinth:jei}{curseforge:238222}
rei(optional){modrinth:rei}{curseforge:310111}
loaders: |
quilt
modrinth-game-versions: |
>=1.19.3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.panszelescik.colorize.fabric;
package pl.panszelescik.colorize.common.api.config;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -16,13 +16,13 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class ColorizeFabricConfig implements ColorizeConfig {
public class BasicConfig implements ColorizeConfig {

public static final String MODID = "colorize";
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
private final Object2BooleanMap<String> booleans;

public ColorizeFabricConfig(@NotNull File configDir) throws IOException {
public BasicConfig(@NotNull File configDir) throws IOException {
var file = new File(configDir, MODID + ".json");

if (file.exists()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pl.panszelescik.colorize.fabric;
package pl.panszelescik.colorize.common.api.config;

import com.google.gson.JsonObject;
import org.jetbrains.annotations.NotNull;
Expand Down
1 change: 1 addition & 0 deletions fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loom.platform=fabric
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.world.InteractionResult;
import pl.panszelescik.colorize.common.api.config.BasicConfig;

import java.io.IOException;

public class ColorizeFabric implements ModInitializer {

@Override
public void onInitialize() {
ColorizeFabricConfig config;
BasicConfig config;
try {
config = new ColorizeFabricConfig(FabricLoader.getInstance().getConfigDir().toFile());
config = new BasicConfig(FabricLoader.getInstance().getConfigDir().toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down
1 change: 0 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
]
},
"depends": {
"fabricloader": ">=0.14",
"fabric-api": "*",
"minecraft": ">=1.19.3",
"java": ">=17"
Expand Down
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
org.gradle.jvmargs=-Xmx8G

minecraft_version=1.20.4
enabled_platforms=fabric,forge
enabled_platforms=fabric,forge,quilt

archives_base_name=colorize
mod_version=1.8.1
mod_version=1.9.0
maven_group=pl.panszelescik.colorize

//architectury_version=9.1.12
Expand All @@ -16,5 +16,8 @@ forge_version=1.20.4-49.0.30

neoforge_version=20.4.161-beta

quilt_loader_version=0.24.0-beta.6
quilt_fabric_api_version=7.5.0+0.91.0-1.20.1

jei_minecraft_version=1.20.4
jei_version=17.3.0.49
87 changes: 87 additions & 0 deletions quilt/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
}

architectury {
platformSetupLoomIde()
loader("quilt")
}

archivesBaseName = rootProject.archives_base_name + "-" + rootProject.minecraft_version + "-quilt"

loom {
accessWidenerPath = project(":common").loom.accessWidenerPath
}

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin since it *excludes* files.
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
}

repositories {
maven { url "https://maven.quiltmc.org/repository/release/" }
maven { url "https://modmaven.dev" }
}

dependencies {
modImplementation "org.quiltmc:quilt-loader:${rootProject.quilt_loader_version}"
modApi "org.quiltmc.quilted-fabric-api:quilted-fabric-api:${rootProject.quilt_fabric_api_version}"
// Remove the next line if you don't want to depend on the API
//modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"

modRuntimeOnly "mezz.jei:jei-${jei_minecraft_version}-fabric:${jei_version}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
}

processResources {
inputs.property "version", project.version

filesMatching("quilt.mod.json") {
expand "group": rootProject.maven_group,
"version": project.version
}
}

shadowJar {
exclude "architectury.common.json"

configurations = [project.configurations.shadowCommon]
archiveClassifier = "dev-shadow"
}

remapJar {
injectAccessWidener = true
input.set shadowJar.archiveFile
dependsOn shadowJar
}

sourcesJar {
def commonSources = project(":common").sourcesJar
dependsOn commonSources
from commonSources.archiveFile.map { zipTree(it) }
}

components.java {
withVariantsFromConfiguration(project.configurations.shadowRuntimeElements) {
skip()
}
}

publishing {
publications {
mavenFabric(MavenPublication) {
artifactId = rootProject.archives_base_name + "-" + project.name
from components.java
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
}
1 change: 1 addition & 0 deletions quilt/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loom.platform=quilt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package pl.panszelescik.colorize.quilt;

import net.fabricmc.fabric.api.event.player.UseBlockCallback;
import net.minecraft.world.InteractionResult;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.loader.api.QuiltLoader;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import pl.panszelescik.colorize.common.api.config.BasicConfig;

import java.io.IOException;

public class ColorizeQuilt implements ModInitializer {

@Override
public void onInitialize(ModContainer mod) {
BasicConfig config;
try {
config = new BasicConfig(QuiltLoader.getConfigDir().toFile());
} catch (IOException e) {
throw new RuntimeException(e);
}

var handler = new ColorizeQuiltHandler(config);

UseBlockCallback.EVENT.register((player, level, hand, hitResult)
-> handler.handle(player, level, hand, hitResult.getBlockPos()) ? InteractionResult.SUCCESS : InteractionResult.PASS);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package pl.panszelescik.colorize.quilt;

import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.NotNull;
import pl.panszelescik.colorize.common.api.ColorizeConfig;
import pl.panszelescik.colorize.common.api.ColorizeEventHandler;
import pl.panszelescik.colorize.common.api.Colors;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;

public class ColorizeQuiltHandler extends ColorizeEventHandler {

private final Object2ObjectMap<Colors, ObjectImmutableList<TagKey<Item>>> tags;

public ColorizeQuiltHandler(@NotNull ColorizeConfig config) {
super(config);
var map = new Object2ObjectOpenHashMap<Colors, ObjectImmutableList<TagKey<Item>>>();

for (Colors c : Colors.values()) {
var dyeColor = c.getDyeColor();
if (dyeColor == null) {
continue;
}

var list = ObjectImmutableList.of(
TagKey.create(Registries.ITEM, new ResourceLocation("c", dyeColor.getName() + "_dye")),
TagKey.create(Registries.ITEM, new ResourceLocation("c", dyeColor.getName() + "_dyes")),
TagKey.create(Registries.ITEM, new ResourceLocation("c", "dye_" + dyeColor.getName()))
);

map.put(c, list);
}

this.tags = Object2ObjectMaps.unmodifiable(map);
}

@Override
protected @NotNull Optional<Colors> getDyeColor(@NotNull ItemStack stack) {
var optional = super.getDyeColor(stack);
if (optional.isPresent()) {
return optional;
}

return this.tags
.object2ObjectEntrySet()
.stream()
.filter(e -> e
.getValue()
.stream()
.anyMatch(stack::is))
.findFirst()
.map(Map.Entry::getKey);
}

public @NotNull Ingredient getColorIngredient(@NotNull Colors color) {
return Ingredient.of(this.tags
.object2ObjectEntrySet()
.stream()
.filter(e -> e.getKey() == color)
.findFirst()
.stream()
.flatMap(t -> t.getValue().stream())
.map(Ingredient::of)
.flatMap(i -> Arrays.stream(i.getItems())));
}
}
44 changes: 44 additions & 0 deletions quilt/src/main/resources/quilt.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"schema_version": 1,
"quilt_loader": {
"group": "${group}",
"id": "colorize",
"version": "${version}",
"metadata": {
"name": "Colorize",
"description": "A short description of your mod.",
"contributors": {
"PanSzelescik": "Owner"
},
"contact": {
"website": "https://www.curseforge.com/minecraft/mc-mods/colorize",
"repo": "https://github.com/PanSzelescik/colorize",
"issues": "https://github.com/PanSzelescik/colorize/issues",
"homepage": "https://www.curseforge.com/minecraft/mc-mods/colorize",
"sources": "https://github.com/PanSzelescik/colorize"
}
},
"intermediate_mappings": "net.fabricmc:intermediary",
"entrypoints": {
"init": [
"pl.panszelescik.colorize.quilt.ColorizeQuilt"
],
"jei_mod_plugin": [
"pl.panszelescik.colorize.common.recipes.jei.ColorizeJEIPlugin"
]
},
"depends": [
{
"id": "quilted_fabric_api",
"versions": "*"
},
{
"id": "minecraft",
"versions": ">=1.19.3"
}
]
},
"minecraft": {
"environment": "*"
}
}
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pluginManagement {
maven { url "https://maven.architectury.dev/" }
maven { url "https://maven.minecraftforge.net/" }
maven { url "https://maven.neoforged.net/releases/" }
maven { url "https://maven.quiltmc.org/repository/release/" }
gradlePluginPortal()
}
}
Expand All @@ -12,5 +13,6 @@ include("common")
include("fabric")
include("forge")
include("neoforged")
include("quilt")

rootProject.name = "colorize"

0 comments on commit 7b74d6f

Please sign in to comment.