Skip to content

Commit

Permalink
Use architectury to implement both fabric and forge
Browse files Browse the repository at this point in the history
  • Loading branch information
tyra314 committed Sep 11, 2022
1 parent 7dd8095 commit da59206
Show file tree
Hide file tree
Showing 669 changed files with 791 additions and 715 deletions.
122 changes: 39 additions & 83 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,101 +1,57 @@
plugins {
id 'fabric-loom' version '0.10-SNAPSHOT'
id 'maven-publish'
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

archivesBaseName = project.archives_base_name
version = project.mod_version + "-mc" + project.minecraft_version
group = project.maven_group

loom {
accessWidenerPath = file("src/main/resources/antiqueatlas.accesswidener")
architectury {
minecraft = rootProject.minecraft_version
}

repositories {
maven {
// for fabric
url = "https://maven.modmuss50.me/"
}
maven {
// for mod menu
url = uri("https://jitpack.io")
}
maven {
// for cloth-config
url = "https://maven.shedaniel.me/"
}
maven {
url = "https://maven.terraformersmc.com/releases"
}
}

dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
subprojects {
apply plugin: "dev.architectury.loom"

modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
loom {
silentMojangMappingsLicense()
}

modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") {
exclude(group: "net.fabricmc.fabric-api")
dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings "net.fabricmc:yarn:${rootProject.yarn_mappings}:v2"
}
}

processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") { // add mod metadata
expand "version": project.version
}
}
allprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "maven-publish"

// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
it.options.release = 16
}
archivesBaseName = rootProject.archives_base_name
version = rootProject.mod_version + "-" + project.name + "-mc" + rootProject.minecraft_version
group = rootProject.maven_group

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()
}

jar {
from("LICENSE") {
rename { "${it}_${project.archivesBaseName}"}
repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

maven {
// for cloth-config
url = "https://maven.shedaniel.me/"
}
maven {
// for mod menu
url = "https://maven.terraformersmc.com/releases"
}
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
// add all the jars that should be included when publishing to maven
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
java {
withSourcesJar()
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hunternif.mc.impl.atlas;

import dev.architectury.event.events.common.LifecycleEvent;
import hunternif.mc.impl.atlas.core.TileDataHandler;
import hunternif.mc.impl.atlas.core.scaning.TileDetectorBase;
import hunternif.mc.impl.atlas.core.AtlasIdData;
Expand All @@ -17,15 +18,13 @@
import hunternif.mc.impl.atlas.structure.*;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.world.World;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AntiqueAtlasMod implements ModInitializer {
public class AntiqueAtlasMod {
public static final String ID = "antiqueatlas";
public static final String NAME = "Antique Atlas";

Expand Down Expand Up @@ -53,8 +52,7 @@ public static AtlasIdData getAtlasIdData(World world) {
return ((ServerWorld) world).getPersistentStateManager().getOrCreate(AtlasIdData::fromNbt, AtlasIdData::new, "antiqueatlas:global_atlas_data");
}

@Override
public void onInitialize() {
public static void init() {
TileDetectorBase.scanBiomeTypes();

AutoConfig.register(AntiqueAtlasConfig.class, JanksonConfigSerializer::new);
Expand All @@ -72,8 +70,8 @@ public void onInitialize() {
NewPlayerConnectionCallback.EVENT.register(globalTileData::onPlayerLogin);
NewPlayerConnectionCallback.EVENT.register(PlayerEventHandler::onPlayerLogin);

ServerWorldEvents.LOAD.register(globalMarkersData::onWorldLoad);
ServerWorldEvents.LOAD.register(globalTileData::onWorldLoad);
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalMarkersData::onWorldLoad);
LifecycleEvent.SERVER_LEVEL_LOAD.register(globalTileData::onWorldLoad);

RecipeCraftedCallback.EVENT.register(new RecipeCraftedHandler());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import hunternif.mc.impl.atlas.client.gui.GuiAtlas;
import hunternif.mc.impl.atlas.network.AntiqueAtlasNetworking;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;

@Environment(EnvType.CLIENT)
public class AntiqueAtlasModClient implements ClientModInitializer {
public class AntiqueAtlasModClient {

private static GuiAtlas guiAtlas;

Expand Down Expand Up @@ -37,8 +36,7 @@ private static void openAtlasGUI(GuiAtlas gui) {
}
}

@Override
public void onInitializeClient() {
public static void init() {
ClientProxy clientProxy = new ClientProxy();
clientProxy.initClient();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package hunternif.mc.impl.atlas;

import dev.architectury.event.events.client.ClientTickEvent;
import dev.architectury.registry.ReloadListenerRegistry;
import hunternif.mc.impl.atlas.client.*;
import hunternif.mc.impl.atlas.marker.MarkerTextureConfig;
import hunternif.mc.impl.atlas.registry.MarkerType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

@Environment(EnvType.CLIENT)
public class ClientProxy implements SimpleSynchronousResourceReloadListener {
public class ClientProxy implements ResourceReloader {
public void initClient() {
// read Textures first from assets
TextureConfig textureConfig = new TextureConfig(Textures.TILE_TEXTURES_MAP);
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES)
.registerReloadListener(textureConfig);
ReloadListenerRegistry.register(ResourceType.CLIENT_RESOURCES, textureConfig);

// than read TextureSets
// then read TextureSets
TextureSetMap textureSetMap = TextureSetMap.instance();
TextureSetConfig textureSetConfig = new TextureSetConfig(textureSetMap);
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES)
.registerReloadListener(textureSetConfig);
ReloadListenerRegistry.register(ResourceType.CLIENT_RESOURCES, textureSetConfig);

// After that, we can read the tile mappings
TileTextureMap tileTextureMap = TileTextureMap.instance();
TileTextureConfig tileTextureConfig = new TileTextureConfig(tileTextureMap, textureSetMap);
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES)
.registerReloadListener(tileTextureConfig);
ReloadListenerRegistry.register(ResourceType.CLIENT_RESOURCES, tileTextureConfig);

// Legacy file name:
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(this);
ReloadListenerRegistry.register(ResourceType.CLIENT_RESOURCES, this);

MarkerTextureConfig markerTextureConfig = new MarkerTextureConfig();
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES)
.registerReloadListener(markerTextureConfig);
ReloadListenerRegistry.register(ResourceType.CLIENT_RESOURCES, markerTextureConfig);

for (MarkerType type : MarkerType.REGISTRY) {
type.initMips();
}

if (!AntiqueAtlasMod.CONFIG.itemNeeded) {
KeyHandler.registerBindings();
ClientTickEvents.START_CLIENT_TICK.register(KeyHandler::onClientTick);
ClientTickEvent.CLIENT_POST.register(KeyHandler::onClientTick);
}

}
Expand Down Expand Up @@ -82,15 +82,17 @@ public static void assignCustomBiomeTextures(ClientWorld world) {
}

@Override
public Identifier getFabricId() {
return AntiqueAtlasMod.id("proxy");
public String getName() {
return AntiqueAtlasMod.id("proxy").toString();
}

@Override
public void reload(ResourceManager var1) {
for (MarkerType type : MarkerType.REGISTRY) {
type.initMips();
}
assignBiomeTextures();
public CompletableFuture<Void> reload(ResourceReloader.Synchronizer synchronizer, ResourceManager manager, Profiler prepareProfiler, Profiler applyProfiler, Executor prepareExecutor, Executor applyExecutor) {
return CompletableFuture.completedFuture(null).thenCompose(synchronizer::whenPrepared).thenCompose(t -> CompletableFuture.runAsync(() -> {
for (MarkerType type : MarkerType.REGISTRY) {
type.initMips();
}
assignBiomeTextures();
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void doDeleteMarker(World world, int atlasID, int markerID) {
AntiqueAtlasMod.markersData.getMarkersData(atlasID, world);
data.removeMarker(markerID);

new DeleteMarkerS2CPacket(atlasID, markerID).send(world.getServer());
new DeleteMarkerS2CPacket(atlasID, markerID).send(((ServerWorld) world).getServer());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package hunternif.mc.impl.atlas.client;

import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.util.profiler.Profiler;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

public interface IResourceReloadListener<T> extends ResourceReloader
{

CompletableFuture<T> load(ResourceManager manager, Profiler profiler, Executor executor);

CompletableFuture<Void> apply(T data,
ResourceManager manager,
Profiler profiler,
Executor executor);


default CompletableFuture<Void> reload(ResourceReloader.Synchronizer synchronizer,
ResourceManager manager,
Profiler prepareProfiler,
Profiler applyProfiler,
Executor prepareExecutor,
Executor applyExecutor)
{
CompletableFuture<T> load = load(manager, prepareProfiler, prepareExecutor);

return load.thenCompose(synchronizer::whenPrepared)
.thenCompose(t -> apply(t, manager, applyProfiler, applyExecutor));
}

}
Original file line number Diff line number Diff line change
@@ -1,40 +1,26 @@
package hunternif.mc.impl.atlas.client;

import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
import hunternif.mc.impl.atlas.AntiqueAtlasModClient;
import hunternif.mc.impl.atlas.client.gui.GuiAtlas;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;

import java.util.ArrayList;
import java.util.List;

@Environment(EnvType.CLIENT)
public class KeyHandler {
/**
* ID's of keys
*/
private static final int KEY_ATLAS = 0;

/**
* List of bindings (at this moment with only one binding)
*/
private static List<KeyBinding> bindings = new ArrayList<>(1);
public static final KeyBinding ATLAS_KEYMAPPING = new KeyBinding("key.openatlas.desc", InputUtil.Type.KEYSYM, 77, "key.antiqueatlas.category");

public static void registerBindings() {
// Initialisation of bindings
bindings.add(KEY_ATLAS, new KeyBinding("key.openatlas.desc", InputUtil.Type.KEYSYM, 77, "key.antiqueatlas.category"));

// Registering all binding
bindings.forEach(KeyBindingHelper::registerKeyBinding);
KeyMappingRegistry.register(ATLAS_KEYMAPPING);
}

public static void onClientTick(MinecraftClient client) {
if (bindings.get(KEY_ATLAS).wasPressed()) {
while (ATLAS_KEYMAPPING.wasPressed()) {
Screen currentScreen = MinecraftClient.getInstance().currentScreen;
if (currentScreen instanceof GuiAtlas) {
currentScreen.close();
Expand Down
Loading

0 comments on commit da59206

Please sign in to comment.