-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Dev0Louis/dev
Nebula V5
- Loading branch information
Showing
47 changed files
with
1,367 additions
and
699 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
98
nebulo/src/main/java/dev/louis/nebulo/client/NebuloClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
nebulo/src/main/java/dev/louis/nebulo/client/SpellKeybindManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
27 changes: 27 additions & 0 deletions
27
nebulo/src/main/java/dev/louis/nebulo/manager/ManagerRegisterer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
nebulo/src/main/java/dev/louis/nebulo/manager/mana/NebuloManaManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
nebulo/src/main/java/dev/louis/nebulo/manager/spell/NebuloSpellManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.