Jump to content

Custom Bow


Lyras

Recommended Posts

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*

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

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*

Link to comment
Share on other sites

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.

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.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When i try to launch Minecraft Java 1.20.1 forge with mods (82 mods),on start it loaded all mods,but at end Java just crashed.  p.s i allocated 8GB ram for minecraft and i didn't runned another instance.Log file pp.s I use ATlauncher   Environment: Organising filesystem [24/04/2024 23:40:08 PM] ATLauncher Version: 3.4.36.3 [11ae0b2334c236e93ee8128de980952b2a1b8900] [24/04/2024 23:40:08 PM] App Arguments: ["--install-method=aur","--no-launcher-update"] [24/04/2024 23:40:08 PM] JVM Arguments: ["-Dawt.useSystemAAFontSettings=on","-Dswing.aatext=true"] [24/04/2024 23:40:08 PM] Java Version: Java 22 (22) [24/04/2024 23:40:08 PM] Java Path: /usr/lib/jvm/java-22-openjdk [24/04/2024 23:40:08 PM] 64 Bit Java: true [24/04/2024 23:40:08 PM] RAM Available: 14931MB [24/04/2024 23:40:08 PM] Launcher Directory: **USERSDIR** [24/04/2024 23:40:08 PM] GPU: IvyBridge GT2 [HD Graphics 4000] (Intel Corporation (0x8086)) unknown 256MB VRAM [24/04/2024 23:40:08 PM] CPU: Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz 4 cores/8 threads [24/04/2024 23:40:08 PM] Operating System: EndeavourOS (unknown (unknown) build 6.8.7-arch1-1) [24/04/2024 23:40:08 PM] Bitness: 64 [24/04/2024 23:40:08 PM] Uptime: 15889 [24/04/2024 23:40:08 PM] Manufacturer: GNU/Linux
    • If you have nvidia graphics, don't touch your amd drivers, otherwise it might fix it but keep running on integrated graphics, which will result in terrible performance. For nvidia graphics, you need to tell windows and nvidia control panel that anything Minecraft related (the launcher, java, etc...) should prefer high performance graphics so that it actually uses your nvidia gpu
    • In the ever-evolving landscape of technology, the rise of cryptocurrencies and digital assets has introduced both unparalleled opportunities and unprecedented challenges. As these digital currencies become increasingly prevalent, so too does the risk of theft and loss. Yet, amidst the complexity and uncertainty, there exists a beacon of hope: ADRIAN LAMO HACKER. Technology has indeed become more sophisticated and enhanced, presenting new challenges in the realm of asset recovery. However, just as any other currency can be stolen or lost, crypto and digital assets are not beyond redemption. With the right expertise and guidance, recovery is possible and achievable. Contact ADRIAN LAMO HACKER via the website: https://adrianlamohackpro.online/ , a trusted, honest, and certified agency specializing in the retrieval of stolen or lost digital assets. In my own experience, I found myself in dire straits after falling victim to cybercriminals who absconded with a significant portion of my crypto holdings. It was a daunting situation, but I refused to succumb to despair. Upon engaging ADRIAN LAMO HACKER, their professionalism, and integrity immediately struck me, as an unwavering commitment to their clients. They deeply understand blockchain technology and utilize advanced methodologies to trace and recover lost or stolen funds. Their approach is meticulous, their expertise unparalleled, and their results speak for themselves. In a matter of days, ADRIAN LAMO HACKER successfully traced and recovered over 90% of my stolen funds, a feat I once believed to be unattainable. Their fees were fair and transparent, and communication throughout the process was nothing short of excellent. They kept me informed every step of the way, providing reassurance and guidance when I needed it most. For anyone who has fallen victim to crypto theft or loss, I wholeheartedly recommend ADRIAN LAMO HACKER. They are not just experts in their field; they are guardians of justice in the digital realm. With their assistance, you can reclaim what's rightfully yours and emerge stronger than ever before. So, if you find yourself grappling with the devastation of lost or stolen digital assets, don't despair. Reach out to ADRIAN LAMO HACKER via website: https://adrianlamohackpro.online/  / Telegram: @ADRIANLAMOHACKERTECH and let them guide you toward a brighter tomorrow.
  • Topics

×
×
  • Create New...

Important Information

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