Jump to content

[1.7.10] [UNSOLVED] Particle not spawning or need rightclick to spawn them


Recommended Posts

Posted

Hello,

 

I created a Campfire, that should ony spawn particles when its burning (because its a bit like a furnace), but it will not spawn them after I re-wrote some stuff. Before I re-wrote it, there where particles but after some time they disappeared and then I must open the GUI of the Campfire that the particles are coming back...

 

But now the particles disappeared forever!

 

BlockPFCampFire.java

    /**
     * Spawns flame particle over the camp fire
     */
    @Override
    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(World world, int x, int y, int z, Random random)
    {
    	TileEntityCampFire tileentityCampfire = (TileEntityCampFire) world.getTileEntity(x, y, z);
    	
    	if(tileentityCampfire != null)
    	{
    		if(tileentityCampfire.isBurning() && tileentityCampfire.burning(world, x, y, z, true))
    		{
    	    	for(int i = 0; i < 3; i++)
    	    	{
    	    		float motionY = (random.nextFloat() / 40F) + 0.025F;
    	    		
    	    		double particleX = ((x + 0.5F) - 0.15F) + (random.nextInt(30) / 100F);
    	    		double particleY = y + 0.1F + (random.nextInt(15) / 100F);
    	    		double particleZ = ((z + 0.5F) - 0.15F) + (random.nextInt(30) / 100F);
    	    		
    	    		PrimevalForest.proxy.spawnFlame(world, particleX, particleY, particleZ, 0.0F, motionY, 0.0F, 16);
    	    		world.spawnParticle("smoke", particleX, particleY, particleZ, 0.0D, 0.05D, 0.0D);
    	    	}
    		}
    	}
    }
    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World world, int x, int y, int z, Random random) 
    {
    	if(world.isRemote)
    		return;
    	
    	TileEntityCampFire tileentityCampfire = (TileEntityCampFire)world.getTileEntity(x, y, z);
    	
    	if(tileentityCampfire != null)
    	{
        	if(tileentityCampfire.burning(world, x, y, z, false))
        		if(world.isRaining() || world.isThundering())
        			if(world.canBlockSeeTheSky(x, y, z))
        				tileentityCampfire.setBurning(false);
    	}
    }

    /**
     * Called upon block activation (right click on the block.)
     */
@Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float px, float py, float pz)
    {
	TileEntityCampFire tileentityCampfire = (TileEntityCampFire)world.getTileEntity(x, y, z);

	if(tileentityCampfire != null)
	{

		if(world.isRemote)
			return false;

		if(!player.isSneaking())
			if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.flint_and_steel)
				if(!world.isRaining() && !world.isThundering() && tileentityCampfire.slots[1] != null)
					tileentityCampfire.setBurning(true);


		player.openGui(PrimevalForest.instance, 1, world, x, y, z);
		return true;
	}

	return false;
    }

 

TileEntityCampFire.java

/** Can the campfire burn or not */
public boolean burning;

@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
	super.writeToNBT(nbtTagCompound);

	nbtTagCompound.setBoolean("isBurning", (boolean)this.burning);
	nbtTagCompound.setShort("BurnTime", (short)this.burnTime);
	nbtTagCompound.setShort("CookTime", (short)this.cookTime);
	nbtTagCompound.setShort("CurrentBurnTime", (short)this.currentItemBurnTime);

	NBTTagList list = new NBTTagList();

	for(int i = 0; i < this.slots.length; i++)
		if(this.slots[i] != null)
		{
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("Slot", (byte)i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}

	nbtTagCompound.setTag("Items", list);

	if(this.hasCustomInventoryName())
		nbtTagCompound.setString("CustomName", this.localizedName);
}

@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
	super.readFromNBT(nbtTagCompound);

	NBTTagList list = nbtTagCompound.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for(int i = 0; i < list.tagCount(); i++)
	{
		NBTTagCompound compound = list.getCompoundTagAt(i);
		byte b = compound.getByte("Slot");

		if(b >= 0 && b < this.slots.length)
			this.slots[b] = ItemStack.loadItemStackFromNBT(compound);
	}

	setBurning(nbtTagCompound.getBoolean("isBurning"));
	this.burnTime = nbtTagCompound.getShort("BurnTime");
	this.cookTime = nbtTagCompound.getShort("CookTime");
	this.currentItemBurnTime = nbtTagCompound.getShort("CurrentBurnTime");

	if(nbtTagCompound.hasKey("CustomName", )
		this.localizedName = nbtTagCompound.getString("CustomName");
}

    /**
     * Camp Fire isBurning
     */
    public boolean isBurning()
    {
        return this.burnTime > 0;
    }
    
    public boolean burning(World world, int x, int y, int z, boolean lastArgNeeded)
    {
    	return !(world.isRaining() || world.isThundering()) || !world.canBlockSeeTheSky(x, y, z) && lastArgNeeded ? burning : true;
    }

@Override
public void updateEntity()
{
	boolean flag = false;

	if(this.isBurning() && burning(worldObj, xCoord, yCoord, zCoord, true))
		this.burnTime--;

	if(!this.worldObj.isRemote)
	{
		if(this.burnTime != 0 || this.slots[1] != null && burning(worldObj, xCoord, yCoord, zCoord, false))
		{
			if(this.burnTime == 0)
			{
				this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);

				if(this.isBurning())
				{
					flag = true;

					if(this.slots[1] != null)
						this.slots[1].stackSize--;

					if(this.slots[1].stackSize == 0)
						this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
				}
			}

			if(this.isBurning() && this.canSmelt())
			{
				this.cookTime++;

				if(this.cookTime == this.campFireSpeed)
				{
					this.cookTime = 0;
					this.smeltItem();
					flag = true;
				}
			}
			else
				this.cookTime = 0;
		}
	}

	if(flag)
		this.markDirty();
}

 

I hope someone can help me with this.

Bektor

 

EDIT: This is not the complete code, but every single line that is using the methods I used for the particle spawn to check if it should spawn or not.

Developer of Primeval Forest.

Posted

Hi

 

I'd suggest you put a breakpoint or some System.out.println() in here to help you narrow it down, eg

 

 

    public void randomDisplayTick(World world, int x, int y, int z, Random random)
    {
    	TileEntityCampFire tileentityCampfire = (TileEntityCampFire) world.getTileEntity(x, y, z);
    	//here- print tileEntityCampfire
    	if(tileentityCampfire != null)
    	{
        //here - print isBurning and .burning(....)
    		if(tileentityCampfire.isBurning() && tileentityCampfire.burning(world, x, y, z, true))

 

-TGG

Posted

Ok.

 

Here is the output:

Tile:minecraftplaye.primevalforest.common.tileentities.TileEntityCampFire@311f9604

BurnTime:true

Wheaterstuff: false

Boolean: false

 

    public void randomDisplayTick(World world, int x, int y, int z, Random random)
    {
    	TileEntityCampFire tileentityCampfire = (TileEntityCampFire) world.getTileEntity(x, y, z);
    	
    	System.out.println("Tile:" + tileentityCampfire);
    	
    	if(tileentityCampfire != null)
    	{
    		System.out.println("BurnTime:" + tileentityCampfire.isBurning());
    		System.out.println("Wheaterstuff: " + tileentityCampfire.burning(world, x, y, z, true));
    		System.out.println("Boolean: " + tileentityCampfire.burning);
    		if(tileentityCampfire.isBurning() && tileentityCampfire.burning(world, x, y, z, true))
    		{

 

But I have no idea why the last two values are false. Its not raining and the campfire is burning (if its not burning: tileentityCampfire.burning = false) And I opened the GUI, its burning...

Developer of Primeval Forest.

Posted

Ok, I found out why its returning false, but after I changed it its still returning false....  :'(

 

    public boolean burning(World world, int x, int y, int z, boolean lastArgNeeded)
    {
    	if(world.isRaining() || world.isThundering())
    	{
    		if(!world.canBlockSeeTheSky(x, y, z))
    		{
    			if(lastArgNeeded)
    				return burning;
    			else
    				return true;
    		}
    		else
    			return false;
    	}
    	else if(lastArgNeeded)
    		return burning;
    	else
    		return true;
    }

So if its raining and the block can't see the sky its returning burning or true. If the block can see the sky its returning false. If its not raining its returing burning or true.

 

So why is it returning false.... And why can the block burn without a rightclick. If one block was burning I need only to break it while its burning and place a new one. There I need then only to put log or wood into it and it starts burning, but thats wrong, it should only burn if there is fuel (log or wood) in it and if I did a right click on it.

 

Please help!

Developer of Primeval Forest.

  • 2 weeks later...
Posted

Ok, I changed it a bit, the output of every three  values is still false:

 

TileEntity

/** The number of ticks that the camp fire will keep burning */
public int burnTime;

/** The number of ticks that a fresh copy of the currently-burning item would keep the camp fire burning for */
public int currentItemBurnTime;

/** The number of ticks that the current item has been cooking for */
public int cookTime;

/** Can the campfire burn or not */
public boolean canBurn;

@Override
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
	super.writeToNBT(nbtTagCompound);

	nbtTagCompound.setBoolean("isBurning", (boolean)this.canBurn);
	nbtTagCompound.setShort("BurnTime", (short)this.burnTime);
	nbtTagCompound.setShort("CookTime", (short)this.cookTime);
	nbtTagCompound.setShort("CurrentBurnTime", (short)this.currentItemBurnTime);

	NBTTagList list = new NBTTagList();

	for(int i = 0; i < this.slots.length; i++)
		if(this.slots[i] != null)
		{
			NBTTagCompound compound = new NBTTagCompound();
			compound.setByte("Slot", (byte)i);
			this.slots[i].writeToNBT(compound);
			list.appendTag(compound);
		}

	nbtTagCompound.setTag("Items", list);

	if(this.hasCustomInventoryName())
		nbtTagCompound.setString("CustomName", this.localizedName);
}

@Override
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
	super.readFromNBT(nbtTagCompound);

	NBTTagList list = nbtTagCompound.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for(int i = 0; i < list.tagCount(); i++)
	{
		NBTTagCompound compound = list.getCompoundTagAt(i);
		byte b = compound.getByte("Slot");

		if(b >= 0 && b < this.slots.length)
			this.slots[b] = ItemStack.loadItemStackFromNBT(compound);
	}

	setBurning(nbtTagCompound.getBoolean("isBurning"));
	this.burnTime = nbtTagCompound.getShort("BurnTime");
	this.cookTime = nbtTagCompound.getShort("CookTime");
	this.currentItemBurnTime = nbtTagCompound.getShort("CurrentBurnTime");

	if(nbtTagCompound.hasKey("CustomName", )
		this.localizedName = nbtTagCompound.getString("CustomName");
}

    /**
     * Do not make give this method the name canInteractWith because it clashes with Container
     * 
     * Can the inventory of this block be used by a player?
     */
@Override
public boolean isUseableByPlayer(EntityPlayer player) 
{
	if(this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this)
		if(player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 14.0D)
			if(player.getCurrentEquippedItem() == null || !player.getCurrentEquippedItem().getItem().equals(Items.flint_and_steel))
				return true;

	return false;
	//return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : (player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 14.0D && player.getCurrentEquippedItem().getItem() != Items.flint_and_steel);
}

@Override
public void openInventory() { }

@Override
public void closeInventory() { }

    /**
     * Camp Fire isBurning
     */
    public boolean isBurning()
    {
        return this.burnTime > 0;
    }
    
    /**
     * Can the camp fire burn
     * 
     * @Par am world The World the camp fire is in
     * @Par am x The xCoord of the camp fire
     * @Par am y The yCoord of the camp fire
     * @Par am z The zCoord of the camp fire
     * @Par am lastArgNeeded needs the camp fire to be activated with a 'flint and steel' item of not
     * 
     * @return true if the camp fire can burn, false if not
     */
    public boolean canBurn(World world, int x, int y, int z, boolean lastArgNeeded)
    {
    	if(!(world.isRaining() || world.isThundering())) // TODO: && world.getBiomeGenForCoords(x, y) != BiomeGenBase.desert
    	{
    		if(!world.canBlockSeeTheSky(x, y, z))
    		{
    			if(lastArgNeeded)
    				return canBurn;
    			else
    				return true;
    		}
    		else
    			return false;
    	}
    	else if(lastArgNeeded)
    		return canBurn;
    	else
    		return true;
    }

@Override
public void updateEntity()
{
	boolean flag = false;

	if(this.isBurning() && canBurn(worldObj, xCoord, yCoord, zCoord, true))
		this.burnTime--;

	if(!this.worldObj.isRemote)
	{
		if(this.burnTime != 0 || this.slots[1] != null && canBurn(worldObj, xCoord, yCoord, zCoord, false))
		{
			if(this.burnTime == 0)
			{
				this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.slots[1]);

				if(this.isBurning())
				{
					flag = true;

					if(this.slots[1] != null)
						this.slots[1].stackSize--;

					if(this.slots[1].stackSize == 0)
						this.slots[1] = this.slots[1].getItem().getContainerItem(this.slots[1]);
				}
			}

			if(this.isBurning() && this.canSmelt())
			{
				this.cookTime++;

				if(this.cookTime == this.campFireSpeed)
				{
					this.cookTime = 0;
					this.smeltItem();
					flag = true;
				}
			}
			else
				this.cookTime = 0;
		}
	}

	if(flag)
		this.markDirty();
}

 

Block

    /**
     * Ticks the block if it's been scheduled
     */
    public void updateTick(World world, int x, int y, int z, Random random) 
    {
    	if(world.isRemote)
    		return;
    	
    	TileEntityCampFire tileentityCampfire = (TileEntityCampFire)world.getTileEntity(x, y, z);
    	
    	if(tileentityCampfire != null)
    	{
        	if(tileentityCampfire.canBurn(world, x, y, z, false))
        		if(world.isRaining() || world.isThundering())
        			if(world.canBlockSeeTheSky(x, y, z))
        				tileentityCampfire.setBurning(false);
    	}
    }

    /**
     * Called upon block activation (right click on the block.)
     */
@Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float px, float py, float pz)
    {
	TileEntityCampFire tileentityCampfire = (TileEntityCampFire)world.getTileEntity(x, y, z);

	if(tileentityCampfire != null)
	{

		if(world.isRemote)
			return false;

		if(!player.isSneaking())
			if(player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() == Items.flint_and_steel)
				if(!world.isRaining() && !world.isThundering() && tileentityCampfire.slots[1] != null)
					tileentityCampfire.setBurning(true);


		player.openGui(PrimevalForest.instance, 1, world, x, y, z);
		return true;
	}

	return false;
    }

    /**
     * Spawns flame particle over the camp fire
     */
    @Override
    @Side Only(Side.CLIENT)
    public void randomDisplayTick(World world, int x, int y, int z, Random random)
    {
    	TileEntityCampFire tileentityCampfire = (TileEntityCampFire) world.getTileEntity(x, y, z);
    	
    	System.out.println("Tile:" + tileentityCampfire);
    	
    	if(tileentityCampfire != null)
    	{
    		System.out.println("BurnTime:" + tileentityCampfire.isBurning());
    		System.out.println("Weatherstuff: " + tileentityCampfire.canBurn(world, x, y, z, false));
    		System.out.println("Boolean: " + tileentityCampfire.canBurn);
    		if(tileentityCampfire.isBurning() && tileentityCampfire.canBurn(world, x, y, z, true))
    		{
    	    	for(int i = 0; i < 3; i++)
    	    	{
    	    		float motionY = (random.nextFloat() / 40F) + 0.025F;
    	    		
    	    		double particleX = ((x + 0.5F) - 0.15F) + (random.nextInt(30) / 100F);
    	    		double particleY = y + 0.1F + (random.nextInt(15) / 100F);
    	    		double particleZ = ((z + 0.5F) - 0.15F) + (random.nextInt(30) / 100F);
    	    		
    	    		PrimevalForest.proxy.spawnFlame(world, particleX, particleY, particleZ, 0.0F, motionY, 0.0F, 16);
    	    		world.spawnParticle("smoke", particleX, particleY, particleZ, 0.0D, 0.05D, 0.0D);
    	    	}
    		}
    	}
    }

 

And for some reason you can break one burning campfire and the next campfire you place is burning after you put wood in it, no need to activate it, like it should be...

So I tried it now for so long and posted in different forum and so on, if its now getting not be fixed I will remove it!

Developer of Primeval Forest.

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.