Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Making particles for a block come from the getTexture instead of getIcon
@SideOnly(Side.CLIENT)
class EntityDiggingParticle extends EntityFX {
public EntityDiggingParticle(wrd: World, pos1X: Double, pos1Y: Double, pos1Z: Double, motX: Double, motY: Double, motZ: Double, icon: Icon){
super(wrd, pos1X, pos1Y, pos1Z, motX, motY, motZ);
particleIcon = icon
particleGravity = 1
particleScale /= 2.0F
}
public EntityDiggingParticle(wrd: World, pos1X: Double, pos1Y: Double, pos1Z: Double, motX: Double, motY: Double, motZ: Double, block: Block, side: Int, x: Int, y: Int, z: Int) {
this(wrd, pos1X, pos1Y, pos1Z, motX, motY, motZ, block.getBlockTexture(wrd, x, y, z, side))
}
public int getFXLayer() = 1
public void renderParticle(Tessellator tess, float deltaV, float xVal, float yVal, float zVal, float uMod, float vMod) {
float u1 = (particleTextureIndexX + particleTextureJitterX / 4.0F) / 16.0F;
float u2 = u1 + 0.015609375F;
float v1 = (particleTextureIndexY + particleTextureJitterY / 4.0F) / 16.0F;
float v2 = v1 + 0.015609375F;
float scale = 0.1F * particleScale;
if (particleIcon != null) {
u1 = particleIcon.getInterpolatedU(particleTextureJitterX * 4);
u2 = particleIcon.getInterpolatedU((particleTextureJitterX + 1) * 4);
v1 = particleIcon.getInterpolatedV(particleTextureJitterY * 4);
v2 = particleIcon.getInterpolatedV((particleTextureJitterY + 1) * 4);
}
val vX = prevPosX + (posX - prevPosX) * deltaV - EntityFX.interpPosX;
val vY = prevPosY + (posY - prevPosY) * deltaV - EntityFX.interpPosY;
val vZ = prevPosZ + (posZ - prevPosZ) * deltaV - EntityFX.interpPosZ;
tess.setColorRGBA(153, 153, 153, 255);
tess.addVertexWithUV(vX - xVal * scale - uMod * scale, vY - yVal * scale, vZ - zVal * scale - vMod * scale, u1, v2);
tess.addVertexWithUV(vX - xVal * scale + uMod * scale, vY + yVal * scale, vZ - zVal * scale + vMod * scale, u1, v1);
tess.addVertexWithUV(vX + xVal * scale + uMod * scale, vY + yVal * scale, vZ + zVal * scale + vMod * scale, u2, v1);
tess.addVertexWithUV(vX + xVal * scale - uMod * scale, vY - yVal * scale, vZ + zVal * scale - vMod * scale, u2, v2);
}
}
public class MyBlock extends Block{
public static final Random rand = new Random();
...
@Override
public boolean addBlockHitEffects(World wrd, MovingObjectPosition tgt, EffectRenderer effRendr){
int x = tgt.blockX;
int y = tgt.blockY;
int z = tgt.blockZ;
int side = tgt.sideHit;
if (wrd.getBlockId(x, y, z) == blockID) {
float f = 0.1F;
double d0 = x + rand.nextDouble() * (getBlockBoundsMaxX() - getBlockBoundsMinX() - f * 2.0F) + f + getBlockBoundsMinX();
double d1 = y + rand.nextDouble() * (getBlockBoundsMaxY() - getBlockBoundsMinY() - f * 2.0F) + f + getBlockBoundsMinY();
double d2 = z + rand.nextDouble() * (getBlockBoundsMaxZ() - getBlockBoundsMinZ() - f * 2.0F) + f + getBlockBoundsMinZ();
switch (side) {
case 0:
d1 = y + getBlockBoundsMinY() - f;
break;
case 1:
d1 = y + getBlockBoundsMaxY() + f;
break;
case 2:
d2 = z + getBlockBoundsMinZ() - f;
break;
case 3:
d2 = z + getBlockBoundsMaxZ() + f;
break;
case 4:
d0 = x + getBlockBoundsMinX() - f;
break;
case 5:
d0 = x + getBlockBoundsMaxX() + f;
break;
}
effRendr.addEffect(new EntityDiggingParticle(wrd, d0, d1, d2, 0.0D, 0.0D, 0.0D, this, side, x, y, z).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
return true;
}
return false;
}
@Override
public boolean addBlockDestroyEffects(World wrd, int x, int y, int z, int meta, EffectRenderer effRendr) {
if (wrd.getBlockId(x, y, z) == blockID) {
for (double k1 = 0; k1 < 4; k1++) {
for (double j1 = 0; j1 < 4; j1++) {
for (double l1 = 0; l1 < 4; l1++) {
double d0 = x + (j1 + 0.5D) / 4D;
double d1 = y + (k1 + 0.5D) / 4D;
double d2 = z + (l1 + 0.5D) / 4D;
int side = rand.nextInt(6);
effRendr.addEffect(new EntityDiggingParticle(wrd, d0, d1, d2, d0 - x - 0.5D, d1 - y - 0.5D, d2 - z - 0.5D, this, side, x, y, z));
}
}
}
return true;
}
return true;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.