添加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.ModUtils;
|
||||||
import com.atsuishio.superbwarfare.network.message.ClientMotionSyncMessage;
|
import com.atsuishio.superbwarfare.network.message.ClientMotionSyncMessage;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.world.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
|
import net.minecraftforge.entity.IEntityAdditionalSpawnData;
|
||||||
import net.minecraftforge.network.PacketDistributor;
|
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) {
|
public FastThrowableProjectile(EntityType<? extends ThrowableItemProjectile> pEntityType, Level pLevel) {
|
||||||
super(pEntityType, 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));
|
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 class ClientMotionSyncMessage {
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
public final double x;
|
public final float x;
|
||||||
public final double y;
|
public final float y;
|
||||||
public final double z;
|
public final float z;
|
||||||
|
|
||||||
public ClientMotionSyncMessage(Entity entity) {
|
public ClientMotionSyncMessage(Entity entity) {
|
||||||
this(entity.getId(), entity.getDeltaMovement());
|
this(entity.getId(), entity.getDeltaMovement());
|
||||||
|
@ -23,23 +23,23 @@ public class ClientMotionSyncMessage {
|
||||||
|
|
||||||
public ClientMotionSyncMessage(int id, Vec3 motion) {
|
public ClientMotionSyncMessage(int id, Vec3 motion) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.x = motion.x;
|
this.x = (float) motion.x;
|
||||||
this.y = motion.y;
|
this.y = (float) motion.y;
|
||||||
this.z = motion.z;
|
this.z = (float) motion.z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void encode(ClientMotionSyncMessage message, FriendlyByteBuf buffer) {
|
public static void encode(ClientMotionSyncMessage message, FriendlyByteBuf buffer) {
|
||||||
buffer.writeVarInt(message.id);
|
buffer.writeVarInt(message.id);
|
||||||
buffer.writeDouble(message.x);
|
buffer.writeFloat(message.x);
|
||||||
buffer.writeDouble(message.y);
|
buffer.writeFloat(message.y);
|
||||||
buffer.writeDouble(message.z);
|
buffer.writeFloat(message.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientMotionSyncMessage decode(FriendlyByteBuf buffer) {
|
public static ClientMotionSyncMessage decode(FriendlyByteBuf buffer) {
|
||||||
int id = buffer.readVarInt();
|
int id = buffer.readVarInt();
|
||||||
double x = buffer.readDouble();
|
double x = buffer.readFloat();
|
||||||
double y = buffer.readDouble();
|
double y = buffer.readFloat();
|
||||||
double z = buffer.readDouble();
|
double z = buffer.readFloat();
|
||||||
return new ClientMotionSyncMessage(id, new Vec3(x, y, z));
|
return new ClientMotionSyncMessage(id, new Vec3(x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue