提取ProjectileType

This commit is contained in:
Light_Quanta 2025-05-12 23:44:34 +08:00
parent 535e7a1305
commit 6340223db3
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
24 changed files with 288 additions and 111 deletions

View file

@ -1,4 +1,4 @@
package com.atsuishio.superbwarfare.entity.projectile; package com.atsuishio.superbwarfare.entity.projectile;
public interface AerialBombEntity { public interface AerialBombEntity extends ExplosiveProjectile {
} }

View file

@ -49,7 +49,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.List; import java.util.List;
public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(Agm65Entity.class, EntityDataSerializers.STRING);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -292,4 +292,20 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, D
public float getVolume() { public float getVolume() {
return 0.7f; return 0.7f;
} }
// TODO setter
@Override
public void setDamage(float damage) {
}
@Override
public void setExplosionDamage(float explosionDamage) {
}
@Override
public void setExplosionRadius(float radius) {
}
} }

View file

@ -42,7 +42,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { public class CannonShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float damage = 0; private float damage = 0;
@ -336,7 +336,7 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
} }
@Override @Override
public SoundEvent getSound() { public @NotNull SoundEvent getSound() {
return ModSounds.SHELL_FLY.get(); return ModSounds.SHELL_FLY.get();
} }
@ -344,4 +344,19 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
public float getVolume() { public float getVolume() {
return 0.07f; return 0.07f;
} }
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public void setExplosionDamage(float damage) {
this.explosionDamage = damage;
}
@Override
public void setExplosionRadius(float radius) {
this.radius = radius;
}
} }

View file

@ -0,0 +1,9 @@
package com.atsuishio.superbwarfare.entity.projectile;
public interface ExplosiveProjectile {
void setDamage(float damage);
void setExplosionDamage(float explosionDamage);
void setExplosionRadius(float radius);
}

View file

@ -29,7 +29,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEntity { public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile {
private float monsterMultiplier = 0.0f; private float monsterMultiplier = 0.0f;
private float damage = 40.0f; private float damage = 40.0f;
@ -50,14 +50,17 @@ public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEnti
this.explosionRadius = explosionRadius; this.explosionRadius = explosionRadius;
} }
@Override
public void setDamage(float damage) { public void setDamage(float damage) {
this.damage = damage; this.damage = damage;
} }
@Override
public void setExplosionDamage(float explosionDamage) { public void setExplosionDamage(float explosionDamage) {
this.explosionDamage = explosionDamage; this.explosionDamage = explosionDamage;
} }
@Override
public void setExplosionRadius(float explosionRadius) { public void setExplosionRadius(float explosionRadius) {
this.explosionRadius = explosionRadius; this.explosionRadius = explosionRadius;
} }

View file

@ -31,7 +31,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class HandGrenadeEntity extends FastThrowableProjectile implements GeoEntity { public class HandGrenadeEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile {
private int fuse = 100; private int fuse = 100;
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -151,4 +151,20 @@ public class HandGrenadeEntity extends FastThrowableProjectile implements GeoEnt
protected double getDefaultGravity() { protected double getDefaultGravity() {
return 0.07F; return 0.07F;
} }
// TODO setter
@Override
public void setDamage(float damage) {
}
@Override
public void setExplosionDamage(float explosionDamage) {
}
@Override
public void setExplosionRadius(float radius) {
}
} }

View file

@ -34,7 +34,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class HeliRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { public class HeliRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float damage = 140f; private float damage = 140f;
@ -166,12 +166,12 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
} }
@Override @Override
public SoundEvent getCloseSound() { public @NotNull SoundEvent getCloseSound() {
return ModSounds.ROCKET_ENGINE.get(); return ModSounds.ROCKET_ENGINE.get();
} }
@Override @Override
public SoundEvent getSound() { public @NotNull SoundEvent getSound() {
return ModSounds.ROCKET_FLY.get(); return ModSounds.ROCKET_FLY.get();
} }
@ -179,4 +179,19 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
public float getVolume() { public float getVolume() {
return 0.1f; return 0.1f;
} }
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public void setExplosionDamage(float damage) {
this.explosionDamage = damage;
}
@Override
public void setExplosionRadius(float radius) {
this.explosionRadius = radius;
}
} }

View file

@ -50,7 +50,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.List; import java.util.List;
public class JavelinMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { public class JavelinMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Boolean> TOP = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> TOP = SynchedEntityData.defineId(JavelinMissileEntity.class, EntityDataSerializers.BOOLEAN);
@ -388,4 +388,19 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
public float getVolume() { public float getVolume() {
return 0.4f; return 0.4f;
} }
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public void setExplosionDamage(float damage) {
this.explosion_damage = damage;
}
@Override
public void setExplosionRadius(float radius) {
this.explosion_radius = radius;
}
} }

View file

@ -19,6 +19,7 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
// TODO 配置文件
public class MelonBombEntity extends FastThrowableProjectile implements DestroyableProjectileEntity, AerialBombEntity { public class MelonBombEntity extends FastThrowableProjectile implements DestroyableProjectileEntity, AerialBombEntity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(MelonBombEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(MelonBombEntity.class, EntityDataSerializers.FLOAT);
@ -108,4 +109,19 @@ public class MelonBombEntity extends FastThrowableProjectile implements Destroya
protected double getDefaultGravity() { protected double getDefaultGravity() {
return 0.05F; return 0.05F;
} }
@Override
public void setDamage(float damage) {
}
@Override
public void setExplosionDamage(float damage) {
}
@Override
public void setExplosionRadius(float radius) {
}
} }

View file

@ -162,4 +162,20 @@ public class Mk82Entity extends FastThrowableProjectile implements GeoEntity, De
public boolean shouldSyncMotion() { public boolean shouldSyncMotion() {
return true; return true;
} }
// TODO setter
@Override
public void setDamage(float damage) {
}
@Override
public void setExplosionDamage(float damage) {
}
@Override
public void setExplosionRadius(float radius) {
}
} }

View file

@ -47,9 +47,9 @@ import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
public class MortarShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { public class MortarShellEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile {
private float damage = 50;
private float damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); private float explosionDamage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get();
private int life = 600; private int life = 600;
private float radius = ExplosionConfig.MORTAR_SHELL_EXPLOSION_RADIUS.get(); private float radius = ExplosionConfig.MORTAR_SHELL_EXPLOSION_RADIUS.get();
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -72,14 +72,14 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
super(ModEntities.MORTAR_SHELL.get(), entity, level); super(ModEntities.MORTAR_SHELL.get(), entity, level);
} }
public MortarShellEntity(LivingEntity entity, Level world, float damage) { public MortarShellEntity(LivingEntity entity, Level world, float explosionDamage) {
super(ModEntities.MORTAR_SHELL.get(), entity, world); super(ModEntities.MORTAR_SHELL.get(), entity, world);
this.damage = damage; this.explosionDamage = explosionDamage;
} }
public MortarShellEntity(LivingEntity entity, Level world, float damage, float radius) { public MortarShellEntity(LivingEntity entity, Level world, float explosionDamage, float radius) {
super(ModEntities.MORTAR_SHELL.get(), entity, world); super(ModEntities.MORTAR_SHELL.get(), entity, world);
this.damage = damage; this.explosionDamage = explosionDamage;
this.radius = radius; this.radius = radius;
} }
@ -100,7 +100,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
@Override @Override
public void addAdditionalSaveData(@NotNull CompoundTag pCompound) { public void addAdditionalSaveData(@NotNull CompoundTag pCompound) {
super.addAdditionalSaveData(pCompound); super.addAdditionalSaveData(pCompound);
pCompound.putFloat("Damage", this.damage); pCompound.putFloat("Damage", this.explosionDamage);
pCompound.putInt("Life", this.life); pCompound.putInt("Life", this.life);
pCompound.putFloat("Radius", this.radius); pCompound.putFloat("Radius", this.radius);
@ -129,9 +129,9 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
public void readAdditionalSaveData(@NotNull CompoundTag pCompound) { public void readAdditionalSaveData(@NotNull CompoundTag pCompound) {
super.readAdditionalSaveData(pCompound); super.readAdditionalSaveData(pCompound);
if (pCompound.contains("Damage")) { if (pCompound.contains("Damage")) {
this.damage = pCompound.getFloat("Damage"); this.explosionDamage = pCompound.getFloat("Damage");
} else { } else {
this.damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); this.explosionDamage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get();
} }
if (pCompound.contains("Life")) { if (pCompound.contains("Life")) {
@ -233,7 +233,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this, this,
this.getOwner()), this.getOwner()),
damage, explosionDamage,
vec3.x, vec3.x,
vec3.y, vec3.y,
vec3.z, vec3.z,
@ -276,7 +276,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
for (MobEffectInstance effect : this.effects) { for (MobEffectInstance effect : this.effects) {
cloud.addEffect(effect); cloud.addEffect(effect);
} }
cloud.setDuration((int) this.damage); cloud.setDuration((int) this.explosionDamage);
cloud.setRadius(this.radius); cloud.setRadius(this.radius);
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
cloud.setOwner(living); cloud.setOwner(living);
@ -285,7 +285,7 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
} }
@Override @Override
public SoundEvent getSound() { public @NotNull SoundEvent getSound() {
return ModSounds.SHELL_FLY.get(); return ModSounds.SHELL_FLY.get();
} }
@ -293,4 +293,19 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
public float getVolume() { public float getVolume() {
return 0.06f; return 0.06f;
} }
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public void setExplosionDamage(float explosionDamage) {
this.explosionDamage = explosionDamage;
}
@Override
public void setExplosionRadius(float radius) {
this.radius = radius;
}
} }

View file

@ -32,7 +32,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class RgoGrenadeEntity extends FastThrowableProjectile implements GeoEntity { public class RgoGrenadeEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile {
private int fuse = 80; private int fuse = 80;
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -138,4 +138,18 @@ public class RgoGrenadeEntity extends FastThrowableProjectile implements GeoEnti
this.xRotO = this.getXRot(); this.xRotO = this.getXRot();
} }
// TODO setter
@Override
public void setDamage(float damage) {
}
@Override
public void setExplosionDamage(float explosionDamage) {
}
@Override
public void setExplosionRadius(float radius) {
}
} }

View file

@ -32,7 +32,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.*; import software.bernie.geckolib.animation.*;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity { public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntity, LoudlyEntity, ExplosiveProjectile {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -67,14 +67,18 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit
this.explosionRadius = explosionRadius; this.explosionRadius = explosionRadius;
} }
public void setExplosionRadius(float explosionRadius) {
this.explosionRadius = explosionRadius;
}
@Override
public void setDamage(float damage) { public void setDamage(float damage) {
this.damage = damage; this.damage = damage;
} }
@Override
public void setExplosionRadius(float explosionRadius) {
this.explosionRadius = explosionRadius;
}
@Override
public void setExplosionDamage(float explosionDamage) { public void setExplosionDamage(float explosionDamage) {
this.explosionDamage = explosionDamage; this.explosionDamage = explosionDamage;
} }

View file

@ -34,7 +34,7 @@ import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.animation.AnimatableManager;
import software.bernie.geckolib.util.GeckoLibUtil; import software.bernie.geckolib.util.GeckoLibUtil;
public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity { public class SmallCannonShellEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile {
private float damage = 40.0f; private float damage = 40.0f;
private float explosionDamage = 80f; private float explosionDamage = 80f;
private float explosionRadius = 5f; private float explosionRadius = 5f;
@ -172,4 +172,19 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
public AnimatableInstanceCache getAnimatableInstanceCache() { public AnimatableInstanceCache getAnimatableInstanceCache() {
return this.cache; return this.cache;
} }
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public void setExplosionDamage(float explosionDamage) {
this.explosionDamage = explosionDamage;
}
@Override
public void setExplosionRadius(float radius) {
this.explosionRadius = radius;
}
} }

View file

@ -45,7 +45,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.List; import java.util.List;
public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile {
public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor<String> TARGET_UUID = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.STRING);
public static final EntityDataAccessor<Float> TARGET_X = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> TARGET_X = SynchedEntityData.defineId(SwarmDroneEntity.class, EntityDataSerializers.FLOAT);
@ -291,7 +291,7 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti
} }
@Override @Override
public SoundEvent getSound() { public @NotNull SoundEvent getSound() {
return ModSounds.DRONE_SOUND.get(); return ModSounds.DRONE_SOUND.get();
} }
@ -299,4 +299,18 @@ public class SwarmDroneEntity extends FastThrowableProjectile implements GeoEnti
public float getVolume() { public float getVolume() {
return 0.07f; return 0.07f;
} }
@Override
public void setDamage(float damage) {
}
@Override
public void setExplosionDamage(float explosionDamage) {
this.explosionDamage = explosionDamage;
}
@Override
public void setExplosionRadius(float radius) {
this.explosionRadius = radius;
}
} }

View file

@ -44,7 +44,7 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity { public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, DestroyableProjectileEntity, LoudlyEntity, ExplosiveProjectile {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(WgMissileEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(WgMissileEntity.class, EntityDataSerializers.FLOAT);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
@ -238,12 +238,12 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
} }
@Override @Override
public SoundEvent getCloseSound() { public @NotNull SoundEvent getCloseSound() {
return ModSounds.ROCKET_ENGINE.get(); return ModSounds.ROCKET_ENGINE.get();
} }
@Override @Override
public SoundEvent getSound() { public @NotNull SoundEvent getSound() {
return ModSounds.ROCKET_FLY.get(); return ModSounds.ROCKET_FLY.get();
} }
@ -251,4 +251,19 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
public float getVolume() { public float getVolume() {
return 0.4f; return 0.4f;
} }
@Override
public void setDamage(float damage) {
this.damage = damage;
}
@Override
public void setExplosionDamage(float explosionDamage) {
this.explosionDamage = explosionDamage;
}
@Override
public void setExplosionRadius(float radius) {
this.explosionRadius = radius;
}
} }

View file

@ -3,6 +3,7 @@ package com.atsuishio.superbwarfare.item.gun;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.PoseTool; import com.atsuishio.superbwarfare.client.PoseTool;
import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.GunImageComponent;
import com.atsuishio.superbwarfare.entity.projectile.ExplosiveProjectile;
import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity;
import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModAttachments;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
@ -25,11 +26,13 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlotGroup; import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.Projectile;
import net.minecraft.world.inventory.tooltip.TooltipComponent; import net.minecraft.world.inventory.tooltip.TooltipComponent;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -45,6 +48,7 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.ParametersAreNonnullByDefault;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer; import java.util.function.Consumer;
@EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD) @EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD)
@ -563,19 +567,40 @@ public abstract class GunItem extends Item implements CustomRendererItem {
*/ */
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
var stack = data.stack; var stack = data.stack;
var level = player.level();
float headshot = (float) data.headshot(); float headshot = (float) data.headshot();
float damage = (float) data.damage(); float damage = (float) data.damage();
float velocity = (float) data.velocity(); float velocity = (float) data.velocity();
float bypassArmorRate = (float) data.bypassArmor(); float bypassArmorRate = (float) data.bypassArmor();
ProjectileEntity projectile = new ProjectileEntity(player.level()) var projectileType = data.projectileType();
.shooter(player) AtomicReference<Projectile> projectileHolder = new AtomicReference<>();
.damage(damage) EntityType.byString(projectileType).ifPresent(entityType -> {
.headShot(headshot) var entity = entityType.create(level);
.zoom(zoom) if (!(entity instanceof Projectile)) return;
.bypassArmorRate(bypassArmorRate) ((Projectile) entity).setOwner(player);
.setGunItemId(stack);
if (entity instanceof ProjectileEntity projectile) {
projectile.shooter(player)
.damage(damage)
.headShot(headshot)
.zoom(zoom)
.bypassArmorRate(bypassArmorRate)
.setGunItemId(stack);
}
if (entity instanceof ExplosiveProjectile explosive) {
explosive.setDamage(damage);
explosive.setExplosionDamage((float) data.explosionDamage());
explosive.setExplosionRadius((float) data.explosionRadius());
}
projectileHolder.set((Projectile) entity);
});
var projectile = projectileHolder.get();
if (projectile == null) return false;
for (Perk.Type type : Perk.Type.values()) { for (Perk.Type type : Perk.Type.values()) {
var instance = data.perk.getInstance(type); var instance = data.perk.getInstance(type);
@ -588,8 +613,8 @@ public abstract class GunItem extends Item implements CustomRendererItem {
} }
projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z); projectile.setPos(player.getX() - 0.1 * player.getLookAngle().x, player.getEyeY() - 0.1 - 0.1 * player.getLookAngle().y, player.getZ() + -0.1 * player.getLookAngle().z);
projectile.shoot(player, player.getLookAngle().x, player.getLookAngle().y + 0.001f, player.getLookAngle().z, velocity, (float) spread); projectile.shoot(player.getLookAngle().x, player.getLookAngle().y + 0.001f, player.getLookAngle().z, velocity, (float) spread);
player.level().addFreshEntity(projectile); level.addFreshEntity(projectile);
return true; return true;
} }

View file

@ -29,6 +29,10 @@ public class DefaultGunData {
public double velocity; public double velocity;
@SerializedName("Magazine") @SerializedName("Magazine")
public int magazine; public int magazine;
@SerializedName("ProjectileType")
public String projectileType = "superbwarfare:projectile";
@SerializedName("ProjectileAmount") @SerializedName("ProjectileAmount")
public int projectileAmount = 1; public int projectileAmount = 1;
@SerializedName("Weight") @SerializedName("Weight")

View file

@ -187,6 +187,10 @@ public class GunData {
return magazine() <= 0; return magazine() <= 0;
} }
public String projectileType() {
return defaultGunData().projectileType;
}
public int projectileAmount() { public int projectileAmount() {
return defaultGunData().projectileAmount; return defaultGunData().projectileAmount;
} }

View file

@ -3,13 +3,10 @@ package com.atsuishio.superbwarfare.item.gun.launcher;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.M79ItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.M79ItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
import com.atsuishio.superbwarfare.entity.projectile.GunGrenadeEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -103,6 +100,7 @@ public class M79Item extends GunItem implements GeoItem {
public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) { public @NotNull Optional<TooltipComponent> getTooltipImage(@NotNull ItemStack pStack) {
return Optional.of(new LauncherImageComponent(pStack)); return Optional.of(new LauncherImageComponent(pStack));
} }
@Override @Override
public String getAmmoDisplayName(GunData data) { public String getAmmoDisplayName(GunData data) {
return "40mm Grenade"; return "40mm Grenade";
@ -110,37 +108,12 @@ public class M79Item extends GunItem implements GeoItem {
@Override @Override
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
if (data.reloading()) return false; if (!super.shootBullet(player, data, spread, zoom)) return false;
if (player.level() instanceof ServerLevel serverLevel) { ParticleTool.sendParticle((ServerLevel) player.level(), ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,
GunGrenadeEntity gunGrenadeEntity = new GunGrenadeEntity(player, serverLevel, player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
(float) data.damage(), player.getZ() + 1.8 * player.getLookAngle().z,
(float) data.explosionDamage(), 4, 0.1, 0.1, 0.1, 0.002, true);
(float) data.explosionRadius()
);
float velocity = (float) data.velocity();
for (Perk.Type type : Perk.Type.values()) {
var instance = data.perk.getInstance(type);
if (instance != null) {
instance.perk().modifyProjectile(data, instance, gunGrenadeEntity);
if (instance.perk() instanceof AmmoPerk ammoPerk) {
velocity = (float) ammoPerk.getModifiedVelocity(data, instance);
}
}
}
gunGrenadeEntity.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
gunGrenadeEntity.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity,
(float) (zoom ? 0.1 : spread));
serverLevel.addFreshEntity(gunGrenadeEntity);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,
player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
player.getZ() + 1.8 * player.getLookAngle().z,
4, 0.1, 0.1, 0.1, 0.002, true);
}
return true; return true;
} }

View file

@ -3,13 +3,10 @@ package com.atsuishio.superbwarfare.item.gun.launcher;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.renderer.item.RpgItemRenderer; import com.atsuishio.superbwarfare.client.renderer.item.RpgItemRenderer;
import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent; import com.atsuishio.superbwarfare.client.tooltip.component.LauncherImageComponent;
import com.atsuishio.superbwarfare.entity.projectile.RpgRocketEntity;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.GunItem;
import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.AmmoPerk;
import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
@ -134,40 +131,13 @@ public class RpgItem extends GunItem implements GeoItem {
@Override @Override
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
Level level = player.level(); if (!super.shootBullet(player, data, spread, zoom)) return false;
if (data.reloading()) return false; ParticleTool.sendParticle((ServerLevel) player.level(), ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,
player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
player.getZ() + 1.8 * player.getLookAngle().z,
30, 0.4, 0.4, 0.4, 0.005, true);
if (player.level() instanceof ServerLevel serverLevel) {
RpgRocketEntity rocket = new RpgRocketEntity(player, level,
(float) data.damage(),
(float) data.explosionDamage(),
(float) data.explosionRadius()
);
float velocity = (float) data.velocity();
for (Perk.Type type : Perk.Type.values()) {
var instance = data.perk.getInstance(type);
if (instance != null) {
instance.perk().modifyProjectile(data, instance, rocket);
if (instance.perk() instanceof AmmoPerk ammoPerk) {
velocity = (float) ammoPerk.getModifiedVelocity(data, instance);
}
}
}
rocket.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
rocket.shoot(player.getLookAngle().x, player.getLookAngle().y, player.getLookAngle().z, velocity,
(float) (zoom ? 0.1 : spread));
level.addFreshEntity(rocket);
ParticleTool.sendParticle(serverLevel, ParticleTypes.CLOUD, player.getX() + 1.8 * player.getLookAngle().x,
player.getY() + player.getBbHeight() - 0.1 + 1.8 * player.getLookAngle().y,
player.getZ() + 1.8 * player.getLookAngle().z,
30, 0.4, 0.4, 0.4, 0.005, true);
}
data.isEmpty.set(true); data.isEmpty.set(true);
data.closeHammer.set(true); data.closeHammer.set(true);

View file

@ -215,6 +215,7 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag
return "40mm Grenade"; return "40mm Grenade";
} }
// TODO 这玩意能提取吗
@Override @Override
public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) { public boolean shootBullet(Player player, GunData data, double spread, boolean zoom) {
if (data.reloading()) return false; if (data.reloading()) return false;

View file

@ -3,6 +3,7 @@
"RecoilX": 0.004, "RecoilX": 0.004,
"RecoilY": 0.023, "RecoilY": 0.023,
"Damage": 40, "Damage": 40,
"ProjectileType": "superbwarfare:gun_grenade",
"ExplosionDamage": 80, "ExplosionDamage": 80,
"ExplosionRadius": 5, "ExplosionRadius": 5,
"Velocity": 3.75, "Velocity": 3.75,

View file

@ -3,6 +3,7 @@
"RecoilX": 0.008, "RecoilX": 0.008,
"RecoilY": 0.018, "RecoilY": 0.018,
"Damage": 270, "Damage": 270,
"ProjectileType": "superbwarfare:rpg_rocket",
"ExplosionDamage": 130, "ExplosionDamage": 130,
"ExplosionRadius": 10, "ExplosionRadius": 10,
"Velocity": 4, "Velocity": 4,