Jump to content

Recommended Posts

Posted

MyBlock.class

public class MyBlock extends Block {

    private Icon blockTop;
    private Icon blockFront;
    private myTileEntity tentity;
    
public MyBlock(int ID) {
	super(ID, Material.iron);
	this.setCreativeTab(CreativeTabs.tabBlock);
	tentity = new myTileEntity();
}
    
    public void onBlockAdded(World par1World, int par2, int par3, int par4)
    {
        super.onBlockAdded(par1World, par2, par3, par4);
        this.setDefaultDirection(par1World, par2, par3, par4);
    }

    public boolean onBlockActivated(World par1World, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
    {
    	 if (par1World.isRemote)
         {
             return true;
         }else{
    	tentity.switchActivated();
    	player.addChatMessage("[" + tentity.getActivated() + "]");
    	return true;
         }
    }
}

 

myTileEntity.class

package com.biosystemstudios;

import net.minecraft.tileentity.TileEntity;

public class myTileEntity extends TileEntity {
private boolean activated = false;

public myTileEntity() {}

public boolean getActivated(){
	return activated;
}
public void setActivated(boolean b){
	activated = b;
}
public void switchActivated(){
	activated = !activated;
}
}

 

There's my code but what the problem is when I place down more than 1 block and right click any one the activated variable is the same from the last block. So if i right click the first block it'll set activated to true but if I go right click the other block it'll set activated back to false

 

Tile Entities are supposed to store data unique to a specific block, how come the variable is still shared?

Bumper Cars!

Posted

Thats how they are supposed to be used yeah..

But that's not how you are using it now.

 

Your block classis only called once, inn the whole game your Block is only stored once.

The only thing stored at a gi en x,y,z location inn the world is a blockId, metadata and sometimes a TileEntity.

 

You need to readup some more on TilEntity's, I suggest following a tutorial for a custom furnace to start learning about TE's :)

 

What you are doing now is saying that Everytime the game looks for your block's TileEntityit will get the same single TilEntity everytime regardless of the world positions it looks at.

If you guys dont get it.. then well ya.. try harder...

Posted

hmm looked around and can't seem to find a tutorial for forge on creating new furnace type tile entities

 

[lmgtfy=forge furnace tutorial]Where did you look?[/lmgtfy] :P

There's a lot of them :)

 

If you guys dont get it.. then well ya.. try harder...

Posted

hmm looked around and can't seem to find a tutorial for forge on creating new furnace type tile entities

 

[lmgtfy=forge furnace tutorial]Where did you look?[/lmgtfy] :P

There's a lot of them :)

 

Haha I've googled but I can only find tutorials for it for 1.3.2 and earlier, and not for forge either

Bumper Cars!

Posted

For most things tutorials from 1.3.X of Minecraft and newer works for 1.5.1

The exception being the things that changed during the patches, like now the code for Icons and textures etc.

But mainly it should work with only minor differences inn your code.

 

Haha I've googled but I can only find tutorials for it for 1.3.2 and earlier, and not for forge either

 

But you found them now, using the link above? :)

Also take a look into the code which is used inn TileEntityFurnace and BlockFurnace as I said, and then look at the other TE's and their blocks.

That should help you out inn understanding how they work and how to use them :)

If you guys dont get it.. then well ya.. try harder...

Posted

For most things tutorials from 1.3.X of Minecraft and newer works for 1.5.1

The exception being the things that changed during the patches, like now the code for Icons and textures etc.

But mainly it should work with only minor differences inn your code.

 

Haha I've googled but I can only find tutorials for it for 1.3.2 and earlier, and not for forge either

 

But you found them now, using the link above? :)

Also take a look into the code which is used inn TileEntityFurnace and BlockFurnace as I said, and then look at the other TE's and their blocks.

That should help you out inn understanding how they work and how to use them :)

 

Lol I do that all the time on finding out how to do a specific thing is look at existing vanilla minecraft classes. But sometimes I get to that point where I just don't know what to do to make it function. Just one real quick final question. Do I ever need to use GameRegistry.registerTileEntity when working with tile entities?

Bumper Cars!

Posted

Whilst this is mostly answered above, I thought I'd drop this in:

 

The reason that they are all accessing the same tile entity is that there is actually only one instance of a particular block ever in Minecraft.  The constructor for your MyBlock is only ever called once, most likely in the Init function of your mod.  The individual instances of blocks don't actually exist (there is no spoon).  The world is just a big array of blockIDs.  When you try to interact with a block, Minecraft looks that blockID up and calls appropriate functions on the block. 

TileEntities are a special case.  They need to exist uniquely for each instance of them in the world.  Which is why you must create a tile entity each time that a block is placed in the world (bit of a hint there). 

Finally, both the client world and the server world contain copies of this tileEntity.  Most of the 'real work' should be done serverside (never trust a client), so now you have the issue of syncing the two. 

 

As for how to proceed, Mazetar is correct.  Your best bet is to have a look at some of the Furnace/CraftingTable/MiniChest tutorials out there.  Some of them are for 1.2.5/1.3.2, and some are for ModLoader, but a comparison of them to the Furnace actually in Vanilla is profitable.

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.