Skip to content

Commit 6ca7f56

Browse files
Merge remote-tracking branch 'origin/1.18.2-forge' into 1.19.4-forge
2 parents 1c2c5b6 + b19a9af commit 6ca7f56

13 files changed

Lines changed: 607 additions & 206 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ In the past UMC has been packaged directly with ImmersiveRailroading as it is wa
2424
| [1.19.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.19.4-fabric) | ![Universal Mod Core 1.19.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.19.4-fabric) |
2525
| [1.20.1-forge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.1-forge) | ![Universal Mod Core 1.20.1-forge](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.1-forge) |
2626
| [1.20.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.1-fabric) | ![Universal Mod Core 1.20.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.1-fabric) |
27-
| [1.20.4-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-neoforge) | ![Universal Mod Core 1.20.4-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.4-neoforge) |
28-
| [1.20.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-fabric) | ![Universal Mod Core 1.20.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.20.4-fabric) |
27+
| [1.20.4-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-neoforge) | EOL |
28+
| [1.20.4-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.20.4-fabric) | EOL |
2929
| [1.21.1-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.21.1-neoforge) | ![Universal Mod Core 1.21.1-neoforge](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.21.1-neoforge) |
3030
| [1.21.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/tree/1.21.1-fabric) | ![Universal Mod Core 1.21.1-fabric](https://github.com/TeamOpenIndustry/UniversalModCore/actions/workflows/build.yml/badge.svg?branch=1.21.1-fabric) |
3131

src/main/java/cam72cam/mod/ModCore.java

Lines changed: 47 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@
2323
import net.minecraft.server.packs.repository.Pack;
2424
import net.minecraft.server.packs.repository.PackSource;
2525
import net.minecraft.server.packs.resources.ReloadableResourceManager;
26-
import net.minecraft.server.packs.resources.Resource;
2726

2827
import java.util.*;
2928

3029
import net.minecraft.resources.*;
31-
import net.minecraftforge.fml.ModList;
3230
import org.apache.logging.log4j.LogManager;
3331
import org.apache.logging.log4j.Logger;
3432

@@ -40,13 +38,13 @@
4038
import cam72cam.mod.net.Packet;
4139
import cam72cam.mod.net.PacketDirection;
4240
import cam72cam.mod.render.Light;
41+
import cam72cam.mod.resource.BuiltinPack;
4342
import cam72cam.mod.resource.Identifier;
4443
import cam72cam.mod.text.Command;
4544
import cam72cam.mod.util.MinecraftFiles;
4645
import cam72cam.mod.util.ModCoreCommand;
4746
import cam72cam.mod.world.ChunkManager;
4847
import net.minecraft.client.Minecraft;
49-
import net.minecraft.resources.ResourceLocation;
5048
import net.minecraft.server.packs.*;
5149
import net.minecraft.util.Unit;
5250
import net.minecraftforge.common.MinecraftForge;
@@ -63,7 +61,6 @@
6361
import org.apache.commons.lang3.StringUtils;
6462
import org.apache.commons.lang3.SystemUtils;
6563

66-
import javax.annotation.Nullable;
6764
import java.io.File;
6865
import java.io.IOException;
6966
import java.util.stream.Collectors;
@@ -198,6 +195,10 @@ public static void catching(Throwable ex) {
198195
}
199196
}
200197

198+
public List<Mod> getLoadedMods() {
199+
return mods;
200+
}
201+
201202
private static Proxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> ServerProxy::new);
202203
/** Hooked into forge's proxy system and fires off corresponding events */
203204
public static class Proxy {
@@ -241,184 +242,61 @@ public void setup() {
241242
}
242243
Config.getMaxTextureSize(); //populate
243244

244-
// Force first and last (and inject mod time) BUG: sounds can still be overridden by resource packs
245-
Minecraft.getInstance().getResourcePackRepository().addPackFinder(consumer -> {
246-
List<PackResources> packs = new ArrayList<>();
247-
packs.add(new TranslationResourcePack());
248-
249-
for (Mod m : mods) {
250-
PackResources modPack = createPack(ModList.get().getModFileById(m.modID()).getFile().getFilePath().toFile());
251-
packs.add(modPack);
252-
String configDir = FMLPaths.CONFIGDIR.get().toString();
253-
new File(configDir).mkdirs();
254-
255-
File folder = new File(configDir + File.separator + m.modID());
256-
if (folder.exists()) {
257-
if (folder.isDirectory()) {
258-
File[] files = folder.listFiles((dir, name) -> name.endsWith(".zip"));
259-
for (File file : files) {
260-
packs.add(createPack(file));
261-
}
245+
BuiltinPack.loadClientResources();
262246

263-
File[] folders = folder.listFiles((dir, name) -> dir.isDirectory());
264-
for (File dir : folders) {
265-
packs.add(createPack(dir));
266-
}
267-
}
268-
} else {
269-
folder.mkdirs();
270-
}
271-
packs.add(modPack);
247+
//Wrapper for lang format language files
248+
BuiltinPack.conditional(ident -> {
249+
String path = ident.getPath();
250+
if (!path.startsWith("lang/") || !path.endsWith(".json")) {
251+
return null;
272252
}
273253

274-
275-
for (PackResources pack : packs) {
276-
consumer.accept(Pack.create(pack.packId(),
277-
Component.literal(""),
278-
true,
279-
s -> pack,
280-
new Pack.Info(Component.literal(""), 13, FeatureFlagSet.of()),
281-
PackType.SERVER_DATA,
282-
Pack.Position.TOP,
283-
true,
284-
PackSource.DEFAULT
285-
));
254+
Identifier lang = new Identifier(ident.toString().replace(".json", ".lang"));
255+
if (!lang.canLoad()) {
256+
return null;
286257
}
287-
});
288-
}
289258

290-
@Override
291-
public void event(ModEvent event, Mod m) {
292-
super.event(event, m);
293-
m.clientEvent(event);
294-
}
295-
296-
private static class TranslationResourcePack extends AbstractPackResources {
297-
public TranslationResourcePack() {
298-
super("translation Hackery", false);
299-
}
300-
301-
@org.jetbrains.annotations.Nullable
302-
@Override
303-
public IoSupplier<InputStream> getRootResource(String... p_252049_) {
304-
return null;
305-
}
259+
Map<String, String> translationMap = new HashMap<>();
260+
try {
261+
for (InputStream stream : lang.getResourceStreamAll()) {
262+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
263+
String line;
264+
while ((line = reader.readLine()) != null) {
265+
//Remove comment
266+
line = line.trim();
267+
if (line.isEmpty() || line.startsWith("#")) {
268+
continue;
269+
}
306270

307-
@org.jetbrains.annotations.Nullable
308-
@Override
309-
public IoSupplier<InputStream> getResource(PackType type, ResourceLocation resourcePath) {
310-
if (resourcePath.getPath().contains("lang/") && resourcePath.getPath().endsWith(".json")) {
311-
// Magical Translations!
312-
ResourceLocation lang = ResourceLocation.fromNamespaceAndPath(resourcePath.getNamespace(), resourcePath.getPath().replace("json", "lang"));
313-
List<Resource> langFiles = Minecraft.getInstance().getResourceManager().getResourceStack(lang);
314-
if (!langFiles.isEmpty()) {
315-
Map<String, String> translationMap = new HashMap<>();
316-
for (Resource resource : langFiles) {
317-
try (BufferedReader reader = resource.openAsReader()) {
318-
String line;
319-
while ((line = reader.readLine()) != null) {
320-
//Remove comment
321-
line = line.trim();
322-
int comment = line.indexOf("#");
323-
if (line.isEmpty() || comment == 0) {
324-
continue;
325-
}
326-
327-
String[] splits = line.split("=", 2);
328-
if (splits.length == 2) {
329-
translationMap.put(splits[0].trim(), splits[1].trim());
330-
}
271+
String[] splits = line.split("=", 2);
272+
if (splits.length == 2) {
273+
translationMap.put(splits[0].trim(), splits[1].trim());
331274
}
332-
} catch (IOException e) {
333-
throw new RuntimeException(e);
334275
}
335276
}
336-
337-
Set<String> translations = new HashSet<>();
338-
translationMap.forEach((key, value) -> {
339-
if (!key.isEmpty()) {
340-
translations.add(String.format("\"%s\": \"%s\"", key, value));
341-
translations.add(String.format("\"%s\": \"%s\"", key.replace(":", "."), value));
342-
translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", ""), value));
343-
translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", "").replace(":", "."), value));
344-
}
345-
});
346-
String output = "{" + String.join(",", translations) + "}";
347-
return () -> new ByteArrayInputStream(output.getBytes(StandardCharsets.UTF_8));
348277
}
278+
} catch (IOException e) {
279+
throw new RuntimeException(e);
349280
}
350-
return null;
351-
}
352-
353-
@Override
354-
public void listResources(PackType p_10289_, String p_251379_, String p_251932_, ResourceOutput p_249347_) {
355-
356-
}
357-
358-
@Override
359-
public Set<String> getNamespaces(PackType p_195759_1_) {
360-
return mods.stream().map(Mod::modID).collect(Collectors.toSet());
361-
}
362281

363-
@Override
364-
public void close() {
365-
366-
}
367-
368-
@Nullable
369-
@Override
370-
public <T> T getMetadataSection(MetadataSectionSerializer<T> p_195760_1_) throws IOException {
371-
return getMetadataFromStream(p_195760_1_, new ByteArrayInputStream("{}".getBytes()));
372-
}
373-
}
374-
375-
private static class UMCFolderPack extends PathPackResources {
376-
private final Path root;
377-
378-
public UMCFolderPack(File folder) {
379-
super(folder.getName(), folder.toPath(), false);
380-
this.root = folder.toPath();
381-
}
382-
383-
@Override
384-
public IoSupplier<InputStream> getResource(PackType p_249352_, ResourceLocation p_251715_) {
385-
Path path = this.root.resolve(p_249352_.getDirectory()).resolve(p_251715_.getNamespace());
386-
return getResource(p_251715_, path);
387-
}
388-
389-
public static IoSupplier<InputStream> getResource(ResourceLocation p_250145_, Path p_251046_) {
390-
return FileUtil.decomposePath(p_250145_.getPath()).get().map((p_251647_) -> {
391-
Path path = FileUtil.resolvePath(p_251046_, p_251647_);
392-
return Files.exists(path) ? new Identifier.IoInputStreamMod(() -> Files.newInputStream(path), path.toFile().lastModified()) : null;
393-
}, (p_248714_) -> {
394-
LogUtils.getLogger().error("Invalid path {}: {}", p_250145_, p_248714_.message());
395-
return null;
282+
Set<String> translations = new HashSet<>();
283+
translationMap.forEach((key, value) -> {
284+
if (!key.isEmpty()) {
285+
translations.add(String.format("\"%s\": \"%s\"", key, value));
286+
translations.add(String.format("\"%s\": \"%s\"", key.replace(":", "."), value));
287+
translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", ""), value));
288+
translations.add(String.format("\"%s\": \"%s\"", key.replace(".name", "").replace(":", "."), value));
289+
}
396290
});
397-
}
398-
}
399-
400-
private static class UMCFilePack extends FilePackResources {
401-
private final File path;
402-
403-
public UMCFilePack(File fileIn) {
404-
super(fileIn.getName(), fileIn, false);
405-
this.path = fileIn;
406-
}
407-
408-
@Override
409-
public IoSupplier<InputStream> getResource(PackType p_249605_, ResourceLocation p_252147_) {
410-
IoSupplier<InputStream> found = super.getResource(p_249605_, p_252147_);
411-
return found != null ? new Identifier.IoInputStreamMod(found, path.lastModified()) : null;
412-
}
291+
String output = "{" + String.join(",", translations) + "}";
292+
return output.getBytes(StandardCharsets.UTF_8);
293+
});
413294
}
414295

415-
416-
private static PackResources createPack(File path) {
417-
if (path.isDirectory()) {
418-
return new UMCFolderPack(path);
419-
} else {
420-
return new UMCFilePack(path);
421-
}
296+
@Override
297+
public void event(ModEvent event, Mod m) {
298+
super.event(event, m);
299+
m.clientEvent(event);
422300
}
423301
}
424302

@@ -473,8 +351,9 @@ public void clientEvent(ModEvent event) {
473351
// Instance can be null during data gen
474352
if (Minecraft.getInstance() != null) {
475353
((ReloadableResourceManager) Minecraft.getInstance().getResourceManager()).registerReloadListener((stage, resourceManager, preparationsProfiler, reloadProfiler, backgroundExecutor, gameExecutor) ->
476-
stage.wait(Unit.INSTANCE).thenRun(ClientEvents::fireReload));
354+
stage.wait(Unit.INSTANCE).thenRun(ClientEvents::fireReload).thenRun(BuiltinPack::reload));
477355
}
356+
break;
478357
case SETUP:
479358
try {
480359
Minecraft.getInstance().createSearchTrees();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cam72cam.mod.event.platform;
2+
3+
import net.minecraft.network.chat.TextComponent;
4+
import net.minecraft.server.packs.PackResources;
5+
import net.minecraft.server.packs.repository.Pack;
6+
import net.minecraft.server.packs.repository.PackCompatibility;
7+
import net.minecraft.server.packs.repository.PackRepository;
8+
import net.minecraft.server.packs.repository.PackSource;
9+
import net.minecraftforge.eventbus.api.Event;
10+
import net.minecraftforge.fml.event.IModBusEvent;
11+
12+
/**
13+
* Fired when datapacks are reloaded, useful when injecting your dynamic datapack implementations.
14+
*/
15+
public class LoadDatapackEvent extends Event implements IModBusEvent {
16+
private final PackRepository infos;
17+
18+
public LoadDatapackEvent(PackRepository infos) {
19+
this.infos = infos;
20+
}
21+
22+
public void addDataPack(PackResources pack) {
23+
infos.addPackFinder((consumer, p_230230_2_) -> {
24+
consumer.accept(new Pack(pack.getName(),
25+
true,
26+
() -> pack,
27+
new TextComponent(""),
28+
new TextComponent(""),
29+
PackCompatibility.COMPATIBLE,
30+
Pack.Position.TOP,
31+
true,
32+
PackSource.DEFAULT,
33+
true));
34+
});
35+
}
36+
}

src/main/java/cam72cam/mod/gui/helpers/GUIHelpers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void drawFluid(Fluid fluid, int x, int y, int width, int height) {
7373
private static void drawSprite(TextureAtlasSprite sprite, int col, int x, int y, int width, int height) {
7474
double zLevel = 0;
7575

76-
float[] oldColor = RenderSystem.getShaderColor();
76+
float[] oldColor = Arrays.copyOf(RenderSystem.getShaderColor(), 4);
7777
ShaderInstance oldShader = RenderSystem.getShader();
7878
RenderSystem.setShader(GameRenderer::getPositionTexShader);
7979
RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_BLOCKS);

0 commit comments

Comments
 (0)