Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

[1.15.2]

 

I am going to have a tough time describing this, so here is a video.

 

https://youtu.be/XEwj8rv0jdo

 

If you saw the video, you saw the after the car go damaged and then healed by my custom item, the car takes way more damage then it should when it hits the cactus. 

I am sure that it is because I am not updating the entity health on server side, so how am I supposed to update the entity's health (on server side)?

 

and here is my code (which heals the car)

 @SubscribeEvent
    public void keyInputEvent(InputEvent.KeyInputEvent event) {
        Minecraft minecraft = Minecraft.getInstance();
        PlayerEntity player = minecraft.player;
        if(player == null)
            return;
        LivingEntity car = (LivingEntity)player.getRidingEntity();
        if (car != null) {
            if (car.getName().getString().equals("Car")) {
                if (event.getKey() == GLFW.GLFW_KEY_R && event.getAction() == GLFW.GLFW_PRESS) {
                    if(player.getHeldItemMainhand().getItem() == RegistryHandler.GAS_CAN.get()){
                        ((Car)car).Refule();
                        car.heal(1);
                        player.getHeldItemMainhand().shrink(1);
                    }
                }
                if(event.getKey() == GLFW.GLFW_KEY_R && event.getAction() == GLFW.GLFW_PRESS){
                    if(player.getHeldItemMainhand().getItem() == RegistryHandler.REPAIR_KIT.get() && car.getHealth() != car.getMaxHealth()){
                        car.heal(6);
                        player.inventory.mainInventory.get(player.inventory.currentItem).shrink(1);
                    }
                }
            }
        }
    }

 

Edited by someRandomKid

3 hours ago, someRandomKid said:

so how am I supposed to update the entity's health (on server side)?

Send a packet to the server or the better answer would be handle the logic on the server completely. Only thing you need to send is nothing.

16 hours ago, someRandomKid said:

if (car.getName().getString().equals("Car")) {

Don't compare strings. Use instanceof. You already use a cast later down.

 

16 hours ago, someRandomKid said:

if (event.getKey() == GLFW.GLFW_KEY_R && event.getAction() == GLFW.GLFW_PRESS) {

16 hours ago, someRandomKid said:

if(event.getKey() == GLFW.GLFW_KEY_R && event.getAction() == GLFW.GLFW_PRESS){

Why are you performing this particular check twice?

 

16 hours ago, someRandomKid said:

if(player == null) return;

16 hours ago, someRandomKid said:

if (car != null) {

Use an early return here like you did with a null player.

 

16 hours ago, someRandomKid said:

((Car)car).Refule();

"Refuel."

 

And finally:
Why are you bothering with R keypresses? Why not use the systems Minecraft already has in place (right clicking with a stack)? Then you don't need this key press handler at all and can put this logic inside your item (where it belongs) and don't need to deal with custom packets.

Edited by Draco18s

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.

Item has methods for onRightClick and onEntityInteract (you'll have to poke around for exact method names). Just override them and put your functionality there.

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.

  • Author

here is code to override for those who are wondering.

 

 @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        Entity entity = playerIn.getRidingEntity();
        if(entity instanceof Car){
            Car car = (Car)entity;
            car.Refuel();
            car.heal(1);
            playerIn.inventory.mainInventory.get(playerIn.inventory.currentItem).shrink(1);
        }
        return ActionResult.resultPass(playerIn.getHeldItem(handIn));
    }

 

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.