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.

Featured Replies

Posted

Hey, It's me again :P

 

As the title says, I am making a custom bow. With some help from some users I already made the bow work partially.

 

2 things don't work:

 

  - The bow does not get a zoom (I mean the zoom you get by pulling the normal bow)

  - When the player collects the arrow, an arrow will be added to the creative inventory

 

Can you help me? Thanks in advance  :'(

 

*Hug*

  - The bow does not get a zoom (I mean the zoom you get by pulling the normal bow)

You need to handle

FOVUpdate

and imitate the vanilla bow's FOV modification if the player is currently using your bow. You can see how I do this here.

 

  - When the player collects the arrow, an arrow will be added to the creative inventory

This is vanilla behaviour.

 

When a player shoots an arrow in creative mode or with a bow that has the Infinity enchantment, the pickup status is set to

CREATIVE_ONLY

; i.e. only players in creative mode can pick it up.

 

When a player shoots an arrow normally, the pickup status is set to

ALLOWED

; i.e. any player can pick it up.

 

When a mob shoots an arrow, the pickup status is set to

DISALLOWED

; i.e. no players can pick it up.

 

If you don't want the arrow to be picked up by anyone, set its pickup status to

DISALLOWED

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author
This is vanilla behaviour.

- I know but the arrow gets collected by the player and gets actually added to the inventory...

[Example: You got an empty slot in your hotbar. When you collect an arrow from the ground which got shot with my custom bow, you will habe an arrow in your horbar]

 

With the normal bow you shot, collect the arrow and it won't be added to the inventory.

[Example: The collected arrow won't be in your hotbar]

*Hug*

In

EntityArrow#onCollideWithPlayer

, the item is only added to the player's inventory if the pickup status is

ALLOWED

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

But the pickup-status is PickupStatus#CREATIVE_ONLY

 

	@Override
    public void onPlayerStoppedUsing ( ItemStack stack , World world , EntityLivingBase entity , int charge ) {

        if ( entity instanceof EntityPlayer ) {
        	
            EntityPlayer player = ( EntityPlayer ) entity;
            boolean ammoRequired = this.isAmmoRequired( stack , player );
            ItemStack ammo = this.getAmmo( player );

            int duration = this.getMaxItemUseDuration( stack ) - charge;
            duration = ForgeEventFactory.onArrowLoose( stack , world , ( EntityPlayer ) entity , duration , stack != null || ammoRequired );
            if ( duration < 0 ) { return; }

            if ( stack != null || ammoRequired ) {
            	
                if ( stack == null ) {
                	
                    stack = new ItemStack ( Items.arrow );
                    
                }

                float velocity = this.func_185059_b( duration );

                if ( ( double ) velocity >= 0.1D ) {
                	
                    boolean unpickable = ammoRequired && stack.getItem() instanceof ItemArrow; //Forge: Fix consuming custom arrows.

                    if ( !world.isRemote ) {
                    	
                        ItemArrow arrowItem = ( ItemArrow ) ( ( ItemArrow ) ( stack.getItem() instanceof ItemArrow ? stack.getItem() : Items.arrow ) );
                        EntityArrow arrow = arrowItem.makeTippedArrow( world , stack, player );
                        arrow.func_184547_a( player , player.rotationPitch , player.rotationYaw , 0.0F , velocity * 3.0F , 1.0F );

                        if ( velocity == 1.0F ) {
                        	
                            arrow.setIsCritical( true );
                            
                        }

                        int levelPower = EnchantmentHelper.getEnchantmentLevel(Enchantments.power, stack);

                        if ( levelPower > 0 ) {
                        	
                            arrow.setDamage( this.baseDamage + arrow.getDamage() + ( double ) levelPower  * 0.5D + 0.5D );
                            System.out.println( this.baseDamage + arrow.getDamage() + ( double ) levelPower  * 0.5D + 0.5D );
                            
                        } else { arrow.setDamage( this.baseDamage + arrow.getDamage() + 0.5D ); System.out.println( this.baseDamage + arrow.getDamage() + 0.5D ); }

                        int levelPunch = EnchantmentHelper.getEnchantmentLevel(Enchantments.punch, stack);

                        if ( levelPunch > 0 ) {
                        	
                            arrow.setKnockbackStrength( levelPunch );
                            
                        }

                        if ( EnchantmentHelper.getEnchantmentLevel( Enchantments.flame , stack ) > 0 ) {
                        	
                            arrow.setFire( 100 );
                            
                        }

                        stack.damageItem( 1 , player );

                        if ( unpickable ) {
                        	
                            arrow.canBePickedUp = EntityArrow.PickupStatus.CREATIVE_ONLY;
                            
                        }

                        world.spawnEntityInWorld( arrow );
                        
                    }

                    world.playSound( ( EntityPlayer ) null , player.posX , player.posY , player.posZ , SoundEvents.entity_arrow_shoot , SoundCategory.NEUTRAL , 1.0F , 1.0F / ( itemRand.nextFloat() * 0.4F + 1.2F ) + velocity * 0.5F );

                    if ( !unpickable && !player.capabilities.isCreativeMode ) {
                    	
                        --ammo.stackSize;

                        if ( ammo .stackSize == 0 ) {
                        	
                            player.inventory.deleteStack( ammo );
                            
                        }
                        
                    }

                    player.addStat( StatList.func_188057_b( this ) );
                    
                }
            }
        }
    }

*Hug*

I have this and this works for me:

public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
	if (entityLiving instanceof EntityPlayer) {
		EntityPlayer entityplayer = (EntityPlayer) entityLiving;
		boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
		ItemStack itemstack = this.findAmmo(entityplayer);
		int i = this.getMaxItemUseDuration(stack) - timeLeft;
		i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, (EntityPlayer) entityLiving, i, itemstack != null || flag);
		if (i < 0) return;
		if (itemstack != null || flag) {
			if (itemstack == null) {
				itemstack = new ItemStack(Items.ARROW);
			}
			float f = getArrowVelocity(i);
			if ((double) f >= 0.1D) {
				boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow ? ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer) : false);
				if (!worldIn.isRemote) {
					ItemArrow itemarrow = (ItemArrow) ((ItemArrow) (itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW));
					EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
					entityarrow.setAim(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
					if (f == 1.0F) {
						entityarrow.setIsCritical(true);
					}
					int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
					entityarrow.setDamage(10.0F);
					if (j > 0) {
						entityarrow.setDamage(entityarrow.getDamage() + (double) j * 0.5D + 0.5D);
					}
					int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
					if (k > 0) {
						entityarrow.setKnockbackStrength(k);
					}
					if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
						entityarrow.setFire(100);
					}
					stack.damageItem(1, entityplayer);
					if (flag1) {
						entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
					}
					worldIn.spawnEntityInWorld(entityarrow);
				}
				worldIn.playSound((EntityPlayer) null, entityplayer.posX, entityplayer.posY, entityplayer.posZ,
						SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
				if (!flag1) {
					--itemstack.stackSize;
					if (itemstack.stackSize == 0) {
						entityplayer.inventory.deleteStack(itemstack);
					}
				}
			}
		}
	}
}

But the pickup-status is PickupStatus#CREATIVE_ONLY

 

boolean unpickable = ammoRequired && stack.getItem() instanceof ItemArrow; //Forge: Fix consuming custom arrows.

if ( unpickable ) {                        	
    arrow.canBePickedUp = EntityArrow.PickupStatus.CREATIVE_ONLY;                            
}

 

You're setting the pickup status to

CREATIVE_ONLY

when ammo is required (i.e. no Infinity enchantment or creative mode). This is the opposite of what you want.

 

I suggest looking at

ItemBow#onPlayerStoppedUsing

again.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

That was my fault. I fixed it but it didn't help me.

 

This is my problem in a collage:

6psHzxo.png

 

I suggest looking at ItemBow#onPlayerStoppedUsing again.

I already done that. I looked at your code for your [glow=red,2,300]TestBow[/glow] and at ItemBow#onPlayerStoppedUsing but I don't know my mistake D:

 

EDIT: Fixed it. But when the shot arrow was something like an "Arrow Of Leaping" it will get turned into a normal arrow and I don't know how to change the FOV properly. I want it to change it like with the normal bow

*Hug*

  • Author
I don't know how to change the FOV properly
Chose wrong words. I just don't know which values I have to take or where I can find them. I already looked up in the API and different mods.

 

Code:

	@Override
    public void onPlayerStoppedUsing ( ItemStack stack , World world , EntityLivingBase entity , int charge ) {

        if ( entity instanceof EntityPlayer ) {
        	
            EntityPlayer player = ( EntityPlayer ) entity;
            boolean ammoRequired = this.isAmmoRequired( stack , player );
            ItemStack ammo = this.findAmmo( player );

            int duration = this.getMaxItemUseDuration( stack ) - charge;
            duration = net.minecraftforge.event.ForgeEventFactory.onArrowLoose( stack , world , ( EntityPlayer ) entity , duration , stack != null || ammoRequired );
            if ( duration < 0 ) { return; }

            if ( stack != null || ammoRequired ) {
            	
                if ( stack == null ) {
                	
                    stack = new ItemStack ( Items.arrow );
                    
                }

                float velocity = this.func_185059_b( duration );

                if ( ( double ) velocity >= 0.1D ) {
                	
                    boolean unpickable = player.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel( Enchantments.infinity , stack ) > 0;

                    if ( !world.isRemote ) {
                    	
                        ItemArrow arrowItem = ( ItemArrow ) ( ( ItemArrow ) ( stack.getItem() instanceof ItemArrow ? stack.getItem() : Items.arrow ) );
                        EntityArrow arrow = arrowItem.makeTippedArrow( world , stack , player );
                        arrow.func_184547_a( player , player.rotationPitch , player.rotationYaw , 0.0F , velocity * 3.0F , 1.0F );

                        if ( velocity == 1.0F ) {
                        	
                            arrow.setIsCritical( true );
                            
                        }

                        int levelPower = EnchantmentHelper.getEnchantmentLevel( Enchantments.power , stack );

                        if ( levelPower > 0 ) {
                        	
                            arrow.setDamage( this.baseDamage + arrow.getDamage() + ( double ) levelPower  * 0.5D + 0.5D );
                            
                        } else { arrow.setDamage( this.baseDamage + arrow.getDamage() + 0.5D ); System.out.println( this.baseDamage + arrow.getDamage() + 0.5D ); }

                        int levelPunch = EnchantmentHelper.getEnchantmentLevel( Enchantments.punch , stack );

                        if ( levelPunch > 0 ) {
                        	
                            arrow.setKnockbackStrength( levelPunch );
                            
                        }

                        if ( EnchantmentHelper.getEnchantmentLevel( Enchantments.flame , stack ) > 0 ) {
                        	
                            arrow.setFire( 100 );
                            
                        }

                        stack.damageItem( 1 , player );

                        if ( unpickable ) {
                        	
                            arrow.canBePickedUp = EntityArrow.PickupStatus.CREATIVE_ONLY;
                            
                        }

                        world.spawnEntityInWorld( arrow );
                        
                    }

                    world.playSound( ( EntityPlayer ) null , player.posX , player.posY , player.posZ , SoundEvents.entity_arrow_shoot , SoundCategory.NEUTRAL , 1.0F , 1.0F / ( itemRand.nextFloat() * 0.4F + 1.2F ) + velocity * 0.5F );

                    if ( !unpickable && !player.capabilities.isCreativeMode ) {
                    	
                        --ammo.stackSize;

                        if ( ammo .stackSize == 0 ) {
                        	
                            player.inventory.deleteStack( ammo );
                            
                        }
                        
                    }

                    player.addStat( StatList.func_188057_b( this ) );
                    
                }
                
            }
            
        }
        
    }

*Hug*

I can't see any obvious problems with your code, I suggest stepping through it in a debugger to see where things go wrong.

 

For the FOV values, look at

AbstractClientPlayer#getFovModifier

(where

FOVUpdateEvent

is fired) or the code from my mod that I linked in my first post.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

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.