richard Posted January 12, 2017 Share Posted January 12, 2017 I've got a "wand" item that, on right-click, I wish to be able to inflict various things on mobs: set on fire or apply a potion effect to them. My two attempts at doing this are below. Apply a poison potion effect: @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer player, EnumHand hand) { RayTraceResult target = Minecraft.getMinecraft().objectMouseOver; if (target.typeOfHit == RayTraceResult.Type.ENTITY) { if (target.entityHit instanceof EntityLivingBase) { EntityLivingBase entitylivingbase = (EntityLivingBase) target.entityHit; Potion potion = Potion.REGISTRY.getObject(new ResourceLocation("poison")); PotionEffect potioneffect = new PotionEffect(potion, 50, 1); if (potion.isInstant()) { potion.affectEntity(null, null, entitylivingbase, potioneffect.getAmplifier(), 0.5D); } else { entitylivingbase.addPotionEffect(potioneffect); } } } return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); } The result of the above is that the potion effect doesn't appear to be applied at all. Changing the code to instead set the entity on fire: @Nonnull @Override public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemstack, World world, EntityPlayer player, EnumHand hand) { RayTraceResult target = Minecraft.getMinecraft().objectMouseOver; if (target.typeOfHit == RayTraceResult.Type.ENTITY) { target.entityHit.setFire(4); } return ActionResult.newResult(EnumActionResult.SUCCESS, itemstack); } This results in a brief flash of fire effect on the entity, but it does not remain on fire for the full 4 seconds that I specify. I know that I've invoked the setFire method correctly because if I do so in a hitEntity() override like so: public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) { target.setFire(4); return true; } The entity stays on fire! Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted January 12, 2017 Share Posted January 12, 2017 Minecraft.getMinecraft().objectMouseOver; Is client side only, meaning since the server doesn't know about this it can't do it. Meaning it is reset next tick for the client. Quote VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator. Link to comment Share on other sites More sharing options...
richard Posted January 12, 2017 Author Share Posted January 12, 2017 OK, thanks. I'm now looking into how to send packets from the client to the server! Solution: I ended up implementing InvokeWandMessage which encoded the RayTraceResult generated by PythonWandItem and sent it to the server for actioning. Works!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.