Jump to content

Recommended Posts

Posted

So I have a block with setTickRandomly enabled, in the updateTick override I perform various actions on the associated tile entity and am attempting to trigger a particle effect on some occasions, however when calling the spawnParticle method from within the updateTick method, the particle does not appear to render in-game.

 

I can trigger the particle via randomDisplayTick method but that just renders the particle continuously.

 

Is there some way to trigger the particle from updateTick, or do I have to check for changes to the tile entity data within randomDisplayTick (seems expensive)?

 

Here's how my updateTick method looks:

public void updateTick(World world, int x, int y, int z, Random rand)
    {
	if (world.provider.isHellWorld) {
            return;
        } else {
        if (world.getSavedLightValue(EnumSkyBlock.Block, x, y, z) > 10 - this.getLightOpacity()) {
            return;
        } else {
        	SoftGlassEntity entity = (SoftGlassEntity) world.getTileEntity(x, y, z);
        	int currentTemperature = entity.getGlassTemperature();
        	if(currentTemperature > 0){
        		currentTemperature--;
        		entity.setGlassTemperature(currentTemperature);
        		world.markBlockForUpdate(x, y, z);
        		world.playSoundEffect((double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, "random.fizz", 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
        		world.spawnParticle("largesmoke", (double)x + 0.5D, (double)y + 1.2D, (double)z + 0.5D, 0.0D, 0.1D, 0.0D);
        	} else {
        		world.setBlock(x, y, z, Blocks.glass);
        		world.removeTileEntity(x, y, z);
        	}
        }
        }
}

The fizz sound effect is playing just fine but the smoke particle doesn't seem to be rendering.

Posted

Solved it by manipulating the block metadata when condition is met and then checking for block metadata changes in the randomDisplayTick, seems similar to how vanilla redstone wire handles their particles.

 

Full code of block and tile entity for reference in case others want to do something like this:

public class SoftGlassBlock extends Block implements ITileEntityProvider {

public SoftGlassBlock(Material material){
	super(material);
	setTickRandomly(true);
	setBlockName("softGlassBlock");
	setBlockTextureName(QuenchProperties.MODID + ":" + getUnlocalizedName().substring(5));
	setCreativeTab(CreativeTabs.tabBlock);
	setLightLevel(0.3F);
	setLightOpacity(3);
}

@SideOnly(Side.CLIENT)
    public int getRenderBlockPass(){
        return 1;
    }

@SideOnly(Side.CLIENT)
    public boolean shouldSideBeRendered(IBlockAccess p_149646_1_, int p_149646_2_, int p_149646_3_, int p_149646_4_, int p_149646_5_)
    {
	Block block = p_149646_1_.getBlock(p_149646_2_, p_149646_3_, p_149646_4_);
	return block == this ? false : super.shouldSideBeRendered(p_149646_1_, p_149646_2_, p_149646_3_, p_149646_4_, p_149646_5_);
    }

public boolean isOpaqueCube(){
	return false;
}

public void updateTick(World world, int x, int y, int z, Random rand)
    {
	if (world.provider.isHellWorld) {
            return;
        } else {
        if (world.getSavedLightValue(EnumSkyBlock.Block, x, y, z) > 10 - this.getLightOpacity()) {
            return;
        } else {
        	SoftGlassEntity entity = (SoftGlassEntity) world.getTileEntity(x, y, z);
        	int currentTemperature = entity.getGlassTemperature();
        	if(currentTemperature > 0){
        		currentTemperature--;
        		entity.setGlassTemperature(currentTemperature);
        		world.markBlockForUpdate(x, y, z);
        		world.playSoundEffect((double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, "random.fizz", 1.0F, world.rand.nextFloat() * 0.1F + 0.9F);
        	} else {
        		world.setBlock(x, y, z, Blocks.glass);
        		world.removeTileEntity(x, y, z);
        	}
        }
        }
    }

@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random rand) {
	int meta = world.getBlockMetadata(x, y, z);
	if(meta > 0){
		world.spawnParticle("largesmoke", (double)x + 0.5D, (double)y + 1.2D, (double)z + 0.5D, 0.0D, 0.1D, 0.0D);
		world.setBlockMetadataWithNotify(x, y, z, 0, 2);
	}
}

@Override
public TileEntity createNewTileEntity(World world, int p_149915_2_) {
	return new SoftGlassEntity();
}

}

 

public class SoftGlassEntity extends TileEntity {

private int glassTemperature;

public SoftGlassEntity(){
	this.glassTemperature = 3;
}

public void setGlassTemperature(int temperature){
	worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2);
	this.glassTemperature = temperature;
}

public int getGlassTemperature(){
	return this.glassTemperature;
}

public void writeToNBT(NBTTagCompound tag)
    {
        super.writeToNBT(tag);
        tag.setInteger("GlassTemperature", this.glassTemperature);
    }

public void readFromNBT(NBTTagCompound tag)
    {
        super.readFromNBT(tag);
        this.glassTemperature = tag.getInteger("GlassTemperature");
    }

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.