Implemented content based syncing

This commit is contained in:
Frank 2021-08-15 13:55:31 +02:00
parent f80b55aa50
commit 5df6de1e3a
7 changed files with 194 additions and 49 deletions

View file

@ -24,7 +24,8 @@ import java.io.OutputStreamWriter;
import java.io.Reader;
public class JsonFactory {
public final static Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public final static Gson GSON = new GsonBuilder().setPrettyPrinting()
.create();
public static JsonObject getJsonObject(InputStream stream) {
try {
@ -61,7 +62,8 @@ public class JsonFactory {
@Nullable
@Environment(EnvType.CLIENT)
public static JsonObject getJsonObject(ResourceLocation location) {
ResourceManager manager = Minecraft.getInstance().getResourceManager();
ResourceManager manager = Minecraft.getInstance()
.getResourceManager();
JsonObject obj = null;
try {
Resource resource = manager.getResource(location);
@ -108,6 +110,13 @@ public class JsonFactory {
public static void storeJson(OutputStream outStream, JsonElement jsonObject) {
OutputStreamWriter writer = new OutputStreamWriter(outStream);
GSON.toJson(jsonObject, writer);
try {
writer.flush();
}
catch (IOException e) {
BCLib.LOGGER.error(e.getMessage());
e.printStackTrace();
}
}
public static int getInt(JsonObject object, String member, int def) {

View file

@ -1,11 +1,31 @@
package ru.bclib.util;
public class Pair <A, B>{
public final A first;
public final B second;
import java.util.Objects;
public Pair(A first, B second) {
this.first = first;
this.second = second;
}
public class Pair<A, B> {
public final A first;
public final B second;
public Pair(A first, B second) {
this.first = first;
this.second = second;
}
@Override
public String toString() {
return "Pair{" + "first=" + first + ", second=" + second + '}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Pair)) return false;
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(first, pair.first) && Objects.equals(second, pair.second);
}
@Override
public int hashCode() {
return Objects.hash(first, second);
}
}

View file

@ -1,10 +1,31 @@
package ru.bclib.util;
public class Triple <A, B, C> extends Pair<A, B>{
public final C third;
import java.util.Objects;
public Triple(A first, B second, C third) {
super(first, second);
this.third = third;
}
public class Triple<A, B, C> extends Pair<A, B> {
public final C third;
public Triple(A first, B second, C third) {
super(first, second);
this.third = third;
}
@Override
public String toString() {
return "Triple{" + "first=" + first + ", second=" + second + ", third=" + third + '}';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Triple)) return false;
if (!super.equals(o)) return false;
Triple<?, ?, ?> triple = (Triple<?, ?, ?>) o;
return Objects.equals(third, triple.third);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), third);
}
}