Jump to content

[1.15.2] How can I make my throwable item spin when in air and make it stick to surfaces?


Recommended Posts

I have my throwable item, which I want it to spin when it is in the air and stick to the surface when it hits a block but I can´t figure out, my item uses a sprite renderer, here´s my code


Item class


public class ItemBatarang extends Item{

    public ItemBatarang(Properties properties) {

    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {

        ItemStack stack = playerIn.getHeldItem(handIn);
        Vec3d look = playerIn.getLookVec();
        EntityBatarang batarang = new EntityBatarang(1.0D,1.0D,1.0D,worldIn);
        batarang.setPosition(playerIn.getPosX() + look.x , playerIn.getPosY() + look.y + 1, playerIn.getPosZ() + look.z);
        batarang.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F,1.5F,0.0F);
        if (!worldIn.isRemote) {

        worldIn.playSound(null,playerIn.getPosition(), SoundEvents.ENTITY_SPLASH_POTION_THROW, SoundCategory.PLAYERS,1.0f,1.0f);

        return new ActionResult<ItemStack>(ActionResultType.SUCCESS, stack);

Entity class


public class EntityBatarang extends ProjectileItemEntity {

    public EntityBatarang(double x, double y, double z, World worldIn) {
        super(EntitiesHolder.BATARANG, x, y, z, worldIn);

    public EntityBatarang( LivingEntity livingEntityIn, World worldIn) {
        super(EntitiesHolder.BATARANG, livingEntityIn, worldIn);

    public EntityBatarang(EntityType<EntityBatarang> entityBatarangEntityType, World world) {
        super(EntitiesHolder.BATARANG, world);

    public IPacket<?> createSpawnPacket() {
        return NetworkHooks.getEntitySpawningPacket(this);

    protected Item getDefaultItem() {
        return ItemHolder.BATARANG;

    protected void onImpact(RayTraceResult result) {

        if (result.getType() == RayTraceResult.Type.ENTITY) {
            ((EntityRayTraceResult)result).getEntity().attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 5.0F);

        if (result instanceof EntityRayTraceResult) {
            EntityRayTraceResult entityRayTraceResult = (EntityRayTraceResult) result;
            if(entityRayTraceResult.getEntity() instanceof MobEntity) {
                MobEntity entity = (MobEntity) entityRayTraceResult.getEntity();

                double d0 = (double)entity.getPosX() ;
                double d1 = (double)entity.getPosY() + 1D;
                double d2 = (double)entity.getPosZ();

                entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,2));

                this.world.playSound(entity.getPosX(),entity.getPosY(),entity.getPosZ(), SoundEvents.BLOCK_ANVIL_HIT, SoundCategory.AMBIENT,1,1,true);


            } else if(entityRayTraceResult.getEntity() instanceof PlayerEntity) {

                PlayerEntity entity = (PlayerEntity) entityRayTraceResult.getEntity();

                entity.addPotionEffect(new EffectInstance(Effects.SLOWNESS,120,2));



        else if (result instanceof BlockRayTraceResult) {

            BlockRayTraceResult blockRayTraceResult = (BlockRayTraceResult) result;
            double x = this.getPosX();
            double y = this.getPosY();
            double z = this.getPosZ();




    public static EntityType register() {
        return EntityType.Builder.<EntityBatarang>create(EntityBatarang::new, EntityClassification.MISC).size(0.8F, 0.8F).build("batarang").setRegistryName(ComicUniverse.MODID,"batarang");

    public void tick() {



ClientProxy class (where it renders)


public class ClientProxy implements IProxy {
    public void init() {

        ScreenManager.registerFactory(BlockHolder.BLOCKGENERATOR_CONTAINER, GUIGenerator::new);
        ScreenManager.registerFactory(BlockHolder.SUITFABRICATOR_CONTAINER, GUISuitfabricator::new);
        RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.RADIOACTIVE_SPIDER, RadioactiveSpiderRenderer::new);
        RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.SMOKE_PELLET, renderManager -> new SpriteRenderer<EntitySmokePellet>(renderManager, Minecraft.getInstance().getItemRenderer()));
        RenderingRegistry.registerEntityRenderingHandler(EntitiesHolder.BATARANG, renderManager -> new SpriteRenderer<EntityBatarang>(renderManager, Minecraft.getInstance().getItemRenderer()));



Link to comment
Share on other sites

Read this: https://cadiboo.github.io/tutorials/1.15.1/forge/1.4-proxies

You’re better off extending the Arrow and adding the spin in your renderer (similar time the arrow shake) as it already sticks into stuff

  • Thanks 1

About Me


My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

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