From 3ae7b6786501a0ef394d101301c0fc2a5b4e1131 Mon Sep 17 00:00:00 2001 From: Atsuihsio <842960157@qq.com> Date: Tue, 31 Dec 2024 19:36:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BF=80=E5=85=89=E7=82=AE?= =?UTF-8?q?=E6=8C=87=E7=A4=BA=E7=81=AFbug=EF=BC=8C=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E4=BA=86=E6=BF=80=E5=85=89=E7=82=AE=E7=A0=B4=E5=9D=8F=E6=96=B9?= =?UTF-8?q?=E5=9D=97=E7=9A=84=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/model/entity/AnnihilatorModel.java | 3 +- .../entity/AnnihilatorEntity.java | 84 +++++++++++-------- .../superbwarfare/tools/CustomExplosion.java | 2 +- 3 files changed, 54 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/AnnihilatorModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/AnnihilatorModel.java index 7abc3a90b..930c180b2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/entity/AnnihilatorModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/entity/AnnihilatorModel.java @@ -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 { 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); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java index f76474bbb..062e29252 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/AnnihilatorEntity.java @@ -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; diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java index a773d2d06..f4727eccd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/CustomExplosion.java @@ -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); } }