Jump to content

Searching right event to suscribe to.


Raycoms

Recommended Posts

Hi there,

We're currently using the following event to handle our actions:

 

    @SubscribeEvent
    public void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event)
    {

 

What we want is, if a player places one of our blocks certain actions should be executed.

But, unfortunately, this event also gets called when the player right clicks a bed with the block or an itemRack or similar.

The block doesn't get placed but the event does get executed. Is there a way around this?

 

Thanks

Link to comment
Share on other sites

You need to use if-checks to check to see if the block placed is one of your blocks.  If it's not, do nothing, if it is, run the code.

 

-or-

 

You could write a custom ItemBlock class.  Which is more better.  You control your own blocks, you can write code that only occurs within your own blocks by writing the code IN your OWN blocks.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I'm checking if it is my own block, but the problem is that sometimes when executing this action the block does not get placed (like when you rightclick a bed with your block in the hand)

 

I need to be able to cancel the event and be able to detect if it really has been placed.

Link to comment
Share on other sites

o..O

What on earth are you trying to accomplish?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

We are implementing minecolonies.

 

A colony gets created around the center of the "TownHallBlock" you placed, when you place it the first time.

The workerHuts (Lumberjack,miner etc) also get created at the place you first placed their "Hutblock".

 

Now when I have the townhall in my hand and rightclick the bed, the colony gets created but the chest not placed.

 

I only want to create the colony when I'm totally sure the chest has been placed.

Link to comment
Share on other sites

Why are you not performing this creation effect in the Block's

onBlockPlaced

method?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You don't cancel events inside the method, there's no event there.

 

That method only runs when the block is added to the world.  It will not fire if the player sleeps in a bed.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Do that in the onBlockPlaced method.  If the placement is invalid, drop the block as an item and set the space to air.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Or you can use the

Block#canPlaceBlockAt()

method to check if the

Block

is placeable at that location.

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/

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.