Skip to content

Commit bd338ae

Browse files
authored
Merge pull request #11 from Dr-Sievert/main
Networking backport
2 parents c63294c + 6ea6234 commit bd338ae

21 files changed

+891
-440
lines changed

src/main/java/dev/overgrown/thaumaturge/Thaumaturge.java

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
import dev.overgrown.thaumaturge.spell.modifier.ScatterModifierEffect;
99
import dev.overgrown.thaumaturge.spell.networking.SpellCastPacket;
1010
import dev.overgrown.thaumaturge.spell.pattern.AspectRegistry;
11-
import dev.overgrown.thaumaturge.spell.utils.SpellHandler;
1211
import net.fabricmc.api.ModInitializer;
13-
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
1412
import net.minecraft.util.Identifier;
15-
1613
import org.slf4j.Logger;
1714
import org.slf4j.LoggerFactory;
1815

@@ -21,23 +18,20 @@ public class Thaumaturge implements ModInitializer {
2118
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
2219

2320
public static Identifier identifier(String path) {
24-
return new Identifier(Thaumaturge.MOD_ID, path);
21+
return new Identifier(MOD_ID, path);
2522
}
2623

2724
@Override
2825
public void onInitialize() {
29-
// Register all items
26+
// Items
3027
ModItems.initialize();
3128

32-
// Register spell components
29+
// Spell components
3330
registerAspectEffects();
3431
registerModifierEffects();
3532

36-
// Register packet handler
37-
ServerPlayNetworking.registerGlobalReceiver(SpellCastPacket.ID, (server, player, handler, buf, responseSender) -> {
38-
SpellCastPacket packet = new SpellCastPacket(buf);
39-
server.execute(() -> SpellHandler.castSpell(player, packet.getHand(), packet.getSpellKey()));
40-
});
33+
// Networking
34+
SpellCastPacket.registerServer();
4135

4236
LOGGER.info("Thaumaturge initialized!");
4337
}
@@ -49,6 +43,5 @@ private void registerAspectEffects() {
4943
private void registerModifierEffects() {
5044
ModifierRegistry.register(identifier("power"), new PowerModifierEffect());
5145
ModifierRegistry.register(identifier("scatter"), new ScatterModifierEffect());
52-
ModifierRegistry.register(identifier("stable"), context -> {}); // Stable does nothing
5346
}
54-
}
47+
}

src/main/java/dev/overgrown/thaumaturge/ThaumaturgeClient.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,36 @@
77
import dev.overgrown.thaumaturge.spell.networking.SpellCastPacket;
88
import net.fabricmc.api.ClientModInitializer;
99
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
10-
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
1110
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
12-
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
13-
import net.minecraft.network.PacketByteBuf;
14-
import net.minecraft.util.Hand;
1511

1612
public class ThaumaturgeClient implements ClientModInitializer {
13+
private static final float DEFAULT_AOE_RADIUS = 3.0f;
14+
1715
@Override
1816
public void onInitializeClient() {
19-
// Add condition to show aspects when player has the lens
20-
AspectsTooltipConfig.addVisibilityCondition((stack, player) ->
21-
AspectLensItem.hasLens(player));
17+
// Tooltips visible only with lens
18+
AspectsTooltipConfig.addVisibilityCondition((stack, player) -> AspectLensItem.hasLens(player));
2219

23-
// Register Spell Keybinds
20+
// Register spell keybinds (original flow)
2421
KeybindManager.registerKeybinds();
2522

26-
// Register Aetheric Goggles overlay
27-
AspectsTooltipConfig.addVisibilityCondition((stack, player) -> AspectLensItem.hasLens(player));
28-
23+
// Overlay
2924
HudRenderCallback.EVENT.register(new AethericGogglesOverlay());
3025

26+
// Handle presses: Primary=Lesser(self), Secondary=Advanced(targeted), Ternary=Greater(aoe)
3127
ClientTickEvents.END_CLIENT_TICK.register(client -> {
32-
if (KeybindManager.PRIMARY_SPELL.wasPressed()) {
33-
sendSpellCastPacket(Hand.MAIN_HAND, 0);
28+
if (client.player == null) return;
29+
30+
while (KeybindManager.PRIMARY_SPELL.wasPressed()) {
31+
SpellCastPacket.sendSelf();
3432
}
35-
if (KeybindManager.SECONDARY_SPELL.wasPressed()) {
36-
sendSpellCastPacket(Hand.MAIN_HAND, 1);
33+
while (KeybindManager.SECONDARY_SPELL.wasPressed()) {
34+
SpellCastPacket.sendTargetedFromCrosshair();
3735
}
38-
if (KeybindManager.TERNARY_SPELL.wasPressed()) {
39-
sendSpellCastPacket(Hand.MAIN_HAND, 2);
36+
while (KeybindManager.TERNARY_SPELL.wasPressed()) {
37+
SpellCastPacket.sendAoeFromCrosshair(DEFAULT_AOE_RADIUS);
4038
}
39+
// The remaining keys (quaternary..denary) are registered for future use, unchanged.
4140
});
4241
}
43-
44-
private void sendSpellCastPacket(Hand hand, int spellKey) {
45-
PacketByteBuf buf = PacketByteBufs.create();
46-
new SpellCastPacket(hand, spellKey).write(buf);
47-
ClientPlayNetworking.send(SpellCastPacket.ID, buf);
48-
}
49-
}
42+
}

src/main/java/dev/overgrown/thaumaturge/client/keybind/KeybindManager.java

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,54 +6,42 @@
66
import net.minecraft.client.util.InputUtil;
77
import org.lwjgl.glfw.GLFW;
88

9+
/**
10+
* KeybindManager.java
11+
* Registers up to 10 spell keybinds (primary → denary).
12+
* No tick handling here—ThaumaturgeClient handles presses.
13+
*/
914
public class KeybindManager {
10-
// Different spell keybindings for different spell slots
11-
public static KeyBinding PRIMARY_SPELL; // Default: R key
12-
public static KeyBinding SECONDARY_SPELL; // Default: V key
13-
public static KeyBinding TERNARY_SPELL; // Default: G key
14-
public static KeyBinding QUATERNARY_SPELL; // Default: B key
15-
public static KeyBinding QUINARY_SPELL; // Default: H key
16-
public static KeyBinding SENARY_SPELL; // Default: N key
17-
public static KeyBinding SEPTENARY_SPELL; // Default: Y key
18-
public static KeyBinding OCTONARY_SPELL; // Default: U key
19-
public static KeyBinding NONARY_SPELL; // Default: I key
20-
public static KeyBinding DENARY_SPELL; // Default: O key
15+
public static KeyBinding PRIMARY_SPELL; // R
16+
public static KeyBinding SECONDARY_SPELL; // V
17+
public static KeyBinding TERNARY_SPELL; // G
18+
public static KeyBinding QUATERNARY_SPELL; // B
19+
public static KeyBinding QUINARY_SPELL; // H
20+
public static KeyBinding SENARY_SPELL; // N
21+
public static KeyBinding SEPTENARY_SPELL; // Y
22+
public static KeyBinding OCTONARY_SPELL; // U
23+
public static KeyBinding NONARY_SPELL; // I
24+
public static KeyBinding DENARY_SPELL; // O
2125

22-
/**
23-
* Registers all keybindings for the mod
24-
* Called during client initialization in ThaumaturgeClient
25-
*/
26+
/** Called during client init from ThaumaturgeClient. */
2627
public static void registerKeybinds() {
27-
PRIMARY_SPELL = registerKey("primary", GLFW.GLFW_KEY_R);
28-
SECONDARY_SPELL = registerKey("secondary", GLFW.GLFW_KEY_V);
29-
TERNARY_SPELL = registerKey("ternary", GLFW.GLFW_KEY_G);
28+
PRIMARY_SPELL = registerKey("primary", GLFW.GLFW_KEY_R);
29+
SECONDARY_SPELL = registerKey("secondary", GLFW.GLFW_KEY_V);
30+
TERNARY_SPELL = registerKey("ternary", GLFW.GLFW_KEY_G);
3031
QUATERNARY_SPELL = registerKey("quaternary", GLFW.GLFW_KEY_B);
31-
QUINARY_SPELL = registerKey("quinary", GLFW.GLFW_KEY_H);
32-
SENARY_SPELL = registerKey("senary", GLFW.GLFW_KEY_N);
33-
SEPTENARY_SPELL = registerKey("septenary", GLFW.GLFW_KEY_Y);
34-
OCTONARY_SPELL = registerKey("octonary", GLFW.GLFW_KEY_U);
35-
NONARY_SPELL = registerKey("nonary", GLFW.GLFW_KEY_I);
36-
DENARY_SPELL = registerKey("denary", GLFW.GLFW_KEY_O);
32+
QUINARY_SPELL = registerKey("quinary", GLFW.GLFW_KEY_H);
33+
SENARY_SPELL = registerKey("senary", GLFW.GLFW_KEY_N);
34+
SEPTENARY_SPELL = registerKey("septenary", GLFW.GLFW_KEY_Y);
35+
OCTONARY_SPELL = registerKey("octonary", GLFW.GLFW_KEY_U);
36+
NONARY_SPELL = registerKey("nonary", GLFW.GLFW_KEY_I);
37+
DENARY_SPELL = registerKey("denary", GLFW.GLFW_KEY_O);
3738
}
3839

39-
/**
40-
* Helper method to register a keybinding with standard naming convention
41-
*
42-
* @param name Base name for the keybind
43-
* @param keycode Default GLFW keycode to assign
44-
* @return The registered KeyBinding
45-
*/
4640
private static KeyBinding registerKey(String name, int keycode) {
4741
String translationKey = "key." + Thaumaturge.MOD_ID + "." + name;
48-
String categoryKey = "key.category." + Thaumaturge.MOD_ID + ".spells";
49-
42+
String categoryKey = "key.category." + Thaumaturge.MOD_ID + ".spells";
5043
return KeyBindingHelper.registerKeyBinding(
51-
new KeyBinding(
52-
translationKey,
53-
InputUtil.Type.KEYSYM,
54-
keycode,
55-
categoryKey
56-
)
44+
new KeyBinding(translationKey, InputUtil.Type.KEYSYM, keycode, categoryKey)
5745
);
5846
}
59-
}
47+
}

src/main/java/dev/overgrown/thaumaturge/mixin/ServerPlayNetworkHandlerMixin.java

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,43 @@
11
package dev.overgrown.thaumaturge.spell.effect;
22

3-
import dev.overgrown.thaumaturge.spell.modifier.ModifierEffect;
4-
import dev.overgrown.thaumaturge.spell.modifier.ModifierRegistry;
5-
import dev.overgrown.thaumaturge.spell.pattern.AspectEffect;
6-
import dev.overgrown.thaumaturge.spell.pattern.AspectRegistry;
73
import dev.overgrown.thaumaturge.spell.utils.SpellContext;
84
import net.minecraft.util.Identifier;
95

6+
/**
7+
* Backport-safe holder for a spell triplet (aspect id, modifier id, amplifier).
8+
*
9+
* In the 1.20.1 backport, actual execution is centralized in SpellHandler +
10+
* delivery classes using AspectsLib/registries. This class no longer resolves
11+
* or invokes Aspect/Modifier effects directly.
12+
*/
1013
public class SpellEffect {
1114
private final Identifier aspectId;
1215
private final Identifier modifierId;
1316
private final int amplifier;
14-
private final AspectEffect aspectEffect;
15-
private final ModifierEffect modifierEffect;
1617

1718
public SpellEffect(Identifier aspectId, Identifier modifierId, int amplifier) {
1819
this.aspectId = aspectId;
1920
this.modifierId = modifierId;
2021
this.amplifier = amplifier;
21-
this.aspectEffect = AspectRegistry.get(aspectId);
22-
this.modifierEffect = ModifierRegistry.get(modifierId);
2322
}
2423

24+
/** Sets the amplifier on the provided context; execution happens elsewhere. */
2525
public void apply(SpellContext context) {
26-
context.setAmplifier(amplifier);
27-
28-
// Apply aspect effect using the context
29-
if (aspectEffect != null) {
30-
aspectEffect.apply(context);
31-
}
32-
33-
// Apply modifier effect
34-
if (modifierEffect != null) {
35-
modifierEffect.modify(context);
26+
if (context != null) {
27+
context.setAmplifier(amplifier);
3628
}
29+
// No direct aspect/modifier calls here in the backport.
3730
}
3831

39-
public Identifier aspectId() {
40-
return aspectId;
41-
}
42-
43-
public Identifier modifierId() {
44-
return modifierId;
45-
}
46-
47-
public int amplifier() {
48-
return amplifier;
49-
}
32+
public Identifier aspectId() { return aspectId; }
33+
public Identifier modifierId() { return modifierId; }
34+
public int amplifier() { return amplifier; }
5035

5136
public boolean hasAspect(Identifier aspect) {
52-
return aspectId.equals(aspect);
37+
return aspect != null && aspect.equals(this.aspectId);
5338
}
5439

5540
public boolean hasModifier(Identifier modifier) {
56-
return modifierId.equals(modifier);
41+
return modifier != null && modifier.equals(this.modifierId);
5742
}
58-
}
43+
}

0 commit comments

Comments
 (0)