If you didn't get a block at a range of 9, then that means the space at that position is clear, so just spawn your explosion at that position - you don't actually have to hit something to cause an explosion.
getLook and getLookVec work on both client and server just fine.
objectMouseOver is part of the Minecraft class and relies on the mouse, meaning it is client only.
For the issue at hand, you have two (three) options:
1. Create an entity, like you are discussing. Set it's speed so that it travels at x blocks per tick, and then in its onUpdate method, kill it after ticksExisted * x = 9. I've done similar things in my own entities, and it works just fine, though it's not easy to get perfectly 9 blocks as the range.
2. Use player.getLookVec() then iterate over that (starting at the player's current position + eye height, of course), knowing that each iteration is one-block's distance. Iterate until you hit something or until you have iterated 9 times.
3. Similar to 2, but using wildbill's suggestion of a custom objectMouseOver implementation. This one will, however, require packets because it is limited to client side only.
EDIT:
Another option is to use rayTraceBlocks. You can use that on the server just fine, and you can pass in any two vectors that you want, e.g. the player's current position and the player's current position + the player's look vector * distance desired.
So this is my code so far. So I have position for player current position and look as the players look vector, how would I use this to spawn fire up to nine blocks away
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
By passing in a Vector with a magnitude of 9, rather than 1. getLookVec returns a normalized Vector, which means it has a magnitude of 1. You need to multiply each coordinate by 9 to get the actual position you want to pass in to rayTraceBlocks.
These will also be the values you add to the player's current position if you want to create the explosion after not hitting anything, e.g. player.posX + (look.xCoord * 9) is the x coordinate you want to spawn at. You also need y and z, obviously, but again, only if you didn't hit a block with the ray trace.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
that and when I try to put in extra coordinates to create more fire, it causes the coordinates to spawn from where the fire lands... is there a way to make it spawn it depending on the player position? what I mean is if I set
world.setBlock(x, y, z, Blocks.fire);
to
world.setBlock(x - 1, y, z, Blocks.fire);
it will spawn the fire from where it landed which isn't a bad thing if I knew how to create a function that could use the direction the player if facing to run a certain method... only issue is I would probably need eight of these because of there being diagonals
Um, your code doesn't really reflect what I was trying to get at. You need to multiply the look vector coordinates BEFORE you pass it in to the ray trace method, and actually pass in a new vector with those new coordinates. Otherwise your raytrace will always fail unless the player happens to be standing right in front of a block.
Also, you should only use the multiplied look coordinates plus the player's position if the ray trace did not hit anything, otherwise you will be spawning fire through walls and such.
As for spawning more fire blocks, what exactly are you trying to do? Spawn more around the point of impact, spawn fire in line, or what? You have the look vector, which is a line from the player that you can iterate across to set blocks that way, and you have the impact / spawn location, which you can then use with a set of for loops to set fire blocks all around it.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
What I am trying to create is a flamethrower so if i could get sort of a funnel shape starting at the player and spreading as it goes... that's kind of what I am aiming for. Also, how do I multiply the look vector, whenever I try to do it (I'm doing it in Vec3 look = player.getLookVec(); just putting it after the getLookVec() and before the semicolon) I get an error where "The operator * is undefined for the argument type(s) Vec3, int" Also, how do make it so that the code recognizes that they ray trace didn't hit anything, I'm sorry if these are obvious, I'm pretty new coding and am trying to teach myself
I think you looked at some of my code before, but here is some code that demonstrates one way to make flames in a "cone" shape (you would need to just spawn more of these than I am) and also multiply a look vector:
I realized that you might not just be able to read the above and see what is going on. I do try to use good naming for variables (helps me remember what I was doing when I look at it a month later).
To spawn more of the particles, change in the for loop, the i < 4 to i < 8 for instance to do double the particles.
The lines like this:
float dx = (world.rand.nextFloat() - 0.5F) / 5;
dx is for delta x, it produces a random float. It subtracts 0.5F to center it between -0.5 and 0.5. It then divides by 5 to make it small, so now in the range of -0.1 to 0.1. Might be other ways to get this small range, but it works, so who cares
dxMin is delta x minimum. It adds to the player position the small random delta (to make the cone shape) and the look vector multiplied by the distance from the player to spawn the particle. So that is the multiplying the vector (look.xCoord * minD). minD could be 0.5F to 4.0F depending on how you want it to look.
The last 3 parameters of spawnParticle are the velocity of the particles (How fast they move away from the player). These are are also multiplied. So they can't be greater than 1.0F (at least in my testing), so I multiply the vector (which is < 1.0F) by 0.05, because I plan to multiply it by a value that is from 1 to 10. I found this velocity looked best by experimentation.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
I know how to spawn particles (my code above has particles being spawned but not in a cone shape, thanks for that :D) but what I am working on is I am trying to cause things to light on fire that the player is looking at whether it be the ground, an entity, or a giant wooden wall right in front of them.
What I am trying to create is a flamethrower so if i could get sort of a funnel shape starting at the player and spreading as it goes... that's kind of what I am aiming for. Also, how do I multiply the look vector, whenever I try to do it (I'm doing it in Vec3 look = player.getLookVec(); just putting it after the getLookVec() and before the semicolon) I get an error where "The operator * is undefined for the argument type(s) Vec3, int" Also, how do make it so that the code recognizes that they ray trace didn't hit anything, I'm sorry if these are obvious, I'm pretty new coding and am trying to teach myself
Well you did say "how do I multiply the look vector", so that was what I was demonstrating with the code.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
Oh, okay it's just that I was told "You need to multiply the look vector coordinates BEFORE you pass it in to the ray trace method, and actually pass in a new vector with those new coordinates" (coolAlias) that's what I was asking about
I know how to spawn particles (my code above has particles being spawned but not in a cone shape, thanks for that :D) but what I am working on is I am trying to cause things to light on fire that the player is looking at whether it be the ground, an entity, or a giant wooden wall right in front of them.
I actually do plan to write some code that does something similar. It will destroy blocks that are below a certain hardness in the direction the player right clicks. Lighting something on fire is similar, except that once you have a block you want to light on fire, instead of destroying it, you set it on fire (I am not actually sure if that is a real thing, you might just spawn fire next to it).
Oh, okay it's just that I was told "You need to multiply the look vector coordinates BEFORE you pass it in to the ray trace method, and actually pass in a new vector with those new coordinates" (coolAlias) that's what I was asking about
Post the snippet of code. If you know how to multiply a vector, and you know the parameters needed by the ray trace method, then multiplying the vector before you pass it in should be trivial (as far as anything in Java goes).
Problem is, what I might consider trivial and what you think is, could be very different I took Calculus 1 & 2 in college, and two quarters of Physics. So I understand what a vector is and how it can be used. When you encounter some new concept, instead of trying to just copy and paste your way through it (not saying you are doing this, but maybe), do a Google search and try and develop an understanding of the concept before moving on. Google search by Google search, you will eventually have the skills to tackle just about any programming problem (might take a few years though
if you scroll up a couple posts, you will see the whole class file
Ah, the post from several days ago. Too tired to look at this now. Maybe later. At first glance, I think you would need to do more checking before you just do a setBlock at some location. If you don't ever want to replace an existing block, do a getBlock first, then see if it is air, and only if air replace it.
If you didn't get a block at a range of 9, then that means the space at that position is clear, so just spawn your explosion at that position - you don't actually have to hit something to cause an explosion.
So this is my code so far. So I have position for player current position and look as the players look vector, how would I use this to spawn fire up to nine blocks away
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
Vec3 position = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ);
Vec3 look = player.getLookVec();
MovingObjectPosition object = world.rayTraceBlocks(position, look);
double dxMin = (double)((float)player.posX + look.xCoord * 1);
double dyMin = (double)((float)player.posY + player.eyeHeight + look.yCoord * 1);
double dzMin = (double)((float)player.posZ + look.zCoord * 1);
for(int i = 0; i <= 5; i++)
for(int j = -1; j <= 1; j++)
for(int k = 0; k <= 5; k++) {
int x = (int)player.posX;
int y = (int)player.posY;
int z = (int)player.posZ;
world.spawnParticle("flame", dxMin, dyMin, dzMin, look.xCoord * 0.05 * i, look.yCoord * 0.05 * j, look.zCoord * 0.05 * k);
}
return itemstack;
}
}
By passing in a Vector with a magnitude of 9, rather than 1. getLookVec returns a normalized Vector, which means it has a magnitude of 1. You need to multiply each coordinate by 9 to get the actual position you want to pass in to rayTraceBlocks.
These will also be the values you add to the player's current position if you want to create the explosion after not hitting anything, e.g. player.posX + (look.xCoord * 9) is the x coordinate you want to spawn at. You also need y and z, obviously, but again, only if you didn't hit a block with the ray trace.
Okay I think I got it this is my code so far, the only issue is that sometimes it will light a block on fire or replace the block with fire XD
public class ByzantineFlamethrowerClass extends Item {
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
Vec3 position = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ);
Vec3 look = player.getLookVec();
MovingObjectPosition object = world.rayTraceBlocks(position, look);
double dxMin = (double)((float)player.posX + look.xCoord * 1);
double dyMin = (double)((float)player.posY + player.eyeHeight + look.yCoord * 1);
double dzMin = (double)((float)player.posZ + look.zCoord * 1);
for(int i = 0; i <= 5; i++)
for(int j = -1; j <= 1; j++)
for(int k = 0; k <= 5; k++) {
int x = (int) (player.posX + (look.xCoord * 9));
int y = (int) (player.posY + (look.yCoord * 9));
int z = (int) (player.posZ + (look.zCoord * 9));
world.spawnParticle("flame", dxMin, dyMin, dzMin, look.xCoord * 0.05 * i, look.yCoord * 0.05 * j, look.zCoord * 0.05 * k);
world.setBlock(x, y, z, Blocks.fire);
}
return itemstack;
}
}
that and when I try to put in extra coordinates to create more fire, it causes the coordinates to spawn from where the fire lands... is there a way to make it spawn it depending on the player position? what I mean is if I set
world.setBlock(x, y, z, Blocks.fire);
to
world.setBlock(x - 1, y, z, Blocks.fire);
it will spawn the fire from where it landed which isn't a bad thing if I knew how to create a function that could use the direction the player if facing to run a certain method... only issue is I would probably need eight of these because of there being diagonals
Um, your code doesn't really reflect what I was trying to get at. You need to multiply the look vector coordinates BEFORE you pass it in to the ray trace method, and actually pass in a new vector with those new coordinates. Otherwise your raytrace will always fail unless the player happens to be standing right in front of a block.
Also, you should only use the multiplied look coordinates plus the player's position if the ray trace did not hit anything, otherwise you will be spawning fire through walls and such.
As for spawning more fire blocks, what exactly are you trying to do? Spawn more around the point of impact, spawn fire in line, or what? You have the look vector, which is a line from the player that you can iterate across to set blocks that way, and you have the impact / spawn location, which you can then use with a set of for loops to set fire blocks all around it.
What I am trying to create is a flamethrower so if i could get sort of a funnel shape starting at the player and spreading as it goes... that's kind of what I am aiming for. Also, how do I multiply the look vector, whenever I try to do it (I'm doing it in Vec3 look = player.getLookVec(); just putting it after the getLookVec() and before the semicolon) I get an error where "The operator * is undefined for the argument type(s) Vec3, int" Also, how do make it so that the code recognizes that they ray trace didn't hit anything, I'm sorry if these are obvious, I'm pretty new coding and am trying to teach myself
I think you looked at some of my code before, but here is some code that demonstrates one way to make flames in a "cone" shape (you would need to just spawn more of these than I am) and also multiply a look vector:
private void spawnFlames(World world, EntityPlayer player, float minD, int amplifier) {
Vec3 look = player.getLookVec();
for (int i = 0; i < 4; i++) {
float dx = (world.rand.nextFloat() - 0.5F) / 5;
float dy = (world.rand.nextFloat() - 0.5F) / 5;
float dz = (world.rand.nextFloat() - 0.5F) / 5;
double dxMin = (double)((float)player.posX + dx + look.xCoord * minD);
double dyMin = (double)((float)player.posY + dy + player.eyeHeight + look.yCoord * minD);
double dzMin = (double)((float)player.posZ + dz + look.zCoord * minD);
world.spawnParticle("smoke", dxMin, dyMin, dzMin, look.xCoord * 0.05 * amplifier, look.yCoord * 0.05 * amplifier,
look.zCoord * 0.05 * amplifier);
world.spawnParticle("flame", dxMin, dyMin, dzMin, look.xCoord * 0.05 * amplifier, look.yCoord * 0.05 * amplifier,
look.zCoord * 0.05 * amplifier);
}
}
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
I realized that you might not just be able to read the above and see what is going on. I do try to use good naming for variables (helps me remember what I was doing when I look at it a month later).
To spawn more of the particles, change in the for loop, the i < 4 to i < 8 for instance to do double the particles.
The lines like this:
float dx = (world.rand.nextFloat() - 0.5F) / 5;
dx is for delta x, it produces a random float. It subtracts 0.5F to center it between -0.5 and 0.5. It then divides by 5 to make it small, so now in the range of -0.1 to 0.1. Might be other ways to get this small range, but it works, so who cares
This line:
double dxMin = (double)((float)player.posX + dx + look.xCoord * minD);
dxMin is delta x minimum. It adds to the player position the small random delta (to make the cone shape) and the look vector multiplied by the distance from the player to spawn the particle. So that is the multiplying the vector (look.xCoord * minD). minD could be 0.5F to 4.0F depending on how you want it to look.
The last 3 parameters of spawnParticle are the velocity of the particles (How fast they move away from the player). These are are also multiplied. So they can't be greater than 1.0F (at least in my testing), so I multiply the vector (which is < 1.0F) by 0.05, because I plan to multiply it by a value that is from 1 to 10. I found this velocity looked best by experimentation.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
I know how to spawn particles (my code above has particles being spawned but not in a cone shape, thanks for that :D) but what I am working on is I am trying to cause things to light on fire that the player is looking at whether it be the ground, an entity, or a giant wooden wall right in front of them.
Well you did say "how do I multiply the look vector", so that was what I was demonstrating with the code.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Oh, okay it's just that I was told "You need to multiply the look vector coordinates BEFORE you pass it in to the ray trace method, and actually pass in a new vector with those new coordinates" (coolAlias) that's what I was asking about
I actually do plan to write some code that does something similar. It will destroy blocks that are below a certain hardness in the direction the player right clicks. Lighting something on fire is similar, except that once you have a block you want to light on fire, instead of destroying it, you set it on fire (I am not actually sure if that is a real thing, you might just spawn fire next to it).
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Post the snippet of code. If you know how to multiply a vector, and you know the parameters needed by the ray trace method, then multiplying the vector before you pass it in should be trivial (as far as anything in Java goes).
Problem is, what I might consider trivial and what you think is, could be very different I took Calculus 1 & 2 in college, and two quarters of Physics. So I understand what a vector is and how it can be used. When you encounter some new concept, instead of trying to just copy and paste your way through it (not saying you are doing this, but maybe), do a Google search and try and develop an understanding of the concept before moving on. Google search by Google search, you will eventually have the skills to tackle just about any programming problem (might take a few years though
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
if you scroll up a couple posts, you will see the whole class file
Ah, the post from several days ago. Too tired to look at this now. Maybe later. At first glance, I think you would need to do more checking before you just do a setBlock at some location. If you don't ever want to replace an existing block, do a getBlock first, then see if it is air, and only if air replace it.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Usually I do that was just for testing sake but now I do have the getBlock function