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?
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.
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.
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.
so did you make the tutorial yet? I thought you'd post it in the tutorial section but I don't see anything new from you about this.
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(){}
}
Sorry I didn't get to the computer much today and I doubt I will tomorrow. If you post your errors someone other than myself can probably help you find the problem if I can't get on.
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));
}
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.
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. :biggrin.gif:
You'll have to post the errors if you want help. Also, the entire java file causing the problem would be great.
That would be great!! Thanks!! I assume you'll post it to the tutorial section so I look for it there.
so did you make the tutorial yet? I thought you'd post it in the tutorial section but I don't see anything new from you about this.
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
mod class
Ok great thanks! But how much of it should I copy into my item class?
You can just copy the onItemRightClick method, and it should work.
Ok so I don't have to add this to my onitemrightclick I just have to replace it
this is for within player's range.
or this
for when u point outside your range.
Mjölnir Hammer Mod
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. :biggrin.gif: