Posted June 9, 201510 yr I want to make an item that spawns lightning were the player is looking. problem is I don't have the right code, I think its out dated because I cant find these things in the vec3 class. here is my code package com.OlympiansMod.Item; import com.OlympiansMod.entity.EntityThunderBolt; import com.OlympiansMod.entity.EntityUndead; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; public class ZThunderBolt extends Item{ public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){ if(!player.capabilities.isCreativeMode){ --itemstack.stackSize; } //world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f); //if(!world.isRemote){ Vec3 posVec = world.getWorldVec3Pool().getVec3FromPool(player.posX, player.posY + player.getEyeHeight(), player.posZ); Vec3 lookVec = player.getLookVec(); MovingObjectPosition mop = world.rayTraceBlocks(posVec, lookVec); int x = mop.blockX; int y = mop.blockY; int z = mop.blockZ; EntityLightningBolt Bolt = new EntityLightningBolt(world, 5, 5, 5); Bolt.setPosition(player.posX = x , player.posY + y , player.posZ + z);; world.spawnEntityInWorld(Bolt); //} return itemstack; } } so yeah what do I do to fix it? btw syntax error on world.getWorldVec3Pool().getVec3FromPool Im serious don't look at it!!
June 9, 201510 yr There is no Vec3Pool any more, just use Vec3 whatever = new Vec3(args); Or, if you don't have that version yet, Vec3Helper.createVector or whatever it used to be. http://i.imgur.com/NdrFdld.png[/img]
June 9, 201510 yr Author nothing is working I think I need to write a new method. do you know any tutorials for 1.7.10 im confused with the new code. ive looked but I cant seem to find a tutorial anywere. Im serious don't look at it!!
June 9, 201510 yr Author can someone just tell me how to do it because so far nothing is working. public class ZThunderBolt extends Item{ public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){ if(!player.capabilities.isCreativeMode){ --itemstack.stackSize; } //world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f); //if(!world.isRemote){ @Override Vec3 posVec = new Vec3(player.posX, player.posY, player.posZ); Vec3 lookVec = player.getLookVec(); MovingObjectPosition mop = world.rayTraceBlocks(posVec, lookVec); int x = mop.blockX; int y = mop.blockY; int z = mop.blockZ; EntityLightningBolt Bolt = new EntityLightningBolt(world, 5, 5, 5); Bolt.setPosition(player.posX = x , player.posY + y , player.posZ + z);; world.spawnEntityInWorld(Bolt); //} return itemstack; } } Im serious don't look at it!!
June 9, 201510 yr You clearly dont understand how to override a method. You need to put @Override above onItemRightClick. Also get rid of all the extra code that doesnt work. If you want to spawn it where the player is looking, why do you need to ray trace when you already use a Vec3 look vector?
June 9, 201510 yr You clearly dont understand how to override a method. You need to put @Override above onItemRightClick. Not to be mean, but you clearly don't understand what @Override actually does - it is simply an extra layer of error-checking within the IDE - it has no effect whatsoever on the compiled code. @OP You probably want to pay more attention to what you are writing in your code: Bolt.setPosition(player.posX = x , player.posY + y , player.posZ + z);; Surely you meant plus (+) and not equals (=) ? Also, why are you adding them at all? The raytrace MovingObjectPosition returns the block position that was hit, as in real world block coordinates. If you add the player's position to that, you will get very bizarre numbers. Example: Player is at 100,64,100 looking east (+x axis); MOP returns a block at 100,64,115 (directly east). Now you add those together, and spawn lightning at 200, 128, 215. Do you really expect to see it? http://i.imgur.com/NdrFdld.png[/img]
June 9, 201510 yr You clearly dont understand how to override a method. You need to put @Override above onItemRightClick. Not to be mean, but you clearly don't understand what @Override actually does - it is simply an extra layer of error-checking within the IDE - it has no effect whatsoever on the compiled code. I'm aware of this, just pointing out that thats not where override goes.
June 9, 201510 yr Author okay guys but that's not the problem. I did have a typo but im getting current errors in my code specifically on new Vec3. I don't exactly know how that works. and I do know that the override goes above the method. but at this point im desperate and new to java so.. anyway what else can I do. and I have the raytraceblocks so that it finds the block that the player is looking at and defines the other int. Im serious don't look at it!!
June 9, 201510 yr Author also how does this method work? Vec3.createVectorHelper(p_72443_0_, p_72443_2_, p_72443_4_); what are the correct args im not sure what they are. Im serious don't look at it!!
June 9, 201510 yr Can you put a System.err.println(); to display the coordinates you are spawning your entity at?
June 9, 201510 yr Yeah, that's the one: Vec3.createVectorHelper. Arguments are the coordinates of the vector you want to create. I don't know what you mean by 'defines the other int' - what int? Listen, I understand you are "desperate" to get this working, but perhaps a time-out to learn about vectors would be helpful? That and going through some basic Java tutorials, of course. http://i.imgur.com/NdrFdld.png[/img]
June 9, 201510 yr Author ok gotcha coolAlias this isn't working for me in my craft. package com.OlympiansMod.Item; import com.OlympiansMod.entity.EntityThunderBolt; import com.OlympiansMod.entity.EntityUndead; import net.minecraft.entity.effect.EntityLightningBolt; import net.minecraft.entity.monster.EntitySlime; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; public class ZThunderBolt extends Item{ public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player){ if(!player.capabilities.isCreativeMode){ --itemstack.stackSize; } //world.playSoundAtEntity(player, "random.fizz", 0.7f, 0.8f); if(!world.isRemote){ Vec3 posVec = Vec3.createVectorHelper(player.posX, player.posY + player.getEyeHeight(), player.posZ); Vec3 lookVec = player.getLookVec(); MovingObjectPosition mop = world.rayTraceBlocks(posVec, lookVec); int x = mop.blockX; int y = mop.blockY; int z = mop.blockZ; System.out.println(x + ","+ y + ","+ z + " " + world.getBlock(x, y, z)); EntitySlime Bolt = new EntitySlime(world); Bolt.setPosition(player.posX + x , player.posY + y , player.posZ + z); world.spawnEntityInWorld(Bolt); } return itemstack; } } is there anything you think I should change to make it work. Im serious don't look at it!!
June 9, 201510 yr To quote myself in answer to your question: Also, why are you adding them at all? The raytrace MovingObjectPosition returns the block position that was hit, as in real world block coordinates. If you add the player's position to that, you will get very bizarre numbers. Example: Player is at 100,64,100 looking east (+x axis); MOP returns a block at 100,64,115 (directly east). Now you add those together, and spawn lightning at 200, 128, 215. Do you really expect to see it? You didn't listen the first time, so perhaps the second? http://i.imgur.com/NdrFdld.png[/img]
June 9, 201510 yr your quote is blank? Not from my end, it isn't, but just in case, here it is, unquoted, again: "Also, why are you adding them at all? The raytrace MovingObjectPosition returns the block position that was hit, as in real world block coordinates. If you add the player's position to that, you will get very bizarre numbers. Example: Player is at 100,64,100 looking east (+x axis); MOP returns a block at 100,64,115 (directly east). Now you add those together, and spawn lightning at 200, 128, 215. Do you really expect to see it?" In summary, use the coordinates from the MovingObjectPosition, and DO NOT ADD anything, certainly not the player's position. It makes no sense at all to do so, as you can see in the example provided. http://i.imgur.com/NdrFdld.png[/img]
June 9, 201510 yr Author okay so I get what your saying but I definitely agree with you, I need to learn more about it so yeah. basically for now I made an entity type throwable that spawns the lightning in on impack Im serious don't look at it!!
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.