Skip to content

Commit

Permalink
Merge pull request #4 from Dev0Louis/dev
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
Dev0Louis authored Apr 16, 2023
2 parents f51a571 + f7abed2 commit b9bc1da
Show file tree
Hide file tree
Showing 21 changed files with 350 additions and 181 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/gradle-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a package using Gradle and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#Publishing-using-gradle

name: Gradle Package

on:
release:
types: [created]

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file

- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build

# The USERNAME and TOKEN need to correspond to the credentials environment variables used in
# the publishing section of your build.gradle
- name: Publish to GitHub Packages
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: publish
env:
USERNAME: ${{ github.actor }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ org.gradle.jvmargs=-Xmx1G
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.19.4
yarn_mappings=1.19.4+build.1
loader_version=0.14.17
loader_version=0.14.19
# Mod Properties
mod_version=2.0.0
mod_version=2.1.0
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.76.0+1.19.4
fabric_version=0.77.0+1.19.4
57 changes: 2 additions & 55 deletions src/main/java/dev/louis/nebula/Nebula.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
package dev.louis.nebula;

import dev.louis.nebula.event.SpellCastCallback;
import dev.louis.nebula.manamanager.ManaManager;
import dev.louis.nebula.manamanager.NebulaManaManager;
import dev.louis.nebula.manamanager.player.PlayerManaManager;
import dev.louis.nebula.networking.SpellCastC2SPacket;
import dev.louis.nebula.spell.Spell;
import dev.louis.nebula.spell.SpellType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
Expand All @@ -24,74 +17,28 @@
import org.slf4j.LoggerFactory;

public class Nebula implements ModInitializer {
private static final String JSON_KEY_DISABLE_NEBULAMANAMANAGER = "nebula:contains_manamanager";
public static final String MOD_ID = "nebula";
public static final Logger LOGGER = LoggerFactory.getLogger("Nebula");

public static Nebula INSTANCE;

private ManaManager<?> activeManaManager;
private boolean hasActiveManaManager = false;

@Override
public void onInitialize() {
INSTANCE = this;
SpellType.init();
registerPacketReceivers();
NebulaRegistries.init();
loadIfNeeded();
if(nebulaManaManagerActive) {
registerManaManager(new NebulaManaManager());
}
NebulaManager.init();
}

public void registerPacketReceivers() {
ServerPlayNetworking.registerGlobalReceiver(SpellCastC2SPacket.ID, ((server, player, handler, buf, responseSender) -> {
ServerPlayNetworking.registerGlobalReceiver(SpellCastC2SPacket.getId(), ((server, player, handler, buf, responseSender) -> {
Spell spell = SpellCastC2SPacket.read(player, buf).spell();
if (SpellCastCallback.EVENT.invoker().interact(player, spell) == ActionResult.PASS) {
spell.cast();
}
}));
}
private static boolean needsLoad = true;
private static boolean nebulaManaManagerActive = true;

private static void loadIfNeeded() {
if (needsLoad) {
for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
final ModMetadata meta = container.getMetadata();
if(meta.getId().equals("nebula"))continue;
if (meta.containsCustomValue(JSON_KEY_DISABLE_NEBULAMANAMANAGER)) {
nebulaManaManagerActive = false;
}
}

needsLoad = false;
}
}
public void registerManaManager(ManaManager<?> manaManager) {
if (manaManager == null) {
throw new NullPointerException("Attempt to register a NULL rendering plug-in.");
} else if (activeManaManager != null) {
throw new UnsupportedOperationException("A second rendering plug-in attempted to register. Multiple rendering plug-ins are not supported.");
} else {
manaManager.setUp();
this.activeManaManager = manaManager;
this.hasActiveManaManager = true;
}
}

public ManaManager<?> getManaManager() {
return activeManaManager;
}

public boolean hasManaManager() {
return hasActiveManaManager;
}

public PlayerManaManager createManaManager(PlayerEntity player) {
return getManaManager().createPlayerManaManager(player);
}



Expand Down
10 changes: 4 additions & 6 deletions src/main/java/dev/louis/nebula/NebulaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;

public class NebulaClient implements ClientModInitializer {
Expand All @@ -19,15 +20,12 @@ public void onInitializeClient() {

private void registerPacketReceivers() {
//Register the Knowledge Packet.
ClientPlayNetworking.registerGlobalReceiver(SynchronizeSpellKnowledgeS2CPacket.ID, (client, handler, buf, responseSender) -> {
ClientPlayNetworking.registerGlobalReceiver(SynchronizeSpellKnowledgeS2CPacket.getID(), (client, handler, buf, responseSender) -> {
SynchronizeSpellKnowledgeS2CPacket packet = SynchronizeSpellKnowledgeS2CPacket.read(buf);
client.executeSync(() -> NebulaPlayer.access(client.player).getSpellKnowledge().updateCastableSpell(packet.spells()));
client.executeSync(() -> NebulaPlayer.access(client.player).getSpellKnowledgeManager().updateCastableSpell(packet.spells()));
});
//Register the ManaAmount Packet.
ClientPlayNetworking.registerGlobalReceiver(SynchronizeManaAmountS2CPacket.ID, ((client, handler, buf, responseSender) -> {
SynchronizeManaAmountS2CPacket packet = SynchronizeManaAmountS2CPacket.read(buf);
NebulaPlayer.access(client.player).setMana(packet.mana());
}));
ClientPlayConnectionEvents.INIT.register(((handler, client) -> ClientPlayNetworking.registerReceiver(SynchronizeManaAmountS2CPacket.PACKET_TYPE, SynchronizeManaAmountS2CPacket::receive)));
}

private void registerAutoConfigIfInstalled() {
Expand Down
98 changes: 98 additions & 0 deletions src/main/java/dev/louis/nebula/NebulaManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package dev.louis.nebula;

import dev.louis.nebula.knowledgemanager.NebulaSpellKnowledgeManager;
import dev.louis.nebula.knowledgemanager.SpellKnowledgeManager;
import dev.louis.nebula.knowledgemanager.player.PlayerSpellKnowledgeManager;
import dev.louis.nebula.manamanager.ManaManager;
import dev.louis.nebula.manamanager.NebulaManaManager;
import dev.louis.nebula.manamanager.player.PlayerManaManager;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.fabricmc.loader.api.metadata.ModMetadata;
import net.minecraft.entity.player.PlayerEntity;

import java.util.Optional;

public class NebulaManager {
private static final String JSON_KEY_CONTAINS_MANAMANAGER = "nebula:contains_manamanager";
private static final String JSON_KEY_CONTAINS_SPELLKNOWLEDGEMANAGER = "nebula:contains_spellknowledgemanager";
public static final NebulaManager INSTANCE = new NebulaManager();


private boolean nebulaManaManagerActive = true;
private boolean nebulaSpellManagerActive = true;
private Optional<ManaManager> manaManager = Optional.empty();
private Optional<SpellKnowledgeManager> spellKnowledgeManager = Optional.empty();


private NebulaManager() {

}

public static void init() {
INSTANCE.internal_init();
}
private void internal_init() {
load();
if(nebulaManaManagerActive) {
registerManaManager(new NebulaManaManager());
}
if(nebulaSpellManagerActive) {
registerSpellKnowledgeManager(new NebulaSpellKnowledgeManager());
}
}


private void load() {
for (ModContainer container : FabricLoader.getInstance().getAllMods()) {
final ModMetadata meta = container.getMetadata();
if(meta.getId().equals("nebula"))continue;
if (meta.containsCustomValue(JSON_KEY_CONTAINS_MANAMANAGER)) {
nebulaManaManagerActive = false;
}
if (meta.containsCustomValue(JSON_KEY_CONTAINS_SPELLKNOWLEDGEMANAGER)) {
nebulaSpellManagerActive = false;
}
}
}
public void registerManaManager(ManaManager<?> manaManager) {
if (manaManager == null) {
throw new NullPointerException("Attempt to register a NULL ManaManager");
} else if (this.manaManager.isPresent()) {
throw new UnsupportedOperationException("A second ManaManager attempted to register. Multiple ManaManagers are not supported.");
} else {
this.manaManager = Optional.of(manaManager);
manaManager.setUp();
}
}

public void registerSpellKnowledgeManager(SpellKnowledgeManager<?> spellKnowledgeManager) {
if (spellKnowledgeManager == null) {
throw new NullPointerException("Attempt to register a NULL SpellKnowledgeManager");
} else if (this.spellKnowledgeManager.isPresent()) {
throw new UnsupportedOperationException("A SpellKnowledgeManager plug-in attempted to register. Multiple SpellKnowledgeManagers are not supported.");
} else {
this.spellKnowledgeManager = Optional.of(spellKnowledgeManager);
spellKnowledgeManager.setUp();
}
}



public ManaManager<?> getManaManager() {
return manaManager.orElseThrow();
}

public SpellKnowledgeManager<?> getSpellKnowledgeManager() {
return spellKnowledgeManager.orElseThrow();
}

public PlayerManaManager createPlayerManaManager(PlayerEntity player) {
return getManaManager().createPlayerManaManager(player);
}

public PlayerSpellKnowledgeManager createPlayerSpellKnowledgeManager(PlayerEntity player) {
return getSpellKnowledgeManager().createPlayerSpellKnowledgeManager(player);
}

}
4 changes: 2 additions & 2 deletions src/main/java/dev/louis/nebula/api/NebulaPlayer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.louis.nebula.api;

import dev.louis.nebula.knowledge.SpellKnowledgeManager;
import dev.louis.nebula.knowledgemanager.player.PlayerSpellKnowledgeManager;
import dev.louis.nebula.manamanager.player.PlayerManaManager;
import net.minecraft.entity.player.PlayerEntity;
import org.jetbrains.annotations.NotNull;
Expand All @@ -10,7 +10,7 @@ public interface NebulaPlayer {
void setPlayerManaManager(PlayerManaManager manaManager);
public int getMana();
public void setMana(int mana);
public SpellKnowledgeManager getSpellKnowledge();
public PlayerSpellKnowledgeManager getSpellKnowledgeManager();

@NotNull
static NebulaPlayer access(PlayerEntity player) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package dev.louis.nebula.event;

import dev.louis.nebula.spell.Spell;
import dev.louis.nebula.spell.SpellType;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;

public interface SpellKnowledgeRemoveCallback {
Event<SpellKnowledgeRemoveCallback> EVENT = EventFactory.createArrayBacked(SpellKnowledgeRemoveCallback.class, (listeners) -> (player, removedSpellType) -> {
for (SpellKnowledgeRemoveCallback event : listeners) {
ActionResult result = event.interact(player, removedSpellType);
import java.util.Map;

public interface SpellKnowledgeUpdateCallback {
Event<SpellKnowledgeUpdateCallback> EVENT = EventFactory.createArrayBacked(SpellKnowledgeUpdateCallback.class, (listeners) -> (player, castableSpells) -> {
for (SpellKnowledgeUpdateCallback event : listeners) {
ActionResult result = event.interact(player, castableSpells);

if (result != ActionResult.PASS) {
return result;
Expand All @@ -20,5 +23,5 @@ public interface SpellKnowledgeRemoveCallback {
}
);

ActionResult interact(PlayerEntity player, SpellType removedSpellType);
ActionResult interact(PlayerEntity player, Map<SpellType<? extends Spell>, Boolean> castableSpells);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.louis.nebula.knowledgemanager;

import dev.louis.nebula.knowledgemanager.player.NebulaPlayerSpellKnowledgeManager;
import net.minecraft.entity.player.PlayerEntity;

public class NebulaSpellKnowledgeManager implements SpellKnowledgeManager<NebulaPlayerSpellKnowledgeManager> {

@Override
public NebulaPlayerSpellKnowledgeManager createPlayerSpellKnowledgeManager(PlayerEntity player) {
return new NebulaPlayerSpellKnowledgeManager(player);
}

@Override
public void setUp() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.louis.nebula.knowledgemanager;

import dev.louis.nebula.knowledgemanager.player.PlayerSpellKnowledgeManager;
import net.minecraft.entity.player.PlayerEntity;

public interface SpellKnowledgeManager<T extends PlayerSpellKnowledgeManager> {
T createPlayerSpellKnowledgeManager(PlayerEntity player);
void setUp();
}
Loading

0 comments on commit b9bc1da

Please sign in to comment.