Отверстие от пули

Версия Minecraft
1.7.10
54
0
Здравствуйте, у меня есть entity пуля, не подскажите как сделать чтобы при выстреле на блоке от неё оставался след?
 

timaxa007

Модератор
5,831
409
672
Получилось это:
Java:
public class ItemWeapon extends Item {

    @Override
    public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
        if (!world.isRemote) {
            EntityBullet entity = new EntityBullet(world, player);
            world.spawnEntityInWorld(entity);
        }
        return super.onItemRightClick(is, world, player);
    }

}
Java:
public class EntityBullet extends EntityThrowable {

    public EntityBullet(World world) {
        super(world);
    }

    public EntityBullet(World world, EntityLivingBase entity) {
        super(world, entity);
    }

    @Override
    public void onImpact(MovingObjectPosition mop) {
        switch(mop.typeOfHit) {
        case ENTITY:
            if (mop.entityHit != null)
                mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 6.0F);
            break;
        case BLOCK:
            if (worldObj.isRemote) {
                Minecraft.getMinecraft().effectRenderer.addEffect(new BulletHoleFX(worldObj,
                        mop.hitVec.xCoord,
                        mop.hitVec.yCoord,
                        mop.hitVec.zCoord,
                        mop.sideHit)
                        );
            }
            break;
        default:break;
        }
        this.setDead();
    }

}
Java:
@SideOnly(Side.CLIENT)
public class BulletHoleFX extends EntityFX {

    static final ResourceLocation textureBulletHole = new ResourceLocation(SMTWeapon.MODID, "textures/bullet_hole.png");
    int side;

    public BulletHoleFX(World world, double x, double y, double z, int sideHit) {
        super(world, x, y, z);
        this.motionX = this.motionY = this.motionZ = 0.0D;
        this.side = sideHit;
        this.particleMaxAge = 600;
    }

    @Override
    public void renderParticle(Tessellator tessellator, float p_70539_2_, float p_70539_3_, float p_70539_4_, float p_70539_5_, float p_70539_6_, float p_70539_7_) {
        float f6 = ((float)this.particleAge + p_70539_2_) / (float)this.particleMaxAge;
        f6 *= f6;
        float f7 = 2.0F - f6 * 2.0F;

        if (f7 > 1.0F) f7 = 1.0F;

        Entity player = Minecraft.getMinecraft().thePlayer;

        this.interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)p_70539_2_;
        this.interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)p_70539_2_;
        this.interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)p_70539_2_;

        //f7 *= 0.2F;
        GL11.glPushMatrix();
        GL11.glDisable(GL11.GL_LIGHTING);
        float f8 = 0.125F;
        float f9 = (float)(this.posX - interpPosX);
        float f10 = (float)(this.posY - interpPosY);
        float f11 = (float)(this.posZ - interpPosZ);
        float f12 = this.worldObj.getLightBrightness(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ));
        Minecraft.getMinecraft().getTextureManager().bindTexture(textureBulletHole);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        //GL11.glDisable(GL11.GL_TEXTURE_2D);
        tessellator.startDrawingQuads();
        tessellator.setColorRGBA_F(f12, f12, f12, f7);

        switch(side) {
        case 0:
            tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 - 0.01F, (double)(f11 - f8), 0.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 - 0.01F, (double)(f11 - f8), 1.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 - 0.01F, (double)(f11 + f8), 1.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 - 0.01F, (double)(f11 + f8), 0.0D, 0.0D);
            break;
        case 1:
            tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 + 0.01F, (double)(f11 + f8), 0.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 + 0.01F, (double)(f11 + f8), 1.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 + 0.01F, (double)(f11 - f8), 1.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 + 0.01F, (double)(f11 - f8), 0.0D, 1.0D);
            break;
        case 2:
            tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 + f8), (double)(f11 - 0.01F), 0.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 + f8), (double)(f11 - 0.01F), 1.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 - f8), (double)(f11 - 0.01F), 1.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 - f8), (double)(f11 - 0.01F), 0.0D, 0.0D);
            break;
        case 3:
            tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 - f8), (double)(f11 + 0.01F), 0.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 - f8), (double)(f11 + 0.01F), 1.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 + f8), (double)(f11 + 0.01F), 1.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 + f8), (double)(f11 + 0.01F), 0.0D, 1.0D);
            break;
        case 4:
            tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 + f8), (double)(f11 + f8), 1.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 + f8), (double)(f11 - f8), 1.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 - f8), (double)(f11 - f8), 0.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 - f8), (double)(f11 + f8), 0.0D, 1.0D);
            break;
        case 5:
            tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 - f8), (double)(f11 + f8), 0.0D, 1.0D);
            tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 - f8), (double)(f11 - f8), 0.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 + f8), (double)(f11 - f8), 1.0D, 0.0D);
            tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 + f8), (double)(f11 + f8), 1.0D, 1.0D);
            break;
        default:break;
        }
       
        tessellator.draw();
        //GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LIGHTING);
        GL11.glPopMatrix();
    }

    @Override
    public void onUpdate() {
        if (this.particleAge++ >= this.particleMaxAge) this.setDead();
    }

    @Override
    public int getFXLayer() {
        return 3;
    }

}
Доделывать надо, писал как пример.

 
Последнее редактирование:
471
5
timaxa007 написал(а):
Доделывать надо, писал как пример.


Офигенно. Вот только будут ли они оставаться на карте, если выйти и зайти в игру?
 
1,990
18
105
Нет - частицы только на клиенте, на сервере их нет.
Да и не нужно это - огромная нагрузка ради нифига же.
В нормальных кейсах, эти дырки от пуль вообще должны через время пропадать, если, например, находятся вне камеры игрока, чтобы не бросалось в глаза.
 
54
0
timaxa007 написал(а):
Получилось это:
Код:
public class ItemWeapon extends Item {

 @Override
 public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player) {
 if (!world.isRemote) {
 EntityBullet entity = new EntityBullet(world, player);
 world.spawnEntityInWorld(entity);
 }
 return super.onItemRightClick(is, world, player);
 }

}
Код:
public class EntityBullet extends EntityThrowable {

 public EntityBullet(World world) {
 super(world);
 }

 public EntityBullet(World world, EntityLivingBase entity) {
 super(world, entity);
 }

 @Override
 public void onImpact(MovingObjectPosition mop) {
 switch(mop.typeOfHit) {
 case ENTITY:
 if (mop.entityHit != null)
 mop.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 6.0F);
 break;
 case BLOCK:
 if (worldObj.isRemote) {
 Minecraft.getMinecraft().effectRenderer.addEffect(new BulletHoleFX(worldObj,
 mop.hitVec.xCoord,
 mop.hitVec.yCoord,
 mop.hitVec.zCoord,
 mop.sideHit)
 );
 }
 break;
 default:break;
 }
 this.setDead();
 }

}
Код:
@SideOnly(Side.CLIENT)
public class BulletHoleFX extends EntityFX {

 static final ResourceLocation textureBulletHole = new ResourceLocation(SMTWeapon.MODID, "textures/bullet_hole.png");
 int side;

 public BulletHoleFX(World world, double x, double y, double z, int sideHit) {
 super(world, x, y, z);
 this.motionX = this.motionY = this.motionZ = 0.0D;
 this.side = sideHit;
 this.particleMaxAge = 600;
 }

 @Override
 public void renderParticle(Tessellator tessellator, float p_70539_2_, float p_70539_3_, float p_70539_4_, float p_70539_5_, float p_70539_6_, float p_70539_7_) {
 float f6 = ((float)this.particleAge + p_70539_2_) / (float)this.particleMaxAge;
 f6 *= f6;
 float f7 = 2.0F - f6 * 2.0F;

 if (f7 > 1.0F) f7 = 1.0F;

 Entity player = Minecraft.getMinecraft().thePlayer;

 this.interpPosX = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)p_70539_2_;
 this.interpPosY = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)p_70539_2_;
 this.interpPosZ = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)p_70539_2_;

 //f7 *= 0.2F;
 GL11.glPushMatrix();
 GL11.glDisable(GL11.GL_LIGHTING);
 float f8 = 0.125F;
 float f9 = (float)(this.posX - interpPosX);
 float f10 = (float)(this.posY - interpPosY);
 float f11 = (float)(this.posZ - interpPosZ);
 float f12 = this.worldObj.getLightBrightness(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ));
 Minecraft.getMinecraft().getTextureManager().bindTexture(textureBulletHole);
 GL11.glEnable(GL11.GL_BLEND);
 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
 //GL11.glDisable(GL11.GL_TEXTURE_2D);
 tessellator.startDrawingQuads();
 tessellator.setColorRGBA_F(f12, f12, f12, f7);

 switch(side) {
 case 0:
 tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 - 0.01F, (double)(f11 - f8), 0.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 - 0.01F, (double)(f11 - f8), 1.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 - 0.01F, (double)(f11 + f8), 1.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 - 0.01F, (double)(f11 + f8), 0.0D, 0.0D);
 break;
 case 1:
 tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 + 0.01F, (double)(f11 + f8), 0.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 + 0.01F, (double)(f11 + f8), 1.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)f10 + 0.01F, (double)(f11 - f8), 1.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 - f8), (double)f10 + 0.01F, (double)(f11 - f8), 0.0D, 1.0D);
 break;
 case 2:
 tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 + f8), (double)(f11 - 0.01F), 0.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 + f8), (double)(f11 - 0.01F), 1.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 - f8), (double)(f11 - 0.01F), 1.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 - f8), (double)(f11 - 0.01F), 0.0D, 0.0D);
 break;
 case 3:
 tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 - f8), (double)(f11 + 0.01F), 0.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 - f8), (double)(f11 + 0.01F), 1.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 + f8), (double)(f10 + f8), (double)(f11 + 0.01F), 1.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 - f8), (double)(f10 + f8), (double)(f11 + 0.01F), 0.0D, 1.0D);
 break;
 case 4:
 tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 + f8), (double)(f11 + f8), 1.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 + f8), (double)(f11 - f8), 1.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 - f8), (double)(f11 - f8), 0.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 - 0.01F), (double)(f10 - f8), (double)(f11 + f8), 0.0D, 1.0D);
 break;
 case 5:
 tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 - f8), (double)(f11 + f8), 0.0D, 1.0D);
 tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 - f8), (double)(f11 - f8), 0.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 + f8), (double)(f11 - f8), 1.0D, 0.0D);
 tessellator.addVertexWithUV((double)(f9 + 0.01F), (double)(f10 + f8), (double)(f11 + f8), 1.0D, 1.0D);
 break;
 default:break;
 }
 
 tessellator.draw();
 //GL11.glEnable(GL11.GL_TEXTURE_2D);
 GL11.glDisable(GL11.GL_BLEND);
 GL11.glEnable(GL11.GL_LIGHTING);
 GL11.glPopMatrix();
 }

 @Override
 public void onUpdate() {
        if (this.particleAge++ >= this.particleMaxAge) this.setDead();
 }

 @Override
 public int getFXLayer() {
 return 3;
 }

}
Доделывать надо, писал как пример.


Золотые у вас руки, спасибо вам большое ;)
 

timaxa007

Модератор
5,831
409
672
Maxik001 написал(а):
Еще бы стекло разлеталось вдребезги со звоном!
Java:
        case BLOCK:
            if (worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ) == Blocks.glass) {
                if (!worldObj.isRemote)
                    worldObj.func_147480_a(mop.blockX, mop.blockY, mop.blockZ, true);
                break;
            }
            if (worldObj.isRemote) {
                Minecraft.getMinecraft().effectRenderer.addEffect(new BulletHoleFX(worldObj,
                        mop.hitVec.xCoord,
                        mop.hitVec.yCoord,
                        mop.hitVec.zCoord,
                        mop.sideHit)
                        );
            }
            break;
 
Последнее редактирование:
643
6
14
timaxa007 написал(а):
Maxik001 написал(а):
Еще бы стекло разлеталось вдребезги со звоном!
Код:
 case BLOCK:
 if (worldObj.getBlock(mop.blockX, mop.blockY, mop.blockZ) == Blocks.glass) {
 if (!worldObj.isRemote)
 worldObj.func_147480_a(mop.blockX, mop.blockY, mop.blockZ, true);
 break;
 }
 if (worldObj.isRemote) {
 Minecraft.getMinecraft().effectRenderer.addEffect(new BulletHoleFX(worldObj,
 mop.hitVec.xCoord,
 mop.hitVec.yCoord,
 mop.hitVec.zCoord,
 mop.sideHit)
 );
 }
 break;
Вечно помогающий, вечно дебажущий.
(На СГ отсылка)
 
Сверху