Jump to content

How do i Check for block neighbor that is for example 5 blocks away


Silverkill95

Recommended Posts

so, my mod blows items npc's mobs and players into a certain direction

however, if you put a block inbetween it will still move you

 

my question is what method do i need to use in my TileEntity to make it so that i stop moving

aka, how do i check for a block in the distance?

 

 

Link to comment
Share on other sites

Well if you can answer this, you should already have the answer in front of you:

 

How can you get a block at any given position? :)

 

ehhhhh.... not really,  i cant seem to figure out a way to check if a block is in front of the block  in a 0 - 20 block  line

 

Link to comment
Share on other sites

If you got access to the world object somehow (Hint: your TileEntity has one) then you can call the below method upon it during whatever method you are invoking, like the update method.

 

world.getBlockId(xPos, yPos, zPos)

couldnt make it work....

besides can you show me how id make it so that it checks for a block in xPos  1-20 for example?

 

Sure, but you won't like my answer.

You may not like it nor believe me, but anyone would give you the same answer:

You need to go back and learn some more java basics :)

 

I recommend looking into these, they are nice and interesting:

http://see.stanford.edu/see/lecturelist.aspx?coll=824a47e1-135f-4508-a5aa-866adcae1111

 

All material available for free, basically the whole course including assignments and handouts/lecture notes

 

If you guys dont get it.. then well ya.. try harder...

Link to comment
Share on other sites

world.getBlockId(xPos, yPos, zPos)

couldnt make it work....

besides can you show me how id make it so that it checks for a block in xPos  1-20 for example?

 

Loops.

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.

Link to comment
Share on other sites

If you want to get really advanced you could use line-of-sight algorithms like this (do not simply copy-paste the code, as it will not work for you):

	for (float i = 0; i <= range; i += 0.25) {
Vec3 vec2 = ReikaVectorHelper.getVec2Pt(x+a, y+b, z+c, x0, y0, z0).normalize();
vec2.xCoord *= i;
vec2.yCoord *= i;
vec2.zCoord *= i;
vec2.xCoord += x0;
vec2.yCoord += y0;
vec2.zCoord += z0;
//ReikaGuiAPI.write(String.format("%f --> %.3f, %.3f, %.3f", i, vec2.xCoord, vec2.yCoord, vec2.zCoord));
int id = world.getBlockId((int)vec2.xCoord, (int)vec2.yCoord, (int)vec2.zCoord);
if ((int)vec2.xCoord == x && (int)vec2.yCoord == y && (int)vec2.zCoord == z) {
//ReikaGuiAPI.writeCoords(world, (int)vec2.xCoord, (int)vec2.yCoord, (int)vec2.zCoord);
return true;
}
else if (id != 0 && (isCollideable(world, (int)vec2.xCoord, (int)vec2.yCoord, (int)vec2.zCoord) && !softBlocks(id))) {
i = (float)(range + 1);
}
}

Link to comment
Share on other sites

Nice code Reika :)

Thank you. :D

 

I am writing a (non-base-class-modifying) API that has a lot of such functions; you can certainly use it in your own mods as a dependency if you want. ;) It has no "mod class", so forge does not recognize it as a true mod, but it is accessible if referenced correctly. It also has functionality to use the old spritesheet system (which Optifine sadly breaks on blocks, though items work beautifully) and some file I/O (including PNG and MIDI files).

Link to comment
Share on other sites

I am writing a (non-base-class-modifying) API that has a lot of such functions; you can certainly use it in your own mods as a dependency if you want. ;) It has no "mod class", so forge does not recognize it as a true mod, but it is accessible if referenced correctly. It also has functionality to use the old spritesheet system (which Optifine sadly breaks on blocks, though items work beautifully) and some file I/O (including PNG and MIDI files).

 

Wow, really cool.

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.

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.