Jump to content

OnBlockActivated Acting slightly strange [SOLVED] [1.7.10]


Recommended Posts

Posted

Okay, so this is really weird, it is a very minor bug, but it is annoying, and has been bugging me for a week or so now.

 

I have several blocks in my mod that when right clicked, open a gui, now when I right click the block, it places down the block I am holding for a split second, then removes it, and puts it back in my inventory, and then opens the gui.

Now this causes a small but noticeable delay in opening the gui, also, if I am standing in the space where it would try to place the block for a split second, it wont let me open the gui because it cant place the block.

 

This is my onBlockActivated methods (pretty much the same on all my gui blocks)

 

 

        @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
	if (!world.isRemote) {
		FMLNetworkHandler.openGui(player, Generator.INSTANCE, Generator.guiId<MyBlocksGui>, world, x, y, z);
		return true;
	}
	return false;
}

 

 

 

Am I doing something wrong here?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

In this case: Always return true;

 

The client thinks nothing happened and places the held block, the server however knows the gui should open and doesn't place the block.

The false block is removed when the server tells the client nothing is there.

 

---

 

If you open a gui both client and server need to return true.

 

Here is one of mine that doesn't always open a gui.

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int face, float posX, float posY, float posZ)
{
    if (world.getBlockMetadata(x, y, z) == 15) {
        if (!world.isRemote) {
            entityPlayer.openGui(PixelPowersWorld.INSTANCE, 5, world, x, y, z);
        }
        return true;
    }
    return false;
}

Posted

Okay, thanks.

 

I also just looked at the onBlockActivated method in the vanilla furnace(probably should have done before posting here), and they also always return true.

 

But one thing that still doesn't make sense, is it the server knows the player opened the gui, but the client doesn't, than how does standing where it would try to place the block stop the gui from opening? because as far as the server knows, the gui is open....

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

Answer:

 

Minecraft is weird.

 

I agree: would you believe that this

public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
        return p_149727_1_.isRemote ? true : ItemLead.func_150909_a(p_149727_5_, p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_);
    }

belongs to blockFence?

I have never tried to right click a fence, but what the heck is that???

Check out my blog!

http://www.whov.altervista.org

Posted

Answer:

 

Minecraft is weird.

 

I agree: would you believe that this

public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
    {
        return p_149727_1_.isRemote ? true : ItemLead.func_150909_a(p_149727_5_, p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_);
    }

belongs to blockFence?

I have never tried to right click a fence, but what the heck is that???

That method checks if you can place a leash on the fence. If you can place it, it places it and returns true, and otherwise it returns false and does nothing.

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/

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.