Skip to content

Commit

Permalink
Merge pull request #30 from Dev0Louis/dev
Browse files Browse the repository at this point in the history
Nebula V5
  • Loading branch information
Dev0Louis authored Jan 22, 2024
2 parents 2fd8c1b + ade49f1 commit 37503bd
Show file tree
Hide file tree
Showing 47 changed files with 1,367 additions and 699 deletions.
14 changes: 12 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
id 'idea'
}

version = project.mod_version
version = project.mod_version + "+" + project.minecraft_version
supported_version = project.supported_version
group = project.maven_group

processResources {
inputs.properties("supported_version": supported_version, "version": project.version)

filesMatching("fabric.mod.json") {
expand "supported_version": supported_version, "version": project.version
}
}

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.4
supported_version=>=1.20.2
yarn_mappings=1.20.4+build.3
loader_version=0.15.3
loader_version=0.15.6
# Mod Properties
mod_version=4.0.3
mod_version=5.0.0-beta.1
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.92.0+1.20.4
fabric_version=0.95.0+1.20.4
5 changes: 5 additions & 0 deletions nebulo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Nebulo

This is the test mod for Nebula.

Feel free to use all code in this test mod.
95 changes: 95 additions & 0 deletions nebulo/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
id 'idea'
}

version = project.mod_version + "+" + project.minecraft_version
supported_version = project.supported_version
group = project.maven_group

processResources {
inputs.properties("supported_version": supported_version, "version": project.version)

filesMatching("fabric.mod.json") {
expand "supported_version": supported_version, "version": project.version
}
}

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.
}

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

implementation(project(path: ":", configuration: "namedElements")) {
exclude group: "net.fabricmc", module: "fabric-loader"
}
}

processResources {
inputs.property "version", project.version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

def targetJavaVersion = 17
tasks.withType(JavaCompile).configureEach {
// 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
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
}

java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
if (JavaVersion.current() < javaVersion) {
toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion)
}
archivesBaseName = project.archives_base_name
// 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}" }
}
}

// configure the maven publication
publishing {
publications {
mavenJava(MavenPublication) {
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.
// 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.
}
}
16 changes: 16 additions & 0 deletions nebulo/src/main/java/dev/louis/nebulo/Nebulo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.louis.nebulo;

import com.mojang.logging.LogUtils;
import net.fabricmc.api.ModInitializer;
import org.slf4j.Logger;

public class Nebulo implements ModInitializer {
public static final String MOD_ID = "nebulo";
public static final Logger LOGGER = LogUtils.getLogger();

@Override
public void onInitialize() {
NebuloSpells.init();
LOGGER.info("Nebulo has been initialized.");
}
}
12 changes: 12 additions & 0 deletions nebulo/src/main/java/dev/louis/nebulo/NebuloSpells.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package dev.louis.nebulo;

import dev.louis.nebula.api.spell.SpellType;
import dev.louis.nebulo.spell.CloudJumpSpell;
import net.minecraft.util.Identifier;

public class NebuloSpells {
public static final SpellType<?> CLOUD_JUMP = SpellType.register(new Identifier(Nebulo.MOD_ID, "cloud_jump"), SpellType.Builder.create(CloudJumpSpell::new, 2));
public static void init() {

}
}
98 changes: 98 additions & 0 deletions nebulo/src/main/java/dev/louis/nebulo/client/NebuloClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package dev.louis.nebulo.client;

import dev.louis.nebula.api.spell.SpellType;
import dev.louis.nebulo.NebuloSpells;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.option.KeyBinding;
import org.lwjgl.glfw.GLFW;

import java.util.concurrent.atomic.AtomicInteger;

public class NebuloClient implements ClientModInitializer {
public int spellCooldown = 0;
@Override
public void onInitializeClient() {
registerKeybind();
registerKeybindCallback();

registerRenderCallback();
}


private static void registerKeybind() {
var keyBind = new KeyBinding(
"key.nebulo.example",
GLFW.GLFW_KEY_UNKNOWN,
"key.categories.nebulo"
);
KeyBindingHelper.registerKeyBinding(keyBind);
SpellKeybindManager.addSpellKeyBinding(NebuloSpells.CLOUD_JUMP, keyBind);
}

private void registerKeybindCallback() {
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (spellCooldown > 0) {
spellCooldown--;
return;
}

for (SpellType<?> spellType : SpellType.REGISTRY) {
var optionalKey = SpellKeybindManager.getKey(spellType);
if(optionalKey.isPresent()) {
var key = optionalKey.get();
if(key.isPressed()) {
client.player.getSpellManager().cast(spellType);
spellCooldown = 10;
return;
}
}
}
});
}

private void registerRenderCallback() {
HudRenderCallback.EVENT.register((drawContext, tickDelta) -> {
var player = MinecraftClient.getInstance().player;
if(player == null)return;
var manaManager = player.getManaManager();
var spellManager = player.getSpellManager();
var mana = String.valueOf(manaManager.getMana());
var maxMana = String.valueOf(manaManager.getMaxMana());
drawContext.drawText(
MinecraftClient.getInstance().textRenderer,
"Mana: " + mana + "/" + maxMana,
10,
10,
0x0000FF,
false
);

drawContext.drawText(
MinecraftClient.getInstance().textRenderer,
"Learned Spells:",
10,
20,
0x00FFFF,
true
);

var spells = spellManager.getLearnedSpells();
AtomicInteger y = new AtomicInteger(30);
spells.forEach(spellType -> {
drawContext.drawText(
MinecraftClient.getInstance().textRenderer,
spellType.getId().toString(),
10,
y.get(),
0x03F6FF,
true
);
y.addAndGet(10);
});
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

package dev.louis.nebulo.client;


import dev.louis.nebula.api.spell.Spell;
import dev.louis.nebula.api.spell.SpellType;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.option.KeyBinding;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Optional;

/**
The SpellKeybinds class stores a mapping between spell types and key bindings.
It allows for easy retrieval of the key binding associated with a specific spell type.
*/
@Environment(EnvType.CLIENT)
public class SpellKeybindManager {

// HashMap that stores the mapping between spell types and key bindings
private static final HashMap<SpellType<? extends Spell>, KeyBinding> keyBindings = new HashMap<>();

/**
* Sets the key binding associated with a specific spell type.
*
* @param spellType the spell type to associate with the key binding
* @param keyBinding the key binding to associate with the spell type
*/
public static void addSpellKeyBinding(SpellType<? extends Spell> spellType, KeyBinding keyBinding) {
keyBindings.put(spellType, keyBinding);
}

/**
* Returns an Optional containing the key binding associated with a specific spell type.
* If there is no key binding associated with the spell type, an empty Optional is returned.
*
* @param spellType the spell type to retrieve the key binding for
* @return an Optional containing the key binding associated with the spell type, or an empty Optional
*/
public static Optional<KeyBinding> getKey(@NotNull SpellType<? extends Spell> spellType){
KeyBinding keyBinding = keyBindings.get(spellType);
if(keyBinding==null)return Optional.empty();
return Optional.of(keyBinding);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.louis.nebulo.manager;

import dev.louis.nebula.api.manager.mana.entrypoint.RegisterManaManagerEntrypoint;
import dev.louis.nebula.api.manager.mana.registerable.ManaManagerRegistrableView;
import dev.louis.nebula.api.manager.spell.entrypoint.RegisterSpellManagerEntrypoint;
import dev.louis.nebula.api.manager.spell.registerable.SpellManagerRegistrableView;
import dev.louis.nebula.networking.SyncManaS2CPacket;
import dev.louis.nebula.networking.UpdateSpellCastabilityS2CPacket;
import dev.louis.nebulo.manager.mana.NebuloManaManager;
import dev.louis.nebulo.manager.spell.NebuloSpellManager;

public class ManagerRegisterer implements RegisterManaManagerEntrypoint, RegisterSpellManagerEntrypoint {
@Override
public void registerSpell(ManaManagerRegistrableView manaManagerRegistrableView) {
manaManagerRegistrableView.registerManaManager(NebuloManaManager::new, SyncManaS2CPacket.ID, NebuloManaManager::receiveSync);
}

@Override
public void registerSpell(SpellManagerRegistrableView spellManagerRegistrableView) {
spellManagerRegistrableView.registerSpellManager(NebuloSpellManager::new, UpdateSpellCastabilityS2CPacket.ID, NebuloSpellManager::receiveSync);
}

@Override
public boolean shouldRegister() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.louis.nebulo.manager.mana;

import dev.louis.nebula.manager.mana.NebulaManaManager;
import net.minecraft.entity.player.PlayerEntity;

public class NebuloManaManager extends NebulaManaManager {
public NebuloManaManager(PlayerEntity player) {
super(player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.louis.nebulo.manager.spell;

import dev.louis.nebula.manager.spell.NebulaSpellManager;
import net.minecraft.entity.player.PlayerEntity;

public class NebuloSpellManager extends NebulaSpellManager {
public NebuloSpellManager(PlayerEntity player) {
super(player);
}
}
Loading

0 comments on commit 37503bd

Please sign in to comment.