Jump to content

Newbie sorry. Do an event when push a metal button


JaviBag

Recommended Posts

Subscribe to the RightClickBlock event. 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I dont know why it doesnt work 

Quote

public class BotonVideoGames extends StoneButtonBlock

{ private Hue hue; boolean luzEncendida; public BotonVideoGames(Properties properties) { super(properties); hue = new Hue(); luzEncendida = true; }

@SubscribeEvent public void onPlayerInteract(PlayerInteractEvent.RightClickBlock e) { try { hue.power(luzEncendida); e.getEntity().sendSystemMessage(Component.literal("La luz esta encendida: " + luzEncendida)); } catch (IOException ev) { throw new RuntimeException(ev); } } }

 

Link to comment
Share on other sites

If it's your own block, you override the use() method.

See ButtonBlock.use();

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Sorry im very new on this.

what I don't understand is how in an event I ask what block the player presses with a RightClickBlock

For example i can use later inside the method e.getItemStack() and return what the player has on the hand but not which block is pushing with this item.

 

or on the side of the block what would be the event to check the ButtonBlock.use()

 

If you can please helpme with both. I know that It's enough with just one.

Thanks a lot!

Link to comment
Share on other sites

Being new is not an excuse. This forum does not exist, so you don't have to do your own research.

It is a support forum not a school.

 

You only need RightClickBlock if it is not your block.

 

For the rest, read the code of ButtonBlock.use() and try to understand what it is doing.

Looking where Block.use() is called from in the other minecraft code will give you more context for what is happening.

Or look at other Block's use() methods that do things more like what you want to do.

 

For your specific questions

* You are passed a Level, BlockState and BlockPos which uniquely identifies the block (this is minecraft 101). A look at ButtonBlock.press() shows how they are used to change the state from unpressed to pressed.

* The BlockHitResult has the side (direction). There have been at least 3 questions just this week in this forum about hit results and many others before that.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Thank you so much Warjot, now i understand how use method works. I didnt found the method who calls use()

Actually I was able to do what I wanted to do but the command I want to execute is thrown twice on the button.
i can fix it with a counter, when it reach 2 it reset.
this is quite ugly but it works but the eyes hurt a little

Link to comment
Share on other sites

The method is called on both the client and sever.

Check level.isClientSide

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Warjort I can ask you for help with something else, I made a button that turns on the light in my house, one for each room. I made a Button class with all the methods. A method that it has, you put the name of the room (the same one that has the smart lamps api) and it creates a String[] with the ids. With another method it turns it on. Then I made a son class with the name of each room to write the attribute with the lamp ids in each one and call the parent method to turn them on.
Can you think of a way so that the user with a set from the minecraft console can modify the operation of the button, to make this mod more universal?
The idea that occurs to me but I don't know if it's possible, that the player writes to the console something from /give Player button X. Example (/give Player button RoomGames) where X is a variable.
Thank you so much.

Link to comment
Share on other sites

I'm not finding it.
All my mod is working
The only thing I want now is to make it universal so I can share it.
I need to do with a command /button String String
and have that give the player a button that was created with the String String parameters. If anyone has any ideas

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.