forked from artynova/hexdummy
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add basic architectury networking setup #3
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 25 additions & 0 deletions
25
template/{{ common_path }}/src/main/java/{{ package_path }}/client/LookClient.java.jinja
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,25 @@ | ||
{% from "macros/mappings.jinja" import mappings as _, import, ns with context -%} | ||
|
||
package {{ package }}.client; | ||
|
||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
{{ import( | ||
mojmap="net.minecraft.client.Minecraft", | ||
yarn="net.minecraft.client.MinecraftClient", | ||
) }}{% set MinecraftClient = ns.import %}; | ||
|
||
/** | ||
* This class is created to separate client-only code into a dedicated package. | ||
*/ | ||
@Environment(EnvType.CLIENT) | ||
public class LookClient { | ||
/** | ||
* Alters the tilt of the player's head. | ||
* @param pitch New pitch or {@code null} | ||
*/ | ||
public static void setLookPitch(float pitch) { | ||
assert {{ MinecraftClient }}.getInstance().player != null; | ||
{{ MinecraftClient }}.getInstance().player.{{ _(mojmap="setXRot", yarn="setPitch") }}(pitch); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
... common_path }}/src/main/java/{{ package_path }}/networking/SetLookPitchS2CMsg.java.jinja
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,52 @@ | ||
{% from "macros/mappings.jinja" import mappings as _, import, ns with context -%} | ||
|
||
package {{ package }}.networking; | ||
|
||
import dev.architectury.networking.NetworkManager; | ||
{{ import( | ||
mojmap="net.minecraft.network.FriendlyByteBuf", | ||
yarn="net.minecraft.network.PacketByteBuf", | ||
) }}{% set ByteBuf = ns.import %}; | ||
import {{ package }}.client.LookClient; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Class that implements the functionality necessary to create, send, and execute a command (in this case rotate view) | ||
* from the server to a client in architectury. | ||
*/ | ||
public class SetLookPitchS2CMsg { | ||
private final float pitch; | ||
|
||
/** | ||
* Constructor for creation on the server. | ||
* @param pitch Head pitch parameter. | ||
*/ | ||
public SetLookPitchS2CMsg(float pitch) { | ||
this.pitch = pitch; | ||
} | ||
|
||
/** | ||
* Constructor for recreation on the client from a {@link {{ ByteBuf }}} onto which it was encoded | ||
* on the server using {@link #encode({{ ByteBuf }})}. | ||
* @param buf Buffer onto which the message was encoded | ||
*/ | ||
public SetLookPitchS2CMsg({{ ByteBuf }} buf) { | ||
this.pitch = buf.readFloat(); | ||
} | ||
|
||
/** | ||
* Method that encodes the message, preparing it for transmission over the network. | ||
* @param buf Buffer onto which the message will be encoded | ||
*/ | ||
public void encode({{ ByteBuf }} buf) { | ||
buf.writeFloat(pitch); | ||
} | ||
|
||
/** | ||
* Executes the command. | ||
* @param contextSupplier Supplier of the context that is used to schedule the timely execution of the message. | ||
*/ | ||
public void apply(Supplier<NetworkManager.PacketContext> contextSupplier) { | ||
contextSupplier.get().queue(() -> LookClient.setLookPitch(pitch)); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
..._path }}/src/main/java/{{ package_path }}/networking/{{ classname }}Networking.java.jinja
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,31 @@ | ||
{% from "macros/mappings.jinja" import mappings as _, import, ns with context -%} | ||
|
||
package {{ package }}.networking; | ||
|
||
import dev.architectury.networking.NetworkChannel; | ||
{{ import( | ||
mojmap="net.minecraft.server.level.ServerPlayer", | ||
yarn="net.minecraft.server.network.ServerPlayerEntity", | ||
) }}{% set ServerPlayer = ns.import %}; | ||
|
||
import static {{ package }}.{{ classname }}.id; | ||
|
||
public class {{ classname }}Networking { | ||
private static final NetworkChannel CHANNEL = NetworkChannel.create(id("networking_channel")); | ||
|
||
public static void init() { | ||
CHANNEL.register(SetLookPitchS2CMsg.class, SetLookPitchS2CMsg::encode, SetLookPitchS2CMsg::new, SetLookPitchS2CMsg::apply); | ||
} | ||
|
||
public static <T> void sendToServer(T message) { | ||
CHANNEL.sendToServer(message); | ||
} | ||
|
||
public static <T> void sendToPlayer({{ ServerPlayer }} player, T message) { | ||
CHANNEL.sendToPlayer(player, message); | ||
} | ||
|
||
public static <T> void sendToPlayers(Iterable<{{ ServerPlayer }}> players, T message) { | ||
CHANNEL.sendToPlayers(players, message); | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should actually take the opportunity to fix this text - doesn't OpCongrats operate directly on the caster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, it really does. That's my oversight in the implementation of the spell, though, because it accepts a player entity (to show an example of a mishap when an incorrect entity is passed) and was supposed to act on that entity. I will be fixing that, thank you for pointing the discrepancy out.