Posted October 13, 20204 yr [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 October 13, 20204 yr by someRandomKid
October 14, 20204 yr 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.
October 14, 20204 yr Author So, I have to send an empty packet to server? Edited October 14, 20204 yr by someRandomKid
October 14, 20204 yr 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 October 14, 20204 yr 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.
October 14, 20204 yr 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.
October 14, 20204 yr 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.