修复激光炮指示灯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; package com.atsuishio.superbwarfare.client.model.entity;
import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.ModUtils;
import com.atsuishio.superbwarfare.config.server.CannonConfig;
import com.atsuishio.superbwarfare.entity.AnnihilatorEntity; import com.atsuishio.superbwarfare.entity.AnnihilatorEntity;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -73,7 +74,7 @@ public class AnnihilatorModel extends GeoModel<AnnihilatorEntity> {
CoreGeoBone ledRed5 = getAnimationProcessor().getBone("ledred5"); CoreGeoBone ledRed5 = getAnimationProcessor().getBone("ledred5");
float coolDown = animatable.getEntityData().get(COOL_DOWN); 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); ledGreen.setHidden(coolDown > 80 || cantShoot);
ledGreen2.setHidden(coolDown > 60 || 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.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.level.block.Block;
import net.minecraft.world.phys.*; import net.minecraft.world.phys.*;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
@ -251,11 +252,26 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
} }
private float laserLength(Vec3 pos, Entity cannon) { private float laserLength(Vec3 pos, Entity cannon) {
if (this.entityData.get(COOL_DOWN) > 98) { if (this.level() instanceof ServerLevel) {
HitResult result = cannon.level().clip(new ClipContext(pos, pos.add(cannon.getViewVector(1).scale(512)), BlockHitResult result = cannon.level().clip(new ClipContext(pos, pos.add(cannon.getViewVector(1).scale(512)),
ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, cannon)); ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, cannon));
Vec3 looking = Vec3.atLowerCornerOf(result.getBlockPos());
Vec3 hitPos = result.getLocation(); 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( 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) { private float laserLengthEntity(Vec3 pos, Entity cannon) {
double distance = 512 * 512; if (this.level() instanceof ServerLevel) {
HitResult hitResult = cannon.pick(512, 1.0f, false); double distance = 512 * 512;
if (hitResult.getType() != HitResult.Type.MISS) { HitResult hitResult = cannon.pick(512, 1.0f, false);
distance = hitResult.getLocation().distanceToSqr(pos); if (hitResult.getType() != HitResult.Type.MISS) {
double blockReach = 5; distance = hitResult.getLocation().distanceToSqr(pos);
if (distance > blockReach * blockReach) { double blockReach = 5;
Vec3 posB = hitResult.getLocation(); if (distance > blockReach * blockReach) {
hitResult = BlockHitResult.miss(posB, Direction.getNearest(pos.x, pos.y, pos.z), BlockPos.containing(posB)); 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); Vec3 viewVec = cannon.getViewVector(1.0F);
AABB aabb = cannon.getBoundingBox().expandTowards(viewVec.scale(512)).inflate(1.0D, 1.0D, 1.0D); Vec3 toVec = pos.add(viewVec.x * 512, viewVec.y * 512, viewVec.z * 512);
EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(cannon, pos, toVec, aabb, p -> !p.isSpectator(), distance); AABB aabb = cannon.getBoundingBox().expandTowards(viewVec.scale(512)).inflate(1.0D, 1.0D, 1.0D);
if (entityhitresult != null) { EntityHitResult entityhitresult = ProjectileUtil.getEntityHitResult(cannon, pos, toVec, aabb, p -> !p.isSpectator(), distance);
Vec3 targetPos = entityhitresult.getLocation(); if (entityhitresult != null) {
double distanceToTarget = pos.distanceToSqr(targetPos); Vec3 targetPos = entityhitresult.getLocation();
if (distanceToTarget > distance || distanceToTarget > 512 * 512) { double distanceToTarget = pos.distanceToSqr(targetPos);
hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos)); if (distanceToTarget > distance || distanceToTarget > 512 * 512) {
} else if (distanceToTarget < distance) { hitResult = BlockHitResult.miss(targetPos, Direction.getNearest(viewVec.x, viewVec.y, viewVec.z), BlockPos.containing(targetPos));
hitResult = entityhitresult; } else if (distanceToTarget < distance) {
} hitResult = entityhitresult;
if (hitResult.getType() == HitResult.Type.ENTITY) { }
Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0); if (hitResult.getType() == HitResult.Type.ENTITY) {
Entity target = ((EntityHitResult) hitResult).getEntity(); Entity passenger = this.getPassengers().isEmpty() ? null : this.getPassengers().get(0);
target.hurt(ModDamageTypes.causeLaserDamage(this.level().registryAccess(), passenger, passenger), (float) 200); Entity target = ((EntityHitResult) hitResult).getEntity();
target.invulnerableTime = 0; target.hurt(ModDamageTypes.causeLaserDamage(this.level().registryAccess(), passenger, passenger), (float) 200);
if (this.entityData.get(COOL_DOWN) > 98) { target.invulnerableTime = 0;
laserExplosion(targetPos); if (this.entityData.get(COOL_DOWN) > 98) {
laserExplosion(targetPos);
}
return (float) pos.distanceTo(target.position());
} }
return (float) pos.distanceTo(target.position());
} }
} }
return 512; return 512;

View file

@ -74,7 +74,7 @@ public class CustomExplosion extends Explosion {
} }
} }
if (pLevel instanceof ServerLevel) { 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);
} }
} }