Skip to content

Commit

Permalink
mc1.21-v1.0.4 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dueris committed Jun 19, 2024
2 parents b830fdf + a25285b commit ae7b929
Show file tree
Hide file tree
Showing 100 changed files with 937 additions and 232 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: softprops/action-gh-release@v1
with:
name: Latest v1.0.2 dev
tag_name: mc1.20/6-v1.0.2
tag_name: mc1.21/0-v1.0.4
body: \"changes\"=${{ github.event.head_commit.message }}
token: ${{ secrets.GIT_TOKEN }}
files: build/libs/*.jar
Expand Down
337 changes: 222 additions & 115 deletions API-DOCS.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
id("io.github.goooler.shadow") version "8.1.7" apply true
}

val paperweightVersion: String = "1.20.6-R0.1-SNAPSHOT"
val paperweightVersion: String = "1.21-R0.1-SNAPSHOT"

allprojects {
apply(plugin = "java")
Expand Down Expand Up @@ -70,13 +70,13 @@ tasks {
}
}
runServer {
minecraftVersion("1.20.6")
minecraftVersion("1.21")
}
}

tasks.register<Jar>("makePublisher") {
dependsOn(tasks.shadowJar)
archiveFileName.set("genesis-v1.0.2-SNAPSHOT.jar")
archiveFileName.set("genesis-v1.0.4-SNAPSHOT.jar")
from(sourceSets.main.get().output)
}

Expand Down Expand Up @@ -105,7 +105,7 @@ publishing {
artifact(tasks.getByName("makePublisher")) {
groupId = "io.github.dueris"
artifactId = "genesis"
version = "v1.0.2-SNAPSHOT"
version = "v1.0.4-SNAPSHOT"
}
}
repositories {
Expand Down
34 changes: 23 additions & 11 deletions calio/src/main/java/me/dueris/calio/CraftCalio.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package me.dueris.calio;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.mojang.datafixers.util.Pair;
import me.dueris.calio.data.*;
import me.dueris.calio.data.AssetIdentifier.AssetType;
Expand Down Expand Up @@ -38,14 +40,13 @@ public static NamespacedKey bukkitIdentifier(String namespace, String path) {
}

public static ResourceLocation nmsIdentifier(String namespace, String path) {
return new ResourceLocation(namespace, path);
return ResourceLocation.fromNamespaceAndPath(namespace, path);
}

/**
* Add a datapack path to the list of directories to parse.
*
* @param path the path to be added
* @return void
*/
public void addDatapackPath(Path path) {
datapackDirectoriesToParse.add(path.toFile());
Expand All @@ -54,8 +55,7 @@ public void addDatapackPath(Path path) {
/**
* A method to start parsing with a provided debug mode and ExecutorService.
*
* @param debug a boolean indicating whether debugging is enabled
* @param threadPool an ExecutorService for managing threads
* @param debug a boolean indicating whether debugging is enabled
*/
public void start(boolean debug) {
this.isDebugging = debug;
Expand Down Expand Up @@ -116,13 +116,13 @@ public void start(boolean debug) {
});
});
this.keys.stream().sorted(Comparator.comparingInt(AccessorKey::getPriority)).forEach(accessorKey -> datapackDirectoriesToParse.forEach(root -> {
packLoop:
for (File datapack : root.listFiles()) {
try {
FileReader fileReader = FileReaderFactory.createFileReader(datapack.toPath());
if (fileReader == null) continue;
List<String> files = fileReader.listFiles();
HashMap<Pair<JsonObject, NamespacedKey>, Integer> newLoadingPrioritySortedMap = new HashMap<>();
fileLoop:
for (String file : files) {
file = file.replace("/", "\\");
if ((file.startsWith("data\\")) && file.endsWith(".json")) {
Expand All @@ -140,12 +140,16 @@ public void start(boolean debug) {
line.append(newLine);
}
String finishedLine = line.toString().replace("\n", "");
if (isCorrupted(finishedLine)) {
getLogger().severe("The json file with ResourceLocation of \"{}\" is corrupted! Please contact the pack author.".replace("{}", namespace + ":" + key));
continue fileLoop;
}
JsonObject powerParser;
try {
powerParser = JsonParser.parseReader(new StringReader(finishedLine)).getAsJsonObject();
} catch (Throwable throwable) {
getLogger().severe("An unhandled exception occurred when parsing a json file! Invalid syntax? The datapack will not be loaded.");
continue packLoop;
getLogger().severe("An unhandled exception occurred when parsing a json file \"{}\"! Invalid syntax? The datapack will not be loaded.".replace("{}", namespace + ":" + key));
continue fileLoop;
}
NamespacedKey namespacedKey = new NamespacedKey(namespace, key);
JsonObject remappedJsonObject = JsonObjectRemapper.remapJsonObject(powerParser, namespacedKey);
Expand All @@ -170,6 +174,18 @@ public void start(boolean debug) {
}));
}

private boolean isCorrupted(String finishedLine) {
try {
JsonElement jsonElement = JsonParser.parseString(finishedLine);
if (!jsonElement.isJsonObject()) {
return true;
}
} catch (JsonSyntaxException e) {
return true;
}
return false;
}

/**
* Logs a debug message if debugging is enabled.
*
Expand Down Expand Up @@ -230,10 +246,6 @@ public <T extends Registrable> void registerAccessor(String directory, int prior
keys.add(new AccessorKey<T>(directory, priority, useTypeDefiner, registryKey, typeOf, null));
}

public <T extends Registrable> void registerAccessor(String directory, int priority, boolean useTypeDefiner, RegistryKey<T> registryKey) {
keys.add(new AccessorKey<T>(directory, priority, useTypeDefiner, registryKey, null, null));
}

public <T extends Registrable> void registerAsset(String directory, int priority, String fileType, AssetType assetType, RegistryKey<T> registryKey) {
assetKeys.add(new AssetIdentifier<>(directory, priority, fileType, assetType, registryKey));
}
Expand Down
9 changes: 5 additions & 4 deletions calio/src/main/java/me/dueris/calio/data/AssetIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import me.dueris.calio.registry.Registrable;
import me.dueris.calio.registry.RegistryKey;

public record AssetIdentifier<T extends Registrable>(String directory, int priority, String fileType, AssetType assetType, RegistryKey<T> registryKey) {
public record AssetIdentifier<T extends Registrable>(String directory, int priority, String fileType,
AssetType assetType, RegistryKey<T> registryKey) {

public static enum AssetType {
IMAGE, JSON;
}
public enum AssetType {
IMAGE, JSON
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* Implementation of a TriPair object
*/
public class FactoryDataDefiner<T> {
private String key;
private Class<T> type;
private final String key;
private final Class<T> type;
private Object defaultVal;

public FactoryDataDefiner(String objName, Class<T> type, T defaultVal) {
Expand All @@ -28,7 +28,7 @@ public FactoryDataDefiner(String objName, Class<T> type, OptionalInstance defaul
}

public Class<T> getType() {
return (Class<T>) this.type;
return this.type;
}

public String getObjName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package me.dueris.calio.util.holders;

public record QuadPair<A, B, C, D>(A a, B b, C c, D d) { }
public record QuadPair<A, B, C, D>(A a, B b, C c, D d) {
}
8 changes: 4 additions & 4 deletions origins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "me.dueris"
version = "mc1.20-v1.0.2"
version = "mc1.21-v1.0.4"
description = "Bringing the Origins Mod to PaperMC"

dependencies {
Expand Down Expand Up @@ -45,7 +45,7 @@ tasks {
"name" to project.name,
"version" to project.version,
"description" to project.description,
"apiVersion" to "1.20"
"apiVersion" to "1.21"
)
inputs.properties(props)
filesMatching("paper-plugin.yml") {
Expand All @@ -56,7 +56,7 @@ tasks {

tasks.register<Jar>("makePublisher") {
dependsOn(tasks.shadowJar)
archiveFileName.set("genesis-v1.0.2-SNAPSHOT.jar")
archiveFileName.set("genesis-v1.0.4-SNAPSHOT.jar")
from(sourceSets.main.get().output)
}

Expand All @@ -65,7 +65,7 @@ publishing {
artifact(tasks.getByName("makePublisher")) {
groupId = "io.github.dueris"
artifactId = "genesis"
version = "v1.0.2-SNAPSHOT"
version = "v1.0.4-SNAPSHOT"
}
}
repositories {
Expand Down
84 changes: 36 additions & 48 deletions origins/src/main/java/me/dueris/genesismc/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,10 @@
import io.papermc.paper.plugin.bootstrap.PluginBootstrap;
import it.unimi.dsi.fastutil.Pair;
import me.dueris.calio.data.JsonObjectRemapper;
import me.dueris.calio.registry.Registrar;
import me.dueris.calio.registry.impl.CalioRegistry;
import me.dueris.genesismc.factory.actions.types.BiEntityActions;
import me.dueris.genesismc.factory.actions.types.BlockActions;
import me.dueris.genesismc.factory.actions.types.EntityActions;
import me.dueris.genesismc.factory.actions.types.ItemActions;
import me.dueris.genesismc.factory.conditions.types.*;
import me.dueris.genesismc.factory.powers.holder.PowerType;
import me.dueris.genesismc.content.NMSBootstrap;
import me.dueris.genesismc.registry.Registries;
import me.dueris.genesismc.registry.nms.OriginLootCondition;
import me.dueris.genesismc.registry.nms.PowerLootCondition;
import me.dueris.genesismc.registry.registries.DatapackRepository;
import me.dueris.genesismc.registry.registries.Layer;
import me.dueris.genesismc.registry.registries.Origin;
import me.dueris.genesismc.screen.ChoosingPage;
import me.dueris.genesismc.util.LangFile;
import me.dueris.genesismc.util.TextureLocation;
import me.dueris.genesismc.util.Util;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import me.dueris.genesismc.util.WrappedBootstrapContext;
import org.apache.commons.io.FilenameUtils;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
Expand All @@ -39,13 +22,14 @@
import java.util.Comparator;
import java.util.Optional;
import java.util.Properties;
import java.util.function.Consumer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

// TODO: MachineMaker PluginDatapacks
// TODO: WaterProtection Enchantment - 1.21
public class Bootstrap implements PluginBootstrap {
public static ArrayList<String> oldDV = new ArrayList<>();
public static ArrayList<Consumer<WrappedBootstrapContext>> apiCalls = new ArrayList<>();

static {
oldDV.add("OriginsGenesis");
Expand All @@ -56,8 +40,6 @@ public class Bootstrap implements PluginBootstrap {
oldDV.add("Origins-GenesisMC[0_2_6]");
}

private CalioRegistry registry;

public static void deleteDirectory(Path directory, boolean ignoreErrors) throws IOException {
if (Files.exists(directory)) {
Files.walk(directory)
Expand All @@ -75,7 +57,7 @@ public static void deleteDirectory(Path directory, boolean ignoreErrors) throws
}
}

public static void copyOriginDatapack(Path datapackPath) {
public static void copyOriginDatapack(Path datapackPath, WrappedBootstrapContext context) {
for (String string : oldDV) {
if (Files.exists(datapackPath)) {
String path = Path.of(datapackPath + File.separator + string).toAbsolutePath().toString();
Expand All @@ -87,7 +69,7 @@ public static void copyOriginDatapack(Path datapackPath) {
} else {
File file = new File(datapackPath.toAbsolutePath().toString());
file.mkdirs();
copyOriginDatapack(datapackPath);
copyOriginDatapack(datapackPath, context);
}
}
try {
Expand Down Expand Up @@ -154,15 +136,20 @@ public static String levelNameProp() {
}

@Override
public void bootstrap(@NotNull BootstrapContext context) {
public void bootstrap(@NotNull BootstrapContext bootContext) {
WrappedBootstrapContext context = new WrappedBootstrapContext(bootContext);
NMSBootstrap.bootstrap(context);
for (Consumer<WrappedBootstrapContext> apiCall : apiCalls) {
apiCall.accept(context);
}
File packDir = new File(this.parseDatapackPath());
try {
File packDir = new File(this.parseDatapackPath());
copyOriginDatapack(packDir.toPath());
copyOriginDatapack(packDir.toPath(), context);
} catch (Exception e) {
// ignore
} finally {
context.initRegistries(packDir.toPath());
}
Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, new ResourceLocation("apoli", "power"), PowerLootCondition.TYPE);
Registry.register(BuiltInRegistries.LOOT_CONDITION_TYPE, new ResourceLocation("origins", "origin"), OriginLootCondition.TYPE);

JsonObjectRemapper.typeMappings.add(new Pair<String, String>() {
@Override
Expand All @@ -185,26 +172,27 @@ public String right() {
JsonObjectRemapper.typeAlias.put("apoli:in_set", "apoli:in_entity_set");
JsonObjectRemapper.typeAlias.put("apoli:set_size", "apoli:entity_set_size");

this.registry = CalioRegistry.INSTANCE;
// Create new registry instances
this.registry.create(Registries.ORIGIN, new Registrar<Origin>(Origin.class));
this.registry.create(Registries.LAYER, new Registrar<Layer>(Layer.class));
this.registry.create(Registries.CRAFT_POWER, new Registrar<PowerType>(PowerType.class));
this.registry.create(Registries.FLUID_CONDITION, new Registrar<FluidConditions.ConditionFactory>(FluidConditions.ConditionFactory.class));
this.registry.create(Registries.ENTITY_CONDITION, new Registrar<EntityConditions.ConditionFactory>(EntityConditions.ConditionFactory.class));
this.registry.create(Registries.BIOME_CONDITION, new Registrar<BiomeConditions.ConditionFactory>(BiomeConditions.ConditionFactory.class));
this.registry.create(Registries.BIENTITY_CONDITION, new Registrar<BiEntityConditions.ConditionFactory>(BiEntityConditions.ConditionFactory.class));
this.registry.create(Registries.BLOCK_CONDITION, new Registrar<BlockConditions.ConditionFactory>(BlockConditions.ConditionFactory.class));
this.registry.create(Registries.ITEM_CONDITION, new Registrar<ItemConditions.ConditionFactory>(ItemConditions.ConditionFactory.class));
this.registry.create(Registries.DAMAGE_CONDITION, new Registrar<DamageConditions.ConditionFactory>(DamageConditions.ConditionFactory.class));
this.registry.create(Registries.ENTITY_ACTION, new Registrar<EntityActions.ActionFactory>(EntityActions.ActionFactory.class));
this.registry.create(Registries.ITEM_ACTION, new Registrar<ItemActions.ActionFactory>(ItemActions.ActionFactory.class));
this.registry.create(Registries.BLOCK_ACTION, new Registrar<BlockActions.ActionFactory>(BlockActions.ActionFactory.class));
this.registry.create(Registries.BIENTITY_ACTION, new Registrar<BiEntityActions.ActionFactory>(BiEntityActions.ActionFactory.class));
this.registry.create(Registries.TEXTURE_LOCATION, new Registrar<TextureLocation>(TextureLocation.class));
this.registry.create(Registries.LANG, new Registrar<LangFile>(LangFile.class));
this.registry.create(Registries.PACK_SOURCE, new Registrar<DatapackRepository>(DatapackRepository.class));
this.registry.create(Registries.CHOOSING_PAGE, new Registrar<ChoosingPage>(ChoosingPage.class));
context.createRegistries(
Registries.ORIGIN,
Registries.LAYER,
Registries.CRAFT_POWER,
Registries.FLUID_CONDITION,
Registries.ENTITY_CONDITION,
Registries.BIOME_CONDITION,
Registries.BIENTITY_CONDITION,
Registries.BLOCK_CONDITION,
Registries.ITEM_CONDITION,
Registries.DAMAGE_CONDITION,
Registries.ENTITY_ACTION,
Registries.ITEM_ACTION,
Registries.BLOCK_ACTION,
Registries.BIENTITY_ACTION,
Registries.TEXTURE_LOCATION,
Registries.LANG,
Registries.PACK_SOURCE,
Registries.CHOOSING_PAGE
);
}

public String parseDatapackPath() {
Expand Down
5 changes: 2 additions & 3 deletions origins/src/main/java/me/dueris/genesismc/GenesisMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ public final class GenesisMC extends JavaPlugin implements Listener {
public static OriginScheduler.MainTickerThread scheduler = null;
public static String version = Bukkit.getVersion().split("\\(MC: ")[1].replace(")", "");
public static boolean isCompatible = false;
public static String pluginVersion = "v1.0.2";
public static String pluginVersion = "v1.0.4";
public static String world_container;
public static ExecutorService loaderThreadPool;
public static ArrayList<String> versions = new ArrayList<>();
public static MinecraftServer server;
private static GenesisMC plugin;

static {
versions.add("1.20.5");
versions.add("1.20.6");
versions.add("1.21");
}

public IRegistry registry;
Expand Down
Loading

0 comments on commit ae7b929

Please sign in to comment.