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.

I need help making my arrows destroy the blocks they hit

Featured Replies

Posted

For my computer science class I'm making a Fortnite Minecraft copy, I am making a gun that is pretty simple and I want the gun to destroy a certain block type which I make myself when the arrow from the gun hits the block. How would  I go about doing this? 

 

This is my code so far

 

GUN CODE

 

package tealsmc.mods.items;

import java.util.Random;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.creativetab.CreativeTabs;
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.world.World;
import net.minecraftforge.event.entity.player.ArrowNockEvent;

public class FortnitePistol extends Item {
    
    public FortnitePistol() {
        setCreativeTab(CreativeTabs.tabTools);
        this.setFull3D();
        this.setMaxStackSize(1);
        this.setMaxDamage(10);
    }
    
    
    
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
        
        EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, 1.0F);
        
        par2World.spawnEntityInWorld(var8);
                 
        
        
        return par1ItemStack;
        
    }
   
    
}
 

 

BLOCK CODE

 

package tealsmc.mods.blocks;


import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;

public class FortniteWood extends Block{
    
    public FortniteWood(Material mat) {
        super(mat);
        setCreativeTab(CreativeTabs.tabBlock);
    }
    
    
    
}
 

 

 

 

I am also using the TEALS educational modpack but it is just Forge, just to clear up any confusion on the package.

Don't take this too seriously, but I'd go for the following method:

 

@SubscribeEvent
    public void regiterItems(ProjectileImpactEvent event) {
        if (event.getRayTraceResult().typeOfHit == RayTraceResult.Type.BLOCK){
            //Destroy block here
        }
    }

This would be the best event to go for, in my opinion.

 

EDIT:

 

For the block destruction, I'd try 

event.getEntity().getEntityWorld().setBlockToAir(event.getRayTraceResult().getBlockPos());

But I haven't tested it. I'm not even sure if event.getEntity() returns the player that shot the arrow....

Edited by RekTek249

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.