调整Ivehicle

This commit is contained in:
Atsuihsio 2024-12-20 13:49:57 +08:00
parent 9108bdea0b
commit 8910859785
7 changed files with 53 additions and 6 deletions

View file

@ -541,6 +541,11 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
return (int)MAX_ENERGY; return (int)MAX_ENERGY;
} }
@Override
public void vehicleShoot(Player player) {
}
@Override @Override
public float getHealth() { public float getHealth() {
return this.entityData.get(HEALTH).intValue(); return this.entityData.get(HEALTH).intValue();
@ -565,4 +570,9 @@ public class AnnihilatorEntity extends Entity implements GeoEntity, ICannonEntit
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
return true; return true;
} }
@Override
public int getAmmoCount() {
return 0;
}
} }

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.entity; package com.atsuishio.superbwarfare.entity;
import net.minecraft.world.entity.player.Player;
public interface ICannonEntity extends IVehicleEntity { public interface ICannonEntity extends IVehicleEntity {
float getHealth(); void cannonShoot(Player player);
float getMaxHealth();
} }

View file

@ -3,10 +3,11 @@ package com.atsuishio.superbwarfare.entity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
public interface IVehicleEntity { public interface IVehicleEntity {
void cannonShoot(Player player); void vehicleShoot(Player player);
float getHealth(); float getHealth();
float getMaxHealth(); float getMaxHealth();
boolean isDriver(Player player); boolean isDriver(Player player);
int mainGunRpm(); int mainGunRpm();
boolean canShoot(Player player); boolean canShoot(Player player);
int getAmmoCount();
} }

View file

@ -421,6 +421,11 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
return this.cache; return this.cache;
} }
@Override
public void vehicleShoot(Player player) {
}
@Override @Override
public float getHealth() { public float getHealth() {
return this.entityData.get(HEALTH).intValue(); return this.entityData.get(HEALTH).intValue();
@ -445,4 +450,9 @@ public class Mk42Entity extends Entity implements GeoEntity, ICannonEntity {
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
return true; return true;
} }
@Override
public int getAmmoCount() {
return 0;
}
} }

View file

@ -516,6 +516,11 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
return this.cache; return this.cache;
} }
@Override
public void vehicleShoot(Player player) {
}
@Override @Override
public float getHealth() { public float getHealth() {
return this.entityData.get(HEALTH).intValue(); return this.entityData.get(HEALTH).intValue();
@ -540,4 +545,9 @@ public class Mle1934Entity extends Entity implements GeoEntity, ICannonEntity {
public boolean canShoot(Player player) { public boolean canShoot(Player player) {
return true; return true;
} }
@Override
public int getAmmoCount() {
return 0;
}
} }

View file

@ -84,7 +84,6 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity { public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity, IVehicleEntity, HasCustomInventoryScreen, ContainerEntity {
public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> ENERGY = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
@ -94,6 +93,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
public static final EntityDataAccessor<Float> ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> ROTOR = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> HEAT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.STRING); protected static final EntityDataAccessor<String> LAST_ATTACKER_UUID = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Integer> AMMO = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT);
public static final float MAX_HEALTH = CannonConfig.SPEEDBOAT_HP.get(); public static final float MAX_HEALTH = CannonConfig.SPEEDBOAT_HP.get();
public static final float MAX_ENERGY = CannonConfig.SPEEDBOAT_MAX_ENERGY.get().floatValue(); public static final float MAX_ENERGY = CannonConfig.SPEEDBOAT_MAX_ENERGY.get().floatValue();
@ -127,6 +127,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
@Override @Override
protected void defineSynchedData() { protected void defineSynchedData() {
this.entityData.define(AMMO, 0);
this.entityData.define(FIRE_ANIM, 0); this.entityData.define(FIRE_ANIM, 0);
this.entityData.define(HEALTH, MAX_HEALTH); this.entityData.define(HEALTH, MAX_HEALTH);
this.entityData.define(ENERGY, 0f); this.entityData.define(ENERGY, 0f);
@ -309,6 +310,10 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
cannotFire = false; cannotFire = false;
} }
// TODO 获取弹药数量
this.entityData.set(AMMO, this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).count());
turretYRotO = this.getTurretYRot(); turretYRotO = this.getTurretYRot();
turretXRotO = this.getTurretXRot(); turretXRotO = this.getTurretXRot();
@ -373,7 +378,7 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
* 机枪塔开火 * 机枪塔开火
*/ */
@Override @Override
public void cannonShoot(Player player) { public void vehicleShoot(Player player) {
if (this.cannotFire) return; if (this.cannotFire) return;
ProjectileEntity projectile = new ProjectileEntity(player.level()) ProjectileEntity projectile = new ProjectileEntity(player.level())
@ -921,4 +926,9 @@ public class SpeedboatEntity extends Entity implements GeoEntity, IChargeEntity,
&& !player.getMainHandItem().is(ModTags.Items.GUN) && !player.getMainHandItem().is(ModTags.Items.GUN)
&& !cannotFire; && !cannotFire;
} }
@Override
public int getAmmoCount() {
return 0;
}
} }

View file

@ -1,5 +1,6 @@
package com.atsuishio.superbwarfare.network.message; package com.atsuishio.superbwarfare.network.message;
import com.atsuishio.superbwarfare.entity.ICannonEntity;
import com.atsuishio.superbwarfare.entity.IVehicleEntity; import com.atsuishio.superbwarfare.entity.IVehicleEntity;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
@ -34,9 +35,13 @@ public class VehicleFireMessage {
return; return;
} }
if (player.getVehicle() instanceof IVehicleEntity entity) { if (player.getVehicle() instanceof ICannonEntity entity) {
entity.cannonShoot(player); entity.cannonShoot(player);
} }
if (player.getVehicle() instanceof IVehicleEntity iVehicle && !(player.getVehicle() instanceof ICannonEntity)) {
iVehicle.vehicleShoot(player);
}
} }
}); });
context.setPacketHandled(true); context.setPacketHandled(true);