MovingObjectPosition movingobjectposition = rayTrace(100, 1.0F);
if(movingobjectposition == null)
{
return;
}
Vec3D temp = movingobjectposition.hitVec;
EntityLightningBolt lightning = new EntityLightningBolt(world, this, temp.xCoord - posX, temp.yCoord - posY, temp.zCoord - posZ);
Latest News Article
Snapshot 13w21a Ready For Testing!
It's time for another exciting Snapshot! The Mojang crew was hanging in Monaco last week, but rest assured, this week's Snapshot is nothing shy of sweet! Let's see what's on the menu:
FEATURES:
Added new UI for horses, to control...
Minecraft Ways to Die - a Parody Song
Continuing with our theme of parody songs, today's offering is an especially clever creation! Minecraft Ways to Die, an odd take on the song 50 Ways to Say Goodbye, is a labor of love from a whole lot of people! This hand-crafted, artisinal s...
Minecraft Monday Show - Let's Play Killers & Great Downloads!
This week, BebopVox covers the recent drama with "Let's Play" videos (including Mojang's stance on the matter), and much more!...
How to make lightning spawn Out of Item range
Started by
UltimateSpartan
, Jan 12 2012 04:33 AM
14 replies to this topic
#1
Posted 12 January 2012 - 04:33 AM
I'm making an Item and I want lightning to spawn when right clicking and it works fine, but it wont spawn anywhere outside of the Item's range. I found this code in some other topic and anyways its supposed to be able to see a block that's outside of the Range so that the item can shoot lightning. I put this in my code and I got some errors so I wanted to know if anyone else knew a better way or something?
#2
Posted 12 January 2012 - 04:38 AM
UltimateSpartan, on 12 January 2012 - 04:33 AM, said:
I put this in my code and I got some errors so I wanted to know if anyone else knew a better way or something?
MovingObjectPosition movingobjectposition = rayTrace(100, 1.0F);
if(movingobjectposition == null)
{
return;
}
Vec3D temp = movingobjectposition.hitVec;
EntityLightningBolt lightning = new EntityLightningBolt(world, this, temp.xCoord - posX, temp.yCoord - posY, temp.zCoord - posZ);
#4
Posted 12 January 2012 - 02:20 PM
Stewiecraft, on 12 January 2012 - 05:48 AM, said:
I was going to do a tutorial for this exactly but I've been busy with my diploma today and I'm about to go to bed. I'll write it sometime tomorrow if you don't get your answer by then.
That would be great!! Thanks!! I assume you'll post it to the tutorial section so I look for it there.
#5
Posted 12 January 2012 - 07:41 PM
Stewiecraft, on 12 January 2012 - 05:48 AM, said:
I was going to do a tutorial for this exactly but I've been busy with my diploma today and I'm about to go to bed. I'll write it sometime tomorrow if you don't get your answer by then.
#6
Posted 12 January 2012 - 11:01 PM
jghgjb790, on 12 January 2012 - 04:38 AM, said:
You'll have to post the errors if you want help. Also, the entire java file causing the problem would be great.
I think I copied what they had in the topic that I found that other peice of code (it was awile back so I dont know fo sho) but here it is
Item class
package net.minecraft.src;
import net.minecraft.client.Minecraft;
public class ItemThorHammer extends Item
{
Minecraft mc = ModLoader.getMinecraftInstance();
public ItemThorHammer(int i, EnumToolMaterial lightningshard)
{
super(i);
maxStackSize = 1;
setMaxDamage(0);
}
public boolean hitEntity(ItemStack itemstack, EntityLiving entityliving, EntityLiving entityliving1)
{
itemstack.damageItem(1, entityliving1);
return true;
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
Minecraft mc = ModLoader.getMinecraftInstance();
if (mc != null && mc.objectMouseOver != null) {
EntityLightningBolt lightningbolt = new EntityLightningBolt(world, entityplayer.posX, 128, entityplayer.posZ);
if (mc.objectMouseOver.typeOfHit == EnumMovingObjectType.TILE) {
lightningbolt.setPosition(mc.objectMouseOver.blockX,
mc.objectMouseOver.blockY + 1,
mc.objectMouseOver.blockZ);
} else {
lightningbolt.setPosition(mc.objectMouseOver.entityHit.posX,
mc.objectMouseOver.entityHit.posY,
mc.objectMouseOver.entityHit.posZ);
}
world.entityJoinedWorld(lightningbolt);
}
return itemstack;
}
}
mod class
package net.minecraft.src;
public class mod_Thor extends BaseMod
{
public static final Item thorhammer = new ItemThorHammer(580, EnumToolMaterial.LIGHTNINGSHARD).setItemName("ThorHammer");
public mod_Thor()
{
thorhammer.iconIndex = ModLoader.addOverride("/gui/items.png", "/ThorsHammer.png");
ModLoader.AddName(thorhammer, "Thor's Hammer");
ModLoader.AddRecipe(new ItemStack(thorhammer, 1), new Object[] {
"KKK", " K ", " K ", Character.valueOf('K'), Item.stick
});
}
public String getVersion()
{
return "1.0.1";
}
public void load(){}
}
#8
Posted 13 January 2012 - 03:36 PM
I have this code and it works although its limited range:
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.*;
public class ItemLightning extends Item implements ITextureProvider
{
public ItemLightning(int i)
{
super(i);
maxStackSize = 1;
}
public String getTextureFile()
{
return "/Aluminium Mod/Items/items.png";
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
Vec3D vec3d = Vec3D.createVector(player.posX, player.posY, player.posZ);
double vecX = -Math.sin(Math.toRadians(player.rotationYaw)) * Math.cos(Math.toRadians(player.rotationPitch)) * 5D;
double vecY = -Math.sin(Math.toRadians(player.rotationPitch)) * 5D;
double vecZ = Math.cos(Math.toRadians(player.rotationYaw)) * Math.cos(Math.toRadians(player.rotationPitch)) * 5D;
Vec3D vec3d1 = vec3d.addVector(vecX, vecY, vecZ);
MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do(vec3d, vec3d1, true);
if(movingobjectposition != null && movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
int x = movingobjectposition.blockX, y = movingobjectposition.blockY, z = movingobjectposition.blockZ;
EntityLightningBolt entitylightningbolt = new EntityLightningBolt(world, x, y, z);
entitylightningbolt.setLocationAndAngles(x + 0.5, y + 1 +entitylightningbolt.yOffset, z + 0.5, player.rotationYaw, player.rotationPitch);
world.spawnEntityInWorld(entitylightningbolt);
}
return itemstack;
}
}
#9
Posted 13 January 2012 - 03:45 PM
KMeister, on 13 January 2012 - 03:36 PM, said:
I have this code and it works although its limited range:
package net.minecraft.src;
import net.minecraft.client.Minecraft;
import net.minecraft.src.forge.*;
public class ItemLightning extends Item implements ITextureProvider
{
public ItemLightning(int i)
{
super(i);
maxStackSize = 1;
}
public String getTextureFile()
{
return "/Aluminium Mod/Items/items.png";
}
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer player)
{
Vec3D vec3d = Vec3D.createVector(player.posX, player.posY, player.posZ);
double vecX = -Math.sin(Math.toRadians(player.rotationYaw)) * Math.cos(Math.toRadians(player.rotationPitch)) * 5D;
double vecY = -Math.sin(Math.toRadians(player.rotationPitch)) * 5D;
double vecZ = Math.cos(Math.toRadians(player.rotationYaw)) * Math.cos(Math.toRadians(player.rotationPitch)) * 5D;
Vec3D vec3d1 = vec3d.addVector(vecX, vecY, vecZ);
MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do(vec3d, vec3d1, true);
if(movingobjectposition != null && movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
{
int x = movingobjectposition.blockX, y = movingobjectposition.blockY, z = movingobjectposition.blockZ;
EntityLightningBolt robotTame = new EntityLightningBolt(world, x, y, z);
robotTame.setLocationAndAngles(x+0.5, y+1+robotTame.yOffset, z+0.5, player.rotationYaw, player.rotationPitch);
world.spawnEntityInWorld(robotTame);
itemstack.stackSize--;
}
return itemstack;
}
}Ok great thanks! But how much of it should I copy into my item class?
#12
Posted 13 January 2012 - 04:46 PM
Yes.
#13
Posted 13 January 2012 - 06:00 PM
public boolean onItemUse(ItemStack itemstack, EntityPlayer entityplayer, World world, int i, int j, int k, int l){
if(l==0)j--;
if(l==1)j++;
if(l==2)k--;
if(l==3)k++;
if(l==4)i--;
if(l==5)i++;
world.entityJoinedWorld(new EntityLightningBolt(world, i, j, k));
}
this is for within player's range.or this
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
{
double maxDistance = 160D;
MovingObjectPosition mop = entityplayer.rayTrace(maxDistance, 1.0F);
int x = mop.blockX;
int y = mop.blockY;
int z = mop.blockZ;
world.entityJoinedWorld(new EntityLightningBolt(world, x, y, z));
}
for when u point outside your range.
clicky the + button :3
#15
Posted 13 January 2012 - 07:07 PM
Stewiecraft, on 13 January 2012 - 06:12 PM, said:
It seems like you got what you need, but I wrote up the tutorial herein the second post. I also cover how to make it an item with a cooldown if that catches your fancy.
Your walkthrough worked!! thank you so much Stewiecraft and everyone else that helped me. When I finish the mod I'll make sure to give you credit.










