Add support for data packs. Closes #6

This commit is contained in:
JFronny 2021-08-24 13:57:42 +02:00
parent 27fcbcd13e
commit ef55ccb9b2
No known key found for this signature in database
GPG Key ID: BEC5ACBBD4EE17E5
13 changed files with 84 additions and 15 deletions

5
.gitignore vendored
View File

@ -117,6 +117,11 @@ gradle-app.setting
!/run/resourcepacks
/run/resourcepacks/*
!/run/resourcepacks/lumi
!/run/saves
/run/saves/*
!/run/saves/New World
/run/saves/New World/*
!/run/saves/New World/datapacks
/test/
logs/

View File

@ -1,7 +1,7 @@
apply from: "https://gitlab.com/-/snippets/2121059/raw/master/jfbase.gradle"
repositories {
maven { url = "https://raw.githubusercontent.com/TerraformersMC/Archive/main/releases/"; name = "ModMenu" }
maven { url = "https://maven.terraformersmc.com/releases/"; name = "ModMenu" }
maven { url = "https://maven.shedaniel.me/"; name = "Cloth Config" }
maven { url = "https://maven.dblsaiko.net/"; name = "Canvas" }
maven { url = 'https://server.bbkr.space/artifactory/libs-release'; name = "Required for canvas" }
@ -15,11 +15,11 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:0.36.1+1.17"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.38.2+1.17"
modImplementation "com.terraformersmc:modmenu:2.0.2"
modImplementation "com.terraformersmc:modmenu:2.0.5"
modApi("me.shedaniel.cloth:cloth-config-fabric:5.0.34")
modApi("me.shedaniel.cloth:cloth-config-fabric:5.0.38")
modCompileOnly "grondag:frex-mc117:+"
/*TODO re-enable after canvas works on 1.17.1

View File

@ -1,9 +1,9 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
# check these on https://fabricmc.net/versions.html
minecraft_version=1.17.1
yarn_mappings=build.1
yarn_mappings=build.43
loader_version=0.11.6
# Mod Properties
mod_version=2.3.0

View File

@ -0,0 +1,20 @@
execute unless entity @a[tag=coords_run] run gamerule commandBlockOutput false
execute unless entity @a[tag=coords_run] run scoreboard objectives add x_coord dummy
execute unless entity @a[tag=coords_run] run scoreboard objectives add y_coord dummy
execute unless entity @a[tag=coords_run] run scoreboard objectives add z_coord dummy
execute unless entity @a[tag=coords_run] run scoreboard objectives add day_num dummy
tag @a[tag=!coords_run] add coords_run
execute as @a store result score @s x_coord run data get entity @s Pos[0]
execute as @a store result score @s y_coord run data get entity @s Pos[1]
execute as @a store result score @s z_coord run data get entity @s Pos[2]
execute as @a store result score @s day_num run time query day
title @a[y_rotation=23..67] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(-)","color":"white"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(+)","color":"white"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"SW","color":"gold"}]
title @a[y_rotation=68..112] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(-)","color":"white"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(=)","color":"gray"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"W ","color":"gold"}]
title @a[y_rotation=113..157] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(-)","color":"white"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(-)","color":"white"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"NW","color":"gold"}]
title @a[y_rotation=158..202] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(=)","color":"gray"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(-)","color":"white"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"N ","color":"gold"}]
title @a[y_rotation=203..247] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(+)","color":"white"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(-)","color":"white"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"NE","color":"gold"}]
title @a[y_rotation=248..292] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(+)","color":"white"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(=)","color":"gray"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"E ","color":"gold"}]
title @a[y_rotation=293..337] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(+)","color":"white"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(+)","color":"white"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"SE","color":"gold"}]
title @a[y_rotation=338..22] actionbar ["",{"text":"x","color":"gold"},{"text":":","color":"gold"},{"text":"(=)","color":"gray"},{"score":{"name":"*","objective":"x_coord"},"color":"aqua"},{"text":" "},{"text":"y","color":"gold"},{"text":":","color":"gold"},{"score":{"name":"*","objective":"y_coord"},"color":"aqua"},{"text":" "},{"text":"z","color":"gold"},{"text":":","color":"gold"},{"text":"(+)","color":"white"},{"score":{"name":"*","objective":"z_coord"},"color":"aqua"},{"text":" "},{"text":"dy ","color":"gold"},{"score":{"name":"*","objective":"day_num"},"color":"white"},{"text":" "},{"text":"S ","color":"gold"}]

View File

@ -0,0 +1,3 @@
{
"values": ["batty:main"]
}

View File

@ -0,0 +1,3 @@
{
"values": ["batty:main"]
}

View File

@ -0,0 +1,5 @@
{
"conditions": [
"battysCoords:india"
]
}

View File

@ -0,0 +1,7 @@
{
"id": "battysCoords",
"version": 3,
"conf": {
"india": false
}
}

View File

@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 7,
"description": "BattyCoords"
}
}

View File

@ -0,0 +1,7 @@
package io.gitlab.jfronny.respackopts.data;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
public record MetadataLocateResult(ResourcePack pack, boolean hasMeta, ResourceType type) {
}

View File

@ -8,6 +8,7 @@ import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.FatalErrorScreen;
import net.minecraft.server.integrated.IntegratedServer;
import net.minecraft.text.TranslatableText;
import java.util.concurrent.atomic.AtomicBoolean;
@ -25,6 +26,11 @@ public class ModMenuCompat implements ModMenuApi {
builder.setSavingRunnable(() -> {
Respackopts.save();
MinecraftClient.getInstance().reloadResources();
IntegratedServer is = MinecraftClient.getInstance().getServer();
if (is != null) {
is.getDataPackManager().scanPacks();
is.reloadResources(is.getDataPackManager().getEnabledNames());
}
});
AtomicBoolean categoryAdded = new AtomicBoolean(false);
Respackopts.CONFIG_BRANCH.forEach((id, conf) -> {

View File

@ -45,7 +45,7 @@ public abstract class ResourcePackEntryMixin {
k = Respackopts.NAME_LOOKUP.get(k);
info.setReturnValue(true);
MinecraftClient c = MinecraftClient.getInstance();
c.openScreen(Respackopts.factory.buildGui(Respackopts.CONFIG_BRANCH.get(k), k, c.currentScreen, () -> Respackopts.forceRespackReload = true));
c.setScreen(Respackopts.factory.buildGui(Respackopts.CONFIG_BRANCH.get(k), k, c.currentScreen, () -> Respackopts.forceRespackReload = true));
}
}
}

View File

@ -1,11 +1,12 @@
package io.gitlab.jfronny.respackopts.mixin;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import io.gitlab.jfronny.respackopts.Respackopts;
import io.gitlab.jfronny.respackopts.data.MetadataLocateResult;
import io.gitlab.jfronny.respackopts.data.Respackmeta;
import io.gitlab.jfronny.respackopts.data.entry.SyncMode;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackProfile;
import net.minecraft.resource.ResourceType;
@ -28,9 +29,10 @@ public class ResourcePackManagerMixin {
private void scanPacks(CallbackInfo info) {
Respackopts.NAME_LOOKUP.clear();
profiles.forEach((s, v) -> {
if (rpo$hasMetadata(v)) {
MetadataLocateResult scan = rpo$locateMetadata(v);
if (scan.hasMeta()) {
try {
Respackmeta conf = Respackopts.GSON.fromJson(rpo$readMetadata(v, Respackopts.GSON), Respackmeta.class);
Respackmeta conf = Respackopts.GSON.fromJson(rpo$readMetadata(scan), Respackmeta.class);
if (Respackopts.META_VERSION < conf.version) {
Respackopts.LOGGER.error(s + " was not loaded as it specifies a newer respackopts version than is installed");
return;
@ -52,18 +54,23 @@ public class ResourcePackManagerMixin {
});
}
private boolean rpo$hasMetadata(ResourcePackProfile v) {
return v.createResourcePack().contains(ResourceType.CLIENT_RESOURCES, Respackopts.CONF_ID);
private MetadataLocateResult rpo$locateMetadata(ResourcePackProfile v) {
ResourcePack pack = v.createResourcePack();
for (ResourceType type : ResourceType.values()) {
if (pack.contains(type, Respackopts.CONF_ID))
return new MetadataLocateResult(pack, true, type);
}
return new MetadataLocateResult(pack, false, null);
}
private JsonObject rpo$readMetadata(ResourcePackProfile v, Gson g) throws IOException {
InputStream is = v.createResourcePack().open(ResourceType.CLIENT_RESOURCES, Respackopts.CONF_ID);
private JsonObject rpo$readMetadata(MetadataLocateResult pack) throws IOException {
InputStream is = pack.pack().open(pack.type(), Respackopts.CONF_ID);
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) != -1) {
os.write(buffer, 0, length);
}
return g.fromJson(os.toString(), JsonElement.class).getAsJsonObject();
return Respackopts.GSON.fromJson(os.toString(), JsonElement.class).getAsJsonObject();
}
}