Skip to content

Commit 24396f1

Browse files
committed
Merge branch '0.8-dev'
2 parents 971dafa + d19d310 commit 24396f1

File tree

17 files changed

+542
-90
lines changed

17 files changed

+542
-90
lines changed

README.MD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ A library mod for 1.7.10 with lots of useful stuff. See the table below for more
77
| [dependencies](src/main/java/com/falsepattern/lib/dependencies) | Runtime dependency loader which uses Maven |
88
| [mixin](src/main/java/com/falsepattern/lib/mixin) | Mixin loader plugin boilerplate code |
99
| [text](src/main/java/com/falsepattern/lib/text) | Better Chat and GUI text processing |
10+
| [updates](src/main/java/com/falsepattern/lib/updates) | Helper code for update checking |
1011
| [util](src/main/java/com/falsepattern/lib/util) | Additional utilities that do not fit the above categories, see below for more information |
1112

1213
The contents of the [util](src/main/java/com/falsepattern/lib/util) package so far:
1314

1415
| Class | Purpose |
1516
|---------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|
1617
| [ResourceUtil](src/main/java/com/falsepattern/lib/util/ResourceUtil.java) | Provides methods for efficiently retrieving resources from SPECIFIC jar files instead of the entire classpath |
18+
| [Async](src/main/java/com/falsepattern/lib/util/Async.java) | Provides asynchronous execution utilities. |
1719

1820

1921
Anything annotated with [@StableAPI](src/main/java/com/falsepattern/lib/StableAPI.java) is guaranteed to not change in patch versions.
2022

23+
The update checker module and the library checker module can be toggled with the `ENABLE_UPDATE_CHECKER` and
24+
`ENABLE_LIBRARY_DOWNLOADS` booleans in the `falsepatternlib.cfg` config file respectively. Note that the update checker
25+
depends on the module downloader to grab [FJson](https://github.com/FalsePattern/FJson), so if it's not already present
26+
on disk, disabling the library loader breaks the update checker. This is only required the first time though.
27+
2128
### This project WILL NOT be ported to any version beyond 1.7.10, don't even ask
2229

2330
[![POOP badge](https://raw.githubusercontent.com/gist/poop-person/991e80f390384bbeef09d208bff208f4/raw/a9ef83add84a70f2202896c2d81117ff7b169be1/poop-badge.svg)](https://gist.github.com/poop-person/991e80f390384bbeef09d208bff208f4)

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//version: 1641429628falsepattern16
1+
//version: 1641429628falsepattern18
22
/*
33
DO NOT CHANGE THIS FILE!
44
@@ -95,6 +95,7 @@ checkPropertyExists("repositoryName")
9595
checkPropertyExists("mavenGroupId")
9696
checkPropertyExists("mavenArtifactId")
9797
checkPropertyExists("hasMixinDeps")
98+
checkPropertyExists("mixinPreinitConfig")
9899

99100

100101
String javaSourceDir = "src/main/java/"
@@ -441,7 +442,7 @@ def getManifestAttributes() {
441442
if(usesMixins.toBoolean()) {
442443
manifestAttributes += [
443444
"TweakClass" : "org.spongepowered.asm.launch.MixinTweaker",
444-
"MixinConfigs" : "mixins." + modId + ".json",
445+
"MixinConfigs" : "mixins." + modId + ".json" + (mixinPreinitConfig ? "," + mixinPreinitConfig : ""),
445446
"ForceLoadAsMod" : containsMixinsAndOrCoreModOnly.toBoolean() == false
446447
]
447448
}

dependencies.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ dependencies {
55
compileOnly("org.spongepowered:mixin:0.7.11-SNAPSHOT") {
66
transitive = false
77
}
8+
compileOnly("com.falsepattern:json:0.4.1")
89
annotationProcessor("org.projectlombok:lombok:1.18.22")
910
}

gradle.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ hasMixinDeps = false
6868
mixinPlugin =
6969
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
7070
mixinsPackage =
71+
# Specify a preinit mixin here. Preinit mixins should be used very rarely, if at all, so this mixin config will not be managed by the buildscript, only included.
72+
mixinPreinitConfig =
7173
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
7274
# This parameter is for legacy compatability only
7375
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
7476
coreModClass = internal.CoreLoadingPlugin
7577
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
7678
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
77-
containsMixinsAndOrCoreModOnly = true
79+
containsMixinsAndOrCoreModOnly = false
7880

7981
# If enabled, you may use 'shadowImplementation' for dependencies. They will be integrated in your jar. It is your
8082
# responsibility check the licence and request permission for distribution, if required.

repositories.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@ repositories {
33
name = "sponge"
44
url = "https://sponge.falsepattern.com/"
55
}
6+
maven {
7+
name = "mavenpattern"
8+
url = "https://maven.falsepattern.com/"
9+
}
610
}

src/main/java/com/falsepattern/lib/dependencies/DependencyLoader.java

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.falsepattern.lib.dependencies;
22

33
import com.falsepattern.lib.StableAPI;
4-
import com.falsepattern.lib.internal.CoreLoadingPlugin;
5-
import com.falsepattern.lib.internal.FalsePatternLib;
4+
import com.falsepattern.lib.internal.*;
5+
66
import java.io.BufferedOutputStream;
77
import java.io.File;
8-
import java.io.FileOutputStream;
98
import java.io.IOException;
109
import java.io.InputStream;
1110
import java.net.URL;
@@ -14,11 +13,8 @@
1413
import java.util.HashSet;
1514
import java.util.Map;
1615
import java.util.Set;
17-
import javax.net.ssl.HttpsURLConnection;
18-
import lombok.Builder;
19-
import lombok.NonNull;
20-
import lombok.val;
21-
import lombok.var;
16+
17+
import lombok.*;
2218
import net.minecraft.launchwrapper.LaunchClassLoader;
2319

2420

@@ -34,21 +30,18 @@ public static void addMavenRepo(String url) {
3430
}
3531

3632
@Builder
37-
public static void loadLibrary(String loadingModId,
38-
String groupId,
39-
String artifactId,
33+
public static void loadLibrary(@NonNull String loadingModId,
34+
@NonNull String groupId,
35+
@NonNull String artifactId,
4036
@NonNull Version minVersion,
4137
Version maxVersion,
4238
@NonNull Version preferredVersion,
4339
String regularSuffix,
4440
String devSuffix) {
4541
val suffix = FalsePatternLib.isDeveloperEnvironment() ? devSuffix : regularSuffix;
42+
val artifactLogName = String.format("%s:%s:%s%s", groupId, artifactId, preferredVersion, suffix != null ? "-" + suffix : "");
4643
FalsePatternLib.getLog()
47-
.info("Adding library {}:{}:{}{}, requested by mod {}",
48-
groupId,
49-
artifactId,
50-
preferredVersion,
51-
suffix != null ? "-" + suffix : "",
44+
.info("Adding library {}, requested by mod {}", artifactLogName,
5245
loadingModId);
5346
var artifact = groupId + ":" + artifactId + ":" + suffix;
5447
if (loadedLibraries.containsKey(artifact)) {
@@ -108,25 +101,25 @@ public static void loadLibrary(String loadingModId,
108101
addToClasspath(file);
109102
loadedLibraries.put(artifact, preferredVersion);
110103
FalsePatternLib.getLog()
111-
.info("Library {}:{}:{}{} successfully loaded from disk!",
112-
groupId,
113-
artifactId,
114-
preferredVersion,
115-
(suffix != null) ? ":" + suffix : "");
104+
.info("Library {} successfully loaded from disk!", artifactLogName);
116105
return;
117106
} catch (RuntimeException e) {
118107
FalsePatternLib.getLog()
119-
.warn("Failed to load library {}:{}:{}{} from file! Redownloading...",
120-
groupId,
121-
artifactId,
122-
preferredVersion,
123-
(suffix != null) ? ":" + suffix : "");
108+
.warn("Failed to load library {} from file! Redownloading...", artifactLogName);
124109
if (!file.delete()) {
125110
FalsePatternLib.getLog().fatal("Failed to delete file {}", file);
126111
throw new RuntimeException("Failed to delete file " + file);
127112
}
128113
}
129114
}
115+
if (!LibraryConfig.ENABLE_LIBRARY_DOWNLOADS) {
116+
val errorMessage = "Failed to load library " + groupId + ":" + artifactId + ":" + preferredVersion +
117+
((suffix != null) ? ":" + suffix : "") + ": " + Tags.MODNAME +
118+
" library downloading has been disabled in the config, and the library is not present " +
119+
"on disk! Requested by mod: " + loadingModId;
120+
FalsePatternLib.getLog().fatal(errorMessage);
121+
throw new IllegalStateException(errorMessage);
122+
}
130123
for (var repo : mavenRepositories) {
131124
try {
132125
if (!repo.endsWith("/")) {
@@ -138,39 +131,24 @@ public static void loadLibrary(String loadingModId,
138131
artifactId,
139132
preferredVersion,
140133
mavenJarName));
141-
142-
val connection = (HttpsURLConnection) url.openConnection();
143-
connection.setConnectTimeout(1500);
144-
connection.setReadTimeout(1500);
145-
connection.setRequestProperty("User-Agent", "FalsePatternLib Downloader");
146-
if (connection.getResponseCode() != 200) {
134+
String finalRepo = repo;
135+
Internet.connect(url, (ex) -> {
147136
FalsePatternLib.getLog()
148-
.info("Artifact {}:{}:{}{} was not found on repo {}",
149-
groupId,
150-
artifactId,
151-
preferredVersion,
152-
(suffix != null) ? ":" + suffix : "",
153-
repo);
154-
connection.disconnect();
155-
continue;
156-
}
157-
FalsePatternLib.getLog()
158-
.info("Downloading {}:{}:{}{} from {}",
159-
groupId,
160-
artifactId,
161-
preferredVersion,
162-
(suffix != null) ? ":" + suffix : "",
163-
repo);
164-
download(connection.getInputStream(), file);
165-
FalsePatternLib.getLog()
166-
.info("Downloaded {}:{}:{}{}",
167-
groupId,
168-
artifactId,
169-
preferredVersion,
170-
(suffix != null) ? ":" + suffix : "");
171-
loadedLibraries.put(artifact, preferredVersion);
172-
loadedLibraryMods.put(artifact, loadingModId);
173-
addToClasspath(file);
137+
.info("Artifact {} could not be downloaded from repo {}: {}",
138+
artifactLogName,
139+
finalRepo,
140+
ex.getMessage());
141+
}, (input) -> {
142+
FalsePatternLib.getLog()
143+
.info("Downloading {} from {}",
144+
artifactLogName,
145+
finalRepo);
146+
download(input, file);
147+
FalsePatternLib.getLog().info("Downloaded {}", artifactLogName);
148+
loadedLibraries.put(artifact, preferredVersion);
149+
loadedLibraryMods.put(artifact, loadingModId);
150+
addToClasspath(file);
151+
});
174152
return;
175153
} catch (IOException ignored) {
176154
}
@@ -192,19 +170,11 @@ private static void addToClasspath(File file) {
192170
}
193171
}
194172

195-
private static void download(InputStream is, File target) throws IOException {
173+
@SneakyThrows
174+
private static void download(InputStream is, File target) {
196175
if (target.exists()) {
197176
return;
198177
}
199-
200-
var bytesRead = 0;
201-
202-
val fileOutput = new BufferedOutputStream(Files.newOutputStream(target.toPath()));
203-
byte[] smallBuffer = new byte[4096];
204-
while ((bytesRead = is.read(smallBuffer)) >= 0) {
205-
fileOutput.write(smallBuffer, 0, bytesRead);
206-
}
207-
fileOutput.close();
208-
is.close();
178+
Internet.transferAndClose(is, new BufferedOutputStream(Files.newOutputStream(target.toPath())));
209179
}
210180
}

src/main/java/com/falsepattern/lib/internal/CoreLoadingPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public String[] getASMTransformerClass() {
2020

2121
@Override
2222
public String getModContainerClass() {
23-
return Tags.GROUPNAME + ".internal.FalsePatternLib";
23+
return null;
2424
}
2525

2626
@Override
Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,77 @@
11
package com.falsepattern.lib.internal;
22

3+
import com.falsepattern.lib.config.ConfigException;
34
import com.falsepattern.lib.config.ConfigurationManager;
4-
import com.falsepattern.lib.util.ResourceUtil;
5-
import com.google.common.eventbus.EventBus;
6-
import com.google.common.eventbus.Subscribe;
7-
import cpw.mods.fml.common.DummyModContainer;
8-
import cpw.mods.fml.common.LoadController;
9-
import cpw.mods.fml.common.MetadataCollection;
5+
import com.falsepattern.lib.internal.proxy.CommonProxy;
6+
import com.falsepattern.lib.text.FormattedText;
7+
import com.falsepattern.lib.updates.ModUpdateInfo;
8+
import com.falsepattern.lib.updates.UpdateChecker;
9+
import cpw.mods.fml.common.*;
1010
import cpw.mods.fml.common.event.FMLConstructionEvent;
11+
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
12+
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
13+
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
14+
import cpw.mods.fml.relauncher.Side;
15+
import cpw.mods.fml.relauncher.SideOnly;
1116
import lombok.Getter;
17+
import lombok.val;
18+
import net.minecraft.client.entity.EntityPlayerSP;
19+
import net.minecraft.client.resources.I18n;
20+
import net.minecraft.event.ClickEvent;
1221
import net.minecraft.launchwrapper.Launch;
22+
import net.minecraft.util.ChatComponentText;
23+
import net.minecraft.util.ChatStyle;
24+
import net.minecraft.util.EnumChatFormatting;
25+
import net.minecraft.util.IChatComponent;
26+
import net.minecraftforge.common.MinecraftForge;
27+
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
1328
import org.apache.logging.log4j.LogManager;
1429
import org.apache.logging.log4j.Logger;
1530

31+
import java.util.ArrayList;
32+
import java.util.List;
33+
import java.util.concurrent.ExecutionException;
34+
import java.util.concurrent.ExecutorService;
35+
import java.util.concurrent.Executors;
36+
import java.util.concurrent.Future;
37+
import java.util.concurrent.atomic.AtomicBoolean;
38+
1639
/**
1740
* Utility class used by FalsePatternLib's internal code. This can change between versions without notice, so do not use
1841
* this in your code!
1942
*/
20-
public class FalsePatternLib extends DummyModContainer {
43+
@SuppressWarnings("UnstableApiUsage")
44+
@Mod(modid = Tags.MODID,
45+
name = Tags.MODNAME,
46+
version = Tags.VERSION,
47+
acceptedMinecraftVersions = "[1.7.10]",
48+
acceptableRemoteVersions = "*")
49+
public class FalsePatternLib {
2150
@Getter private static final Logger log = LogManager.getLogger(Tags.MODNAME);
2251

2352
@Getter private static final boolean developerEnvironment =
2453
(boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
2554

55+
@SidedProxy(clientSide = Tags.GROUPNAME + ".internal.proxy.ClientProxy", serverSide = Tags.GROUPNAME + ".internal.proxy.CommonProxy")
56+
private static CommonProxy proxy;
57+
2658
public FalsePatternLib() {
27-
super(MetadataCollection.from(ResourceUtil.getResourceFromJar("/mcmod.info", FalsePatternLib.class), Tags.MODID)
28-
.getMetadataForId(Tags.MODID, null));
2959
log.info("Version " + Tags.VERSION + " initialized!");
3060
}
3161

32-
@SuppressWarnings("UnstableApiUsage")
33-
@Subscribe
62+
@Mod.EventHandler
3463
public void construct(FMLConstructionEvent e) {
35-
ConfigurationManager.init();
64+
proxy.construct(e);
3665
}
3766

38-
@SuppressWarnings("UnstableApiUsage")
39-
@Override
40-
public boolean registerBus(EventBus bus, LoadController controller) {
41-
bus.register(this);
42-
return true;
67+
@Mod.EventHandler
68+
public void preInit(FMLPreInitializationEvent e) {
69+
proxy.preInit(e);
4370
}
71+
72+
@Mod.EventHandler
73+
public void postInit(FMLPostInitializationEvent e) {
74+
proxy.postInit(e);
75+
}
76+
4477
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.falsepattern.lib.internal;
2+
3+
import lombok.val;
4+
import lombok.var;
5+
6+
import java.io.*;
7+
import java.net.HttpURLConnection;
8+
import java.net.URL;
9+
import java.util.function.Consumer;
10+
11+
public class Internet {
12+
public static void connect(URL URL, Consumer<Exception> onError, Consumer<InputStream> onSuccess) {
13+
try {
14+
val connection = (HttpURLConnection) URL.openConnection();
15+
connection.setConnectTimeout(3500);
16+
connection.setReadTimeout(5000);
17+
connection.setRequestProperty("User-Agent", "FalsePatternLib Internet Connector");
18+
if (connection.getResponseCode() != 200) {
19+
onError.accept(new Exception("HTTP response code " + connection.getResponseCode()));
20+
} else {
21+
onSuccess.accept(connection.getInputStream());
22+
}
23+
connection.disconnect();
24+
} catch (Exception e) {
25+
onError.accept(e);
26+
}
27+
}
28+
29+
30+
public static void transferAndClose(InputStream is, OutputStream target) throws IOException {
31+
var bytesRead = 0;
32+
33+
byte[] smallBuffer = new byte[4096];
34+
while ((bytesRead = is.read(smallBuffer)) >= 0) {
35+
target.write(smallBuffer, 0, bytesRead);
36+
}
37+
target.close();
38+
is.close();
39+
}
40+
}

0 commit comments

Comments
 (0)