Add NetworkManager hook for Entity spawn packets (#88)

* New utility hook for creating a entity spawn packet. before every mod had to implement this in itself.

* Apply suggestions from code review

Co-authored-by: shedaniel <daniel@shedaniel.me>

* Update common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java

* Update common/src/main/java/me/shedaniel/architectury/networking/NetworkManager.java

* Properly implement SpawnEntityPacket & Format style

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Format

Signed-off-by: shedaniel <daniel@shedaniel.me>

* createEntitySpawnPacket -> createAddEntityPacket for mojmap consistency

Signed-off-by: shedaniel <daniel@shedaniel.me>

* Bump version to 1.17

Co-authored-by: Max <maxh2709@gmail.com>
Co-authored-by: shedaniel <daniel@shedaniel.me>
This commit is contained in:
canitzp
2021-05-27 19:34:50 +02:00
committed by GitHub
parent 30dcaa480b
commit 371925b28d
9 changed files with 193 additions and 2 deletions

View File

@@ -28,6 +28,7 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import java.util.Objects;
@@ -74,6 +75,20 @@ public final class NetworkManager {
throw new AssertionError();
}
/**
* Easy to use utility method to create an entity spawn packet.
* This packet is needed everytime any mod adds a non-living entity.
* The entity should override {@link Entity#getAddEntityPacket()} to point to this method!
*
* @param entity The entity which should be spawned.
* @return The ready to use packet to spawn the entity on the client.
* @see Entity#getAddEntityPacket()
*/
@ExpectPlatform
public static Packet<?> createAddEntityPacket(Entity entity) {
throw new AssertionError();
}
@FunctionalInterface
public interface NetworkReceiver {
void receive(FriendlyByteBuf buf, PacketContext context);