|
1
|
|
|
package de.pewpewproject.lasertag.networking.client.callbacks; |
|
2
|
|
|
|
|
3
|
|
|
import de.pewpewproject.lasertag.LasertagMod; |
|
4
|
|
|
import de.pewpewproject.lasertag.entity.LaserRayEntity; |
|
5
|
|
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; |
|
6
|
|
|
import net.fabricmc.fabric.api.networking.v1.PacketSender; |
|
7
|
|
|
import net.minecraft.client.MinecraftClient; |
|
8
|
|
|
import net.minecraft.client.network.ClientPlayNetworkHandler; |
|
9
|
|
|
import net.minecraft.network.PacketByteBuf; |
|
10
|
|
|
import net.minecraft.util.math.Vec3d; |
|
11
|
|
|
|
|
12
|
|
|
import java.util.UUID; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Callback to handle the laser ray spawned networking event |
|
16
|
|
|
* |
|
17
|
|
|
* @author Étienne Muser |
|
18
|
|
|
*/ |
|
19
|
|
|
public class LaserRaySpawnedCallback implements ClientPlayNetworking.PlayChannelHandler { |
|
20
|
|
|
@Override |
|
21
|
|
|
public void receive(MinecraftClient client, ClientPlayNetworkHandler handler, PacketByteBuf buf, PacketSender responseSender) { |
|
22
|
|
|
|
|
23
|
|
|
try { |
|
24
|
|
|
|
|
25
|
|
|
double x = buf.readDouble(); |
|
26
|
|
|
double y = buf.readDouble(); |
|
27
|
|
|
double z = buf.readDouble(); |
|
28
|
|
|
|
|
29
|
|
|
double endX = buf.readDouble(); |
|
30
|
|
|
double endY = buf.readDouble(); |
|
31
|
|
|
double endZ = buf.readDouble(); |
|
32
|
|
|
|
|
33
|
|
|
Vec3d pos = new Vec3d(x, y, z); |
|
34
|
|
|
Vec3d endPos = new Vec3d(endX, endY, endZ); |
|
35
|
|
|
|
|
36
|
|
|
float yaw = buf.readFloat(); |
|
37
|
|
|
float pitch = buf.readFloat(); |
|
38
|
|
|
|
|
39
|
|
|
int entityId = buf.readInt(); |
|
40
|
|
|
UUID uuid = buf.readUuid(); |
|
41
|
|
|
|
|
42
|
|
|
int color = buf.readInt(); |
|
43
|
|
|
|
|
44
|
|
|
client.execute(() -> { |
|
45
|
|
|
LaserRayEntity entity = new LaserRayEntity(client.world, pos, yaw, pitch, color, endPos); |
|
46
|
|
|
entity.setId(entityId); |
|
47
|
|
|
entity.setUuid(uuid); |
|
48
|
|
|
|
|
49
|
|
|
client.world.addEntity(entityId, entity); |
|
50
|
|
|
}); |
|
51
|
|
|
} catch (Exception ex) { |
|
52
|
|
|
LasertagMod.LOGGER.error("Error in LaserRaySpawnedCallback", ex); |
|
53
|
|
|
throw ex; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|