Jump to content

[N Help/Advice Modding] Detection Player->specificBlock [solved]


Ghoul159

Recommended Posts

Does anyone have an idea how i can get the distance from player to a specific block like placed torches?

 

i tried "ModLoader.getMinecraftInstance().theWorld.getEntitiesWithinAABB" but it only works with entities like the name says xP...

 

anyone knowing a good way?

 

edit: on second page is a working solution

Link to comment
Share on other sites

  AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)this.xCoord, (double)this.yCoord, (double)this.zCoord, (double)(this.xCoord + 1), (double)(this.yCoord + 1), (double)(this.zCoord + 1)).expand(var1, var1, var1);

         

List var5 = this.worldObj.getEntitiesWithinAABB(EntityPlayer.class, var4);

            Iterator var6 = var5.iterator();

            EntityPlayer var7;

 

            while (var6.hasNext())

            {

                var7 = (EntityPlayer)var6.next();

                do stuff

}

Link to comment
Share on other sites

thanks! but i have a few questions..

 

...this.xCoord... should this be the player position? or from the toch?

 

is var1 the radius of the detection?

 

Edit: and i dont want to use it in a new block i want to detect things that are already in the game..

Link to comment
Share on other sites

this will return a list of colliding boxes

AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)player.posX + how blocks u want(double)player.posY + how blocks u want(double)player.posZ + how blocks u want(double)(player.posX + 1), (double)(player.posY + 1), (double)(player.posZ + 1));

    List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4);

Link to comment
Share on other sites

list.equals(string)

 

ok i tried this:

 

			AxisAlignedBB var4 = AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)plX + 10,(double)plY + 10,(double)plZ + 10,(double)(plX + 1), (double)(plY + 1), (double)(plZ + 1));
	       List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4);

            Iterator var6 = list.iterator();
            EntityPlayer var7;
            
            if(list.equals("50"))
            while (var6.hasNext())
            {
            	System.out.println("got one torch!");
                var7 = (EntityPlayer)var6.next();
            }

 

but the list is empty xP

Link to comment
Share on other sites

System.out.println(list);

see what u get on console

 

ok now i got the coordinates in the list like:

[iNFO] [sTDOUT] [box[-295.0, 68.0, 277.0 -> -294.0, 69.0, 278.0], box[-295.0, 69.0, 277.0 -> -294.0, 70.0, 278.0], box[-295.0, 70.0, 277.0 -> -294.0, 71.0, 278.0], box[-295.0, 68.0, 278.0 -> -294.0, 69.0, 279.0],...]

 

but how do i go through this with a block specific comparison? ^^

 

complete code:

[hide]

			AxisAlignedBB var4 = AxisAlignedBB.getBoundingBox(plX, plY, plZ, plX + 1.0D, plY + 1.0D, plZ + 1.0D).expand(4D, 2D, 4D);
	       List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4);

            Iterator var6 = list.iterator();
            EntityPlayer var7;
            
            if(list.equals("50"))
            while (var6.hasNext())
            {
            	System.out.println("got one torch!");
                var7 = (EntityPlayer)var6.next();
            }
            System.out.println(list);

[/hide]

Link to comment
Share on other sites

String ing =  list.toString();

System.out.println(ing);

 

do you mean i have to write a function which goes through the string; takes the specific coordinates; compares them if they are torches; and gives a return statement?

because the " System.out.println(ing);" output is the same...

 

Link to comment
Share on other sites

sorry, torch dosent have aabb so change

                      if(list.equals("50"))

              to

if(!list)

 

if(!list) is red underlined i took if(list != null)...

 

but the game crashes in the while at:

var7 = (EntityPlayer)var6.next();

 

edit: nevermind saw my bug^^

 

 

			AxisAlignedBB var4 = AxisAlignedBB.getBoundingBox(plX, plY, plZ, plX + 1.0D, plY + 1.0D, plZ + 1.0D).expand(4D, 2D, 4D);
	       List list = Minecraft.getMinecraft().theWorld.getAllCollidingBoundingBoxes(var4);

            Iterator var6 = list.iterator();
            EntityPlayer var7;
            
            if(list != null)
            while (var6.hasNext())
            {
            	
                var7 = (EntityPlayer)var6.next();
            }
            
            String ing =     list.toString();
            System.out.println(ing);   

 

 

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



×
×
  • Create New...

Important Information

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