generated from neoforged/MDK
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0c1846
commit 64bcfe0
Showing
7 changed files
with
67 additions
and
2 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/leclowndu93150/modular_angelring/networking/KeyPressedPayload.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,24 @@ | ||
package com.leclowndu93150.modular_angelring.networking; | ||
|
||
import com.leclowndu93150.modular_angelring.AngelRingMain; | ||
import com.leclowndu93150.modular_angelring.render.AngelRingRenderer; | ||
import net.minecraft.network.RegistryFriendlyByteBuf; | ||
import net.minecraft.network.codec.ByteBufCodecs; | ||
import net.minecraft.network.codec.StreamCodec; | ||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; | ||
import net.minecraft.resources.ResourceLocation; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public record KeyPressedPayload(int key) implements CustomPacketPayload { | ||
public static final Type<KeyPressedPayload> TYPE = new Type<>(ResourceLocation.fromNamespaceAndPath(AngelRingMain.MODID, "keypressed_payload")); | ||
public static final StreamCodec<RegistryFriendlyByteBuf, KeyPressedPayload> STREAM_CODEC = StreamCodec.composite( | ||
ByteBufCodecs.INT, | ||
KeyPressedPayload::key, | ||
KeyPressedPayload::new | ||
); | ||
|
||
@Override | ||
public @NotNull Type<? extends CustomPacketPayload> type() { | ||
return TYPE; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/leclowndu93150/modular_angelring/networking/NetworkingEvents.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,16 @@ | ||
package com.leclowndu93150.modular_angelring.networking; | ||
|
||
import com.leclowndu93150.modular_angelring.AngelRingMain; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; | ||
import net.neoforged.neoforge.network.registration.PayloadRegistrar; | ||
|
||
@EventBusSubscriber(modid = AngelRingMain.MODID, bus = EventBusSubscriber.Bus.MOD) | ||
public final class NetworkingEvents { | ||
@SubscribeEvent | ||
public static void registerPayloads(RegisterPayloadHandlersEvent event) { | ||
PayloadRegistrar registrar = event.registrar(AngelRingMain.MODID); | ||
registrar.playToServer(KeyPressedPayload.TYPE, KeyPressedPayload.STREAM_CODEC, PayloadActions::keyPressedAction); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/leclowndu93150/modular_angelring/networking/PayloadActions.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,20 @@ | ||
package com.leclowndu93150.modular_angelring.networking; | ||
|
||
import com.leclowndu93150.modular_angelring.AngelRingMain; | ||
import com.leclowndu93150.modular_angelring.registry.KeyBindRegistry; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.neoforged.neoforge.network.handling.IPayloadContext; | ||
|
||
public final class PayloadActions { | ||
public static void keyPressedAction(KeyPressedPayload payload, IPayloadContext ctx) { | ||
// SERVER-SIDE | ||
Player player = ctx.player(); | ||
Level level = player.level(); | ||
int key = payload.key(); | ||
if (key == KeyBindRegistry.INERTIA_MODULE.get().getKey().getValue()) { | ||
// do stuff if inertia module key was pressed | ||
System.out.println("Inertia pressed"); | ||
} | ||
} | ||
} |
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