Jump to content

MultiBlock


endershadow

Recommended Posts

I've already made the multiBlock work when placed and everything, but I would like to know how I can make all the blocks redirect to the master block. any help is appreciated. Also, this method is the method in the non-master blocks which are normal blocks.

@Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int idk, float what, float these, float are)
    {
    	if (player.isSneaking())
    	{
    		return false;
    	}
    	else if(world.getBlockTileEntity(x+1, y, z+1) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x+1, y, z+1);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x+1, y, z) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x+1, y, z);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x+1, y, z-1) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x+1, y, z-1);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x, y, z+1) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x, y, z+1);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x, y, z-1) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x, y, z-1);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x-1, y, z+1) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x-1, y, z+1);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x-1, y, z) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x-1, y, z);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x-1, y, z-1) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x-1, y, z-1);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x, y-1, z) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x, y-1, z);
        	return true;
    	}
    	else if(world.getBlockTileEntity(x, y-2, z) == new TileEntitySuperCalc())
    	{
    		player.openGui(CodeLyoko.instance, 0, world, x, y-2, z);
        	return true;
    	}
    	return false;
    }

Link to comment
Share on other sites

if(world.getBlockTileEntity(x+1, y, z+1) == new TileEntitySuperCalc())

 

This makes no sense. You're doing a reference comparison between an existing tile entity and a newly created instance of TileEntitySuperCalc. This will always be false.

 

I think what you mean is:

 

  if (world.getBlockTileEntity(x+1, y, z+1) instanceof TileEntitySuperCalc) {...

 

Also, you can make your redirecting code a lot more compact using some loops, e.g.

 

   for (int dx = -1; dx <= 1; dx++)
    for (int dz = -1; dz <= 1; dz++)
      if (world.getBlockTileEntity(x+dx, y, z+dz) instance of TileEntitySuperCalc) {
        player.openGui(CodeLyoko.instance, 0, world, x+dx, y, z+dz);
        return true;
      }

(General programming tip: If you ever find yourself writing very similar code over and over again, there's almost always a better way of doing it!)

Link to comment
Share on other sites

I haven't done any multiblock structure (yet), but I think it could be solved either using metadata or TEs. in both ways the "slaves" would save master's position when being created and then on clicking/interacting they would just "redirect" event to the master (without searching around, actively looking for a maste block). in your case you would just call master's onBlockActivated instead.

 

the code you pasted is strange, how could it ever work? you create new TE and then ask if it's the same as one in the world - it can be never the same. you can do something like this (pseudo code):

TAB = table with shifts (like { {1,0,1}, {1,0,0}, ... })
foreach S in TAB do
  TE = getTE; <- coordinates being calculated from S (the shift of x,y and z)
  if TE != null and TE.getClass() == TileEntitySuperCalc.class then call it's onBlockActivated with correct parameters
end foreach

 

damn it, gcewing was faster :/

mnn.getNativeLang() != English

If I helped you please click on the "thank you" button.

Link to comment
Share on other sites

if(world.getBlockTileEntity(x+1, y, z+1) == new TileEntitySuperCalc())

 

This makes no sense. You're doing a reference comparison between an existing tile entity and a newly created instance of TileEntitySuperCalc. This will always be false.

 

I think what you mean is:

 

  if (world.getBlockTileEntity(x+1, y, z+1) instanceof TileEntitySuperCalc) {...

Thank you!! using instanceof worked! I also forgot about for loops, thanks for reminding me.

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.