Jump to content

[1.7.2] Multi Block Structure Help


Recommended Posts

This doesn't work...I did try again though

 

Block Class

 

 

public class Forge extends BlockContainer{

public Forge(int id, Material material){
	super(material);
	this.setCreativeTab(TestCraft.TestCraftTab);
}

public void onBlockAdded(World world, int x, int y, int z){
	TileEntityForge tile = new TileEntityForge();
	if(!tile.shouldRender){
		if(world.getBlock(x, y, z) == Blocks.stone
    			&& world.getBlock(x, y-1, z) == Blocks.stone
    			&& world.getBlock(x, y+1, z) == Blocks.stone
    			&& world.getBlock(x-1, y, z) == Blocks.stone
    			&& world.getBlock(x-1, y-1, z) == Blocks.stone
    			&& world.getBlock(x-1, y+1, z) == Blocks.stone
    			&& world.getBlock(x+1, y, z) == Blocks.stone
    			&& world.getBlock(x+1, y-1, z) == Blocks.stone
    			&& world.getBlock(x+1, y+1, z) == Blocks.stone){
			System.out.println("I am put together!");
    		((TileEntityForge)tile).shouldRender = true; 
		}
	}

}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
	return new TileEntityForge();
}
}

 

 

 

And the TileEntity Class

 

 

public class TileEntityForge extends TileEntity{
public boolean shouldRender = false;

@Override
public Packet getDescriptionPacket()
{
	NBTTagCompound tag = new NBTTagCompound();
	this.writeToNBT(tag);
	return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
	NBTTagCompound tag = pkt.func_148857_g();
	this.readFromNBT(tag);
}

@Override
public void readFromNBT(NBTTagCompound tagCompound)
{
	super.readFromNBT(tagCompound);
	this.shouldRender = tagCompound.getBoolean("shouldRender");
}

@Override
public void writeToNBT(NBTTagCompound tagCompound)
{
	super.writeToNBT(tagCompound);
	tagCompound.setBoolean("shouldRender", this.shouldRender);
}
}

 

 

 

Any help? I have tried many methods...

TileEntityForge tile = new TileEntityForge();

Why are you making a brand new instance instead of getting the block's actual tile entity? ><

TileEntityForge blockTile = (TileEntityForge) world.getTileEntity(x, y, z);

Also, I why are you checking in your block added section instead of the checkMultiBlockForm from the tile (assuming you're using the tutorial). Judging by your code, you want your block to be surrounded by stone. If you followed the tutorial, all you would have to do to check if it formed was change that method to the following:

public boolean checkMultiBlockForm() {
    int i = 0;
    // Scan a 3x3x3 area, starting with the bottom left corner
    for (int x = xCoord - 1; x < xCoord + 2; x++)
        for (int y = yCoord -1; y < yCoord + 2; y++)
            for (int z = zCoord - 1; z < zCoord + 2; z++) {
                if (world.getBlock(x, y, z) == Blocks.stone)
                    i++;
            }
    return i == 26;
}

This would allow your block to constantly check around itself to make sure it's surrounded by stone.

 

Edit: Since you guys seem to have trouble grasping how this simple implementation works. I made an example mod that adds two types of multiblock blocks. The 1st requires you make a 3x3x3 structure with a hollow center using the block and it'll spawn a diamond block 6 blocks above the master. The 2nd require you surround it with stone and will turn said stone into diamonds once it sees that the structure is formed.

 

https://github.com/Lomeli12/MultiBlock-Tutorial

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.

Announcements



×
×
  • Create New...

Important Information

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