julesmaster7 Posted October 18, 2016 Posted October 18, 2016 Hi there, I was trying to make my item get all the entitys within a 10 block radius and take away 2 health + if it is a player play a sound. All on right click. Here is my right click method: @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { AxisAlignedBB bb = new AxisAlignedBB(10, 10, 10, 10, 10, 10); worldIn.getEntitiesWithinAABB(EntityLiving.class, bb); return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand); } I can't figure out how to hurt the entitys that it finds. Quote
Draco18s Posted October 18, 2016 Posted October 18, 2016 That AABB is both 0 in size and centered near the origin of the world. You should be using new AxisAlignedBB(playerIn.pos.getX() - 10, playerIn.pos.getY() - 10, playerIn.pos.getZ() - 10, playerIn.pos.getX() + 10, playerIn.pos.getY() + 10, playerIn.pos.getZ() + 10) Quote 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.
Kokkie Posted October 18, 2016 Posted October 18, 2016 I would suggest doing AxisAlignedBB bb = playerIn.getEntityBoundingBox().expand(20.0D, 20.0D, 20.0D) and for hurting them something like this: List<EntityLivingBase> entitiesInAABB = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, bb); for(int i = 0; i < entitiesInAABB.size(); i++) { EntityLivingBase entityInAABB = entitiesInAABB.get(i); entityInAABB.attackEntityFrom(DamageSource.magic, 1.0F); } Quote Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
julesmaster7 Posted October 18, 2016 Author Posted October 18, 2016 Thank you guys! One extra thing: how do I set a cooldown for my onItemRightClick. Quote
Animefan8888 Posted October 19, 2016 Posted October 19, 2016 On 10/18/2016 at 11:19 PM, julesmaster7 said: Thank you guys! One extra thing: how do I set a cooldown for my onItemRightClick. Instead of having the code for the effect in onItemRightClicked have it in onPlayerStoppedUsing (i believe it was that name may have changed). For an example of this look at ItemBow. 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.
julesmaster7 Posted October 19, 2016 Author Posted October 19, 2016 On 10/19/2016 at 2:18 AM, Animefan8888 said: Quote Thank you guys! One extra thing: how do I set a cooldown for my onItemRightClick. Instead of having the code for the effect in onItemRightClicked have it in onPlayerStoppedUsing (i believe it was that name may have changed). For an example of this look at ItemBow. That method gets called after you release the right button. in the case of the bow it releases the arrow. I want to know how to set a cooldown for onItemRightClick. Quote
Animefan8888 Posted October 19, 2016 Posted October 19, 2016 Then you will have to use a custom capability or maybe an IProperty I personally have not worked with either of these, but im pretty sure you want to use the later. 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.
Choonster Posted October 19, 2016 Posted October 19, 2016 Vanilla already has an item cooldown system: CooldownTracker . I suggest you look for usages of this in vanilla code, e.g. ItemEnderPearl . Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
jabelar Posted October 19, 2016 Posted October 19, 2016 It always amazes me that people ask questions about how to make cool-down timer type functionality. I think people forget that modding is just programming and anything you can do with Java you can probably do in your mod. While items do have a built-in system for cool-down (as mentioned by Choonster) I feel compelled to point out that this is a very basic programming problem. You simply need an int field that gets set to a value (since Minecraft works on 20 steps per second, it would probably be set to 20 * the number of seconds you want for cool-down) whenever the action starts and decrements by one in some method that runs every tick (like updateLiving()) until it reaches zero (then stays there). Then whenever you want to start the action you just check to make sure that field is at 0 and do it all over again. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
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.