乐趣区

关于java:Minecraft-1122模组开发二十三-霰弹枪

package com.Joy187.newmod.entity;
import java.util.Random;
import java.util.UUID;
import javax.annotation.Nullable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityWitherSkeleton;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.projectile.EntityFireball;
import net.minecraft.entity.projectile.EntitySnowball;
import net.minecraft.entity.projectile.EntityThrowable;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.DamageSource;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
public class EntityM1897B extends EntitySnowball{

private static final DataParameter<Byte> CRITICAL = EntityDataManager.<Byte>createKey(EntityM1897B.class, DataSerializers.BYTE);
protected EntityLivingBase thrower;
private String throwerName;
public Entity shootingEntity;
private double damage;  // 定义子弹挫伤
public EntityM1897B(World worldIn)
{super(worldIn);
    this.setSize(1.0F, 1.0F);   // 设置子弹大小
    this.damage = 8.0D;     // 设定子弹挫伤
}
public EntityM1897B(World worldIn, EntityLivingBase throwerIn)
{super(worldIn, throwerIn);
}
public EntityM1897B(World worldIn, double x, double y, double z)
{this(worldIn);
    this.setPosition(x, y, z);
}    
// 定义子弹撞击物体的函数
protected void onImpact(RayTraceResult result)
{Random rand = new Random();
    float k = rand.nextFloat();
    if (result.entityHit != null)
    {
        int i = 6;
        // 如果子弹打到 Zombie 或凋零,[金融期货](https://www.gendan5.com/futures/ff.html) 就增大 3 点攻击力
        if (result.entityHit instanceof EntityZombie || result.entityHit instanceof EntityWitherSkeleton)
        {i = 9;}           result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i*(1+k));
    }
    //this.world.newExplosion((Entity)null, this.posX, this.posY, this.posZ, (float)this.explosionPower, false, true);
    if (!this.world.isRemote)
    {this.world.setEntityState(this, (byte)3);
        this.setDead();}
} 
@Nullable
public EntityLivingBase getThrower()
{if (this.thrower == null && this.throwerName != null && !this.throwerName.isEmpty())
    {this.thrower = this.world.getPlayerEntityByName(this.throwerName);
        if (this.thrower == null && this.world instanceof WorldServer)
        {
            try
            {Entity entity = ((WorldServer)this.world).getEntityFromUuid(UUID.fromString(this.throwerName));
                if (entity instanceof EntityLivingBase)
                {this.thrower = (EntityLivingBase)entity;
                }
            }
            catch (Throwable var2)
            {this.thrower = null;}
        }
    }
    return this.thrower;
}    
public void setIsCritical(boolean critical)
{byte b0 = ((Byte)this.dataManager.get(CRITICAL)).byteValue();
    if (critical)
    {this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 | 1)));
    }
    else
    {this.dataManager.set(CRITICAL, Byte.valueOf((byte)(b0 & -2)));
    }
}     
public double getDamage()
{return this.damage;}
public void setDamage(double damageIn)
{this.damage = damageIn;}

}

退出移动版