Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.function.Consumer;
Expand All @@ -26,6 +28,10 @@
* Utilities used to implement {@link HydraulicFabricBootstrap}.
*/
public class FabricUtil {
private static final List<String> USER_BLOCKED_MODS = Arrays.stream(
System.getProperty("hydraulic.ignored_mods", "").split(",")
).toList();

public static final int ICON_SIZE = 256;

/**
Expand Down Expand Up @@ -102,8 +108,25 @@ public static void resolveJiJ(Collection<Path> roots, Consumer<ModInfo> output)

@Nullable
private static ModInfo createModInfo(JsonObject metadata, Collection<Path> roots, int schemaVersion) {
// Fabric Loom generation checks, if generated, is not actually a mod, but a library
final JsonElement custom = metadata.get("custom");
if (custom instanceof JsonObject object && new JsonPrimitive(true).equals(object.get("fabric-loom:generated"))) {
if (custom instanceof JsonObject object) {
if (
new JsonPrimitive(true).equals(object.get("fabric-loom:generated")) ||
new JsonPrimitive(true).equals(object.get("hydraulic:ignore"))
) {
return null;
} else if (object.get("modmenu") instanceof JsonObject modMenuData) {
final JsonElement badges = modMenuData.get("badges");
if (badges instanceof JsonArray badgeArray && badgeArray.contains(new JsonPrimitive("library"))) {
return null;
}
}
}

// Server sided mod check, ignore polymer content and other lib mods
final JsonElement environment = metadata.get("environment");
if (environment instanceof JsonPrimitive primitive && primitive.getAsString().equals("server")) {
return null;
}

Expand All @@ -113,6 +136,8 @@ private static ModInfo createModInfo(JsonObject metadata, Collection<Path> roots
return null;
}

if (USER_BLOCKED_MODS.contains(id.getAsString())) return null;

JsonElement name = metadata.get("name");
if (name != null && !(name instanceof JsonPrimitive)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
Expand All @@ -23,6 +24,10 @@
import java.util.stream.Collectors;

public class HydraulicNeoForgeBootstrap implements HydraulicBootstrap {
private static final List<String> USER_BLOCKED_MODS = Arrays.stream(
System.getProperty("hydraulic.ignored_mods", "").split(",")
).toList();

private final Supplier<Map<String, ModInfo>> modsList = Suppliers.memoize(() ->
ModList.get()
.getMods()
Expand All @@ -38,6 +43,7 @@ public class HydraulicNeoForgeBootstrap implements HydraulicBootstrap {
List.of(modPath)
);
})
.filter(modInfo -> !USER_BLOCKED_MODS.contains(modInfo.id()))
.collect(Collectors.toUnmodifiableMap(ModInfo::id, Function.identity()))
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void initialize() {
});

for (ModInfo mod : mods) {
if (IGNORED_MODS.contains(mod.id())) {
if (shouldIgnoreMod(mod)) {
continue;
}

Expand Down Expand Up @@ -202,7 +202,7 @@ boolean createPack(@NotNull ModInfo mod, @NotNull Path packPath) {

private void callEvents(@NotNull Event event) {
for (ModInfo mod : this.hydraulic.mods()) {
if (IGNORED_MODS.contains(mod.id())) {
if (shouldIgnoreMod(mod)) {
continue;
}

Expand Down Expand Up @@ -313,6 +313,10 @@ private static ModelStitcher.Provider createModelProvider(
};
}

private static boolean shouldIgnoreMod(ModInfo mod) {
return IGNORED_MODS.contains(mod.id());
}

public ListMultimap<String, ModInfo> getNamespacesToMods() {
return namespacesToMods;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,41 @@
import org.geysermc.hydraulic.pack.PackModule;
import org.geysermc.hydraulic.pack.context.PackPostProcessContext;
import org.geysermc.hydraulic.util.GeoUtil;
import org.geysermc.pack.converter.type.texture.TextureMappings;
import org.geysermc.pack.converter.util.JsonMappings;
import org.jetbrains.annotations.NotNull;

import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;

@AutoService(PackModule.class)
public class HydraulicPackModule extends PackModule<HydraulicPackModule> {
public HydraulicPackModule() {
this.postProcess(context -> {
// Map all block textures files as valid names
for (Map.Entry<String, Object> entry : ((Map<String, Object>) TextureMappings.textureMappings().textures("block")).entrySet()) {
if (entry.getValue() instanceof String str) {
context.bedrockResourcePack().addBlockTexture(Constants.MOD_ID + ":" + str, "textures/blocks/" + str);
} else if (entry.getValue() instanceof List<?> list) {
for (String str : (List<String>) list) {
context.bedrockResourcePack().addBlockTexture(Constants.MOD_ID + ":" + str, "textures/blocks/" + str);
}
Map<String, List<String>> mappings;

JsonMappings jsonMappings = JsonMappings.getMapping("textures");
if (jsonMappings != null) {
try {
Field mappingsField = JsonMappings.class.getDeclaredField("mappings");
mappingsField.setAccessible(true);

mappings = (Map<String, List<String>>) mappingsField.get(jsonMappings);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
}
} else {
mappings = Map.of();
}

// Map all item textures files as valid names
for (Map.Entry<String, Object> entry : ((Map<String, Object>) TextureMappings.textureMappings().textures("item")).entrySet()) {
if (entry.getValue() instanceof String str) {
context.bedrockResourcePack().addItemTexture(Constants.MOD_ID + ":" + str, "textures/items/" + str);
} else if (entry.getValue() instanceof List<?> list) {
for (String str : (List<String>) list) {
// Map all block and item textures files as valid names
for (Map.Entry<String, List<String>> entry : mappings.entrySet()) {
if (entry.getKey().startsWith("block")) {
for (String str : entry.getValue()) {
context.bedrockResourcePack().addBlockTexture(Constants.MOD_ID + ":" + str, "textures/blocks/" + str);
}
} else if (entry.getKey().startsWith("item")) {
for (String str : entry.getValue()) {
context.bedrockResourcePack().addItemTexture(Constants.MOD_ID + ":" + str, "textures/items/" + str);
}
}
Expand Down
26 changes: 10 additions & 16 deletions shared/src/main/java/org/geysermc/hydraulic/util/PackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.mojang.logging.LogUtils;
import net.kyori.adventure.key.Key;
import org.geysermc.hydraulic.Constants;
import org.geysermc.pack.converter.type.texture.TextureMappings;
import org.geysermc.pack.converter.util.JsonMappings;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;

Expand All @@ -15,8 +15,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Stream;

Expand All @@ -33,25 +31,21 @@ public static String getTextureName(@NotNull String modelName) {
if (modelName.startsWith(Key.MINECRAFT_NAMESPACE)) {
String modelValue = modelName.split(":")[1];

String type = modelValue.substring(0, modelValue.indexOf("/"));
String value = modelValue.substring(modelValue.indexOf("/") + 1);

// Need to use the Bedrock value for vanilla textures
Map<String, Object> textures = (Map<String, Object>) TextureMappings.textureMappings().textures(type);
if (textures != null) {
Object textureValue = textures.getOrDefault(value, "");
JsonMappings mappings = JsonMappings.getMapping("textures");
if (mappings != null) {
String output = mappings.map(modelValue).getFirst();

String textureName = textureValue instanceof List<?> ? ((List<String>) textureValue).getFirst() : (String) textureValue;
String value = output.substring(output.indexOf("/") + 1);

if (textureName.isEmpty()) {
textureName = value;
} else {
textureName = Constants.MOD_ID + ":" + textureName;
if (modelValue.equals(output)) {
return value;
}
return textureName;

return Constants.MOD_ID + ":" + value;
}

return value;
return modelValue.substring(modelValue.indexOf("/") + 1);
}

return modelName.replace("block/", "").replace("item/", "");
Expand Down
Loading