添加fast projectile的additional data
This commit is contained in:
parent
43829c9b0c
commit
5933a59d2d
2 changed files with 28 additions and 13 deletions
|
@ -2,13 +2,15 @@ package com.atsuishio.superbwarfare.entity.projectile;
|
|||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.network.message.ClientMotionSyncMessage;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||
import net.minecraftforge.network.PacketDistributor;
|
||||
|
||||
public abstract class FastThrowableProjectile extends ThrowableItemProjectile implements CustomSyncMotionEntity {
|
||||
public abstract class FastThrowableProjectile extends ThrowableItemProjectile implements CustomSyncMotionEntity, IEntityAdditionalSpawnData {
|
||||
|
||||
public FastThrowableProjectile(EntityType<? extends ThrowableItemProjectile> pEntityType, Level pLevel) {
|
||||
super(pEntityType, pLevel);
|
||||
|
@ -36,4 +38,17 @@ public abstract class FastThrowableProjectile extends ThrowableItemProjectile im
|
|||
ModUtils.PACKET_HANDLER.send(PacketDistributor.ALL.noArg(), new ClientMotionSyncMessage(this));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(FriendlyByteBuf buffer) {
|
||||
var motion = this.getDeltaMovement();
|
||||
buffer.writeFloat((float) motion.x);
|
||||
buffer.writeFloat((float) motion.y);
|
||||
buffer.writeFloat((float) motion.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(FriendlyByteBuf additionalData) {
|
||||
this.setDeltaMovement(additionalData.readFloat(), additionalData.readFloat(), additionalData.readFloat());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,9 +13,9 @@ import java.util.function.Supplier;
|
|||
public class ClientMotionSyncMessage {
|
||||
|
||||
public final int id;
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
public final float x;
|
||||
public final float y;
|
||||
public final float z;
|
||||
|
||||
public ClientMotionSyncMessage(Entity entity) {
|
||||
this(entity.getId(), entity.getDeltaMovement());
|
||||
|
@ -23,23 +23,23 @@ public class ClientMotionSyncMessage {
|
|||
|
||||
public ClientMotionSyncMessage(int id, Vec3 motion) {
|
||||
this.id = id;
|
||||
this.x = motion.x;
|
||||
this.y = motion.y;
|
||||
this.z = motion.z;
|
||||
this.x = (float) motion.x;
|
||||
this.y = (float) motion.y;
|
||||
this.z = (float) motion.z;
|
||||
}
|
||||
|
||||
public static void encode(ClientMotionSyncMessage message, FriendlyByteBuf buffer) {
|
||||
buffer.writeVarInt(message.id);
|
||||
buffer.writeDouble(message.x);
|
||||
buffer.writeDouble(message.y);
|
||||
buffer.writeDouble(message.z);
|
||||
buffer.writeFloat(message.x);
|
||||
buffer.writeFloat(message.y);
|
||||
buffer.writeFloat(message.z);
|
||||
}
|
||||
|
||||
public static ClientMotionSyncMessage decode(FriendlyByteBuf buffer) {
|
||||
int id = buffer.readVarInt();
|
||||
double x = buffer.readDouble();
|
||||
double y = buffer.readDouble();
|
||||
double z = buffer.readDouble();
|
||||
double x = buffer.readFloat();
|
||||
double y = buffer.readFloat();
|
||||
double z = buffer.readFloat();
|
||||
return new ClientMotionSyncMessage(id, new Vec3(x, y, z));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue