Jump to content

How do i make a block do stuff, if i aim at it and press a specific key on keyboard?


Recommended Posts

Posted (edited)

Hello

 

I want to add more blockstates and models to a button (for redstone) out of glazed terracotta.

Now i want to add a key control to change the model between ones with the same shape-orientation and and different texture-rotations, to match all possible rotations of the glazed terracotta-block.

I think, i van add a custom blockstate and expand the json files.

i also know the line for changing the blockstate for another model.

 

But how do i code a key-control for the block?

It should do the stuff above, if i aim at it and press a given key on the peyboard (for sample "R" for rotation)

Edited by Drachenbauer
Posted

I do not know of any for 1.15. However, the process isn't quite difficult from what I remember. Just create a final instance of the KeyBinding by using its constructor and then register using ClientRegistry#registerKeyBinding during the FMLClientSetupEvent. Remember that this is client-side only so any data received must be sent via packet to the server.

Posted (edited)

Is sent via packet to server only needed, if it should be used in multiplayer, too?

 

I created an instance for the keybinding and registered it in clientside.

How do i now use it in my Block?

Edited by Drachenbauer
Posted
45 minutes ago, Drachenbauer said:

Is sent via packet to server only needed, if it should be used in multiplayer, too?

No, it's mandatory to send a client to server packet.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted
5 minutes ago, Drachenbauer said:

How do i now use the registered keybinding and how do i send a packet?

Use the keybinds using events, specifically InputEvent, packets are pretty well documented on the forge docs, but basically you want to use SimpleChannel#sendToServer with your custom packet.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted (edited)

I do it understand better with samples.

But i cannot find some about the inputEvent for 1.15 on the web...

 

And i don´t know, where i should place the stuff about the package.

In the block-class?

In the main-class?

some where else?

Edited by Drachenbauer
Posted (edited)
12 minutes ago, Drachenbauer said:

I do it understand better with samples.

But i cannot find some about the inputEvent for 1.15 on the web...

 

And i don´t know, where i should place the stuff about the package.

In the block-class?

In the main-class?

some where else?

Have you even looked at InputEvent in your IDE? Use isKeyDown from it for your purposes. What do you mean by "stuff about the package"?

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted (edited)
2 minutes ago, Drachenbauer said:

I mean the line of code, that sends the data package from client to server.

Do you have a packet system? If not then look at the Forge documentation to make one

Edited by kaydogz
Posted

I´m not sure, how to find the InputEvent in my ide...

Actualla most times i used call-hirachy or "find references" to find stuff.

But i have nothing open, that has references to InputEvent.

And i don´t know, where in the big file-system of the referenced library it is.

Posted
1 minute ago, Drachenbauer said:

I´m not sure, how to find the InputEvent in my ide...

Actualla most times i used call-hirachy or "find references" to find stuff.

But i have nothing open, that has references to InputEvent.

And i don´t know, where in the big file-system of the referenced library it is.

net.minecraftforge.client.event.InputEvent.KeyInputEvent

Posted

In the forgedocs page about the simple channel packet system, it says register packet.

But it does not tell, where i have to call INSTANCE.registerMessage.

What is the right location for this?

Posted
4 minutes ago, Drachenbauer said:

In the forgedocs page about the simple channel packet system, it says register packet.

But it does not tell, where i have to call INSTANCE.registerMessage.

What is the right location for this?

Main constructor.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Posted (edited)

It also doesn´t show the call-line, filled with all the needed parameters...

 

And for this, i don´t know, how to replace "MyMessage"

    public static void handle(MyMessage msg, Supplier<NetworkEvent.Context> ctx)
    {
        ctx.get().enqueueWork(() ->
        {
            // Work that needs to be threadsafe (most work)
            EntityPlayerMP sender = ctx.get().getSender(); // the client that sent this packet
            // do stuff
        }
        );
        
        ctx.get().setPacketHandled(true);
    }

EntityPlayerMP must be ServerPlayerEntity to have this line free from red underscored errors.

Edited by Drachenbauer
Posted
3 minutes ago, Drachenbauer said:

Must i create an extra class for my packet?

 

The instruction-page does not tell that.

Your packet class is the class which has the Handlersubclass.

Posted

Must i call INSTANCE.sendToServer(new MyMessage()) in the net.minecraftforge.client.event.InputEvent.KeyInputEvent?

 

And where do i place this event?

And how exactly do i define the content of the packet?

 

Posted
1 minute ago, Drachenbauer said:

Must i call INSTANCE.sendToServer(new MyMessage()) in the net.minecraftforge.client.event.InputEvent.KeyInputEvent?

 

And where do i place this event?

And how exactly do i define the content of the packet?

 

Yes, you must. The event should go in an event handler. All of the code you want to run on sending the packet should be called after ctx.enqueWork in handle, the content of the packet is whatever you want!

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I've tried the java version you linked to and got a new exit code of 127 Here is the new console log I also tried making sure that I had Java 8 selected with the version of Java 8 I already had installed and got the same exit code Here is the console log with that installation in case it has any differences I do notice both say 'Java checker returned some invalid data we don't understand:' followed by 'Minecraft might not start properly.' which could be some issues.  
    • Looking for unbeatable savings on Temu in 2025? Our exclusive Temu code [ald244107] is your key to unlocking a $100 OFF discount, plus much more! This verified promo code works for both new and existing customers, giving you up to 50% off your next order and even bigger savings on clearance items. With Temu coupon code [ald244107], you'll get a flat $100 discount on top of existing sales. First-time users can enjoy an extra 100% off select items, while returning shoppers automatically qualify for the $100 OFF when applying the code at checkout. Imagine saving up to 90% on your favorite products across the USA, Canada, UK, and many other countries! 🔥 Temu Coupon Highlights with Code [ald244107]:  * Temu New User Offer: Use ald244107 for 50% off your first order + $100 OFF.  * Temu Existing Customer Promo: Apply ald244107 to get an instant $100 OFF.  * Global Reach: Valid in the USA, UK, Canada, Germany, France, Japan, Chile, Colombia, Malaysia, Mexico, South Korea, Philippines, Saudi Arabia, Qatar, Pakistan, and more.  * Top 2025 Deal: Secure $200 OFF plus 100% bonus discounts with ald244107. Maximize Your Savings: Top Temu Deals for 2025 (Code: ald244107)  * ✅ Temu Memorial Day Sale: Save $100 with ald244107  * ✅ Temu First Order Special: Use ald244107 for 50% + $100 OFF  * ✅ Temu USA Exclusive: Get $100 off instantly with ald244107  * ✅ International Temu Codes: ald244107 works in Japan, Germany, Chile, and many others.  * ✅ Temu Reddit Discount: Enjoy $100 OFF for both new and old users.  * ✅ Temu Coupon Bundle 2025: Combine $100 OFF with up to 50% slash deals.  * ✅ 100% OFF Free Gift Code: Use ald244107 – no invitation needed!  * ✅ Temu Sign-Up Bonus: Instantly get a welcome $100 OFF.  * ✅ Free Temu Code for New Users: Apply ald244107 – no referral required.  * ✅ Temu Clearance Codes 2025: Use ald244107 for 85–100% discounts. This Temu code [ald244107] is more than just a discount; it's your ticket to free shipping, exclusive first-order deals, and stackable coupon bundles across electronics, fashion, home goods, and beauty products. You can truly unlock up to 90% OFF plus an additional $100 OFF on qualified orders. 💡 Pro Tip: Don't forget to apply ald244107 during checkout on the Temu app or website to activate your instant $100 discount, even if you’re a returning customer! Temu $100 OFF Code by Country (All Use ald244107):  * 🇺🇸 Temu USA – ald244107  * 🇯🇵 Temu Japan – ald244107  * 🇲🇽 Temu Mexico – ald244107  * 🇨🇱 Temu Chile – ald244107  * 🇨🇴 Temu Colombia – ald244107  * 🇲🇾 Temu Malaysia – ald244107  * 🇵🇭 Temu Philippines – ald244107  * 🇰🇷 Temu Korea – ald244107  * 🇵🇰 Temu Pakistan – ald244107  * 🇫🇮 Temu Finland – ald244107  * 🇸🇦 Temu Saudi Arabia – ald244107  * 🇶🇦 Temu Qatar – ald244107  * 🇫🇷 Temu France – ald244107  * 🇩🇪 Temu Germany – ald244107 Real Shoppers, Real Savings: User Reviews We love hearing about your experiences! Here’s what some happy shoppers are saying about using the Temu code [ald244107]:  * Alice W., USA ⭐️⭐️⭐️⭐️⭐️ (5/5) "Great experience! Temu's promo code {ald244107} saved me a lot on my first order. Highly recommend this offer!"  * James T., UK ⭐️⭐️⭐️⭐️ (4/5) "Very happy with the quality and prices on Temu. The $100 credits offer was a nice bonus using {ald244107}. Will shop again."  * Sara M., Canada ⭐️⭐️⭐️ (3/5) "Got some decent deals with the {ald244107} code, though shipping took a bit longer than expected. Overall satisfied with the credits."
    • Thank you so much! I didnt see it in the log😭😭  
    • So im completely new to modding in general, i have some experience in Behavior packs in minecraft bedrock and i would like to modify entities stats and attributes like in a behavior pack (health, damage, speed, xp drop...). The problem is that i cant find any information online on how to do that, and I have no clue on what to do and where to start. I am currently modding in 1.20.4 with IntelliJ if that helps. My final objective is to buff mobs health and damage (double it for exemple), but since there is no entity file anywhere i don't know how to change it... 😢
    • Hey there, nothing to do with the code, I am just suggesting you use Intelij IDEA. Trust me, it is the best.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.