提高所有弹射物的穿透性(恼

This commit is contained in:
Atsuishio 2025-06-17 15:19:50 +08:00 committed by Light_Quanta
parent 1555e1f785
commit 8bccd8426b
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
12 changed files with 552 additions and 292 deletions

View file

@ -32,10 +32,9 @@ import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
@ -59,6 +58,8 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
private float explosionRadius = ExplosionConfig.AGM_65_EXPLOSION_RADIUS.get().floatValue(); private float explosionRadius = ExplosionConfig.AGM_65_EXPLOSION_RADIUS.get().floatValue();
private boolean distracted = false; private boolean distracted = false;
private int durability = 100;
public Agm65Entity(EntityType<? extends Agm65Entity> type, Level world) { public Agm65Entity(EntityType<? extends Agm65Entity> type, Level world) {
super(type, world); super(type, world);
this.noCulling = true; this.noCulling = true;
@ -147,7 +148,7 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle()) if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle())
return; return;
if (this.level() instanceof ServerLevel && tickCount > 8) { if (this.level() instanceof ServerLevel) {
if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle())) if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return; return;
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
@ -165,58 +166,87 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
} }
for (int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
apExplode(result, i); apExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i)));
} }
causeExplode(result); causeExplode(result.getLocation());
this.discard(); this.discard();
} }
} }
@Override
public boolean isNoGravity() {
return true;
}
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
double x = blockHitResult.getLocation().x; BlockPos resultPos = blockHitResult.getBlockPos();
double y = blockHitResult.getLocation().y;
double z = blockHitResult.getLocation().z;
float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness == -1) {
this.discard();
causeExplode(blockHitResult.getLocation());
return;
} else {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) { if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime(); this.level().destroyBlock(resultPos, true);
if (hardness <= 50 && hardness != -1) {
BlockPos blockPos = BlockPos.containing(x, y, z);
Block.dropResources(this.level().getBlockState(blockPos), this.level(), BlockPos.containing(x, y, z), null);
this.level().destroyBlock(blockPos, true);
} }
} }
for (int i = 0; i < 5; i++) { causeExplode(blockHitResult.getLocation());
apExplode(blockHitResult, i);
}
causeExplode(blockHitResult); for (int i = 0; i < 8; i++) {
Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
AABB aabb = new AABB(hitPos, hitPos).inflate(0.25);
if (durability > 0) {
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
durability -= (int) hard;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true);
}
apExplode(hitPos);
});
}
}
if (durability <= 0) {
discard();
}
} }
} }
private void apExplode(HitResult result, int index) { private void causeExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this, this,
this.getOwner()), this.getOwner()),
explosionDamage, explosionDamage,
result.getLocation().x + index * getDeltaMovement().normalize().x, vec3.x,
result.getLocation().y + index * getDeltaMovement().normalize().y, vec3.y,
result.getLocation().z + index * getDeltaMovement().normalize().z, vec3.z,
0.5f * explosionRadius, explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1); setDamageMultiplier(1);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), vec3);
}
private void apExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
} }
@Override @Override
@ -281,22 +311,9 @@ public class Agm65Entity extends FastThrowableProjectile implements GeoEntity, E
this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f)); this.setDeltaMovement(this.getDeltaMovement().multiply(f, f, f));
} }
private void causeExplode(HitResult result) { @Override
CustomExplosion explosion = new CustomExplosion(this.level(), this, public boolean isNoGravity() {
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), return true;
this,
this.getOwner()),
this.explosionDamage,
this.getX(),
this.getEyeY(),
this.getZ(),
this.explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), result.getLocation());
} }
private PlayState movementPredicate(AnimationState<Agm65Entity> event) { private PlayState movementPredicate(AnimationState<Agm65Entity> event) {

View file

@ -17,6 +17,7 @@ import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.players.OldUsersConverter; import net.minecraft.server.players.OldUsersConverter;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
@ -412,6 +413,17 @@ public class C4Entity extends Entity implements GeoEntity, OwnableEntity {
} }
} }
if (this.level() instanceof ServerLevel) {
AABB aabb = new AABB(pos, pos).inflate(3);
BlockPos.betweenClosedStream(aabb).forEach((blockPos) -> {
float hard = this.level().getBlockState(blockPos).getBlock().defaultDestroyTime();
if (ExplosionConfig.EXPLOSION_DESTROY.get() && hard != -1 && new Vec3(blockPos.getX(), blockPos.getY(), blockPos.getZ()).distanceTo(position()) < 2) {
this.level().destroyBlock(blockPos, true);
}
});
}
CustomExplosion explosion = new CustomExplosion(level(), this, CustomExplosion explosion = new CustomExplosion(level(), this,
ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(), ModDamageTypes.causeProjectileBoomDamage(level().registryAccess(), this, this.getOwner()), ExplosionConfig.C4_EXPLOSION_DAMAGE.get(),
pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1); pos.x, pos.y, pos.z, ExplosionConfig.C4_EXPLOSION_RADIUS.get(), ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1);

View file

@ -2,7 +2,10 @@ package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.network.message.receive.ClientMotionSyncMessage; import com.atsuishio.superbwarfare.network.message.receive.ClientMotionSyncMessage;
import com.atsuishio.superbwarfare.tools.ChunkLoadTool; import com.atsuishio.superbwarfare.tools.ChunkLoadTool;
@ -23,12 +26,9 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
@ -51,7 +51,6 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
private float fireProbability = 0; private float fireProbability = 0;
private int fireTime = 0; private int fireTime = 0;
private int durability = 40; private int durability = 40;
private boolean firstHit = true;
public Set<Long> loadedChunks = new HashSet<>(); public Set<Long> loadedChunks = new HashSet<>();
private float gravity = 0.1f; private float gravity = 0.1f;
@ -174,55 +173,38 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
double x = blockHitResult.getLocation().x; BlockPos resultPos = blockHitResult.getBlockPos();
double y = blockHitResult.getLocation().y;
double z = blockHitResult.getLocation().z;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) { float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime();
BlockState blockState = this.level().getBlockState(BlockPos.containing(x, y, z));
if (hardness == -1) { if (hardness == -1) {
this.discard(); this.discard();
causeExplode(blockHitResult.getLocation()); causeExplode(blockHitResult.getLocation());
return; return;
}
this.durability -= (int) hardness;
if (hardness <= 50) {
BlockPos blockPos = BlockPos.containing(x, y, z);
Block.dropResources(this.level().getBlockState(blockPos), this.level(), BlockPos.containing(x, y, z), null);
this.level().destroyBlock(blockPos, true);
}
if (blockState.is(ModBlocks.SANDBAG.get()) || blockState.is(Blocks.NETHERITE_BLOCK)) {
this.durability -= 10;
}
if (blockState.is(Blocks.IRON_BLOCK) || blockState.is(Blocks.COPPER_BLOCK)) {
this.durability -= 5;
}
if (blockState.is(Blocks.GOLD_BLOCK)) {
this.durability -= 3;
}
if (this.durability <= 0) {
causeExplode(blockHitResult.getLocation());
} else { } else {
if (this.firstHit) { if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
ParticleTool.cannonHitParticles(this.level(), this.position(), this); this.level().destroyBlock(resultPos, true);
}
}
causeExplode(blockHitResult.getLocation()); causeExplode(blockHitResult.getLocation());
this.firstHit = false;
for (int i = 0; i < 5; i++) {
Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
AABB aabb = new AABB(hitPos, hitPos).inflate(0.25);
if (durability > 0) {
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
durability -= (int) hard;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true);
} }
apExplode(blockHitResult); apExplode(hitPos);
});
} }
} else {
if (this.durability > 0) {
apExplode(blockHitResult);
} }
causeExplode(blockHitResult.getLocation()); if (durability <= 0) {
discard();
} }
} }
} }
@ -279,10 +261,9 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
} else { } else {
ParticleTool.spawnMediumExplosionParticles(this.level(), vec); ParticleTool.spawnMediumExplosionParticles(this.level(), vec);
} }
this.discard();
} }
private void apExplode(HitResult result) { private void apExplode(Vec3 vec3) {
if (Math.random() > fireProbability) { if (Math.random() > fireProbability) {
fireTime = 0; fireTime = 0;
} }
@ -292,22 +273,15 @@ public class CannonShellEntity extends FastThrowableProjectile implements GeoEnt
this, this,
this.getOwner()), this.getOwner()),
explosionDamage, explosionDamage,
result.getLocation().x + 5 * getDeltaMovement().normalize().x, vec3.x,
result.getLocation().y + 5 * getDeltaMovement().normalize().y, vec3.y,
result.getLocation().z + 5 * getDeltaMovement().normalize().z, vec3.z,
radius, radius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1).setFireTime(fireTime); setDamageMultiplier(1).setFireTime(fireTime);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
if (radius > 7) {
ParticleTool.spawnHugeExplosionParticles(this.level(), result.getLocation());
} else {
ParticleTool.spawnMediumExplosionParticles(this.level(), result.getLocation());
}
this.discard();
} }
private PlayState movementPredicate(AnimationState<CannonShellEntity> event) { private PlayState movementPredicate(AnimationState<CannonShellEntity> event) {

View file

@ -1,5 +1,6 @@
package com.atsuishio.superbwarfare.entity.projectile; package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModDamageTypes;
import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
@ -152,21 +153,26 @@ public class GunGrenadeEntity extends FastThrowableProjectile implements GeoEnti
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if (this.level() instanceof ServerLevel) {
float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness != -1) {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(resultPos, true);
}
}
}
if (state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
} }
if (this.tickCount > 0) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
ProjectileTool.causeCustomExplode(this, ProjectileTool.causeCustomExplode(this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()),
this, this.explosionDamage, this.explosionRadius, this.monsterMultiplier); this, this.explosionDamage, this.explosionRadius, this.monsterMultiplier);
} }
}
this.discard(); this.discard();
} }

View file

@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage; import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -22,8 +23,10 @@ import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -41,6 +44,8 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
private float explosionDamage = 60f; private float explosionDamage = 60f;
private float explosionRadius = 5f; private float explosionRadius = 5f;
private int durability = 50;
public HeliRocketEntity(EntityType<? extends HeliRocketEntity> type, Level world) { public HeliRocketEntity(EntityType<? extends HeliRocketEntity> type, Level world) {
super(type, world); super(type, world);
this.noCulling = true; this.noCulling = true;
@ -95,6 +100,9 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle()) if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle())
return; return;
if (this.level() instanceof ServerLevel) {
if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return;
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) { if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
@ -109,29 +117,88 @@ public class HeliRocketEntity extends FastThrowableProjectile implements GeoEnti
entity.invulnerableTime = 0; entity.invulnerableTime = 0;
} }
if (this.tickCount > 1) { for (int i = 0; i < 3; i++) {
if (this.level() instanceof ServerLevel) { apExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i)));
causeRocketExplode(this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()),
entity, this.explosionDamage, this.explosionRadius, 1);
}
} }
causeExplode(result.getLocation());
this.discard(); this.discard();
} }
}
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
if (this.tickCount > 1) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
causeRocketExplode(this, BlockPos resultPos = blockHitResult.getBlockPos();
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()),
this, this.explosionDamage, this.explosionRadius, 1); float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness == -1) {
this.discard();
causeExplode(blockHitResult.getLocation());
return;
} else {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(resultPos, true);
} }
} }
this.discard(); causeExplode(blockHitResult.getLocation());
for (int i = 0; i < 3; i++) {
Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
AABB aabb = new AABB(hitPos, hitPos).inflate(0.25);
if (durability > 0) {
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
durability -= (int) hard;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true);
}
apExplode(hitPos);
});
}
}
if (durability <= 0) {
discard();
}
}
}
private void causeExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), vec3);
}
private void apExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
} }
@Override @Override

View file

@ -33,11 +33,9 @@ import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BellBlock; import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
@ -63,19 +61,21 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
private float explosionDamage = 140f; private float explosionDamage = 140f;
private float explosionRadius = 6f; private float explosionRadius = 6f;
private boolean distracted = false; private boolean distracted = false;
private int guide_type = 0; private int guideType = 0;
private int durability = 70;
public JavelinMissileEntity(EntityType<? extends JavelinMissileEntity> type, Level world) { public JavelinMissileEntity(EntityType<? extends JavelinMissileEntity> type, Level world) {
super(type, world); super(type, world);
this.noCulling = true; this.noCulling = true;
} }
public JavelinMissileEntity(LivingEntity entity, Level level, float damage, float explosionDamage, float explosionRadius, int guide_type, Vec3 targetPos) { public JavelinMissileEntity(LivingEntity entity, Level level, float damage, float explosionDamage, float explosionRadius, int guideType, Vec3 targetPos) {
super(ModEntities.JAVELIN_MISSILE.get(), entity, level); super(ModEntities.JAVELIN_MISSILE.get(), entity, level);
this.damage = damage; this.damage = damage;
this.explosionDamage = explosionDamage; this.explosionDamage = explosionDamage;
this.explosionRadius = explosionRadius; this.explosionRadius = explosionRadius;
this.guide_type = guide_type; this.guideType = guideType;
this.entityData.set(TARGET_X, (float) targetPos.x); this.entityData.set(TARGET_X, (float) targetPos.x);
this.entityData.set(TARGET_Y, (float) targetPos.y); this.entityData.set(TARGET_Y, (float) targetPos.y);
this.entityData.set(TARGET_Z, (float) targetPos.z); this.entityData.set(TARGET_Z, (float) targetPos.z);
@ -169,12 +169,20 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
return true; return true;
} }
@Override
public boolean isNoGravity() {
return true;
}
@Override @Override
protected void onHitEntity(EntityHitResult result) { protected void onHitEntity(EntityHitResult result) {
float damageMultiplier = 1 + this.monsterMultiplier; float damageMultiplier = 1 + this.monsterMultiplier;
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle()) if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle())
return; return;
if (this.level() instanceof ServerLevel) {
if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return;
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) { if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
@ -193,37 +201,88 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
entity.invulnerableTime = 0; entity.invulnerableTime = 0;
} }
if (this.tickCount > 1) { for (int i = 0; i < 3; i++) {
if (this.level() instanceof ServerLevel) { apExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i)));
causeExplode(result);
}
} }
causeExplode(result.getLocation());
this.discard(); this.discard();
} }
@Override
public boolean isNoGravity() {
return true;
} }
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult); if (this.level() instanceof ServerLevel) {
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos);
if (state.getBlock() instanceof BellBlock bell) { float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
}
if (this.tickCount > 1) {
if (this.level() instanceof ServerLevel) {
causeExplode(blockHitResult);
}
}
if (hardness == -1) {
this.discard(); this.discard();
causeExplode(blockHitResult.getLocation());
return;
} else {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(resultPos, true);
}
}
causeExplode(blockHitResult.getLocation());
for (int i = 0; i < 3; i++) {
Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
AABB aabb = new AABB(hitPos, hitPos).inflate(0.25);
if (durability > 0) {
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
durability -= (int) hard;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true);
}
apExplode(hitPos);
});
}
}
if (durability <= 0) {
discard();
}
}
}
private void causeExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(this.monsterMultiplier);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), vec3);
}
private void apExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(this.monsterMultiplier);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
} }
@Override @Override
@ -239,7 +298,7 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
} }
} }
if (guide_type == 0 || !entityData.get(TARGET_UUID).equals("none")) { if (guideType == 0 || !entityData.get(TARGET_UUID).equals("none")) {
if (entity != null) { if (entity != null) {
if (entity.level() instanceof ServerLevel) { if (entity.level() instanceof ServerLevel) {
this.entityData.set(TARGET_X, (float) entity.getX()); this.entityData.set(TARGET_X, (float) entity.getX());
@ -280,7 +339,7 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
} }
} }
} }
} else if (guide_type == 1) { } else if (guideType == 1) {
double px = this.getX(); double px = this.getX();
double ex = this.entityData.get(TARGET_X); double ex = this.entityData.get(TARGET_X);
double pz = this.getZ(); double pz = this.getZ();
@ -345,24 +404,6 @@ public class JavelinMissileEntity extends FastThrowableProjectile implements Geo
this.setDeltaMovement(this.getDeltaMovement().multiply(0.96, 0.96, 0.96)); this.setDeltaMovement(this.getDeltaMovement().multiply(0.96, 0.96, 0.96));
} }
private void causeExplode(HitResult result) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
this.getX(),
this.getEyeY(),
this.getZ(),
explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(this.monsterMultiplier);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), result.getLocation());
}
private PlayState movementPredicate(AnimationState<JavelinMissileEntity> event) { private PlayState movementPredicate(AnimationState<JavelinMissileEntity> event) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle"));
} }

View file

@ -1,11 +1,14 @@
package com.atsuishio.superbwarfare.entity.projectile; package com.atsuishio.superbwarfare.entity.projectile;
import com.atsuishio.superbwarfare.config.server.ExplosionConfig;
import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.tools.ProjectileTool; import com.atsuishio.superbwarfare.tools.ProjectileTool;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.AreaEffectCloud; import net.minecraft.world.entity.AreaEffectCloud;
@ -15,7 +18,9 @@ import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class MelonBombEntity extends FastThrowableProjectile implements ExplosiveProjectile { public class MelonBombEntity extends FastThrowableProjectile implements ExplosiveProjectile {
@ -99,10 +104,19 @@ public class MelonBombEntity extends FastThrowableProjectile implements Explosiv
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult); if (this.level() instanceof ServerLevel) {
AABB aabb = new AABB(blockHitResult.getLocation(), blockHitResult.getLocation()).inflate(5);
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
if (ExplosionConfig.EXPLOSION_DESTROY.get() && hard != -1 && new Vec3(pos.getX(), pos.getY(), pos.getZ()).distanceTo(blockHitResult.getLocation()) < 3) {
this.level().destroyBlock(pos, true);
}
});
ProjectileTool.causeCustomExplode(this, this.explosionDamage, this.explosionRadius, 1.5f); ProjectileTool.causeCustomExplode(this, this.explosionDamage, this.explosionRadius, 1.5f);
this.discard(); this.discard();
} }
}
@Override @Override
public void tick() { public void tick() {

View file

@ -5,10 +5,12 @@ import com.atsuishio.superbwarfare.init.ModEntities;
import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.tools.ProjectileTool; import com.atsuishio.superbwarfare.tools.ProjectileTool;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
@ -19,7 +21,9 @@ import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.entity.projectile.ThrownPotion; import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.animatable.instance.AnimatableInstanceCache;
@ -116,10 +120,19 @@ public class Mk82Entity extends FastThrowableProjectile implements GeoEntity, Ex
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult); if (this.level() instanceof ServerLevel) {
AABB aabb = new AABB(blockHitResult.getLocation(), blockHitResult.getLocation()).inflate(5);
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
if (ExplosionConfig.EXPLOSION_DESTROY.get() && hard != -1 && new Vec3(pos.getX(), pos.getY(), pos.getZ()).distanceTo(blockHitResult.getLocation()) < 3) {
this.level().destroyBlock(pos, true);
}
});
ProjectileTool.causeCustomExplode(this, this.explosionDamage, this.explosionRadius, 1.2f); ProjectileTool.causeCustomExplode(this, this.explosionDamage, this.explosionRadius, 1.2f);
this.discard(); this.discard();
} }
}
@Override @Override
public void tick() { public void tick() {

View file

@ -193,10 +193,19 @@ public class MortarShellEntity extends FastThrowableProjectile implements GeoEnt
} }
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if (this.level() instanceof ServerLevel) {
float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness != -1) {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(resultPos, true);
}
}
}
if (state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
} }

View file

@ -24,10 +24,10 @@ import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3;
import net.neoforged.neoforge.event.EventHooks; import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.network.PacketDistributor; import net.neoforged.neoforge.network.PacketDistributor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -46,6 +46,8 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit
private float explosionDamage = 200f; private float explosionDamage = 200f;
private float explosionRadius = 10; private float explosionRadius = 10;
private int durability = 50;
public RpgRocketEntity(EntityType<? extends RpgRocketEntity> type, Level world) { public RpgRocketEntity(EntityType<? extends RpgRocketEntity> type, Level world) {
super(type, world); super(type, world);
this.noCulling = true; this.noCulling = true;
@ -130,6 +132,9 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle()) if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle())
return; return;
if (this.level() instanceof ServerLevel) {
if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return;
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) { if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
@ -148,58 +153,88 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit
entity.invulnerableTime = 0; entity.invulnerableTime = 0;
} }
if (this.tickCount > 1) { for (int i = 0; i < 5; i++) {
if (this.level() instanceof ServerLevel) { apExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i)));
ProjectileTool.causeCustomExplode(this, this.explosionDamage, this.explosionRadius, this.monsterMultiplier);
}
} }
causeExplode(result.getLocation());
this.discard(); this.discard();
} }
}
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
double x = blockHitResult.getLocation().x; BlockPos resultPos = blockHitResult.getBlockPos();
double y = blockHitResult.getLocation().y;
double z = blockHitResult.getLocation().z;
float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness == -1) {
this.discard();
causeExplode(blockHitResult.getLocation());
return;
} else {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) { if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
float hardness = this.level().getBlockState(BlockPos.containing(x, y, z)).getBlock().defaultDestroyTime(); this.level().destroyBlock(resultPos, true);
if (hardness <= 10 && hardness != -1) {
BlockPos blockPos = BlockPos.containing(x, y, z);
Block.dropResources(this.level().getBlockState(blockPos), this.level(), BlockPos.containing(x, y, z), null);
this.level().destroyBlock(blockPos, true);
} }
} }
if (this.tickCount > 1) { causeExplode(blockHitResult.getLocation());
for (int i = 1; i < 3; i++) {
apExplode(blockHitResult, i);
}
if (this.level() instanceof ServerLevel) { for (int i = 0; i < 5; i++) {
ProjectileTool.causeCustomExplode(this, this.explosionDamage, this.explosionRadius, this.monsterMultiplier); Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
AABB aabb = new AABB(hitPos, hitPos).inflate(0.25);
if (durability > 0) {
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
durability -= (int) hard;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true);
} }
apExplode(hitPos);
});
}
}
if (durability <= 0) {
discard();
} }
} }
} }
private void apExplode(HitResult result, int index) { private void causeExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this, CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this, this,
this.getOwner()), this.getOwner()),
explosionDamage, explosionDamage,
result.getLocation().x + index * getDeltaMovement().normalize().x, vec3.x,
result.getLocation().y + index * getDeltaMovement().normalize().y, vec3.y,
result.getLocation().z + index * getDeltaMovement().normalize().z, vec3.z,
0.5f * explosionRadius, explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true). ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(this.monsterMultiplier); setDamageMultiplier(this.monsterMultiplier);
explosion.explode(); explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion); EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false); explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), vec3);
}
private void apExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(this.monsterMultiplier);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
} }
@Override @Override

View file

@ -121,10 +121,19 @@ public class SmallCannonShellEntity extends FastThrowableProjectile implements G
} }
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
BlockPos resultPos = blockHitResult.getBlockPos(); BlockPos resultPos = blockHitResult.getBlockPos();
BlockState state = this.level().getBlockState(resultPos); BlockState state = this.level().getBlockState(resultPos);
if (this.level() instanceof ServerLevel) {
float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness != -1) {
if (ExplosionConfig.EXPLOSION_DESTROY.get() && this.blockInteraction == null) {
this.level().destroyBlock(resultPos, true);
}
}
}
if (state.getBlock() instanceof BellBlock bell) { if (state.getBlock() instanceof BellBlock bell) {
bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection()); bell.attemptToRing(this.level(), resultPos, blockHitResult.getDirection());
} }

View file

@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessag
import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.CustomExplosion;
import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.TraceTool; import com.atsuishio.superbwarfare.tools.TraceTool;
import net.minecraft.core.BlockPos;
import net.minecraft.core.particles.ParticleTypes; import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor; import net.minecraft.network.syncher.EntityDataAccessor;
@ -30,6 +31,7 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.EntityHitResult; import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -41,8 +43,6 @@ 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;
import javax.annotation.Nullable;
public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, ExplosiveProjectile { public class WgMissileEntity extends FastThrowableProjectile implements GeoEntity, 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);
@ -52,6 +52,8 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
private float explosionDamage = 200f; private float explosionDamage = 200f;
private float explosionRadius = 10f; private float explosionRadius = 10f;
private int durability = 70;
public WgMissileEntity(EntityType<? extends WgMissileEntity> type, Level level) { public WgMissileEntity(EntityType<? extends WgMissileEntity> type, Level level) {
super(type, level); super(type, level);
this.noCulling = true; this.noCulling = true;
@ -135,10 +137,11 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
@Override @Override
protected void onHitEntity(EntityHitResult result) { protected void onHitEntity(EntityHitResult result) {
Entity entity = result.getEntity(); Entity entity = result.getEntity();
if (this.tickCount < 1) return;
if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle()) if (this.getOwner() != null && this.getOwner().getVehicle() != null && entity == this.getOwner().getVehicle())
return; return;
if (this.level() instanceof ServerLevel) {
if (entity == this.getOwner() || (this.getOwner() != null && entity == this.getOwner().getVehicle()))
return;
if (this.getOwner() instanceof LivingEntity living) { if (this.getOwner() instanceof LivingEntity living) {
if (!living.level().isClientSide() && living instanceof ServerPlayer player) { if (!living.level().isClientSide() && living instanceof ServerPlayer player) {
living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1); living.level().playSound(null, living.blockPosition(), ModSounds.INDICATION.get(), SoundSource.VOICE, 1, 1);
@ -153,21 +156,90 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
entity.invulnerableTime = 0; entity.invulnerableTime = 0;
} }
if (this.tickCount > 2) { for (int i = 0; i < 5; i++) {
if (this.level() instanceof ServerLevel) { apExplode(result.getLocation().add(getDeltaMovement().normalize().scale(i)));
causeMissileExplode(ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), this.explosionDamage, this.explosionRadius);
} }
causeExplode(result.getLocation());
this.discard();
} }
} }
@Override @Override
public void onHitBlock(@NotNull BlockHitResult blockHitResult) { public void onHitBlock(@NotNull BlockHitResult blockHitResult) {
super.onHitBlock(blockHitResult);
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
causeMissileExplode(ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), this.explosionDamage, this.explosionRadius); BlockPos resultPos = blockHitResult.getBlockPos();
float hardness = this.level().getBlockState(resultPos).getBlock().defaultDestroyTime();
if (hardness == -1) {
this.discard();
causeExplode(blockHitResult.getLocation());
return;
} else {
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(resultPos, true);
} }
} }
causeExplode(blockHitResult.getLocation());
for (int i = 0; i < 5; i++) {
Vec3 hitPos = blockHitResult.getLocation().add(getDeltaMovement().normalize().scale(i));
AABB aabb = new AABB(hitPos, hitPos).inflate(0.25);
if (durability > 0) {
BlockPos.betweenClosedStream(aabb).forEach((pos) -> {
float hard = this.level().getBlockState(pos).getBlock().defaultDestroyTime();
durability -= (int) hard;
if (ExplosionConfig.EXPLOSION_DESTROY.get()) {
this.level().destroyBlock(pos, true);
}
apExplode(hitPos);
});
}
}
if (durability <= 0) {
discard();
}
}
}
private void causeExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnHugeExplosionParticles(this.level(), vec3);
}
private void apExplode(Vec3 vec3) {
CustomExplosion explosion = new CustomExplosion(this.level(), this,
ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(),
this,
this.getOwner()),
explosionDamage,
vec3.x,
vec3.y,
vec3.z,
explosionRadius * 0.5f,
ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).
setDamageMultiplier(1);
explosion.explode();
EventHooks.onExplosionStart(this.level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(this.level(), vec3);
}
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
@ -210,21 +282,12 @@ public class WgMissileEntity extends FastThrowableProjectile implements GeoEntit
if (this.tickCount > 300 || this.isInWater() || this.entityData.get(HEALTH) <= 0) { if (this.tickCount > 300 || this.isInWater() || this.entityData.get(HEALTH) <= 0) {
if (this.level() instanceof ServerLevel) { if (this.level() instanceof ServerLevel) {
causeMissileExplode(ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), this.explosionDamage, this.explosionRadius); causeExplode(position());
} }
this.discard(); this.discard();
} }
} }
public void causeMissileExplode(@Nullable DamageSource source, float damage, float radius) {
CustomExplosion explosion = new CustomExplosion(level(), this, source, damage,
this.getX(), this.getY(), this.getZ(), radius, ExplosionConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP, true).setDamageMultiplier(1.25f);
explosion.explode();
EventHooks.onExplosionStart(level(), explosion);
explosion.finalizeExplosion(false);
ParticleTool.spawnMediumExplosionParticles(level(), position());
discard();
}
private PlayState movementPredicate(AnimationState<WgMissileEntity> event) { private PlayState movementPredicate(AnimationState<WgMissileEntity> event) {
return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle")); return event.setAndContinue(RawAnimation.begin().thenLoop("animation.jvm.idle"));