fcelon Posted January 21, 2017 Share Posted January 21, 2017 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. Quote Link to comment Share on other sites More sharing options...
fcelon Posted January 21, 2017 Author Share Posted January 21, 2017 Thanks, the problem with worldObj.getClosestPlayerToEntity was, that the entity wasn't in the world yet at the moment the event triggered. Quote Link to comment Share on other sites More sharing options...
fcelon Posted January 21, 2017 Author Share Posted January 21, 2017 Oh, I didn't even see that... Don't use getClosestPlayerToEntity . Use EntityArrow::shootingEntity . There is no getter in EntityArrow class. Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted January 21, 2017 Share Posted January 21, 2017 shootingEntity is public 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...
fcelon Posted January 21, 2017 Author Share Posted January 21, 2017 Sorry, but I'm still quite unfamiliar with Java. When I tried use Arrow.shootingEntity, it always returned me null. What should I do? Quote Link to comment Share on other sites More sharing options...
Animefan8888 Posted January 21, 2017 Share Posted January 21, 2017 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. 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...
fcelon Posted January 21, 2017 Author Share Posted January 21, 2017 @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"); }; } } 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.