The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
I have been working on creating a Byzantine Grenade for minecraft, for those of you who don't know your mythology it is a grenade that when coming on impact with the ground bursts into flames.The issue is that I can't seem to make it spawn fire at all no matter what I have tried. Please help and thanks. Here is the code that I have in the Entity Class for the grenade so far.
public class EntityByzantineGrenade extends EntityThrowable {
public EntityByzantineGrenade(World world) {
super(world);
}
public EntityByzantineGrenade(World world, EntityLivingBase entity) {
super(world, entity);
}
There are two ways you could do this: First, I believe onImpact can also be defined relative to a block position aswell as a moving object. Look into that, then you'll want to set the block it hits to fire. Literally add an argument so it changes the block hit to a fire block. Or, if you're looking for grenades, you can have the grenade summon an explosion entity onImpact, look into EntityTNT and EntityCreeper to see how that is achieved.
Apologies for the lack of distinct code examples, I'm currently without PC and can't construct the arguments for you from memory.
the only issue is that I keep getting an error where it is saying that it won't accept this.posX this.posY and this.posZ because "The method setBlock(int, int, int, Block) in the type World is not applicable for the arguments (double, double, double, BlockFire)"
and I am looking to set a block on fire not to replace it with fire and I already know how to create explosions onImpact but thanks
also, I am hoping to make it not just that one block that gets lit on fire but also a couple blocks surrounding it
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
I could have sworn I tried initializing them already but I tried again anyways and it works so thanks it will also spawn fire one block above or below depending on the terrain. Now the only thing I need to figure out is how to make a flamethrower I'll post the code below as well. Thanks again.
......X......
...X X X...
X X X X X
...X X X...
......X......
public class EntityByzantineGrenade extends EntityThrowable {
public EntityByzantineGrenade(World world) {
super(world);
}
public EntityByzantineGrenade(World world, EntityLivingBase entity) {
super(world, entity);
}
That is actually a bit harder than a EntityThrowable because part of the code needs to run on the client, and then packets need to be sent to the server, to actual catch the entity on fire that you throw flames at (on the client side).
No, not just an item that spawns a projectile. I already have fireballs that do that.
For some of the dragons in Draco Animus, we wanted the actual look of a fire breathing (flame throwing) dragon.
So what I did was use spawnParticle (I'm going from memory here, I think that is right) to make flames like those produced by a torch. I put a velocity on them so they head towards the look point. I then also did an extended reach method (none of the built in ones will work for this, I modified the mouse over one to not use the normal 4.5F and put my own distance in there).
The spawnParticle is on the client, so then I sent a message to the server for the location of the entity from the extended reach. When the message is received it does what ever attack is needed (in this case, sets the entity on fire).
BTW, don't even attempt trying to copy what I did, let alone create it on your own unless you have a strong grasp of how client/server works in Minecraft and also a strong knowledge of the Java language too.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
So did you make a throwable that OnRightClick it would spawn a bunch of particles with velocity on them depending on the direction the player is facing and then you got the position of a few blocks in front of the player and if there were entities or anything flammable in that area, they were lit on fire?
So, I think you are asking me. I did get the particles to spawn in front of the player. I found that some particles seem to behave differently than others, even though I used world.spawnParticle for all of them.
What I found that seemed to work the best is something like this:
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
Okay, that makes more sense, I was trying to use the Vec incorrectly, thanks for clearing this up. So if I understand correctly, the next thing you did was you used your extended reach method to make is so that anything within that reach was lit aflame? I am assuming by extended reach you mean how far the player can reach, the only issue I can see with this is when they attempt to break blocks, they can reach further to do so either that or they can't reach as far depending on how you did it (I'm assuming further). So is there any way to negate that? Also, how would you set anything within that reach on fire especially if the fire that you are spawning in (particles) are traveling to the side, you wouldn't want to set just the entities directly in front of the player but also those engulfed in the flames. So pretty much how do you keep them breaking blocks past 4.5 blocks away and how do you cause entities and/or blocks to become lit on fire while in front of the player and to the side but still in the flame particles
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
nevermind, found out how to make is so that they can't build or break while using the item, just set the playercapability allowEdit to false while they are using the flamethrower so just the whole setting on fire thing
Ya, the extended reach thing only works with the one weapon that I made (the Dragon Staff). It only sets fire to the first entity you point to. Also the extended reach just does that one thing. If you use the staff to hit a mob, it just goes the normal reach of 4.5.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/22/2015
Posts:
99
Member Details
So I can get it to set more than just what you are looking at on fire, so more than one thing at once, the only issue is that it will set things on fire only in one direction. Here is the code that I got so far
public class ByzantineFlamethrowerClass extends Item{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
So it may not be apparent just looking at the code, but when you consider that this code is actually running twice. Once on the client side, once on the server side, it makes sense that it is only one direction.
On the client, the code that does anything is effectively:
In order to see and control what is really running, I always use a:
if (player.worldObj.isRemote) or if (!player.worldObj.isRemote)
That way your code as written is doing what it looks like it should be doing and not some strange combination of what runs and what doesn't run on the client and server side of where this function executes.
So to be clear, the getLook only does anything useful on the client, the SpawnParticle is only a client side function (it deals with rendering). The setBlock can be run on both server and client, but must run on the server to make anything permanent happen.
So aside from a modder creating a way, there isn't a way for the server to get the direction that the player is facing?
Wasn't saying that, was just saying that the above method doesn't work on the server. The getLook or another one like it called getLookVec, work by returning the vector for where the cursor is pointing, The cursor as far as I know doesn't exist on the server, it is just on the client.
You can always send a packet to the server with the x, y, z of the vector returned from getLook on the client, and then the server will know the direction the player is looking.
I have been working on creating a Byzantine Grenade for minecraft, for those of you who don't know your mythology it is a grenade that when coming on impact with the ground bursts into flames.The issue is that I can't seem to make it spawn fire at all no matter what I have tried. Please help and thanks. Here is the code that I have in the Entity Class for the grenade so far.
public class EntityByzantineGrenade extends EntityThrowable {
public EntityByzantineGrenade(World world) {
super(world);
}
public EntityByzantineGrenade(World world, EntityLivingBase entity) {
super(world, entity);
}
@Override
protected void onImpact(MovingObjectPosition object) {
for(int i = 0; i < 10; i++) {
this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0.1F, 0.1F, 0.1F);
}
if(!this.worldObj.isRemote) {
this.setDead();
if(!this.worldObj.isRemote) {
}
}
}
}
Oh yeah... and if you know anything about how to make a flamethrower... that would help as well...
There are two ways you could do this: First, I believe onImpact can also be defined relative to a block position aswell as a moving object. Look into that, then you'll want to set the block it hits to fire. Literally add an argument so it changes the block hit to a fire block. Or, if you're looking for grenades, you can have the grenade summon an explosion entity onImpact, look into EntityTNT and EntityCreeper to see how that is achieved.
Apologies for the lack of distinct code examples, I'm currently without PC and can't construct the arguments for you from memory.
Check out my Youtube channel, where I build a theme park in vanilla Minecraft!
https://www.youtube.com/playlist?list=PLeCiIIOoWhe-mq3nYd_nXXrKw9MkjnUU7
Thanks for the posts and I have already tried
if(!worldObj.isRemote)
{
worldObj.setBlock(this.posX,this.posY,this.posZ, Blocks.fire);
}
the only issue is that I keep getting an error where it is saying that it won't accept this.posX this.posY and this.posZ because "The method setBlock(int, int, int, Block) in the type World is not applicable for the arguments (double, double, double, BlockFire)"
and I am looking to set a block on fire not to replace it with fire and I already know how to create explosions onImpact but thanks
also, I am hoping to make it not just that one block that gets lit on fire but also a couple blocks surrounding it
I could have sworn I tried initializing them already but I tried again anyways and it works so thanks it will also spawn fire one block above or below depending on the terrain. Now the only thing I need to figure out is how to make a flamethrower I'll post the code below as well. Thanks again.
......X......
...X X X...
X X X X X
...X X X...
......X......
public class EntityByzantineGrenade extends EntityThrowable {
public EntityByzantineGrenade(World world) {
super(world);
}
public EntityByzantineGrenade(World world, EntityLivingBase entity) {
super(world, entity);
}
@Override
protected void onImpact(MovingObjectPosition object) {
if(object.entityHit != null)
{
object.entityHit.setFire(2000);
}
for(int i = 0; i < 10; i++) {
this.worldObj.spawnParticle("largesmoke", this.posX, this.posY, this.posZ, 0.1F, 0.1F, 0.1F);
}
if(!this.worldObj.isRemote) {
this.setDead();
if(!this.worldObj.isRemote) {
int x = (int)this.posX;
int y = (int)this.posY;
int z = (int)this.posZ;
worldObj.setBlock(x, y, z, Blocks.fire);
if(worldObj.getBlock(x, y, z + 1) == Blocks.air) {
worldObj.setBlock(x , y, z + 1, Blocks.fire);
}else if(worldObj.getBlock(x , y + 1, z + 1) == Blocks.air) {
worldObj.setBlock(x , y + 1, z + 1, Blocks.fire);
}
if(worldObj.getBlock(x + 1, y, z + 1) == Blocks.air) {
worldObj.setBlock(x + 1, y, z + 1, Blocks.fire);
}else if(worldObj.getBlock(x + 1, y - 1, z + 1) == Blocks.air) {
worldObj.setBlock(x + 1, y - 1, z + 1, Blocks.fire);
}
if(worldObj.getBlock(x - 1, y, z + 1) == Blocks.air) {
worldObj.setBlock(x - 1, y, z + 1, Blocks.fire);
}else if(worldObj.getBlock(x - 1, y + 1, z + 1) == Blocks.air) {
worldObj.setBlock(x - 1, y + 1, z + 1, Blocks.fire);
}
if(worldObj.getBlock(x, y, z + 2) == Blocks.air) {
worldObj.setBlock(x, y, z + 2, Blocks.fire);
}else if(worldObj.getBlock(x, y + 1, z + 2) == Blocks.air) {
worldObj.setBlock(x, y + 1, z + 2, Blocks.fire);
}
if(worldObj.getBlock(x + 1, y, z) == Blocks.air) {
worldObj.setBlock(x + 1, y, z, Blocks.fire);
}else if(worldObj.getBlock(x + 1, y + 1, z) == Blocks.air) {
worldObj.setBlock(x + 1, y + 1, z, Blocks.fire);
}
if(worldObj.getBlock(x + 2, y, z) == Blocks.air) {
worldObj.setBlock(x + 2, y, z, Blocks.fire);
}else if(worldObj.getBlock(x + 2, y + 1, z) == Blocks.air) {
worldObj.setBlock(x + 2, y + 1, z, Blocks.fire);
}
if(worldObj.getBlock(x - 1, y, z) == Blocks.air) {
worldObj.setBlock(x - 1, y, z, Blocks.fire);
}else if(worldObj.getBlock(x - 1, y + 1, z) == Blocks.air) {
worldObj.setBlock(x - 1, y + 1, z, Blocks.fire);
}
if(worldObj.getBlock(x - 2, y, z) == Blocks.air) {
worldObj.setBlock(x - 2, y, z, Blocks.fire);
}else if(worldObj.getBlock(x - 2, y + 1, z) == Blocks.air) {
worldObj.setBlock(x - 2, y + 1, z, Blocks.fire);
}
if(worldObj.getBlock(x, y, z - 1) == Blocks.air) {
worldObj.setBlock(x, y, z - 1, Blocks.fire);
}else if(worldObj.getBlock(x, y + 1, z - 1) == Blocks.air) {
worldObj.setBlock(x, y + 1, z - 1, Blocks.fire);
}
if(worldObj.getBlock(x - 1, y, z - 1) == Blocks.air) {
worldObj.setBlock(x - 1, y, z - 1, Blocks.fire);
} else if(worldObj.getBlock(x - 1, y + 1, z - 1) == Blocks.air) {
worldObj.setBlock(x - 1, y + 1, z - 1, Blocks.fire);
}
if(worldObj.getBlock(x, y, z - 2) == Blocks.air) {
worldObj.setBlock(x, y, z - 2, Blocks.fire);
}else if(worldObj.getBlock(x, y + 1, z - 2) == Blocks.air) {
worldObj.setBlock(x, y + 1, z - 2, Blocks.fire);
}
if(worldObj.getBlock(x + 1, y, z - 1) == Blocks.air) {
worldObj.setBlock(x + 1, y, z - 1, Blocks.fire);
} else if(worldObj.getBlock(x + 1, y + 1, z - 1) == Blocks.air) {
worldObj.setBlock(x + 1, y + 1, z - 1, Blocks.fire);
}
if(worldObj.getBlock(x , y - 1, z + 1) == Blocks.air) {
worldObj.setBlock(x , y - 1, z + 1, Blocks.fire);
}
if(worldObj.getBlock(x + 1, y + 1, z + 1) == Blocks.air) {
worldObj.setBlock(x + 1, y + 1, z + 1, Blocks.fire);
}
if(worldObj.getBlock(x - 1, y - 1, z + 1) == Blocks.air) {
worldObj.setBlock(x - 1, y - 1, z + 1, Blocks.fire);
}
if(worldObj.getBlock(x, y - 1, z + 2) == Blocks.air) {
worldObj.setBlock(x, y - 1, z + 2, Blocks.fire);
}
if(worldObj.getBlock(x + 1, y - 1, z) == Blocks.air) {
worldObj.setBlock(x + 1, y - 1, z, Blocks.fire);
}
if(worldObj.getBlock(x + 2, y - 1, z) == Blocks.air) {
worldObj.setBlock(x + 2, y - 1, z, Blocks.fire);
}
if(worldObj.getBlock(x - 1, y - 1, z) == Blocks.air) {
worldObj.setBlock(x - 1, y - 1, z, Blocks.fire);
}
if(worldObj.getBlock(x - 2, y - 1, z) == Blocks.air) {
worldObj.setBlock(x - 2, y - 1, z, Blocks.fire);
}
if(worldObj.getBlock(x, y - 1, z - 1) == Blocks.air) {
worldObj.setBlock(x, y - 1, z - 1, Blocks.fire);
}
if(worldObj.getBlock(x - 1, y - 1, z - 1) == Blocks.air) {
worldObj.setBlock(x - 1, y - 1, z - 1, Blocks.fire);
}
if(worldObj.getBlock(x, y - 1, z - 2) == Blocks.air) {
worldObj.setBlock(x, y - 1, z - 2, Blocks.fire);
}
if(worldObj.getBlock(x + 1, y - 1, z - 1) == Blocks.air) {
worldObj.setBlock(x + 1, y - 1, z - 1, Blocks.fire);
}
}
}
}
}
I'm also working on a flame thrower.
That is actually a bit harder than a EntityThrowable because part of the code needs to run on the client, and then packets need to be sent to the server, to actual catch the entity on fire that you throw flames at (on the client side).
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
No, not just an item that spawns a projectile. I already have fireballs that do that.
For some of the dragons in Draco Animus, we wanted the actual look of a fire breathing (flame throwing) dragon.
So what I did was use spawnParticle (I'm going from memory here, I think that is right) to make flames like those produced by a torch. I put a velocity on them so they head towards the look point. I then also did an extended reach method (none of the built in ones will work for this, I modified the mouse over one to not use the normal 4.5F and put my own distance in there).
The spawnParticle is on the client, so then I sent a message to the server for the location of the entity from the extended reach. When the message is received it does what ever attack is needed (in this case, sets the entity on fire).
BTW, don't even attempt trying to copy what I did, let alone create it on your own unless you have a strong grasp of how client/server works in Minecraft and also a strong knowledge of the Java language too.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
So did you make a throwable that OnRightClick it would spawn a bunch of particles with velocity on them depending on the direction the player is facing and then you got the position of a few blocks in front of the player and if there were entities or anything flammable in that area, they were lit on fire?
Also, on the note of spawning particles, how do you make it so that the particles spawn the direction the player is facing
So, I think you are asking me. I did get the particles to spawn in front of the player. I found that some particles seem to behave differently than others, even though I used world.spawnParticle for all of them.
What I found that seemed to work the best is something like this:
Vec3 look = player.getLook(1.0F);
double dxMin = (double)((float)player.posX + look.xCoord * minD);
double dyMin = (double)((float)player.posY + player.eyeHeight + look.yCoord * minD);
double dzMin = (double)((float)player.posZ + 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);
The above spawns 2 particles, but you could do more, it sends them away from the player towards the target you are looking at.
I don't completely understand how this works, as some types of particles move differently than others, even with exactly the same code to spawn them.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Okay, that makes more sense, I was trying to use the Vec incorrectly, thanks for clearing this up. So if I understand correctly, the next thing you did was you used your extended reach method to make is so that anything within that reach was lit aflame? I am assuming by extended reach you mean how far the player can reach, the only issue I can see with this is when they attempt to break blocks, they can reach further to do so either that or they can't reach as far depending on how you did it (I'm assuming further). So is there any way to negate that? Also, how would you set anything within that reach on fire especially if the fire that you are spawning in (particles) are traveling to the side, you wouldn't want to set just the entities directly in front of the player but also those engulfed in the flames. So pretty much how do you keep them breaking blocks past 4.5 blocks away and how do you cause entities and/or blocks to become lit on fire while in front of the player and to the side but still in the flame particles
nevermind, found out how to make is so that they can't build or break while using the item, just set the playercapability allowEdit to false while they are using the flamethrower so just the whole setting on fire thing
Oh, cool.
Ya, the extended reach thing only works with the one weapon that I made (the Dragon Staff). It only sets fire to the first entity you point to. Also the extended reach just does that one thing. If you use the staff to hit a mob, it just goes the normal reach of 4.5.
If you are interested in the code is in GitHub at: https://github.com/DracoAnimus/Coding/blob/master/src/main/java/net/wildbill22/draco/items/weapons/ItemDragonStaff.java
You can look for getMouseOver, which has the same name as an existing function in Minecraft, but slightly modified for this.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
So it won't set fire to a certain area only what you are looking at directly?
Right.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
Okay good to know, I'll see if I can do anything about this if not well... that's just how it goes but if I can I'll let you know
So I can get it to set more than just what you are looking at on fire, so more than one thing at once, the only issue is that it will set things on fire only in one direction. Here is the code that I got so far
public class ByzantineFlamethrowerClass extends Item{
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player) {
Vec3 look = player.getLook(1.0F);
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);
if(world.getBlock(x+i, y+j, z+k) == Blocks.air) {
world.setBlock((int) (dxMin + i), (int) (dyMin + j), (int) (dzMin + k), Blocks.fire);
}
}
return itemstack;
}
}
So it may not be apparent just looking at the code, but when you consider that this code is actually running twice. Once on the client side, once on the server side, it makes sense that it is only one direction.
On the client, the code that does anything is effectively:
Vec3 look = player.getLook(1.0F);
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++) {
world.spawnParticle("flame", dxMin, dyMin, dzMin, look.xCoord * 0.05 * i, look.yCoord * 0.05 * j, look.zCoord * 0.05 * k);
On the server the code that does anything is:
double dxMin = (double)((float)player.posX );
double dyMin = (double)((float)player.posY + player.eyeHeight);
double dzMin = (double)((float)player.posZ);
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;
if(world.getBlock(x+i, y+j, z+k) == Blocks.air) {
world.setBlock((int) (dxMin + i), (int) (dyMin + j), (int) (dzMin + k), Blocks.fire);
}
}
return itemstack;
In order to see and control what is really running, I always use a:
if (player.worldObj.isRemote) or if (!player.worldObj.isRemote)
That way your code as written is doing what it looks like it should be doing and not some strange combination of what runs and what doesn't run on the client and server side of where this function executes.
So to be clear, the getLook only does anything useful on the client, the SpawnParticle is only a client side function (it deals with rendering). The setBlock can be run on both server and client, but must run on the server to make anything permanent happen.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]
So aside from a modder creating a way, there isn't a way for the server to get the direction that the player is facing?
Wasn't saying that, was just saying that the above method doesn't work on the server. The getLook or another one like it called getLookVec, work by returning the vector for where the cursor is pointing, The cursor as far as I know doesn't exist on the server, it is just on the client.
You can always send a packet to the server with the x, y, z of the vector returned from getLook on the client, and then the server will know the direction the player is looking.
[url=2482915-wip-arkcraft-survival-evolved-dinos-taming]