-
Notifications
You must be signed in to change notification settings - Fork 12
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
Refactored 1.21 networking #29
Conversation
private NetworkingUtil() { | ||
} | ||
|
||
public static boolean cantEditGlowcase(ServerPlayerEntity player, BlockPos pos, GlowcaseBlock glowcase) { |
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.
I know Intellij disagrees with me here, but I think it's more readable to have it be "canEditGlowcase" (even if that means it's always inverted)
this.url = tag.getString("url"); | ||
} | ||
|
||
public EditHyperlinkBlock createPacketData() { |
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.
I might rename this to "createEditPacket" since I think that's more descriptive. But that'd be in a separate codestyle pass, nothing that would block this pr
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.
I guess this would apply for all the other BEs with packets too, then?
I wonder if something like an interface or abstract super class would be good to enforce / abstract this whole structure a bit better.
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.
Also, I think I will move from short to byte for the enum packet codec entries too.
If there is ever going to be an enum with more entries than the byte size, there is something definitely wrong with the enum, and it should probably refactored to be something like a list or map...
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.
my suggestion on this - EditPacket<T extends BlockEntity> extends CustomPayload
contains
void send()
- defaulted c2s send.void receive(context)
- abstract for packets to implementEditPacket create(T blockEntity)
- construct packet from blockentity.
Anything that's not public from the BE that needs to be, just make it public.
…enum packed codec size from short to byte
# Conflicts: # src/main/java/dev/hephaestus/glowcase/block/entity/HyperlinkBlockEntity.java # src/main/java/dev/hephaestus/glowcase/block/entity/ItemDisplayBlockEntity.java # src/main/java/dev/hephaestus/glowcase/block/entity/TextBlockEntity.java # src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/HyperlinkBlockEditScreen.java # src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/ItemDisplayBlockEditScreen.java # src/main/java/dev/hephaestus/glowcase/client/gui/screen/ingame/TextBlockEditScreen.java # src/main/java/dev/hephaestus/glowcase/networking/GlowcaseClientNetworking.java # src/main/java/dev/hephaestus/glowcase/networking/GlowcaseCommonNetworking.java
src/main/java/dev/hephaestus/glowcase/networking/packet/EditItemDisplayBlockSettings.java
Show resolved
Hide resolved
src/main/java/dev/hephaestus/glowcase/networking/packet/EditItemDisplayBlockSettings.java
Show resolved
Hide resolved
this.url = tag.getString("url"); | ||
} | ||
|
||
public EditHyperlinkBlock createPacketData() { |
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.
my suggestion on this - EditPacket<T extends BlockEntity> extends CustomPayload
contains
void send()
- defaulted c2s send.void receive(context)
- abstract for packets to implementEditPacket create(T blockEntity)
- construct packet from blockentity.
Anything that's not public from the BE that needs to be, just make it public.
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.
Looking good! One main suggestion to better encapsulate packet logic.
Notes
this.blockEntitiy.createPacketData().send();
so block entities create the data for their packets. You can also just create a new instance of the packet manually if needed thoPACKET_CODEC
for enums uses short values now instead of int values since the amount of enum entries will never reach an integer size (even byte might be enough for most enums?)ServerPlayConnectionEvents.INIT
event and registered global receivers now