实现projectile的发射物字段存储
This commit is contained in:
parent
46ecff5efa
commit
7db5683de1
8 changed files with 36 additions and 11 deletions
|
@ -99,6 +99,7 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
|
||||||
private float knockback = 0.05f;
|
private float knockback = 0.05f;
|
||||||
private boolean forceKnockback = false;
|
private boolean forceKnockback = false;
|
||||||
private final ArrayList<MobEffectInstance> mobEffects = new ArrayList<>();
|
private final ArrayList<MobEffectInstance> mobEffects = new ArrayList<>();
|
||||||
|
private String gunItemId;
|
||||||
|
|
||||||
public ProjectileEntity(EntityType<? extends ProjectileEntity> entityType, Level level) {
|
public ProjectileEntity(EntityType<? extends ProjectileEntity> entityType, Level level) {
|
||||||
super(entityType, level);
|
super(entityType, level);
|
||||||
|
@ -322,6 +323,10 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
|
||||||
|
|
||||||
this.beast = tag.getBoolean("Beast");
|
this.beast = tag.getBoolean("Beast");
|
||||||
this.forceKnockback = tag.getBoolean("ForceKnockback");
|
this.forceKnockback = tag.getBoolean("ForceKnockback");
|
||||||
|
|
||||||
|
if (tag.contains("GunId")) {
|
||||||
|
this.gunItemId = tag.getString("GunId");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -336,6 +341,10 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
|
||||||
|
|
||||||
tag.putBoolean("Beast", this.beast);
|
tag.putBoolean("Beast", this.beast);
|
||||||
tag.putBoolean("ForceKnockback", this.forceKnockback);
|
tag.putBoolean("ForceKnockback", this.forceKnockback);
|
||||||
|
|
||||||
|
if (this.gunItemId != null) {
|
||||||
|
tag.putString("GunId", this.gunItemId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -807,6 +816,11 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
|
||||||
return this.zoom;
|
return this.zoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getGunItemId() {
|
||||||
|
return this.gunItemId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builders
|
* Builders
|
||||||
*/
|
*/
|
||||||
|
@ -891,4 +905,14 @@ public class ProjectileEntity extends Projectile implements IEntityWithComplexSp
|
||||||
this.forceKnockback = true;
|
this.forceKnockback = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProjectileEntity setGunItemId(ItemStack stack) {
|
||||||
|
this.gunItemId = stack.getDescriptionId();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectileEntity setGunItemId(String id) {
|
||||||
|
this.gunItemId = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -567,7 +567,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
worldPositionLeft = transformPosition(transform, x, y, z);
|
worldPositionLeft = transformPosition(transform, x, y, z);
|
||||||
|
|
||||||
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
ProjectileEntity projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player);
|
ProjectileEntity projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player).setGunItemId(this.getType().getDescriptionId());
|
||||||
|
|
||||||
projectileRight.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z);
|
projectileRight.setPos(worldPositionRight.x, worldPositionRight.y, worldPositionRight.z);
|
||||||
projectileRight.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.018, this.getLookAngle().z, 20,
|
projectileRight.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.018, this.getLookAngle().z, 20,
|
||||||
|
@ -580,7 +580,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
ProjectileEntity projectileLeft = ((ProjectileWeapon) getWeapon(0)).create(player);
|
ProjectileEntity projectileLeft = ((ProjectileWeapon) getWeapon(0)).create(player).setGunItemId(this.getType().getDescriptionId());
|
||||||
|
|
||||||
projectileLeft.setPos(worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z);
|
projectileLeft.setPos(worldPositionLeft.x, worldPositionLeft.y, worldPositionLeft.z);
|
||||||
projectileLeft.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.018, this.getLookAngle().z, 20,
|
projectileLeft.shoot(player, this.getLookAngle().x, this.getLookAngle().y + 0.018, this.getLookAngle().z, 20,
|
||||||
|
|
|
@ -335,7 +335,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
|
||||||
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
||||||
|
|
||||||
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
var projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player);
|
var projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player).setGunItemId(this.getType().getDescriptionId());
|
||||||
|
|
||||||
projectileRight.bypassArmorRate(0.2f);
|
projectileRight.bypassArmorRate(0.2f);
|
||||||
projectileRight.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
projectileRight.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
||||||
|
|
|
@ -283,7 +283,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
|
||||||
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
||||||
|
|
||||||
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) {
|
||||||
var projectile = ((ProjectileWeapon) getWeapon(0)).create(player);
|
var projectile = ((ProjectileWeapon) getWeapon(0)).create(player).setGunItemId(this.getType().getDescriptionId());
|
||||||
|
|
||||||
projectile.bypassArmorRate(0.2f);
|
projectile.bypassArmorRate(0.2f);
|
||||||
projectile.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
projectile.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
||||||
|
|
|
@ -204,7 +204,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo
|
||||||
|
|
||||||
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
Vector4f worldPosition = transformPosition(transform, x, y, z);
|
||||||
|
|
||||||
var projectile = ((ProjectileWeapon) getWeapon(0)).create(player);
|
var projectile = ((ProjectileWeapon) getWeapon(0)).create(player).setGunItemId(this.getType().getDescriptionId());
|
||||||
|
|
||||||
projectile.bypassArmorRate(0.4f);
|
projectile.bypassArmorRate(0.4f);
|
||||||
projectile.setPos(worldPosition.x + 0.5 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z + 0.5 * this.getDeltaMovement().z);
|
projectile.setPos(worldPosition.x + 0.5 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z + 0.5 * this.getDeltaMovement().z);
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
|
|
||||||
if (reloadCoolDown > 0 && (
|
if (reloadCoolDown > 0 && (
|
||||||
(entityData.get(LOADED_AMMO_TYPE) == 0 && (hasCreativeAmmo || countItem(ModItems.AP_5_INCHES.get()) > 0)) ||
|
(entityData.get(LOADED_AMMO_TYPE) == 0 && (hasCreativeAmmo || countItem(ModItems.AP_5_INCHES.get()) > 0)) ||
|
||||||
(entityData.get(LOADED_AMMO_TYPE) == 1 && (hasCreativeAmmo || countItem(ModItems.HE_5_INCHES.get()) > 0))
|
(entityData.get(LOADED_AMMO_TYPE) == 1 && (hasCreativeAmmo || countItem(ModItems.HE_5_INCHES.get()) > 0))
|
||||||
)) {
|
)) {
|
||||||
reloadCoolDown--;
|
reloadCoolDown--;
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Level level = player.level();
|
Level level = player.level();
|
||||||
final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ());
|
final Vec3 center = new Vec3(this.getX(), this.getEyeY(), this.getZ());
|
||||||
|
|
||||||
|
@ -454,7 +453,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
Vector4f worldPosition = transformPosition(transform, -0.12f, 0.15f, 2f);
|
Vector4f worldPosition = transformPosition(transform, -0.12f, 0.15f, 2f);
|
||||||
|
|
||||||
if (this.entityData.get(MG_AMMO) > 0 || hasCreativeAmmo) {
|
if (this.entityData.get(MG_AMMO) > 0 || hasCreativeAmmo) {
|
||||||
var projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player);
|
var projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player).setGunItemId(this.getType().getDescriptionId() + ".1");
|
||||||
|
|
||||||
projectileRight.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
projectileRight.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
||||||
projectileRight.shoot(player, getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, 36,
|
projectileRight.shoot(player, getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, 36,
|
||||||
|
@ -499,7 +498,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
|
||||||
Vector4f worldPosition = transformPosition(transform, 0, -0.25f, 0);
|
Vector4f worldPosition = transformPosition(transform, 0, -0.25f, 0);
|
||||||
|
|
||||||
var projectile = (ProjectileWeapon) getWeapon(1);
|
var projectile = (ProjectileWeapon) getWeapon(1);
|
||||||
var projectileEntity = projectile.create(player);
|
var projectileEntity = projectile.create(player).setGunItemId(this.getType().getDescriptionId() + ".2");
|
||||||
|
|
||||||
projectileEntity.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
projectileEntity.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z);
|
||||||
projectileEntity.shoot(getGunnerVector(1).x, getGunnerVector(1).y + 0.005f, getGunnerVector(1).z, 20, 0.3f);
|
projectileEntity.shoot(getGunnerVector(1).x, getGunnerVector(1).y + 0.005f, getGunnerVector(1).z, 20, 0.3f);
|
||||||
|
|
|
@ -202,7 +202,8 @@ public class GunEventHandler {
|
||||||
.damage(perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? projectileAmount * damage : damage)
|
.damage(perk instanceof AmmoPerk ammoPerk && ammoPerk.slug ? projectileAmount * damage : damage)
|
||||||
.damage(damage)
|
.damage(damage)
|
||||||
.headShot(headshot)
|
.headShot(headshot)
|
||||||
.zoom(zoom);
|
.zoom(zoom)
|
||||||
|
.setGunItemId(stack);
|
||||||
|
|
||||||
if (perk instanceof AmmoPerk ammoPerk) {
|
if (perk instanceof AmmoPerk ammoPerk) {
|
||||||
int level = data.perk.getLevel(perk);
|
int level = data.perk.getLevel(perk);
|
||||||
|
|
|
@ -140,7 +140,8 @@ public record FireMessage(int msgType) implements CustomPacketPayload {
|
||||||
ProjectileEntity projectile = new ProjectileEntity(player.level())
|
ProjectileEntity projectile = new ProjectileEntity(player.level())
|
||||||
.shooter(player)
|
.shooter(player)
|
||||||
.headShot(headshot)
|
.headShot(headshot)
|
||||||
.zoom(zoom);
|
.zoom(zoom)
|
||||||
|
.setGunItemId(stack);
|
||||||
|
|
||||||
if (perk instanceof AmmoPerk ammoPerk) {
|
if (perk instanceof AmmoPerk ammoPerk) {
|
||||||
int level = data.perk.getLevel(perk);
|
int level = data.perk.getLevel(perk);
|
||||||
|
|
Loading…
Add table
Reference in a new issue