# [1.7.2] Multi Block Structure Help

## Recommended Posts

I want to create a normal multi block structure in my mod, but I have no idea where to start. Can anybody at least point me in the right direction or help me do this?

##### Share on other sites

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

1.12 -> 1.13 primer by williewillus.

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

##### Share on other sites

How would I go about doing the block class?

##### Share on other sites

How would I go about doing the block class?

I see what you mean. That blog post should be properly titled, a multi-TE TileEntity, since there are no blocks involved in their code.

-S- (if I helped, please click Thank and applaud)

##### Share on other sites

I'm a fan of just doing it with good ol' "brute force".  Just take some graph paper and draw out what you want.  Then create a method that places each block in the location (probably a relative location to some starting point).

For any regularly shaped features, like a straight wall, you can use for loops to cut down on the lines of code you need.

I actually do it with 2D arrays for each layer, and then loop through the arrays.  For example, imagine if you set a int code to represent each type of block you want.  Like air/nothing = 0, sandstone = 1, or whatever blocks you are happening to use.

Then you can have an int array for first layer that sets the foundation for the walls, something like this for a room:

```int[][] wallsRoom1 = new int[][]
{{1,1,1,1,1,1,1},
{1,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,0,0,0,0,0,1},
{1,1,1,0,1,1,1},
{0,0,1,0,1,0,0},
{0,0,1,0,1,0,0}};```

And then you can loop through that placing the block indicated in the location indicated.  You could build up this wall by looping through at multiple heights.

I like this method because it is almost like just drawing the structure right in code -- very easy to visualize.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

##### Share on other sites

I can't get my multiblock to form, any more words of wisdom you can offer?

##### Share on other sites

I don't really get the idea of how this works. Is there some documentation or full tutorial on this?

##### Share on other sites

Guy who wrote the tutorial here. Just finished fixing some errors in it. What don't you seem to get?

##### Share on other sites

Guy who wrote the tutorial here. Just finished fixing some errors in it. What don't you seem to get?

Thank you for your tutorial, it helps me (who is new to modding) get the tile entity class. But I don't get the Block class and how to decide each block, and where they go, and then call it. I've tried some methods that didn't work and got frustrated before deleting that code and writing new code that still won't work. Any help is appreciated!

##### Share on other sites

Just have your Block class either extend BlockContainer (instead of simply Block) or implement ITileEntityProvider. It'll generate a method called createNewTileEntity, which should be as such:

```public TileEntity createNewTileEntity(World world, int meta) {
return new TileMultiBlock(); //or whatever you name your tile entity class
}```

Also remember to register your TileEntity, or else it will not work

```//Recommend doing this somewhere in your FMLInitializationEvent.
GameRegistry.registerTileEntity(TileMultiBlock.class, "modmod.tilemultiblock");```

##### Share on other sites

Just have your Block class either extend BlockContainer (instead of simply Block) or implement ITileEntityProvider. It'll generate a method called createNewTileEntity, which should be as such:

```public TileEntity createNewTileEntity(World world, int meta) {
return new TileMultiBlock(); //or whatever you name your tile entity class
}```

Also remember to register your TileEntity, or else it will not work

```//Recommend doing this somewhere in your FMLInitializationEvent.
GameRegistry.registerTileEntity(TileMultiBlock.class, "modmod.tilemultiblock");```

I am sorry to be such a noob, but where and how do I specify my specific blocks I am using and the location of each one?

##### Share on other sites

I am sorry to be such a noob, but where and how do I specify my specific blocks I am using and the location of each one?

In the checkMultiBlockForm method in the Tile Entity. ATM, the way the tutorial is written, it checks for blocks that have the same tile entity (so if you want all your multiblocks to be made of the same block, the tutorial has it already set up). If you want to check for specific blocks, you'd have to do that manually, and change setupStructure method accordingly.

##### Share on other sites

How would I do an onBlockActivated of the MultiBlock = player.openGui?

##### Share on other sites

How would I do an onBlockActivated of the MultiBlock = player.openGui?

```public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
if (!world.isRemote && !player.isSneaking()) {
TileMultiBlock tile = (TileMultiBlock) world.getTileEntity(x, y, z);
if (tile != null) {
if (tile.hasMaster()) {
if (tile.isMaster())
player.openGui(Mod.instance, 99, world, x, y, z);
else
player.openGui(Mod.instance, 99, world, tile.getMasterX(), tile.getMasterY(), tile.getMasterZ());
return true;
}
}
}
return false;
}
```

Replace the values accordingly.

##### Share on other sites

Can you post a tutorial on github or something that has a working 3x3x3 multi block with all the needed classes used, and using stone? It would help a lot of us.

##### Share on other sites

Why is everyone requesting code when i gave them a good tutorial for themto use? The only thing you have to do is make the block class, and that's explained in the tutorial as well (the opening-gui part). More then that you don't need.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

1.12 -> 1.13 primer by williewillus.

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

##### Share on other sites

Why am I getting an error: "The method hasMaster() is undefined for the type TileEntity" on

``` if (this.isMaster()) {
if (tile.hasMaster())
i++;
} else if (!tile.hasMaster())
i++;```

##### Share on other sites

Well, can anybody at least teach me how to do it, or write a tutorial. I don't need the code to copy and paste. I just want to learn, and I bet many other people would benefit as well.

##### Share on other sites

Why am I getting an error: "The method hasMaster() is undefined for the type TileEntity" on

``` if (this.isMaster()) {
if (tile.hasMaster())
i++;
} else if (!tile.hasMaster())
i++;```

Opps, another derp on my part, cast the tiles as instanceof of TileMultiBlock (or whatever you named your class)

##### Share on other sites

So how would you change it to be using stone as the entire structure? (just as an example)

##### Share on other sites

This would be really helpful for me too

##### Share on other sites

So how would you change it to be using stone as the entire structure? (just as an example)

This would be really helpful for me too

##### Share on other sites

I'm going further on what Lomeli12 has said:

He has showed you how to create a tile entity.

--Make sure it is registered by the game.

Create a Block Class which extends the BlockContainer Class:

Below is an example, I have to it passing the x, y, z co-ordinates which the block was placed.

```package com.example.examplemod.blocks;

import com.example.examplemod.entity.TileMultiBlock;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class BlockMainBlock extends BlockContainer {

// Normal setting up block stuff
public BlockMainBlock() {
super(Material.rock);
setBlockName("mainBlock");
setCreativeTab(CreativeTabs.tabBlock);
}

// Called when block is placed
@Override
public void onBlockAdded(World world, int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}

// Method you must use to create a new TileEntity.
@Override
public TileEntity createNewTileEntity(World world, int p_149915_2_) {

return new TileMultiBlock(x, y, z);
}
}
```

Later I'll get back to you on detecting stone..

Thank You Lomeli12, For your tutorial! Helped me a ton!

##### Share on other sites

I'm going further on what Lomeli12 has said:

He has showed you how to create a tile entity.

--Make sure it is registered by the game.

Create a Block Class which extends the BlockContainer Class:

Below is an example, I have to it passing the x, y, z co-ordinates which the block was placed.

```package com.example.examplemod.blocks;

import com.example.examplemod.entity.TileMultiBlock;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

public class BlockMainBlock extends BlockContainer {

// Normal setting up block stuff
public BlockMainBlock() {
super(Material.rock);
setBlockName("mainBlock");
setCreativeTab(CreativeTabs.tabBlock);
}

// Called when block is placed
@Override
public void onBlockAdded(World world, int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}

// Method you must use to create a new TileEntity.
@Override
public TileEntity createNewTileEntity(World world, int p_149915_2_) {

return new TileMultiBlock(x, y, z);
}
}
```

Thank you, can't wait for that next part

##### Share on other sites

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();
}

@Override
{
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...

## 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.

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

### Announcements

×

• #### Activity

×
• Create New...