Posted January 21, 20178 yr I tried to create a bow enchantment, that adds shot arrows custom ability (like explosion upon impact), but it seems to be impossible in 1.10. I tried to use ArrowLooseEvent, but there is no information about EntinyArrow, that was shot, so I can't give it custom tag. I also tried EntityConstructingEvent, but for EntinyArrow is no way to get the entity, that shot the arrow, so I can't check if the is it the player with enchanted bow. Finally, I tried to get closest player to the arrow and test if he has the enchantment, but it always returns null. @SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true) public void onEvent(EntityEvent.EntityConstructing event) { if (event.getEntity() instanceof EntityArrow) { EntityArrow arrow = (EntityArrow) event.getEntity(); System.out.println("arrow detected"); EntityPlayer player = arrow.worldObj.getClosestPlayerToEntity(arrow, 5D); if(EnchantmentHelper.getEnchantedItem(ModEnchantments.blast, player) !=null) { arrow.addTag("explosive"); System.out.println("Blast detected"); }; } } I have absolutely no idea, why Forge doesn' t allow us to get the entity, that shot the arrow and why worldObj.getClosestPlayerToEntity doesn't work for me.
January 21, 20178 yr Author Thanks, the problem with worldObj.getClosestPlayerToEntity was, that the entity wasn't in the world yet at the moment the event triggered.
January 21, 20178 yr Author Oh, I didn't even see that... Don't use getClosestPlayerToEntity . Use EntityArrow::shootingEntity . There is no getter in EntityArrow class.
January 21, 20178 yr shootingEntity is public 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.
January 21, 20178 yr Author Sorry, but I'm still quite unfamiliar with Java. When I tried use Arrow.shootingEntity, it always returned me null. What should I do?
January 21, 20178 yr Sorry, but I'm still quite unfamiliar with Java. When I tried use Arrow.shootingEntity, it always returned me null. What should I do? Post your code. 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.
January 21, 20178 yr Author @SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true) public void onEvent(EntityJoinWorldEvent event) { if (event.getEntity() instanceof EntityArrow) { EntityArrow arrow = (EntityArrow) event.getEntity(); System.out.println("arrow detected"); EntityLivingBase player = (EntityLivingBase) arrow.shootingEntity; if(EnchantmentHelper.getEnchantedItem(ModEnchantments.blast, player) !=null) { arrow.addTag("explosive"); System.out.println("Blast detected"); }; } }
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.