修复激光炮指示灯bug,提升了激光炮破坏方块的能力

This commit is contained in:
Atsuihsio 2024-12-31 19:36:29 +08:00
parent e6cfb83259
commit 3ae7b67865
3 changed files with 54 additions and 35 deletions

View file

@ -1,6 +1,7 @@
package com.atsuishio.superbwarfare.client.model.entity;
import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.AnnihilatorEntity;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
@ -73,7 +74,7 @@ public class AnnihilatorModel extends GeoModel<AnnihilatorEntity> {
CoreGeoBone ledRed5 = getAnimationProcessor().getBone("ledred5");
float coolDown = animatable.getEntityData().get(COOL_DOWN);
boolean cantShoot = animatable.getEnergy() < animatable.getMaxEnergy();
boolean cantShoot = animatable.getEnergy() < CannonConfig.ANNIHILATOR_SHOOT_COST.get();
ledGreen.setHidden(coolDown > 80 || cantShoot);
ledGreen2.setHidden(coolDown > 60 || cantShoot);

View file

@ -34,6 +34,7 @@ import net.minecraft.world.entity.projectile.ProjectileUtil;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.phys.*;
import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PacketDistributor;
@ -251,11 +252,26 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
}
private float laserLength(Vec3 pos, Entity cannon) {
if (this.entityData.get(COOL_DOWN) > 98) {
HitResult result = cannon.level().clip(new ClipContext(pos, pos.add(cannon.getViewVector(1).scale(512)),
if (this.level() instanceof ServerLevel) {
BlockHitResult result = cannon.level().clip(new ClipContext(pos, pos.add(cannon.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, cannon));
Vec3 looking = Vec3.atLowerCornerOf(result.getBlockPos());
Vec3 hitPos = result.getLocation();
laserExplosion(hitPos);
BlockPos _pos = BlockPos.containing(looking.x, looking.y, looking.z);
float hardness = this.level().getBlockState(_pos).getBlock().defaultDestroyTime();
if (ExplosionDestroyConfig.EXPLOSION_DESTROY.get() && hardness != -1) {
Block.dropResources(this.level().getBlockState(_pos), this.level(), _pos, null);
this.level().destroyBlock(_pos, true);
}
if (this.entityData.get(COOL_DOWN) > 98) {
laserExplosion(hitPos);
}
this.level().explode(this, hitPos.x, hitPos.y, hitPos.z,5, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE);
}
return (float) pos.distanceTo((Vec3.atLowerCornerOf(cannon.level().clip(
@ -264,37 +280,39 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
}
private float laserLengthEntity(Vec3 pos, Entity cannon) {
double distance = 512 * 512;
HitResult hitResult = cannon.pick(512, 1.0f, false);
if (hitResult.getType() != HitResult.Type.MISS) {
distance = hitResult.getLocation().distanceToSqr(pos);
double blockReach = 5;
if (distance > blockReach * blockReach) {
Vec3 posB = hitResult.getLocation();
hitResult = BlockHitResult.miss(posB, Direction.getNearest(pos.x, pos.y, pos.z), BlockPos.containing(posB));
}
}
Vec3 viewVec = cannon.getViewVector(1.0F);
Vec3 toVec = pos.add(viewVec.x * 512, viewVec.y * 512, viewVec.z * 512);
AABB aabb = cannon.getBoundingBox().expandTowards(viewVec.scale(512)).inflate(1.0D, 1.0D, 1.0D);
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(cannon, pos, toVec, aabb, p -> !p.isSpectator(), distance);
if (entityhitresult != null) {
Vec3 targetPos = entityhitresult.getLocation();
double distanceToTarget = pos.distanceToSqr(targetPos);
if (distanceToTarget > distance || distanceToTarget > 512 * 512) {
hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos));
} else if (distanceToTarget < distance) {
hitResult = entityhitresult;
}
if (hitResult.getType() == HitResult.Type.ENTITY) {
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
Entity target = ((EntityHitResult) hitResult).getEntity();
target.hurt(ModDamageTypes.causeLaserDamage(this.level().registryAccess(), passenger, passenger), (float) 200);
target.invulnerableTime = 0;
if (this.entityData.get(COOL_DOWN) > 98) {
laserExplosion(targetPos);
if (this.level() instanceof ServerLevel) {
double distance = 512 * 512;
HitResult hitResult = cannon.pick(512, 1.0f, false);
if (hitResult.getType() != HitResult.Type.MISS) {
distance = hitResult.getLocation().distanceToSqr(pos);
double blockReach = 5;
if (distance > blockReach * blockReach) {
Vec3 posB = hitResult.getLocation();
hitResult = BlockHitResult.miss(posB, Direction.getNearest(pos.x, pos.y, pos.z), BlockPos.containing(posB));
}
}
Vec3 viewVec = cannon.getViewVector(1.0F);
Vec3 toVec = pos.add(viewVec.x * 512, viewVec.y * 512, viewVec.z * 512);
AABB aabb = cannon.getBoundingBox().expandTowards(viewVec.scale(512)).inflate(1.0D, 1.0D, 1.0D);
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(cannon, pos, toVec, aabb, p -> !p.isSpectator(), distance);
if (entityhitresult != null) {
Vec3 targetPos = entityhitresult.getLocation();
double distanceToTarget = pos.distanceToSqr(targetPos);
if (distanceToTarget > distance || distanceToTarget > 512 * 512) {
hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos));
} else if (distanceToTarget < distance) {
hitResult = entityhitresult;
}
if (hitResult.getType() == HitResult.Type.ENTITY) {
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
Entity target = ((EntityHitResult) hitResult).getEntity();
target.hurt(ModDamageTypes.causeLaserDamage(this.level().registryAccess(), passenger, passenger), (float) 200);
target.invulnerableTime = 0;
if (this.entityData.get(COOL_DOWN) > 98) {
laserExplosion(targetPos);
}
return (float) pos.distanceTo(target.position());
}
return (float) pos.distanceTo(target.position());
}
}
return 512;

View file

@ -74,7 +74,7 @@ public class CustomExplosion extends Explosion {
}
}
if (pLevel instanceof ServerLevel) {
pLevel.explode(source == null ? null : source.getEntity(), pToBlowX, pToBlowY, pToBlowZ, pRadius / 2, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE);
pLevel.explode(source == null ? null : source.getEntity(), pToBlowX, pToBlowY, pToBlowZ, 0.8f * pRadius , ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Level.ExplosionInteraction.BLOCK : Level.ExplosionInteraction.NONE);
}
}