Posted January 27, 20205 yr Hi I am a bit new in Minecraft. I want to make an axe that can spit lighting when I right click on my mouse. When I execute below code, I was hoping it would strike a cow that is front of my character, but all it did was produced the lightning sound, but I don't see any lightning anywhere. I thought my code, would produce a lighting 20 steps in front of me. I think what I was missing in my code was a way to get a reference to the animal (cow) in front of me. I feel if I can get a reference of cow in front of me, I can set the my LightningBoltEntity to that animal position. But this is just a guess package com.ayclogic.aycfirstmod.item; import com.ayclogic.aycfirstmod.init.ModItemGroup; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.effect.LightningBoltEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResultType; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class AycLightningAxe extends AxeItem { public static final Logger LOGGER = LogManager.getLogger(AycFireballAxe.class); public AycLightningAxe() { super(ItemTier.IRON, 6.0F, -3.1F, new Item.Properties().group(ModItemGroup.MOD_ITEM_GROUP)); } public AycLightningAxe(IItemTier tier, float attackDamageIn, float attackSpeedIn, Item.Properties builder) { super(tier, attackDamageIn, attackSpeedIn, builder); } public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand handIn) { if (!world.isRemote) { Vec3d vec3d = player.getEyePosition(1.0F); Vec3d vec3d1 = player.getLook(1.0F); Vec3d vec3d2 = vec3d.add(20, 0, 0); BlockPos blockPos = new BlockPos(vec3d2); LightningBoltEntity lightning = new LightningBoltEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), false); ItemStack itemStack = player.getHeldItem(handIn); itemStack.damageItem(1, player, (p_220040_1_) -> { p_220040_1_.sendBreakAnimation(handIn); }); world.addEntity(lightning); } LOGGER.info("********** Abigail Lighting swing **************"); return super.onItemRightClick(world, player, handIn); } //AycLightningAxe } Any assistance would be greatly appreciated.
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.