Jump to content

I need help making my arrows destroy the blocks they hit


Recommended Posts

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




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() {
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
        EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, 1.0F);
        return par1ItemStack;




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) {




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

Link to comment
Share on other sites

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


    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.




For the block destruction, I'd try 


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

Edited by RekTek249
Link to comment
Share on other sites

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


  • Create New...

Important Information

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