Skip to content

Commit

Permalink
complete arch refactor for fabric+forge duo on 1.17.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed Nov 1, 2021
1 parent 532e22e commit 048a64c
Show file tree
Hide file tree
Showing 174 changed files with 3,092 additions and 1,178 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ bin/
run/
/server/
/logs/
/.architectury-transformer/debug.log
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# Identity

*Identity* is a mod inspired by [Morph](https://www.curseforge.com/minecraft/mc-mods/morph), built for the Fabric mod loader on 1.15.2.
*Identity* is a mod inspired by [Morph](https://www.curseforge.com/minecraft/mc-mods/morph), built for the Fabric mod loader (and recently ported to Forge).

**WARNING:** the 1.17.1 Architectury version of Identity (2.0.0+), which supports Forge & Fabric, is in a heavy beta state. Back up your worlds often and expect things to break.

---

**Versions**:

| | Fabric | Forge |
| ----------- | ----------- | ----------- |
| 1.16 |||
| 1.17 |||

**Required Libraries (1.17.1+):**

Fabric => [Architectury API (Fabric)](https://www.curseforge.com/minecraft/mc-mods/architectury-fabric)

Forge => [Architectury API (Forge)](https://www.curseforge.com/minecraft/mc-mods/architectury-forge)

---

With *Identity*, you can become anything you want, friend or foe, hot or cold, fluffy or rough.

Expand Down
113 changes: 31 additions & 82 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,99 +1,48 @@
plugins {
id 'fabric-loom' version '0.8-SNAPSHOT'
id 'maven-publish'
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.10.0-SNAPSHOT" apply false
}

sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16

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

minecraft {
accessWidener "src/main/resources/identity.accesswidener"
architectury {
minecraft = rootProject.minecraft_version
}

repositories {
maven { url 'https://jitpack.io' }
subprojects {
apply plugin: "dev.architectury.loom"

maven {
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
content {
includeGroup 'io.github.ladysnake'
includeGroupByRegex 'io\\.github\\.onyxstudios.*'
}
loom {
silentMojangMappingsLicense()
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

// Player Ability Lib: https://github.com/Ladysnake/PlayerAbilityLib
include "io.github.ladysnake:PlayerAbilityLib:${project.pal_version}"
modImplementation ("io.github.ladysnake:PlayerAbilityLib:${project.pal_version}") {
exclude group: "net.fabricmc.fabric-api"
dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
mappings "net.fabricmc:yarn:1.17.1+build.63:v2"
}

// Cardinal Components: https://github.com/OnyxStudios/Cardinal-Components-API
modImplementation "io.github.onyxstudios:Cardinal-Components-API:${project.cardinal_version}"
include "io.github.onyxstudios:Cardinal-Components-API:${project.cardinal_version}"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-base:${project.cardinal_version}"
include "io.github.onyxstudios.Cardinal-Components-API:cardinal-components-entity:${project.cardinal_version}"

// config
modImplementation 'com.github.Draylar.omega-config:omega-config-base:1.0.4-beta'
include 'com.github.Draylar.omega-config:omega-config-base:1.0.4-beta:min'
}

processResources {
inputs.property "version", project.version
allprojects {
apply plugin: "java"
apply plugin: "architectury-plugin"
apply plugin: "maven-publish"

filesMatching('fabric.mod.json') {
expand "version": project.version
}
}
archivesBaseName = rootProject.archives_base_name + "-" + it.name
version = rootProject.mod_version + "-" + rootProject.minecraft_version
group = rootProject.maven_group

// 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"
}

// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this task, sources will not be generated.
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}

jar {
from "LICENSE"
}
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.
}

// 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 = 16
}

// select the repositories you want to publish to
repositories {
// uncomment to publish to the local maven
// mavenLocal()
java {
withSourcesJar()
}
}
}
40 changes: 40 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"

// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:${rootProject.architectury_version}"
}

architectury {
common()
}

afterEvaluate {
remapJar {
remapAccessWidener = false
}
}

configurations {
dev
}

artifacts {
dev(jar)
}

publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
from components.java
}
}

// 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.
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package draylar.identity;

import draylar.identity.ability.AbilityRegistry;
import draylar.identity.config.IdentityConfig;
import draylar.identity.api.platform.IdentityConfig;
import draylar.identity.api.platform.PlayerIdentity;
import draylar.identity.network.ServerNetworking;
import draylar.identity.registry.Commands;
import draylar.identity.registry.Components;
import draylar.identity.registry.EntityTags;
import draylar.identity.registry.EventHandlers;
import draylar.omegaconfig.OmegaConfig;
import io.github.ladysnake.pal.AbilitySource;
import io.github.ladysnake.pal.Pal;
import net.fabricmc.api.ModInitializer;
import net.minecraft.advancement.Advancement;
import net.minecraft.advancement.AdvancementProgress;
import net.minecraft.entity.EntityType;
Expand All @@ -23,39 +19,38 @@

import java.util.List;

public class Identity implements ModInitializer {
public class Identity {

public static final IdentityConfig CONFIG = OmegaConfig.register(IdentityConfig.class);
public static final AbilitySource ABILITY_SOURCE = Pal.getAbilitySource(id("equipped_identity"));

@Override
public void onInitialize() {
public void initialize() {
EntityTags.init();
AbilityRegistry.init();
EventHandlers.init();
EventHandlers.registerHostilityUpdateHandler();
EventHandlers.registerRavagerRidingHandler();
Commands.init();
ServerNetworking.init();
ServerNetworking.registerIdentityRequestPacketHandler();
ServerNetworking.registerFavoritePacketHandler();
ServerNetworking.registerUseAbilityPacketHandler();
}

public static Identifier id(String name) {
return new Identifier("identity", name);
}

public static boolean hasFlyingPermissions(ServerPlayerEntity player) {
LivingEntity identity = Components.CURRENT_IDENTITY.get(player).getIdentity();
LivingEntity identity = PlayerIdentity.getIdentity(player);

if(identity != null && Identity.CONFIG.enableFlight && EntityTags.FLYING.contains(identity.getType())) {
List<String> requiredAdvancements = CONFIG.advancementsRequiredForFlight;
if(identity != null && IdentityConfig.getInstance().enableFlight() && EntityTags.FLYING.contains(identity.getType())) {
List<String> requiredAdvancements = IdentityConfig.getInstance().advancementsRequiredForFlight();

// requires at least 1 advancement, check if player has them
if (!requiredAdvancements.isEmpty()) {
if(!requiredAdvancements.isEmpty()) {

boolean hasPermission = true;
for (String requiredAdvancement : requiredAdvancements) {
Advancement advancement = player.server.getAdvancementLoader().get(new Identifier(requiredAdvancement));
AdvancementProgress progress = player.getAdvancementTracker().getProgress(advancement);

if (!progress.isDone()) {
if(!progress.isDone()) {
hasPermission = false;
}
}
Expand All @@ -76,6 +71,6 @@ public static boolean isAquatic(LivingEntity entity) {

public static int getCooldown(EntityType<?> type) {
String id = Registry.ENTITY_TYPE.getId(type).toString();
return CONFIG.abilityCooldownMap.getOrDefault(id, 20);
return IdentityConfig.getInstance().getAbilityCooldownMap().getOrDefault(id, 20);
}
}
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
package draylar.identity;

import dev.architectury.event.events.client.ClientTickEvent;
import dev.architectury.registry.client.keymappings.KeyMappingRegistry;
import draylar.identity.ability.AbilityOverlayRenderer;
import draylar.identity.ability.AbilityRegistry;
import draylar.identity.api.model.EntityArms;
import draylar.identity.api.model.EntityUpdaters;
import draylar.identity.api.platform.IdentityConfig;
import draylar.identity.api.platform.PlayerIdentity;
import draylar.identity.network.ClientNetworking;
import draylar.identity.registry.Components;
import draylar.identity.screen.IdentityScreen;
import net.fabricmc.api.ClientModInitializer;
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.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.entity.LivingEntity;
import org.lwjgl.glfw.GLFW;

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

public static final KeyBinding MENU_KEY = KeyBindingHelper.registerKeyBinding(
public static final KeyBinding MENU_KEY =
new KeyBinding(
"key.identity",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_GRAVE_ACCENT,
"key.categories.identity"));
"key.categories.identity");

public static final KeyBinding ABILITY_KEY = KeyBindingHelper.registerKeyBinding(
public static final KeyBinding ABILITY_KEY =
new KeyBinding(
"key.identity_ability",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_R,
"key.categories.identity"));
"key.categories.identity");

@Override
public void onInitializeClient() {
public void initialize() {
KeyMappingRegistry.register(MENU_KEY);
KeyMappingRegistry.register(ABILITY_KEY);

// Register client-side event handlers
EntityUpdaters.init();
ClientNetworking.init();
AbilityOverlayRenderer.register();
EntityArms.init();

// add screen opening key-bind
ClientTickEvents.START_CLIENT_TICK.register(client -> {
ClientTickEvent.CLIENT_PRE.register(client -> {
assert client.player != null;

if(MENU_KEY.wasPressed()) {
if(Identity.CONFIG.enableClientSwapMenu || client.player.hasPermissionLevel(3)) {
if(IdentityConfig.getInstance().enableClientSwapMenu() || client.player.hasPermissionLevel(3)) {
MinecraftClient.getInstance().setScreen(new IdentityScreen());
}
}
});

// when the use-ability key is pressed, trigger ability
ClientTickEvents.START_CLIENT_TICK.register(client -> {
ClientTickEvent.CLIENT_PRE.register(client -> {
assert client.player != null;

if(ABILITY_KEY.wasPressed()) {
// TODO: maybe the check should be on the server to allow for ability extension mods?
// Only send the ability packet if the identity equipped by the player has one
LivingEntity identity = Components.CURRENT_IDENTITY.get(client.player).getIdentity();
LivingEntity identity = PlayerIdentity.getIdentity(client.player);

if(identity != null) {
if(AbilityRegistry.has(identity.getType())) {
Expand Down
Loading

0 comments on commit 048a64c

Please sign in to comment.