From 39ca3a253709cc2d718d49fd3d9e16f7548560b8 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 10 Mar 2025 00:44:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E6=8F=90=E5=8F=96=E6=AD=A6?= =?UTF-8?q?=E5=99=A8=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Yx100Entity.java | 76 +++++++++---------- .../vehicle/weapon/CannonShellWeapon.java | 56 ++++++++++++++ .../vehicle/weapon/ProjectileWeapon.java | 38 ++++++++++ .../entity/vehicle/weapon/VehicleWeapon.java | 2 +- 4 files changed, 131 insertions(+), 41 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/CannonShellWeapon.java create mode 100644 src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/ProjectileWeapon.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index c8b0c3c2e..7bb19aa47 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -3,12 +3,12 @@ package com.atsuishio.superbwarfare.entity.vehicle; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; -import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; -import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; +import com.atsuishio.superbwarfare.entity.vehicle.weapon.CannonShellWeapon; +import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; @@ -117,11 +117,33 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti // TODO 正确实现武器创建 return new VehicleWeapon[][]{ new VehicleWeapon[]{ - new VehicleWeapon().sound(ModSounds.INTO_MISSILE.get()), - new VehicleWeapon().sound(ModSounds.INTO_CANNON.get()), + // AP + new CannonShellWeapon() + .hitDamage(500) + .explosionRadius(4) + .explosionDamage(100) + .fireProbability(0) + .fireTime(0) + .durability(60) + .velocity(40) + .sound(ModSounds.INTO_MISSILE.get()), + // HE + new CannonShellWeapon() + .hitDamage(100) + .explosionRadius(10) + .explosionDamage(150) + .fireProbability(0.18F) + .fireTime(2) + .durability(1) + .sound(ModSounds.INTO_CANNON.get()), }, new VehicleWeapon[]{ - new VehicleWeapon(), + // 机枪 + new ProjectileWeapon() + .damage(VehicleConfig.SPEEDBOAT_GUN_DAMAGE.get()) + .headShot(2) + .zoom(false) + .bypassArmorRate(0.4f), } }; } @@ -344,37 +366,14 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public void vehicleShoot(Player player, int type) { if (reloadCoolDown == 0 && type == 0) { Matrix4f transform = getBarrelTransform(); - float hitDamage, explosionRadius, explosionDamage, fireProbability; - int fireTime, durability; - float v; - - if (getWeaponType(0) == 0) { - hitDamage = 500; - explosionRadius = 4; - explosionDamage = 100; - fireProbability = 0; - fireTime = 0; - durability = 60; - v = 40; - } else if (getWeaponType(0) == 1) { - hitDamage = 100; - explosionRadius = 10; - explosionDamage = 150; - fireProbability = 0.18F; - fireTime = 2; - durability = 1; - v = 25; - } else { - throw new IllegalStateException("Unexpected value: " + getWeaponType(0)); - } Vector4f worldPosition = transformPosition(transform, 0, 0, 0); - CannonShellEntity entityToSpawn = new CannonShellEntity(player, level(), hitDamage, explosionRadius, explosionDamage, fireProbability, fireTime) - .durability(durability); + var cannonShell = (CannonShellWeapon) getWeapon(0); + var entityToSpawn = cannonShell.create(player, level()); entityToSpawn.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); - entityToSpawn.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, v, 0.02f); + entityToSpawn.shoot(getBarrelVector(1).x, getBarrelVector(1).y + 0.005f, getBarrelVector(1).z, cannonShell.velocity, 0.02f); level().addFreshEntity(entityToSpawn); if (!player.level().isClientSide) { @@ -451,16 +450,13 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti Matrix4f transform = getGunTransform(); Vector4f worldPosition = transformPosition(transform, 0, -0.25f, 0); - ProjectileEntity projectile = new ProjectileEntity(player.level()) - .shooter(player) - .damage(VehicleConfig.SPEEDBOAT_GUN_DAMAGE.get()) - .headShot(2f) - .zoom(false); + var projectile = (ProjectileWeapon) getWeapon(1); + var projectileEntity = projectile.create(player); - projectile.bypassArmorRate(0.4f); - projectile.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); - projectile.shoot(getGunVector(1).x, getGunVector(1).y + 0.005f, getGunVector(1).z, 20, 0.3f); - this.level().addFreshEntity(projectile); + projectileEntity.setPos(worldPosition.x - 1.1 * this.getDeltaMovement().x, worldPosition.y, worldPosition.z - 1.1 * this.getDeltaMovement().z); + projectileEntity.shoot(getGunVector(1).x, getGunVector(1).y + 0.005f, getGunVector(1).z, 20, 0.3f); + + this.level().addFreshEntity(projectileEntity); float pitch = this.entityData.get(MACHINE_GUN_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - this.entityData.get(MACHINE_GUN_HEAT))); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/CannonShellWeapon.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/CannonShellWeapon.java new file mode 100644 index 000000000..1d0775673 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/CannonShellWeapon.java @@ -0,0 +1,56 @@ +package com.atsuishio.superbwarfare.entity.vehicle.weapon; + +import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.Level; + +public class CannonShellWeapon extends VehicleWeapon { + public float hitDamage, explosionRadius, explosionDamage, fireProbability, velocity; + public int fireTime, durability; + + public CannonShellWeapon hitDamage(float hitDamage) { + this.hitDamage = hitDamage; + return this; + } + + public CannonShellWeapon explosionRadius(float explosionRadius) { + this.explosionRadius = explosionRadius; + return this; + } + + public CannonShellWeapon explosionDamage(float explosionDamage) { + this.explosionDamage = explosionDamage; + return this; + } + + public CannonShellWeapon fireProbability(float fireProbability) { + this.fireProbability = fireProbability; + return this; + } + + public CannonShellWeapon velocity(float velocity) { + this.velocity = velocity; + return this; + } + + public CannonShellWeapon fireTime(int fireTime) { + this.fireTime = fireTime; + return this; + } + + public CannonShellWeapon durability(int durability) { + this.durability = durability; + return this; + } + + public CannonShellEntity create(Player player, Level level) { + return new CannonShellEntity(player, + level, + this.hitDamage, + this.explosionRadius, + this.explosionDamage, + this.fireProbability, + this.fireTime + ).durability(this.durability); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/ProjectileWeapon.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/ProjectileWeapon.java new file mode 100644 index 000000000..41f32b0f4 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/ProjectileWeapon.java @@ -0,0 +1,38 @@ +package com.atsuishio.superbwarfare.entity.vehicle.weapon; + +import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; +import net.minecraft.world.entity.LivingEntity; + +public class ProjectileWeapon extends VehicleWeapon { + public float headShot, damage, bypassArmorRate; + public boolean zoom; + + public ProjectileWeapon headShot(float headShot) { + this.headShot = headShot; + return this; + } + + public ProjectileWeapon damage(float damage) { + this.damage = damage; + return this; + } + + public ProjectileWeapon bypassArmorRate(float bypassArmorRate) { + this.bypassArmorRate = bypassArmorRate; + return this; + } + + public ProjectileWeapon zoom(boolean zoom) { + this.zoom = zoom; + return this; + } + + public ProjectileEntity create(LivingEntity shooter) { + return new ProjectileEntity(shooter.level()) + .shooter(shooter) + .headShot(headShot) + .damage(damage) + .bypassArmorRate(bypassArmorRate) + .zoom(zoom); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java index 415fb25e4..9ba4cdb3a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java @@ -5,7 +5,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.ItemStack; -public class VehicleWeapon { +public abstract class VehicleWeapon { // 武器的图标 public ResourceLocation icon;