Jump to content

Detect all nearby entities to player and then shoot lightning at them


Xile

Recommended Posts

Hello everyone,

ย 

I'm new to modding and java in general, and I'm currently working on an RF powered armor set. The issue is I would like to make my armor detect nearby players and mobs within a configurable radius around the player and then constantly zap them with lightning at a configurable interval. If anyone could provide insight into how I would go about doing this I would be immensely grateful.

ย 

Thank you.

Link to comment
Share on other sites

Do you mean like just vanilla lightning raining down from the sky, or zaps coming from the player to mobs? If the latter, you'll have to create your own entity.

ย 

Initially i was going to do my own zaps, but this is my first mod and im a noob so I just want to make vanilla lightning from sky hit them.

ย 

To get the players around you, entites have methods for finding other ones inside an AABB, just go through the list.

ย 

This is what I have tried so far. to no avail.

ย 

//Bounding Box Attempt :/

ย  ย  public double minX;

ย  ย  public double minY;

ย  ย  public double minZ;

ย  ย  public double maxX;

ย  ย  public double maxY;

ย  ย  public double maxZ;

ย  ย  public AxisAlignedBB axisalignedbb = AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ); {

ย  ย  ย  ย  this.minX = 0;

ย  ย  ย  ย  this.minY = 0;

ย  ย  ย  ย  this.minZ = 0;

ย  ย  ย  ย  this.maxX = 10;

ย  ย  ย  ย  this.maxY = 10;

ย  ย  ย  ย  this.maxZ = 10;

}

@Override

ย  ย  public void onArmorTick(World world, EntityPlayer player, ItemStack armor) {

ย 

ย  ย  ย  ย  List entities = world.getEntitiesWithinAABB(getClass(), axisalignedbb);

ย  ย  ย  ย  System.out.println("These Entities Are within Range!" + entities + "");

ย 

ย 

ย  ย  ย  ย  }

ย 

It doesn't detect any entities unfortunately :(

Link to comment
Share on other sites

I'm not sure, but I think the bounding box minX, maxX, etc. are absolute positions.ย  I mean you're looking between 0 and 10 but do you even know where that is in the world?ย  How are you sure there are even any entities there?ย  I think that might be way underground or something.

Check out my tutorials here:ย http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

List players = getWorldObj().getEntitiesWithinAABB(EntityPlayer.class,player.getBoundingBox().expand(3, 3, 3);

ย 

this will get all players around the player (and probably the origin player too) just change what class to find to something else or use the base class, I think EntityLiving? EntitiyLivingBase? then when spawning lightening just make sure you're not spawning one on whoever created the bounding box.

Link to comment
Share on other sites

List players = getWorldObj().getEntitiesWithinAABB(EntityPlayer.class,player.getBoundingBox().expand(3, 3, 3);

ย 

this will get all players around the player (and probably the origin player too) just change what class to find to something else or use the base class, I think EntityLiving? EntitiyLivingBase? then when spawning lightening just make sure you're not spawning one on whoever created the bounding box.

ย 

Thank you very much! However getWorldObj() says that it cannot find that method. I forgot to mention this is on 1.7.10. That may be why?

Link to comment
Share on other sites

Ok this is what I tried.

ย 

List players = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, player.getBoundingBox().expand(3, 3, 3));

ย  ย  ย  ย  System.out.println("Nearby Entities" + players + "!");

ย 

Is this correct? apologies if this is a noob question. I've been able to figure out some stuff myself but this one has been stumping me.

Link to comment
Share on other sites

yeah I didn't want to give copy paste ready code (which i'm bad for) because I was hoping you'd see the error and go "maybe it just takes a world object/instance"

ย 

but the expand(3,3,3) can be any numbers you want it to be. I just used 3's as a placeholder to show you how to use it.

ย 

PreEdit:

you might want to use an Iterator and a while loop, or some kindof loop to go through the list for each entry. you can also refactor the "players" to something like "entities" or "targets" idk whatever you want to call it. I used it for a block that would store mana, and recharge nearby mages.

ย 

but yeah looks a bit better, altho since it's an "onArmorTick" it should have a world param that you can toss in.

like par2World.getEntitiesWithin.....

and if it doesn't it should at least reference the player or entity wearing it (since zombies and skeletons can wear armor) and you can get the world object from there too.

Link to comment
Share on other sites

You guys have all been an immense help thus far!

ย 

This is what I currently have in the armortick

ย 

//Armor Effects

@Override

ย  ย  public void onArmorTick(World world, EntityPlayer player, ItemStack armor) {

ย 

ย 

ย  ย  EnergyStored = armor.stackTagCompound.getInteger("Energy");

ย  ย  if (EnergyStored < 1) NoPower = true;

ย  ย  if (KeyInputHandler.ArmorOn == true)

ย  ย  ย  ย  if (NoPower != true)

ย  ย  ย  ย  ย  ย  System.out.println("Tesla AOE Activated");

ย  ย  ย  ย  else System.out.println("Tesla Ability Deactivated");

ย 

ย 

ย  ย  //Just A Test For Charging Armor Without External Mods!

ย  ย  if (KeyInputHandler.ArmorOn == false)

ย  ย  ย  ย  armor.stackTagCompound.setInteger("Energy", (EnergyStored + 1000));

ย 

ย  ย  //PotionEffects Not sure why they dont work when all armor equipped... is weird..

ย 

ย  ย  if (player.inventory.armorItemInSlot(2) == ItemLoader.armorTeslaLegs) {

ย  ย  ย  ย  if (NoPower != true)

ย  ย  ย  ย  ย  ย  player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 500, 4));

ย  ย  }

ย 

ย 

ย  ย  if (player.inventory.armorItemInSlot(3) == ItemLoader.armorTeslaBoots) {

ย  ย  ย  ย  if (NoPower != true)

ย  ย  ย  ย  ย  ย  player.addPotionEffect(new PotionEffect(Potion.jump.id, 500, 4));

ย  ย  }

ย  ย  while (KeyInputHandler.ArmorOn == true) {

ย  ย  ย  ย  List players = world.getEntitiesWithinAABB(EntityLivingBase.class, player.getBoundingBox().expand(7, 7, 7));

ย  ย  ย  ย  System.out.println("Nearby Entities" + players + "!");

ย  ย  }

}

ย 

currently I'm just testing random things to find out how they work but the bounding box crashes the game when my world with me wearing my armor loads up with this crash.

ย 

http://pastebin.com/KgYbz6gh

ย 

I got this crash when i was previously messing with bounding boxes as well. I feel like its something obvious I'm missing here.

Link to comment
Share on other sites

Disregard that!

ย 

After some searching I was able to get it working with this code:

ย 

List entities = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 7, player.posY + 7, player.posZ + 7)

ย 

This correctly prints out all nearby entities in the console as well :)

ย 

Thank you everyone!

Link to comment
Share on other sites

No, they are vanilla files and you can look at them yourself (located at Referenced Libraries->forgeSrc.jar)

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

ย 

1.12 -> 1.13 primer by williewillus.

ย 

1.7.10 and older versions of Minecraft are no longer supported due to it's age!ย Update to the latest version for support.

ย 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Edit: Nevermind I fixed it! Should I just use this code after the lightning spawn to make it only fire every half second?

try {

ย  ย  TimeUnit.MILLISECONDS.sleep(500);

ย 

} catch (InterruptedException e) {

ย  ย  //Handle exception

}

ย 

ย 

ย 

Working Code:

ย 

//Attempt at Entity scan and target

ย  ย  if (KeyInputHandler.ArmorOn == true) {

ย  ย  ย  ย  System.out.println("Scanner Activated");

ย  ย  ย  ย  List entities = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 7, player.posY + 7, player.posZ + 7));

ย  ย  ย  ย  if (entities != null && !entities.isEmpty()) {

ย  ย  ย  ย  ย  ย  Iterator iterator = entities.iterator();

ย 

ย  ย  ย  ย  ย  ย  double posX;

ย  ย  ย  ย  ย  ย  double posY;

ย  ย  ย  ย  ย  ย  double posZ;

ย  ย  ย  ย  ย  ย  EntityLivingBase ent;

ย 

ย  ย  ย  ย  ย  ย  ย  ย  while (iterator.hasNext())

ย  ย  ย  ย  ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  ย  ย  ent = (EntityLivingBase) iterator.next();

ย  ย  ย  ย  ย  ย  ย  ย  posX = ent.posX;

ย  ย  ย  ย  ย  ย  ย  ย  posY = ent.posY;

ย  ย  ย  ย  ย  ย  ย  ย  posZ = ent.posZ;

ย 

ย  ย  ย  ย  ย  ย  ย  ย  EntityLightningBolt Lightning = new EntityLightningBolt(world, posX, posY, posZ);

ย 

ย  ย  ย  ย  ย  ย  ย  ย  world.spawnEntityInWorld(Lightning);

ย  ย  ย  ย  ย  ย  }

ย  ย  ย  ย  }

ย  ย  }

ย 

}

ย 

ย 

Pre Edit:

ย 

ย 

Ok, I feel like this should work. However as soon as I activate it my whole game just freezes with no errors :/

ย 

//Attempt at Entity scan and target

ย  ย  if (KeyInputHandler.ArmorOn == true) {

ย  ย  ย  ย  System.out.println("Scanner Activated");

ย  ย  ย  ย  List entities = player.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.getBoundingBox(player.posX - 5, player.posY - 5, player.posZ - 5, player.posX + 7, player.posY + 7, player.posZ + 7));

ย  ย  ย  ย  Iterator iterator = entities.iterator();

ย  ย  ย  ย  double posX;

ย  ย  ย  ย  double posY;

ย  ย  ย  ย  double posZ;

ย  ย  ย  ย  EntityLivingBase ent;

ย  ย  ย  ย  while (iterator.hasNext());

ย  ย  ย  ย  ent = (EntityLivingBase)iterator.next();

ย  ย  ย  ย  posX = ent.posX;

ย  ย  ย  ย  posY = ent.posY;

ย  ย  ย  ย  posZ = ent.posZ;

ย 

ย  ย  ย  ย  EntityLightningBolt Lightning = new EntityLightningBolt(world, posX, posY, posZ);

ย 

ย  ย  ย  ย  world.spawnEntityInWorld(Lightning);

ย 

Link to comment
Share on other sites

Thank you very much! You have all been a great help. One thing that's been giving me issues is that for some reason the detection of the armor that is equipped doesnt work properly. Currently this is how I am detecting what armor is worn. It doesn't seem to work at all though. This is just a test.

ย 

public void onArmorTick(World world, EntityPlayer player, ItemStack armor) {

ย  ย  //0 is Boots

ย  ย  //1 is Legs

ย  ย  //2 is Chest

ย  ย  //3 is Helm

ย  ย  ItemStack armorslot = player.inventory.armorItemInSlot(0);

ย  ย  System.out.println(armorslot + " Is Equipped");

ย 

ย  ย  if (player.inventory.armorItemInSlot(0) == ItemLoader.ArmorTeslaBoots) {

ย  ย  ย  ย  System.out.println("Boots worn");

ย 

in console it prints:

ย 

1xitem.ArmorTeslaBoots@0 Is Equipped

ย 

however it does not print "Boots Worn" when equipped...

ย 

ย 

Link to comment
Share on other sites

the problem is "armorItemInSlot(0)" returns an ItemStack, you can't compare ItemStacks with Items you will always get a false. You want

armorItemInSlot(0).getItem()

.equals(item) or

== item,

or instanceof item

ย 

also you already have the itemstack from this line:

ItemStack armorslot = player.inventory.armorItemInSlot(0);

ย 

so just use

if (armorslot.getItem()ย  == ItemLoader.ArmorTeslaBoots)

{

//do stuff

}

Link to comment
Share on other sites

You should take a look at the getEntitiesWithinAABB(...) method and the other methods around it in its class. By that I mean to select the method name in your code in Eclipse, then right-click on it, then use the popup menu to view the method's declaration. You'll learn much more that way much faster than coming here to ask others to go do that reading for you.

ย 

Once there, you will see several such methods. Look at their arguments. You can exclude an entity or include only a certain type of entity. I think you'll also see some calls to underlying methods in the chunk management class. Investigating those might give you more ideas how to refine your search to get exactly those entities you want to electrocute (i.e. you probably don't want lightning shooting at paintings and lead-knots).

ย 

Good Luck!

ย 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Dalam dunia perjudian online yang berkembang pesat, mencari platform yang dapat memberikan kemenangan maksimal dan hasil terbaik adalah impian setiap penjudi. OLXTOTO, dengan bangga, mempersembahkan dirinya sebagai jawaban atas pencarian itu. Sebagai platform terbesar untuk kemenangan maksimal dan hasil optimal, OLXTOTO telah menciptakan gelombang besar di komunitas perjudian online. Satu dari banyak keunggulan yang dimiliki OLXTOTO adalah koleksi permainan yang luas dan beragam. Dari togel hingga slot online, dari live casino hingga permainan kartu klasik, OLXTOTO memiliki sesuatu untuk setiap pemain. Dibangun dengan teknologi terkini dan dikembangkan oleh para ahli industri, setiap permainan di platform ini dirancang untuk memberikan pengalaman yang tak tertandingi bagi para penjudi. Namun, keunggulan OLXTOTO tidak hanya terletak pada variasi permainan yang mereka tawarkan. Mereka juga menonjol karena komitmen mereka terhadap keamanan dan keadilan. Dengan sistem keamanan tingkat tinggi dan proses audit yang ketat, OLXTOTO memastikan bahwa setiap putaran permainan berjalan dengan adil dan transparan. Para pemain dapat merasa aman dan yakin bahwa pengalaman berjudi mereka di OLXTOTO tidak akan terganggu oleh masalah keamanan atau keadilan. Tak hanya itu, OLXTOTO juga terkenal karena layanan pelanggan yang luar biasa. Tim dukungan mereka selalu siap sedia untuk membantu para pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Dengan respon cepat dan solusi yang efisien, OLXTOTO memastikan bahwa pengalaman berjudi para pemain tetap mulus dan menyenangkan. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi pilihan utama bagi jutaan penjudi online di seluruh dunia. Jika Anda mencari platform yang dapat memberikan kemenangan maksimal dan hasil optimal, tidak perlu mencari lebih jauh dari OLXTOTO. Bergabunglah dengan OLXTOTO hari ini dan mulailah petualangan Anda menuju kemenangan besar dan hasil terbaik!
    • Selamat datang diย OLXTOTO,ย situs slot gacorย terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, makaย OLXTOTOย adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasiย slot onlineย terlengkap dan peluang memenangkan jackpotย slot maxwinย yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermainย judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI ย  Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpotย slot maxwinย yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiahย jackpot slot maxwinย kami. Jackpot slot maxwinย merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir denganย jackpot slot maxwinย yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda. ย  Kesimpulan OLXTOTO adalahย situs slot gacorย terbaik yang memberikan pengalaman bermain judi slot online yang tak terlupakan. Dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering, OLXTOTO menjadi pilihan terbaik bagi para pemain yang mencari kesenangan dan kemenangan besar dalam perjudian online. Di samping itu, OLXTOTO juga menawarkan layanan pelanggan yang ramah dan responsif, siap membantu setiap pemain dalam mengatasi masalah teknis atau pertanyaan seputar perjudian online. Kami menjaga integritas game dan memberikan lingkungan bermain yang adil serta menjalankan kebijakan perlindungan pelanggan yang cermat. Bergabunglah dengan OLXTOTO sekarang dan nikmati pengalaman bermain slot online yang luar biasa. Jadilah bagian dari komunitas perjudian yang mengagumkan ini dan raih kesempatan untuk meraih kemenangan besar. Dapatkan akses mudah dan praktis ke situs OLXTOTO dan rasakan sensasi bermain judi slot yang tak terlupakan. ย 
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa Di dunia perjudian online yang begitu kompetitif, mencari platform yang dapat memberikan kemenangan maksimal (Maxwin) dan hasil terbaik (Gacor) adalah prioritas bagi para penjudi yang cerdas. Dalam upaya ini, OLXTOTO telah muncul sebagai pemain kunci yang mengubah lanskap perjudian online dengan menawarkan pengalaman tanpa tandingan. ย  ย  Sejak diluncurkan, OLXTOTO telah menjadi sorotan industri perjudian online. Dikenal sebagai "Platform Maxwin dan Gacor Terbesar Sepanjang Masa", OLXTOTO telah menarik perhatian pemain dari seluruh dunia dengan reputasinya yang solid dan kinerja yang luar biasa. Salah satu fitur utama yang membedakan OLXTOTO dari pesaingnya adalah komitmen mereka untuk memberikan pengalaman berjudi yang unik dan memuaskan. Dengan koleksi game yang luas dan beragam, termasuk togel, slot online, live casino, dan banyak lagi, OLXTOTO menawarkan sesuatu untuk semua orang. Dibangun dengan teknologi terkini dan didukung oleh tim ahli yang berdedikasi, platform ini memastikan bahwa setiap pengalaman berjudi di OLXTOTO tidak hanya menghibur, tetapi juga menguntungkan. Namun, keunggulan OLXTOTO tidak hanya terletak pada permainan yang mereka tawarkan. Mereka juga terkenal karena keamanan dan keadilan yang mereka berikan kepada para pemain mereka. Dengan sistem keamanan tingkat tinggi dan audit rutin yang dilakukan oleh otoritas regulasi independen, para pemain dapat yakin bahwa setiap putaran permainan di OLXTOTO adalah adil dan transparan. Tidak hanya itu, OLXTOTO juga dikenal karena layanan pelanggan yang luar biasa. Dengan tim dukungan yang ramah dan responsif, para pemain dapat yakin bahwa setiap pertanyaan atau masalah mereka akan ditangani dengan cepat dan efisien. Dengan semua fitur dan keunggulan yang ditawarkannya, tidak mengherankan bahwa OLXTOTO telah menjadi platform pilihan bagi para penjudi online yang mencari kemenangan maksimal dan hasil terbaik. Jadi, jika Anda ingin bergabung dengan jutaan pemain yang telah merasakan keajaiban OLXTOTO, jangan ragu untuk mendaftar dan mulai bermain hari ini! ย 
    • OLXTOTO adalah bandar slot yang terkenal dan terpercaya di Indonesia. Mereka menawarkan berbagai jenis permainan slot yang menarik dan menghibur. Dengan tampilan yang menarik dan grafis yang berkualitas tinggi, pemain akan merasa seperti berada di kasino sungguhan. OLXTOTO juga menyediakan layanan pelanggan yang ramah dan responsif, siap membantu pemain dengan segala pertanyaan atau masalah yang mereka hadapi. Daftar =ย ย https://surkale.me/Olxtotodotcom1
    • DAFTAR & LOGIN BIGO4D ย  Bigo4D adalah situs slot online yang populer dan menarik perhatian banyak pemain slot di Indonesia. Dengan berbagai game slot yang unik dan menarik, Bigo4D menjadi tempat yang ideal untuk pemula dan pahlawan slot yang berpengalaman. Dalam artikel ini, kami akan membahas tentang Bigo4D sebagai situs slot terbesar dan menarik yang saat ini banyak dijajaki oleh pemain slot online.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.