Minecraft的爆炸算法

MC中的爆炸其实挺科学的,在空中爆炸冲击波传得远,破坏范围比较大;在地面爆炸破坏范围小但是破坏深度较深

不科学的地方是它的爆炸范围是正方体,只不过一般范围小到看不出是正方体。至于为什么MOD里的核弹爆炸范围是球体,那是别人重新实现了爆炸函数把范围改掉了…

类名net.minecraft.world.World

    /**
     * Creates an explosion. Args: entity, x, y, z, strength
     */
    public Explosion createExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isSmoking)
    {
        return this.newExplosion(entityIn, x, y, z, strength, false, isSmoking);
    }

    /**
     * returns a new explosion. Does initiation (at time of writing Explosion is not finished)
     */
    // isFlaming影响是否着火,isSmoking影响是否生成粒子和破坏方块
    public Explosion newExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking)
    {
        Explosion explosion = new Explosion(this, entityIn, x, y, z, strength, isFlaming, isSmoking);
        if (net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this, explosion)) return explosion;
        // 第一阶段,计算被破坏的方块,伤害实体
        explosion.doExplosionA();
        // 第二阶段,破坏方块,生成粒子效果和掉落物
        explosion.doExplosionB(true);
        return explosion;
    }

类名net.minecraft.world.Explosion

    public Explosion(World worldIn, Entity p_i45754_2_, double p_i45754_3_, double p_i45754_5_, double p_i45754_7_, float size, boolean p_i45754_10_, boolean p_i45754_11_)
    {
        this.explosionRNG = new Random();
        this.affectedBlockPositions = Lists.<BlockPos>newArrayList();
        this.playerKnockbackMap = Maps.<EntityPlayer, Vec3>newHashMap();
        this.worldObj = worldIn;
        this.exploder = p_i45754_2_;
        // 就是上面的strength
        this.explosionSize = size;
        this.explosionX = p_i45754_3_;
        this.explosionY = p_i45754_5_;
        this.explosionZ = p_i45754_7_;
        this.isFlaming = p_i45754_10_;
        this.isSmoking = p_i45754_11_;
        this.position = new Vec3(explosionX, explosionY, explosionZ);
    }

    /**
     * Does the first part of the explosion (destroy blocks)
     */
    public void doExplosionA()
    {
        Set<BlockPos> blocksToDestroy = Sets.<BlockPos>newHashSet();

        // 遍历16*16*16正方体边界上各点,从中心向边界连线,计算是否破坏连线上的方块
        // 由于这里正方体尺寸写死了,如果爆炸范围太大边界就会有些方块没有遍历到
        for (int x = 0; x < 16; ++x)
        {
            for (int y = 0; y < 16; ++y)
            {
                for (int z = 0; z < 16; ++z)
                {
                    // 在边界
                    if (x == 0 || x == 15 || y == 0 || y == 15 || z == 0 || z == 15)
                    {
                        // 这里只有-1或1两个取值
                        double xStep = (double
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值