Jump to content

Recommended Posts

Posted

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.

Posted

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/

Posted

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!

Posted

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");

Posted

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?

Posted

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.

Posted

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.

Posted

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.

 

http://www.howoldisminecraft1710.today/

Posted

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++;

Posted

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)

Posted

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! :)

Posted

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 :)

Posted

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

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.