Skip to content

Commit

Permalink
Version 1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Aug 30, 2024
1 parent 3f1bae9 commit bca1829
Show file tree
Hide file tree
Showing 808 changed files with 13,470 additions and 16,496 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
if: "!contains(github.event.head_commit.message, '--skip') && !contains(github.event.head_commit.commit.message, '--skip')"
uses: softprops/action-gh-release@v1
with:
name: Latest v1.2.1 dev
tag_name: mc1.21/0-v1.2.1
name: Latest v1.2.2 dev
tag_name: mc1.21/0-v1.2.2
body: \"changes\"=${{ github.event.head_commit.message }}
token: ${{ secrets.GIT_TOKEN }}
files: build/libs/*.jar
Expand Down
2 changes: 1 addition & 1 deletion API-DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
}

dependencies {
implementation("io.github.Dueris:OriginsPaper:mc1.21~0-v1.2.1")
implementation("io.github.Dueris:OriginsPaper:mc1.21~0-v1.2.2")
}
```

Expand Down
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val paperweightVersion: String = "1.21-R0.1-SNAPSHOT"

extra["mcMajorVer"] = "21"
extra["mcMinorVer"] = "1"
extra["pluginVer"] = "v1.2.1"
extra["pluginVer"] = "v1.2.2"

val mcMajorVer = extra["mcMajorVer"] as String
val mcMinorVer = extra["mcMinorVer"] as String
Expand Down Expand Up @@ -66,7 +66,8 @@ allprojects {
"pluginVer" to pluginVer,
"fullVer" to "mc$mcVer-$pluginVer",
"apiVer" to "1.$mcMajorVer",
"supportedVersions" to listOf("1.21", "1.21.1")
"supported" to listOf("1.21", "1.21.1"),
"apoli" to "2.12.0-alpha.10+mc.1.21.x"
)
inputs.properties(props)
filesMatching("paper-plugin.yml") {
Expand Down
18 changes: 4 additions & 14 deletions calio/src/main/java/io/github/dueris/calio/CalioParserBuilder.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
package io.github.dueris.calio;

import io.github.dueris.calio.data.AccessorKey;
import io.github.dueris.calio.parser.ParsingStrategy;
import io.github.dueris.calio.registry.RegistryKey;
import io.github.dueris.calio.test.ModMeta;
import io.github.dueris.calio.data.DataBuildDirective;
import it.unimi.dsi.fastutil.objects.AbstractObjectSet;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.minecraft.resources.ResourceLocation;

import java.util.List;

public class CalioParserBuilder {
protected static final AbstractObjectSet<AccessorKey<?>> accessorKeys = new ObjectOpenHashSet<>();
protected static final AbstractObjectSet<DataBuildDirective<?>> DATA_BUILD_DIRECTIVES = new ObjectOpenHashSet<>();
private final CraftCalio calio;

public CalioParserBuilder(CraftCalio calio) {
this.calio = calio;
accessorKeys.add(
new AccessorKey<>(List.of("calio"), "test", ModMeta.class, 0, ParsingStrategy.DEFAULT,
new RegistryKey<>(ModMeta.class, ResourceLocation.fromNamespaceAndPath("calio", "test")))
);
}

public CalioParserBuilder withAccessor(AccessorKey<?> key) {
accessorKeys.add(key);
public CalioParserBuilder withAccessor(DataBuildDirective<?> key) {
DATA_BUILD_DIRECTIVES.add(key);
return this;
}

Expand Down
143 changes: 44 additions & 99 deletions calio/src/main/java/io/github/dueris/calio/CraftCalio.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
package io.github.dueris.calio;

import io.github.dueris.calio.data.AccessorKey;
import io.github.dueris.calio.data.DataBuildDirective;
import io.github.dueris.calio.parser.CalioParser;
import io.github.dueris.calio.parser.reader.system.FileSystemReader;
import io.github.dueris.calio.util.Util;
import io.github.dueris.calio.util.thread.ParserFactory;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tags.TagKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Tuple;
import net.minecraft.world.level.storage.LevelResource;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executors;
import java.util.function.BiConsumer;

Expand All @@ -44,107 +33,63 @@ public record CraftCalio(boolean threaded, int threadCount) {
* Creates the calio parser instance and allows for providing
* arguments like {@code async} to make it run threaded parsing.
*/
@Contract("_ -> new")
public static @NotNull CraftCalio buildInstance(String[] args) {
OptionParser parser = new OptionParser();

parser.accepts("async").withOptionalArg().ofType(Boolean.class).defaultsTo(false);

OptionSet options = parser.parse(args);

boolean threaded = (Boolean) options.valueOf("async");
public static @NotNull CraftCalio buildInstance() {
int threadCount = 4;
if (threaded) {
CalioParser.threadedParser = Executors.newFixedThreadPool(threadCount, new ParserFactory(threadCount));
CalioParser.threaded = true;
}
return new CraftCalio(threaded, threadCount);
}

public static <T> boolean areTagsEqual(ResourceKey<? extends Registry<T>> registryKey, TagKey<T> tag1, TagKey<T> tag2) {
return areTagsEqual(tag1, tag2);
}

public static <T> boolean areTagsEqual(TagKey<T> tag1, TagKey<T> tag2) {
return tag1 == tag2
|| tag1 != null
&& tag2 != null
&& tag1.registry().equals(tag2.registry())
&& tag1.location().equals(tag2.location());
CalioParser.threadedParser = Executors.newFixedThreadPool(threadCount, new ParserFactory(threadCount));
CalioParser.threaded = true;
return new CraftCalio(true, threadCount);
}

/**
* Creates a new builder for calio parsing to add {@link AccessorKey}s
* Creates a new builder for calio parsing to add {@link DataBuildDirective}s
*/
@Contract(value = " -> new", pure = true)
public @NotNull CalioParserBuilder startBuilder() {
return new CalioParserBuilder(this);
}

/**
* Begins parsing instances defined by the {@link AccessorKey}s in the
* CalioParserBuilder in both the plugins directory(and sub-dirs), and the
* datapacks directory defined by the {@code server.properties} file.
* Parses the datapack path provided to build registries
* Example: {@code /world/datapacks/example/}
*
* @throws Throwable
* @param pathToParse The datapack path to parse
*/
public boolean parse() throws Throwable {
MinecraftServer server = MinecraftServer.getServer();
if (server == null) {
throw new IllegalAccessException("Server instance not created yet! Please wait until MinecraftServer is spun!");
} else {
Bukkit.getLogger().info("Starting CraftCalio parsing with mod implementation version '{}'".replace("{}", "1.14.0-alpha.5+mc.1.21.x"));
Path datapackDirPath = server.getWorldPath(LevelResource.DATAPACK_DIR);
if (!datapackDirPath.toFile().exists()) {
datapackDirPath.toFile().mkdirs();
@SuppressWarnings("unchecked")
public <T> boolean parse(@NotNull Path pathToParse) {
Object2ObjectLinkedOpenHashMap<DataBuildDirective<T>, List<Tuple<ResourceLocation, String>>> priorityParsingQueue = new Object2ObjectLinkedOpenHashMap<>();
CalioParserBuilder.DATA_BUILD_DIRECTIVES.forEach((key) -> {
priorityParsingQueue.put((DataBuildDirective<T>) key, new CopyOnWriteArrayList<>());
});
BiConsumer<String, String> jsonVerificationFilter = (path, jsonContents) -> {

for (DataBuildDirective<?> key : CalioParserBuilder.DATA_BUILD_DIRECTIVES) {
if (jsonContents != null && path != null && Util.pathMatchesAccessor(path, key)) {
priorityParsingQueue.get(key).add(new Tuple<>(Objects.requireNonNull(Util.buildResourceLocationFromPath(path, key)), jsonContents));
}
}

File datapackDirectory = datapackDirPath.toFile();
if (!datapackDirectory.isDirectory()) {
throw new IllegalStateException("'datapacks' directory is not a directory! Corrupted?");
} else {
for (Path pathToParse : new Path[]{Paths.get("plugins"), datapackDirPath}) {
Object2ObjectLinkedOpenHashMap<AccessorKey<?>, ConcurrentLinkedQueue<Tuple<String, String>>> priorityParsingQueue = new Object2ObjectLinkedOpenHashMap<>();
CalioParserBuilder.accessorKeys.forEach((key) -> {
priorityParsingQueue.put(key, new ConcurrentLinkedQueue<>());
});
if (pathToParse.toFile().listFiles() != null) {
BiConsumer<String, String> jsonVerificationFilter = (path, jsonContents) -> {

for (AccessorKey<?> key : CalioParserBuilder.accessorKeys) {
if (jsonContents != null && path != null && Util.pathMatchesAccessor(path, key)) {
priorityParsingQueue.get(key).add(new Tuple<>(path, jsonContents));
}
}

};
FileSystemReader.processDatapacks(pathToParse, jsonVerificationFilter);
}

List<Map.Entry<AccessorKey<?>, ConcurrentLinkedQueue<Tuple<String, String>>>> entries = new ArrayList<>(priorityParsingQueue.object2ObjectEntrySet());
entries.sort(Comparator.comparingInt((ent) -> {
return ent.getKey().priority();
}));
for (Map.Entry<AccessorKey<?>, ConcurrentLinkedQueue<Tuple<String, String>>> entry : entries) {
try {
CalioParser.fromJsonFile(entry).forEach((out) -> {
if (out.getA() == null || out.getB() == null) {
throw new RuntimeException("Output instance or output ResourceLocation was null!");
}
});
} catch (Throwable throwable) {
throwable.printStackTrace();
}
}

}
};
try {
FileSystemReader.processDatapacks(pathToParse, jsonVerificationFilter);
} catch (IOException e) {
throw new RuntimeException("Unable to process datapacks to parse", e);
}

if (CalioParser.threadedParser != null) {
CalioParser.threadedParser.shutdown();
}
return true;
for (Map.Entry<DataBuildDirective<T>, List<Tuple<ResourceLocation, String>>> entry : new LinkedList<>(priorityParsingQueue.object2ObjectEntrySet()).stream().sorted(Comparator.comparingInt((ent) -> ent.getKey().priority())).toList()) {
try {
CalioParser.parseFiles(entry);
} catch (Throwable throwable) {
log.info("An unexpected exception occurred when building instances of {}, {}", entry.getKey().builder().type().getSimpleName(), throwable);
throwable.printStackTrace();
}
}
return true;
}

public void shutdown() {
if (CalioParser.threadedParser != null) {
CalioParser.threadedParser.shutdown();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.codecs.PrimitiveCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.dueris.calio.data.SerializableData;
import io.github.dueris.calio.data.SerializableDataBuilder;
import io.github.dueris.calio.data.exceptions.DataException;
import io.github.dueris.calio.parser.SerializableData;
import io.github.dueris.calio.registry.RegistryKey;
import io.github.dueris.calio.registry.impl.CalioRegistry;
import io.github.dueris.calio.util.ArgumentWrapper;
Expand Down Expand Up @@ -268,7 +268,7 @@ public <T> T write(DynamicOps<T> ops, Number value) {
}
}
};
List<Ingredient.Value> entries = new ArrayList<>();
List<Ingredient.Value> entries = new LinkedList<>();
if (jsonElement.isJsonObject()) {
initValues.accept(jsonElement.getAsJsonObject(), entries);
} else if (jsonElement.isJsonArray()) {
Expand Down Expand Up @@ -376,7 +376,7 @@ public <T> T write(DynamicOps<T> ops, Number value) {
jo, FoodProperties.class
);

List<FoodProperties.PossibleEffect> effects = new ArrayList<>();
List<FoodProperties.PossibleEffect> effects = new LinkedList<>();

data.<FoodProperties.PossibleEffect>ifPresent("effect", effects::add);
data.<List<FoodProperties.PossibleEffect>>ifPresent("effects", effects::addAll);
Expand Down
11 changes: 0 additions & 11 deletions calio/src/main/java/io/github/dueris/calio/data/AccessorKey.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.dueris.calio.data;

import io.github.dueris.calio.parser.RootResult;
import io.github.dueris.calio.registry.RegistryKey;

import java.util.List;

public record DataBuildDirective<T>(List<String> modids, String folder, SerializableDataBuilder<RootResult<T>> builder,
int priority, RegistryKey<T> registryKey) {
}
Loading

0 comments on commit bca1829

Please sign in to comment.