Jump to content

Recommended Posts

Posted

I have created a custom arrow on Minecraft 1.12.2. The arrow makes all the proper sounds when shot, as well as dealing damage, but appears invisible. I have created a render class as well as an arrow entity class. Any suggestions?

  • 2 months later...
Posted

Hi, 

I'm having the same issue I have a custom bow (cannon) and an arrow which is a gem that will turn into a laser. Everything works but the arrow, even out of the normal Minecraft bow its invisible.

 

cannon class:

package com.ClueDoh.test.objects.items.cannon;

import javax.annotation.Nullable;
import javax.swing.Action;

import com.ClueDoh.test.Main;
import com.ClueDoh.test.TestItemGroups;
import com.ClueDoh.test.init.ModItems;
import com.ClueDoh.test.util.IHasModel;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class CannonBase extends ItemBow implements IHasModel
{
	public CannonBase(String name) 
	{
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(TestItemGroups.TESTITEMS);
		setMaxStackSize(1);
		setMaxDamage(800);
		
		ModItems.ITEMS.add(this);

	this.addPropertyOverride(new ResourceLocation("pull"), new IItemPropertyGetter()
    {
        @SideOnly(Side.CLIENT)
        public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
        {
            if (entityIn == null)
            {
                return 0.0F;
            }
            else
            {
                return entityIn.getActiveItemStack().getItem() != ModItems.CANNON ? 0.0F : (float)(stack.getMaxItemUseDuration() - entityIn.getItemInUseCount()) / 20.0F;
            }
        }
    });
    this.addPropertyOverride(new ResourceLocation("pulling"), new IItemPropertyGetter()
    {
        @SideOnly(Side.CLIENT)
        public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
        {
            return entityIn != null && entityIn.isHandActive() && entityIn.getActiveItemStack() == stack ? 1.0F : 0.0F;
        }
    });
	
	ModItems.ITEMS.add(this);
}

@Override
public int getItemEnchantability() 
{
	return 10;
}

protected boolean isArrow(ItemStack stack) 
{
	if(stack.getItem() == ModItems.GEM)
	{
		return true;
	}
	return false;
}
@Override
public void registerModels() 

{
	
	Main.proxy.registerItemRenderer(this, 0, "inventory");

	
}

    
}

 

 

Gem Class (arrow):

package com.ClueDoh.test.objects.items.cannon;

import com.ClueDoh.test.Main;
import com.ClueDoh.test.TestItemGroups;
import com.ClueDoh.test.entity.laser.EntityLaser;
import com.ClueDoh.test.init.ModItems;
import com.ClueDoh.test.util.IHasModel;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class GemBase extends ItemArrow implements IHasModel
{
	public GemBase(String name) 
	{
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(TestItemGroups.TESTITEMS);
		
		ModItems.ITEMS.add(this);
	}
	
	
	public void registerModels() 
	{
		
		Main.proxy.registerItemRenderer(this, 0, "inventory");

		
	}	
	@Override
	public EntityArrow createArrow(World worldIn, ItemStack stack, EntityLivingBase shooter) 
	{
		EntityLaser entityLaser = new EntityLaser(worldIn, shooter);
		return entityLaser;
	}
	

}

 

 

EntityLaser:

package com.ClueDoh.test.entity.laser;

import java.util.Random;

import com.ClueDoh.test.init.ModItems;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;

public class EntityLaser extends EntityArrow 
{
	public EntityLaser(World worldIn) 
	{
		super(worldIn);
	}
	
	public EntityLaser(World worldIn, double x, double y, double z) 
	{
		super(worldIn, x, y, z);
	}
	
	public EntityLaser(World worldIn, EntityLivingBase shooter) 
	{
		super(worldIn, shooter);
	}
	
	@Override
	protected ItemStack getArrowStack() 
	{
		return new ItemStack(ModItems.GEM);
	}
	
	@Override
	protected void arrowHit(EntityLivingBase living) 
	{
		super.arrowHit(living);
	}
	
	@Override
	public void onUpdate() 
	{
		super.onUpdate();
		if(this.world.isRemote)
		{
			if(this.inGround)
			{
				if(this.timeInGround % 5 == 0)
				{
					this.spawnParticles(1);
				}
			}
			else
			{
				this.spawnParticles(2);
			}
		}
	}
	
	private void spawnParticles(int particleCount)
	{
		Random rand = new Random();
		int i = rand.nextInt(15);
		double d0 = (double)(i >> 16 & 255) / 255.0D;
		double d1 = (double)(i >> 8 & 255) / 255.0D;
		double d2 = (double)(i >> 0 & 255) / 255.0D;
		for(int j = 0; j < particleCount; ++j)
		{
			this.world.spawnParticle(EnumParticleTypes.DRIP_LAVA, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width, this.posY + this.rand.nextDouble() * (double)this.height, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width, d0, d1, d2);
		}
	}
	
}

 

 

RenderLaser:

package com.ClueDoh.test.entity.laser;

import com.ClueDoh.test.util.Reference;

import net.minecraft.client.renderer.entity.RenderArrow;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;


public class RenderLaser extends RenderArrow<EntityLaser>
{
	public RenderLaser(RenderManager manager) 
	{
		super(manager);
	}
	
	@Override
	protected ResourceLocation getEntityTexture(EntityLaser entity) 
	{
		return new ResourceLocation(Reference.MOD_ID + ":textures/entity/laser/laser.png");
	}

}

 

can someone help I've been searching the web for hours trying to fix this and been working on a gun for 2 days? HELP!!!

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hey! I noticed you're trying to register your alexandrite item and possibly set its resource location manually with setId(...). I wanted to help clarify a few things that might simplify your code and avoid errors. ✅ The issue: You're using setId(...) inside the item registration like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties().useItemDescriptionPrefix() .setId(ResourceKey.create(Registries.ITEM, ResourceLocation.fromNamespaceAndPath(TutorialMod.MOD_ID, "alexandrite"))))); But: Item.Properties does not have a setId(...) method — this line will either fail or do nothing meaningful. useItemDescriptionPrefix() is mostly used for translation keys (like "item.modid.name") but isn't needed unless you have a very specific reason. 🛠 The fix: You only need to register your item like this:   public static final RegistryObject<Item> ALEXANDRITE = ITEMS.register("alexandrite", () -> new Item(new Item.Properties())); Forge automatically handles the ResourceLocation (modid:alexandrite) based on the name passed into .register(...), so there’s no need to manually assign it. 📝 For the texture: Make sure you have this file in your resources: src/main/resources/assets/tutorialmod/models/item/alexandrite.json { "parent": "item/generated", "textures": { "layer0": "tutorialmod:item/alexandrite" } } And your texture PNG goes here: src/main/resources/assets/tutorialmod/textures/item/alexandrite.png 🌍 For the name in-game: Add this to your en_us.json under: src/main/resources/assets/tutorialmod/lang/en_us.json { "item.tutorialmod.alexandrite": "Alexandrite" }   Note: if im wrong about the issues you are encountering, i apologize.
    • 🛠️ Fix for Transparent or Clipping Item Render Issues When Held in First Person (Forge 1.20+) Hey everyone! I recently ran into a frustrating bug while making a custom item (a rocket) for my Forge mod, and I’m sharing the fix because it’s a bit obscure — and it worked wonders. 💥 The Problem: My item rendered semi-transparent and see-through — but only in first person. It also clipped through nearby blocks when held, unlike default items like swords or leads. The texture file was confirmed to be fully opaque (alpha 255), so the issue wasn’t the PNG itself. Interestingly, when no texture was present and the default purple-black checkerboard appeared, the clipping issue disappeared. ✅ The Fix: I ended up resolving it by randomly trying something I found on a Forge forum post about block rendering. I added this property to my item's model JSON — even though it's typically only used for blocks: { "parent": "item/generated", "textures": { "layer0": "farbeyond:item/rocket_item" }, "render_type": "minecraft:cutout" } Boom. That single line forced the item to render using a proper opaque (cutout) layer, removing all the unwanted transparency and clipping behavior in first person. 🙌 Credit: I originally found the "render_type" trick mentioned here, in a block rendering context: 👉 https://forums.minecraftforge.net/topic/149644-1201-help-with-transparent-blocks/ Even though it was meant for blocks, I thought, why not try it on an item? And it worked! Big thanks to the poster — this fix wouldn’t have happened without that tip. Hopefully this helps anyone else stuck on a weird rendering bug like I was. This isn’t a common item solution, so feel free to share it further. I’d love to know if it works for you too.
    • Use Java 21 instead of Java 24   Also make a test without modernfix
    • Ive been on this world for 2 days now, my computer blue screens pretty often so maybe that has something to do with it. maybe just incompatible mods like a lot of people so im hoping someone more knowledgeable can help me find what i need to get rid of. thank you! paste bin
    • Should probably say that i am running minecraft 1.21.1 and with quite a lot of mods (many of which im unsure should even be on the server side)
  • Topics

×
×
  • Create New...

Important Information

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