修复激光炮指示灯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,12 +252,27 @@ 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();
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); 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(
new ClipContext(pos, pos.add(cannon.getViewVector(1).scale(512)), new ClipContext(pos, pos.add(cannon.getViewVector(1).scale(512)),
@ -264,6 +280,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
} }
private float laserLengthEntity(Vec3 pos, Entity cannon) { private float laserLengthEntity(Vec3 pos, Entity cannon) {
if (this.level() instanceof ServerLevel) {
double distance = 512 * 512; double distance = 512 * 512;
HitResult hitResult = cannon.pick(512, 1.0f, false); HitResult hitResult = cannon.pick(512, 1.0f, false);
if (hitResult.getType() != HitResult.Type.MISS) { if (hitResult.getType() != HitResult.Type.MISS) {
@ -297,6 +314,7 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
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);
} }
} }