Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.