Mutual existence of entities

Started by Oskarxisee on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Mutual existence of entities

Hello. I want to make mutual existence. That is, the procedure for an entity that checks whether there is another same entity within a radius of 4 blocks. It must be the same entity. But I don't know how to check if there is another entity of the same type in area 4 of the block, or even nearby. Thank

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To check entities around…
Tue, 01/17/2023 - 16:07

To check entities around there's a procedure for it ("For each entity as...")

To check if entities are the same, then you need an if statement with a code snippet in previous mentioned procedure (you can try this inside a code snippet: "entityiterator instanceof entity"). 

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Update, try this code…
Tue, 01/17/2023 - 16:16

Update, try this code snippet:

entityiterator.getType() == entity.getType()

It checks if entities (entity from event and entityiterator is entity from "for each entity" procedure) are the same type. 

comparing objects with == is…
Tue, 01/17/2023 - 16:55

comparing objects with == is a very bad idea in Java. Instead, you should use the equals() method.

Joined Oct 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Sorry, I'm mainly C++ so u…
Tue, 01/17/2023 - 18:51

Sorry, I'm mainly C++ so u know :>

entity.getType().equals(entityiterator.getType())

I think this should be good then >:3

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank! It's work
Wed, 01/18/2023 - 17:05

Thank! It's work