Jump to content

Placing blocks in the world [Solved]


zimooo2

Recommended Posts

Whenever I try to place a block in the world, it will get placed, but once I hit "save and quit" and reload the game, the block returns to how it was.

 

[spoiler=Simplified Code]

    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
             par1World.setBlock(par2, par3, par4, Core.Stick.blockID);
             [color=red]par1World.markBlockForUpdate(par2, par3, par4);[/color]
    }

This code that I think should force the block to be saved, but is not working

 

 

[spoiler=Full code]

    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        int l = par1World.getBlockMetadata(par2, par3, par4);
        double d0 = (double)((float)par2 + 0.5F);
        double d1 = (double)((float)par3 + 0.7F);
        double d2 = (double)((float)par4 + 0.5F);
        double d3 = 0.2199999988079071D;
        double d4 = 0.27000001072883606D;

        TileEntityTorch tileentitytorch = (TileEntityTorch)par1World.getBlockTileEntity(par2, par3, par4);
        System.out.println(tileentitytorch);
        if(tileentitytorch.getBurnout() == -10)
        {
        	tileentitytorch.setBurnout(100);
        }
        if(tileentitytorch.getBurnout() >= 0)
        	tileentitytorch.setBurnout(tileentitytorch.getBurnout() - 1);
        System.out.println(tileentitytorch.getBurnout());
        
        
        if(tileentitytorch.getBurnout() <= 0)
        {
        	par1World.setBlock(par2, par3, par4, Core.Stick.blockID);
            if (par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 2);
            }
            else if (par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
            }
            else if (par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
            }
            else if (par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
            }
            else if (this.canPlaceTorchOn(par1World, par2, par3 - 1, par4))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
            }
            par1World.markBlockForUpdate(par2, par3, par4);
            par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));
            par1World.setblock
        }
        if (l == 1 && tileentitytorch.getBurnout() >= 0)
        {
            par1World.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
            par1World.spawnParticle("flame", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
        }
        else if (l == 2 && tileentitytorch.getBurnout() >= 0)
        {
            par1World.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
            par1World.spawnParticle("flame", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
        }
        else if (l == 3&& tileentitytorch.getBurnout() >= 0)
        {
            par1World.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
            par1World.spawnParticle("flame", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
        }
        else if (l == 4&& tileentitytorch.getBurnout() >= 0)
        {
            par1World.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
            par1World.spawnParticle("flame", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
        }
        else if(tileentitytorch.getBurnout() >= 0)
        {
            par1World.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
            par1World.spawnParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
        }
    }

 

 

thanks in advance, I will be unable to respond for a few hours as I will be going to sleep.

Link to comment
Share on other sites

When placed manually the block will save, but when the burnout time is reached and the block tries to replace itself with the stick, it will not save.

 

edit:

I put your code in, and it didn't place the block correctly. Here is some code that I left out of the simplified code that I think would be important

[spoiler=missing important code]

            if (par1World.isBlockSolidOnSide(par2 - 1, par3, par4, EAST, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 1, 2);
            }
            else if (par1World.isBlockSolidOnSide(par2 + 1, par3, par4, WEST, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
            }
            else if (par1World.isBlockSolidOnSide(par2, par3, par4 - 1, SOUTH, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
            }
            else if (par1World.isBlockSolidOnSide(par2, par3, par4 + 1, NORTH, true))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
            }
            else if (this.canPlaceTorchOn(par1World, par2, par3 - 1, par4))
            {
                par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
            }

 

Link to comment
Share on other sites

Solution

[spoiler=TileEntity]

package zimooo2.groundUp.tileEntity;

import net.minecraft.block.BlockYourBlock;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.tileentity.TileEntity;

public class TileEntityYourBlock extends TileEntity
{
int YourBlockBurnoutTime;
public TileEntityYourBlock () {
	 YourBlockBurnoutTime= -10;
}

public int getBurnout()
{
	return YourBlockBurnoutTime;
}
public void setBurnout(int YourBlock)
{
	YourBlockBurnoutTime = YourBlock;
}

    public void updateEntity()
    {
    	BlockYourBlock.ToNewBlock(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
    }
}

 

[spoiler=function to put in your block]

    public static void ToStick( World par1World, int par2, int par3, int par4)
    {
        TileEntityYourBlock tileentityYourBlock = (TileEntityYourBlock)par1World.getBlockTileEntity(par2, par3, par4);
        System.out.println(tileentityYourBlock);
        if(tileentityYourBlock.getBurnout() == -10)
        {
        	tileentityYourBlock.setBurnout(100);
        }
        if(tileentityYourBlock.getBurnout() >= 0)
        	tileentityYourBlock.setBurnout(tileentityYourBlock.getBurnout() - 1);
        System.out.println(tileentityYourBlock.getBurnout());
        
        
        if(tileentityYourBlock.getBurnout() <= 0)
        { 
        	System.out.println("tick ran");
        	par1World.setBlock(par2, par3, par4, Core.Stick.blockID);
        }
    	
    }

 

Link to comment
Share on other sites

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.

×
×
  • Create New...

Important Information

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