Jump to content

Recommended Posts

Posted

Hey everyone,

 

I'm currently in the middle of making a Mod called Omega Craft, a technical mod which I decided to make so that I can learn how to mod first hand. Now one of the blocks that I am making needs to know where the current position of the nearest mob is in a certain radius, I've tried a few things but nothing has worked so far.

 

Now for example would anyone know how to find out if there is a creeper in a radius of 18 blocks of the block you place down?

 

Any help will be hugely appreciated.

Posted

Step 1:Make an axis aligned BB

Step 2:Make a list with it (it should have a method to convert it to a list)

Step 3:Make an iterator of that list Ex Iterator iter = list.iterator

Step 4:Do this

while(iter.hasNext()){

if(iter.next() instanceof EntityCreeper){

EntityCreeper ent = (EntityCreeper)iter.next();

//do whatever you want to do with this entitycreeper

}

}

 

You are now educated

 

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Posted
  On 3/29/2013 at 12:16 AM, thebest108 said:

AxisAlignedBB bb = new AxisAlignedBB(minx, miny, minz, maxx, maxy, maxz);

 

Wrong. The constructor of the AxisAlignedBB is protected. The correct call would be

AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(minx, miny, minz, maxx, maxy, maxz);

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • 2 weeks later...
Posted

After trailing and erroring, then finally giving up on this. I have decided to see it though, the biggest problem I had with making this work was, making it to list all the mobs nearby. How would I go about making an iterator to do this?

Posted
  On 3/29/2013 at 11:03 AM, TheDrunkMafia said:

So pretty much this:

 

protected AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(1, 1, 1, 16, 16, 16);

 

hm, I will give you some code to get a List of all entities:

First make a right AABB:

AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(this.posX - 16, this.posY, this.posZ - 16, this.posX + 16, this.posY + 16, this.posZ + 16);

 

'this' is the entity instance which you want to be at the center (for example the player if you wanna check if there are entities around it)

 

Next thing you do is to get a list of entities inside that bounding box. You have two possibillities:

List<EntityCreeper> entities = worldObj.getEntitiesWithinAABB(EntityCreeper.class, bb);

This will give you all entities which classes are equal to or are extending the class given (here you will get all entities which have EntityCreeper as a class or extend this class). This works also for interfaces (for example if you use IMob.class as parameter, it'll give you all entities which implement IMob, like Creepers, Zombies, Slimes etc).

List entities = worldObj.getEntitiesWithinAABBExcludingEntity(EntityPlayer.class, bb);

This will give you all entities (also paintings, arrows, fireballs etc.), so you have to check what entity it is when you iterate over the list. The class parameter in this will determine which entities won't be recognized, here the EntityPlayer. As above the rule is: Each entity which it's class is equal, extending or implementing the parameter class, will be excluded from the list.

 

Now the rest you have to figure out yourself. If you have any questions or errors, post them.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted
  On 4/13/2013 at 12:24 PM, TheDrunkMafia said:

The only error that I have got to far is that "worldObj" does not exist. I'm using 1.5.1 Forge.

 

where do you want to use your code? Can I see what you've got so far?

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

  Quote

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

    private int blockposX = 0;
    private int blockposY = 0;
    private int blockposZ = 0;
    private Entity entities;
    private String texturePath;
    private AxisAlignedBB bb = AxisAlignedBB.getBoundingBox(this.blockposX - 16, this.blockposY, this.blockposZ - 16, this.blockposX + 16, this.blockposY + 16, this.blockposZ + 16);
    
    public CreeperDetector(int par1, int par2, Material par3Material, String par4Str, String par5Str) {
        super(par1, par3Material);
        
        this.texturePath = par4Str;
    }
    
    public static void GetEntitys(){
                List<EntityCreeper> entities = worldObj.getEntitiesWithinAABB(EntityCreeper.class, bb);
                while(entities != null){
                    if(((EntityCreeper) entities) instanceof EntityCreeper){
                    EntityCreeper ent = (EntityCreeper)entities;
                    EntityWithinRadius();
                }
          }
    }

 

Basically when the block is finished the block will have two modes, defense which pushing the mob out of the radius and redstone which emits a redstone signal when a mob is in the radius.

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

    • Betafort Recovery has emerged as a prominent figure in the realm of cryptocurrency recovery, gaining a reputation for their exceptional ability to retrieve lost Bitcoin (BTC) and other cryptocurrencies. Their expertise and track record have made them a beacon of hope for individuals facing the distressing situation of lost or inaccessible crypto assets.  
    • When you name a method like that, with no return value, it is a constructor. The constructor must have the same name as the class it constructs, in this case, ModItems. I would strongly advise reading up on some basic Java tutorials, because you will definitely be running into a lot more issues as you go along without the basics. *I should also add that the Forge documentation is a reference, not a tutorial. Even following tutorials, you should know Java basics, otherwise the smallest of mistakes will trip you up as you copy someone elses code.
    • so, I'm starting modding and I'm following the official documantation for forge: https://docs.minecraftforge.net, but in the registries part it is not working as it is in the docs:   public class ModItems { private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, DarkStarvation.MOD_ID); public static final RegistryObject<Item> TEST_ITEM = ITEMS.register("test_item", () -> new Item(new Item.Properties())); public DarkStarvation(FMLJavaModLoadingContext context) { ITEMS.register(context.getModEventBus()); } } in 'public DarkStarvation(...' the DarkStarvation has this error: Invalid method declaration; return type required and the getModEventBus(): Cannot resolve method 'getModEventBus' in 'FMLJavaModLoadingContext' please help, I asked gpt but it is saying that I'm using an old method, but I'm following the latest version of Forge Docs???
    • I merged your second post with the original , there is no need to post a new thread asking for an answer. If someone sees your post and can help, they will reply. If you are seeking a quicker response, you could try asking in the Minecraft Forge diacord.
    • Create a new instance and start with cobblemon - if this works, add the rest of your mods in groups   Maybe another mod is conflicting - like Sodium/Iris or Radical Cobblemon Trainers
  • Topics

×
×
  • Create New...

Important Information

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