Skip to content

Commit

Permalink
1.20.6 :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev0Louis committed May 14, 2024
1 parent 52b9fe3 commit 5cc6e0b
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 154 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.5-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'maven-publish'
id 'idea'
}
Expand Down
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
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.7
minecraft_version=1.20.6
supported_version=>=1.20.5
yarn_mappings=1.20.6+build.1
loader_version=0.15.11
# Mod Properties
mod_version=6.0.0
mod_version=6.1.0
maven_group=dev.louis
archives_base_name=Nebula
# Dependencies
# check this on https://modmuss50.me/fabric.html
fabric_version=0.96.4+1.20.4
fabric_version=0.98.0+1.20.6
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 4 additions & 2 deletions src/main/java/dev/louis/nebula/Nebula.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import dev.louis.nebula.api.spell.SpellType;
import dev.louis.nebula.command.NebulaCommand;
import dev.louis.nebula.manager.NebulaManager;
import dev.louis.nebula.networking.SpellCastC2SPacket;
import dev.louis.nebula.networking.c2s.SpellCastPayload;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import org.jetbrains.annotations.ApiStatus;
import org.slf4j.Logger;
Expand All @@ -25,7 +26,8 @@ public void onInitialize() {
}

public void registerPacketReceivers() {
ServerPlayNetworking.registerGlobalReceiver(SpellCastC2SPacket.TYPE, SpellCastC2SPacket::receive);
PayloadTypeRegistry.playC2S().register(SpellCastPayload.ID, SpellCastPayload.CODEC);
ServerPlayNetworking.registerGlobalReceiver(SpellCastPayload.ID, SpellCastPayload::receive);
}
}

12 changes: 8 additions & 4 deletions src/main/java/dev/louis/nebula/NebulaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import dev.louis.nebula.manager.mana.NebulaManaManager;
import dev.louis.nebula.manager.spell.NebulaSpellManager;
import dev.louis.nebula.networking.SyncManaS2CPacket;
import dev.louis.nebula.networking.UpdateSpellCastabilityS2CPacket;
import dev.louis.nebula.networking.s2c.SyncManaPayload;
import dev.louis.nebula.networking.s2c.UpdateSpellCastabilityPayload;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;

public class NebulaClient implements ClientModInitializer {

Expand All @@ -15,7 +16,10 @@ public void onInitializeClient() {
}

public void registerPacketReceivers() {
ClientPlayNetworking.registerGlobalReceiver(UpdateSpellCastabilityS2CPacket.TYPE, NebulaSpellManager::receiveSync);
ClientPlayNetworking.registerGlobalReceiver(SyncManaS2CPacket.TYPE, NebulaManaManager::receiveSync);
PayloadTypeRegistry.playS2C().register(UpdateSpellCastabilityPayload.ID, UpdateSpellCastabilityPayload.CODEC);
ClientPlayNetworking.registerGlobalReceiver(UpdateSpellCastabilityPayload.ID, NebulaSpellManager::receiveSync);

PayloadTypeRegistry.playS2C().register(SyncManaPayload.ID, SyncManaPayload.CODEC);
ClientPlayNetworking.registerGlobalReceiver(SyncManaPayload.ID, NebulaManaManager::receiveSync);
}
}
1 change: 0 additions & 1 deletion src/main/java/dev/louis/nebula/api/spell/Spell.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ protected final void stop() {
/**
* If true {@link Spell#applyCost()} and {@link Spell#cast()} will be called in that order. <br>
* If false nothing will be called. <br>
* {@link SpellType.Builder#castability(SpellType.Castability)} instead if possible.
*/
public boolean isCastable() {
return this.getType().isCastable(this.caster);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/louis/nebula/api/spell/SpellType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Optional;

public class SpellType<T extends Spell> {
private static final RegistryKey<Registry<SpellType<?>>> REGISTRY_KEY =
public static final RegistryKey<Registry<SpellType<?>>> REGISTRY_KEY =
RegistryKey.ofRegistry(new Identifier(Nebula.MOD_ID, "spell_type"));
public static final SimpleRegistry<SpellType<?>> REGISTRY =
FabricRegistryBuilder.createSimple(REGISTRY_KEY).attribute(RegistryAttribute.SYNCED).buildAndRegister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import dev.louis.nebula.Nebula;
import dev.louis.nebula.api.manager.mana.ManaManager;
import dev.louis.nebula.api.spell.SpellType;
import dev.louis.nebula.mixin.ClientPlayerEntityAccessor;
import dev.louis.nebula.networking.SyncManaS2CPacket;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import dev.louis.nebula.networking.s2c.SyncManaPayload;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -85,15 +83,14 @@ public boolean sendSync() {
int syncMana = this.getMana();
if (syncMana == this.lastSyncedMana) return true;
this.lastSyncedMana = syncMana;
ServerPlayNetworking.send(serverPlayerEntity, new SyncManaS2CPacket(syncMana));
ServerPlayNetworking.send(serverPlayerEntity, new SyncManaPayload(syncMana));
return true;
}
return false;
}

public static boolean receiveSync(SyncManaS2CPacket packet, ClientPlayerEntity player, PacketSender responseSender) {
((ClientPlayerEntityAccessor)player).getClient().executeSync(() -> player.getManaManager().setMana(packet.mana()));
return true;
public static void receiveSync(SyncManaPayload spellCastPayload, ClientPlayNetworking.Context context) {
context.client().executeSync(() -> context.player().getManaManager().setMana(spellCastPayload.mana()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
import dev.louis.nebula.api.manager.spell.SpellManager;
import dev.louis.nebula.api.spell.Spell;
import dev.louis.nebula.api.spell.SpellType;
import dev.louis.nebula.mixin.ClientPlayerEntityAccessor;
import dev.louis.nebula.networking.SpellCastC2SPacket;
import dev.louis.nebula.networking.UpdateSpellCastabilityS2CPacket;
import dev.louis.nebula.networking.c2s.SpellCastPayload;
import dev.louis.nebula.networking.s2c.UpdateSpellCastabilityPayload;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
Expand Down Expand Up @@ -90,7 +87,7 @@ public boolean cast(Spell spell) {
spell.cast();
this.activeSpells.add(spell);
} else {
ClientPlayNetworking.send(new SpellCastC2SPacket(spell.getType()));
ClientPlayNetworking.send(new SpellCastPayload(spell.getType()));
}
return true;
}
Expand Down Expand Up @@ -140,17 +137,17 @@ public boolean sendSync() {
if (this.player instanceof ServerPlayerEntity serverPlayerEntity && serverPlayerEntity.networkHandler != null) {
Map<SpellType<?>, Boolean> castableSpells = new HashMap<>();
SpellType.REGISTRY.forEach(spellType -> castableSpells.put(spellType, this.hasLearned(spellType)));
ServerPlayNetworking.send(serverPlayerEntity, new UpdateSpellCastabilityS2CPacket(castableSpells));
ServerPlayNetworking.send(serverPlayerEntity, new UpdateSpellCastabilityPayload(castableSpells));
dirty = false;
return true;
}
return false;
}


public static boolean receiveSync(UpdateSpellCastabilityS2CPacket packet, ClientPlayerEntity player, PacketSender responseSender) {
((ClientPlayerEntityAccessor)player).getClient().executeSync(() -> {
SpellManager spellManager = player.getSpellManager();
public static boolean receiveSync(UpdateSpellCastabilityPayload packet, ClientPlayNetworking.Context context) {
context.client().executeSync(() -> {
SpellManager spellManager = context.player() .getSpellManager();
packet.spells().forEach((spellType, learned) -> {
if (learned) spellManager.learnSpell(spellType);
else spellManager.forgetSpell(spellType);
Expand Down
49 changes: 0 additions & 49 deletions src/main/java/dev/louis/nebula/networking/SpellCastC2SPacket.java

This file was deleted.

25 changes: 0 additions & 25 deletions src/main/java/dev/louis/nebula/networking/SyncManaS2CPacket.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dev.louis.nebula.networking.c2s;

import dev.louis.nebula.Nebula;
import dev.louis.nebula.api.spell.SpellType;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public class SpellCastPayload implements CustomPayload {
public static final Id<SpellCastPayload> ID = new CustomPayload.Id<>(Identifier.of(Nebula.MOD_ID, "spellcast"));
public static final PacketCodec<RegistryByteBuf, SpellCastPayload> CODEC = PacketCodec.of(
SpellCastPayload::write,
SpellCastPayload::read
);
public final SpellType<?> spellType;

public SpellCastPayload(SpellType<?> spellType) {
this.spellType = spellType;
}

public static SpellCastPayload read(RegistryByteBuf buf) {
SpellType<?> spellType = PacketCodecs.registryValue(SpellType.REGISTRY_KEY).decode(buf);

if (spellType == null) throw new IllegalStateException("Spell type not found in registry");
return new SpellCastPayload(spellType);
}

public void write(RegistryByteBuf buf) {
PacketCodecs.registryValue(SpellType.REGISTRY_KEY).encode(buf, this.spellType);
}

public static void receive(SpellCastPayload packet, ServerPlayNetworking.Context context) {
context.player().server.executeSync(() -> context.player().getSpellManager().cast(packet.spellType));
}

@Override
public String toString() {
return "SpellCastC2SPacket[" +
"spellType=" + spellType + ']';
}

@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}
25 changes: 25 additions & 0 deletions src/main/java/dev/louis/nebula/networking/s2c/SyncManaPayload.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package dev.louis.nebula.networking.s2c;

import dev.louis.nebula.Nebula;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.util.Identifier;

public record SyncManaPayload(int mana) implements CustomPayload {
public static final Id<SyncManaPayload> ID = new CustomPayload.Id<>(Identifier.of(Nebula.MOD_ID, "synchronizemana"));
public static final PacketCodec<PacketByteBuf, SyncManaPayload> CODEC = PacketCodec.of(SyncManaPayload::write, SyncManaPayload::read);

public static SyncManaPayload read(PacketByteBuf buf) {
return new SyncManaPayload(buf.readVarInt());
}

public void write(PacketByteBuf buf) {
buf.writeVarInt(mana);
}

@Override
public Id<? extends CustomPayload> getId() {
return ID;
}
}
Loading

0 comments on commit 5cc6e0b

Please sign in to comment.