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

Posted

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

 
 
 
 
Spoiler

public class ItemBatarang extends Item{



    public ItemBatarang(Properties properties) {
        super(properties);
        setRegistryName("item_batarang");
    }


    @Override
    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.addEntity(batarang);
        }

        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

 
 
 
 
Spoiler

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);
    }

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

    @Override
    protected Item getDefaultItem() {
        return ItemHolder.BATARANG;
    }

    @Override
    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);
              //3400

                this.remove();

            } 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();

            this.setMotion(x,y,z);





        }

    }



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

    @Override
    public void tick() {
        super.tick();


        this.motionMultiplier.rotatePitch(5);




    }
}

ClientProxy class (where it renders)

 
 
 
 
Spoiler

public class ClientProxy implements IProxy {
    @Override
    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()));


    }

 

Posted

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

Spoiler

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)

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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