|
13 | 13 | import net.minecraft.core.BlockPos; |
14 | 14 | import net.minecraft.core.particles.ParticleOptions; |
15 | 15 | import net.minecraft.core.particles.ParticleTypes; |
| 16 | +import net.minecraft.core.registries.BuiltInRegistries; |
16 | 17 | import net.minecraft.network.chat.MessageSignature; |
17 | 18 | import net.minecraft.sounds.SoundEvent; |
18 | 19 | import net.minecraft.sounds.SoundSource; |
| 20 | +import net.minecraft.util.Mth; |
19 | 21 | import net.minecraft.world.entity.Entity; |
20 | 22 | import net.minecraft.world.entity.EntityType; |
21 | 23 | import net.minecraft.world.entity.projectile.Projectile; |
@@ -86,43 +88,64 @@ private static void handlePlaySound(PacketCustom packet, Minecraft mc) { |
86 | 88 | mc.level.playLocalSound(pos, sound, category, volume, pitch, distanceDelay); |
87 | 89 | } |
88 | 90 |
|
| 91 | +// PacketCustom packet = new PacketCustom(CHANNEL_NAME, C_SPAWN_ENTITY, entity.registryAccess()); |
| 92 | +// packet.writeInt(entity.getId()); |
| 93 | +// packet.writeUUID(entity.getUUID()); |
| 94 | +// |
| 95 | +// packet.writeDouble(serverEntity.getPositionBase().x()); |
| 96 | +// packet.writeDouble(serverEntity.getPositionBase().y()); |
| 97 | +// packet.writeDouble(serverEntity.getPositionBase().z()); |
| 98 | +// packet.writeByte((byte) Mth.floor(serverEntity.getLastSentXRot() * 256.0F / 360.0F)); |
| 99 | +// packet.writeByte((byte) Mth.floor(serverEntity.getLastSentYRot() * 256.0F / 360.0F)); |
| 100 | +// packet.writeByte((byte) (entity.getYHeadRot() * 256.0F / 360.0F)); |
| 101 | +// |
| 102 | +// packet.writeRegistryId(BuiltInRegistries.ENTITY_TYPE, entity.getType()); |
| 103 | +// packet.writeVarInt(ownerId); |
| 104 | +// |
| 105 | +// Vec3 velocity = entity.getDeltaMovement(); |
| 106 | +// packet.writeFloat((float) velocity.x); |
| 107 | +// packet.writeFloat((float) velocity.y); |
| 108 | +// packet.writeFloat((float) velocity.z); |
| 109 | + |
89 | 110 | private static void handleEntitySpawn(PacketCustom packet, Minecraft mc) { |
90 | 111 | if (mc.level == null) { |
91 | 112 | return; |
92 | 113 | } |
93 | | - |
94 | | - EntityType<?> type = packet.readRegistryId();//ForgeRegistries.ENTITY_TYPES.byId(packet.readVarInt()); |
95 | 114 | int entityID = packet.readInt(); |
96 | 115 | UUID uuid = packet.readUUID(); |
| 116 | + |
97 | 117 | double posX = packet.readDouble(); |
98 | 118 | double posY = packet.readDouble(); |
99 | 119 | double posZ = packet.readDouble(); |
100 | | - byte yaw = packet.readByte(); |
101 | | - byte pitch = packet.readByte(); |
102 | | - byte headYaw = packet.readByte(); |
| 120 | + byte xRot = packet.readByte(); |
| 121 | + byte yRot = packet.readByte(); |
| 122 | + byte headYRot = packet.readByte(); |
| 123 | + |
| 124 | + EntityType<?> type = packet.readRegistryId();//ForgeRegistries.ENTITY_TYPES.byId(packet.readVarInt()); |
| 125 | + int ownerId = packet.readVarInt(); |
103 | 126 | Vec3 velocity = new Vec3(packet.readFloat(), packet.readFloat(), packet.readFloat()); |
104 | | - int data = packet.readVarInt(); |
| 127 | + |
105 | 128 | Entity entity = type.create(mc.level); |
106 | 129 | if (entity == null) { |
107 | 130 | return; |
108 | 131 | } |
109 | 132 |
|
110 | | - //THis is a hack, but meh. Should work. |
111 | | - if (entity instanceof Projectile projectile && data != 0) { |
112 | | - Entity e = mc.level.getEntity(data); |
| 133 | + //This is a hack, but meh. Should work. |
| 134 | + if (entity instanceof Projectile projectile && ownerId != 0) { |
| 135 | + Entity e = mc.level.getEntity(ownerId); |
113 | 136 | if (e != null) { |
114 | 137 | projectile.setOwner(entity); |
115 | 138 | } |
116 | 139 | } |
117 | 140 |
|
118 | | - entity.setPosRaw(posX, posY, posZ); |
119 | | - entity.absMoveTo(posX, posY, posZ, (pitch * 360) / 256.0F, (yaw * 360) / 256.0F); |
120 | | - entity.setYHeadRot((headYaw * 360) / 256.0F); |
121 | | - entity.setYBodyRot((headYaw * 360) / 256.0F); |
| 141 | + entity.setDeltaMovement(velocity); |
| 142 | + entity.syncPacketPositionCodec(posX, posY, posZ); |
| 143 | + entity.moveTo(posX, posY, posZ); |
| 144 | + entity.setXRot(xRot); |
| 145 | + entity.setYRot(yRot); |
122 | 146 | entity.setId(entityID); |
123 | 147 | entity.setUUID(uuid); |
124 | 148 | mc.level.addEntity(entity); |
125 | | - entity.lerpMotion(velocity.x, velocity.y, velocity.z); |
126 | 149 | } |
127 | 150 |
|
128 | 151 | private static void handleEntityVelocity(PacketCustom packet, Minecraft mc) { |
|
0 commit comments