Jump to content

Recommended Posts

Posted (edited)

I have coded an achievement for wearing specific armor while holding a specific item in each hand. I have the coded it but I do not know how to figure out what isnt working, or why it isnt working.

My code:

        public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
            int TitaniumArmorPeices = 0;
            if(player.getArmorInventoryList() != null) {
                Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
                while(iterator.hasNext()) {
                    ItemStack stack = iterator.next();
                    if(stack != null) {
                        if(stack.getItem() instanceof ItemModArmor) {
                            ItemModArmor item = (ItemModArmor) stack.getItem();
                            if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
                                TitaniumArmorPeices++;
                                continue;
                            }
                        }
                    }
                }
            }
            if(TitaniumArmorPeices == 4) {
                if(player.getHeldItemMainhand() != null) {
                    boolean iterator = player.getHeldItemMainhand().equals(ModCombat.titaniumSword);
                    while (player.getHeldItemOffhand() != null) {
                        boolean iterator1 = player.getHeldItemOffhand().equals(ModCombat.titaniumShield);
                        {
                                    continue;
                                }
                            }
                        }
                    }
                    if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
                        if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
                            player.addStat(AchievementHandler.achievementBattleReady);
                }
            }
        }

Edited by ModderInTraining
I forgot the code
Posted

I don't know. Maybe invoke it on the item stack in the player's hand?

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

 

11 minutes ago, ModderInTraining said:

Where should I put this?

 

 

3 minutes ago, ModderInTraining said:

 

I havent been modding very long, and dont know very much. What is invoking, and how do you do it?

You should start by learning some general Java. ItemStack#getItem is a method which you call on an ItemStack instance, and returns an Item instance. You have access to an ItemStack (in the player's hand) and you want an Item (to compare to the correct Item for your achievement). If that isn't enough information for you to get started, you probably need a better understanding of Java before you will make much progress with modding.

Posted

Would this work?

 

        public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
            int TitaniumArmorPeices = 0;
            if(player.getArmorInventoryList() != null) {
                Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
                while(iterator.hasNext()) {
                    ItemStack stack = iterator.next();
                    if(stack != null) {
                        if(stack.getItem() instanceof ItemModArmor) {
                            ItemModArmor item = (ItemModArmor) stack.getItem();
                            if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
                                TitaniumArmorPeices++;
                                continue;
                            }
                        }
                    }
                }
            }
            if(TitaniumArmorPeices == 4) {
                ItemStack getItem = player.getHeldItemMainhand();
                ItemStack getItem1 = player.getHeldItemOffhand();
                if(player.getHeldItemMainhand() != null) {
                    boolean iterator = player.getHeldItemMainhand().equals(ModCombat.titaniumSword);
                    while (player.getHeldItemOffhand() != null) {
                        boolean iterator1 = player.getHeldItemOffhand().equals(ModCombat.titaniumShield);
                        {
                                    continue;
                                }
                            }
                        }
                    }
                    if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
                        if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
                            player.addStat(AchievementHandler.achievementBattleReady);
                }
            }
        }

Posted (edited)

Next time, please post your code using the <> button and a spoiler (eye icon), it makes it much easier to read.

 

24 minutes ago, ModderInTraining said:

if(TitaniumArmorPeices == 4) {
                ItemStack getItem = player.getHeldItemMainhand();
                ItemStack getItem1 = player.getHeldItemOffhand();
                if(player.getHeldItemMainhand() != null) {
                    boolean iterator = player.getHeldItemMainhand().equals(ModCombat.titaniumSword);
                    while (player.getHeldItemOffhand() != null) {
                        boolean iterator1 = player.getHeldItemOffhand().equals(ModCombat.titaniumShield);
                        {
                                    continue;
                                }
                            }
                        }
                    }
                    if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
                        if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
                            player.addStat(AchievementHandler.achievementBattleReady);
                }
            }

 

I'm really confused about what you're doing here.

  • You declare two ItemStacks which you then never refer to (getItem and getItem1).
  • You declare two booleans which you then never refer to (iterator and iterator1 - and why on earth did you pick such confusing variable names?)
  • You still haven't used ItemStack#getItem in the way I suggested, so you are still comparing an ItemStack instance to an Item instance in the line player.getHeldItemMainhand().equals(ModCombat.titaniumSword).
  • You're using a while loop for something which doesn't need to be looped at all, and seem to have a random mess of opening and closing brackets in the middle for no reason.
  • You don't actually check any of the item conditions before applying the achievement.
Edited by Jay Avery
Posted

And you're still comparing an ItemStack to an Item

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

It can't possibly be the only way you can figure out: it doesn't work for a variety of reasons.

You have a meaningless loop (for example, if player.getHeldItemOffhand() isn't null, it will loop forever and never exit so really, what did you expect?)

 

Have you tried player.getHeldItemOffhand().getItem() possibly?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
18 minutes ago, ModderInTraining said:

This is the only way I can figure of doing it, how would you suggest I do it?

 

I gave a list of the problems with your code, so try fixing those and then show us what you have if it still doesn't work as you want.

Posted (edited)

I tried this but it doesnt seem to accept boolean.

Spoiler

        public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
            int TitaniumArmorPeices = 0;
            if(player.getArmorInventoryList() != null) {
                Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
                while(iterator.hasNext()) {
                    ItemStack stack = iterator.next();
                    if(stack != null) {
                        if(stack.getItem() instanceof ItemModArmor) {
                            ItemModArmor item = (ItemModArmor) stack.getItem();
                            if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
                                TitaniumArmorPeices++;
                                continue;
                            }
                        }
                    }
                }
            }
            if(TitaniumArmorPeices == 4) {
                boolean (player.getHeldItemMainhand().getItem().equals(ModCombat.titaniumSword) = true) {
                    boolean (player.getHeldItemOffhand().getItem().equals(ModCombat.titaniumShield) = true) {
                            }
                        }
                    }
                    if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
                        if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
                            player.addStat(AchievementHandler.achievementBattleReady);
                }
            }
        }

Edited by ModderInTraining
Posted
Spoiler

		public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
			int TitaniumArmorPeices = 0;
			if(player.getArmorInventoryList() != null) {
				Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
				while(iterator.hasNext()) {
					ItemStack stack = iterator.next();
					if(stack != null) {
						if(stack.getItem() instanceof ItemModArmor) {
							ItemModArmor item = (ItemModArmor) stack.getItem();
							if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
								TitaniumArmorPeices++;
								continue;
							}
						}
					}
				}
			}
			if(TitaniumArmorPeices == 4) {
				if(player.getHeldItemMainhand().getItem().equals(ModCombat.titaniumSword)) {
					if(player.getHeldItemOffhand().getItem().equals(ModCombat.titaniumShield)) {
							}
						}
					}
					if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
						if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
							player.addStat(AchievementHandler.achievementBattleReady);
				}
			}
		}

 

Can someone explain why this isnt working?

 

Posted

Computer-Guy-Facepalm.jpg

  • Like 2

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Still no success. Im bad at this.

Spoiler

		public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
			int TitaniumArmorPeices = 0;
			if(player.getArmorInventoryList() != null) {
				Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
				while(iterator.hasNext()) {
					ItemStack stack = iterator.next();
					if(stack != null) {
						if(stack.getItem() instanceof ItemModArmor) {
							ItemModArmor item = (ItemModArmor) stack.getItem();
							if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
								TitaniumArmorPeices++;
								continue;
							}
						}
					}
				}
			}
			if(TitaniumArmorPeices == 4) {
				if(player.getHeldItemMainhand().getItem().equals(ModCombat.titaniumSword)) {
					if(player.getHeldItemOffhand().getItem().equals(ModCombat.titaniumShield)) {
					if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
						if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
							player.addStat(AchievementHandler.achievementBattleReady);
							}
						}
					}
				}
			}
		}

 

Posted
2 minutes ago, diesieben07 said:

Yes, you are. Because you are trying to mod without Java knowledge. That's like saying "I am going to learn swimming by being dropped in the middle of the ocean. In a storm." No, you are not going to learn to swim (read: program), you are going to drown.

I have a basic knowledge of Java, but it is very basic and limited

 

Posted (edited)
1 hour ago, ModderInTraining said:
  Hide contents


		public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
			int TitaniumArmorPeices = 0;
			if(player.getArmorInventoryList() != null) {
				Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
				while(iterator.hasNext()) {
					ItemStack stack = iterator.next();
					if(stack != null) {
						if(stack.getItem() instanceof ItemModArmor) {
							ItemModArmor item = (ItemModArmor) stack.getItem();
							if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
								TitaniumArmorPeices++;
								continue;
							}
						}
					}
				}
			}
			if(TitaniumArmorPeices == 4) {
				if(player.getHeldItemMainhand().getItem().equals(ModCombat.titaniumSword)) {
					if(player.getHeldItemOffhand().getItem().equals(ModCombat.titaniumShield)) {
							}
						}
					}
					if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
						if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
							player.addStat(AchievementHandler.achievementBattleReady);
				}
			}
		}

 

Can someone explain why this isnt working?

 

Your brackets are in the wrong places. This is really basic Java stuff that you're struggling with. I'm going to highlight each pair of opening and closing brackets in different colours so you can see:

 

if(TitaniumArmorPeices == 4) {            if(player.getHeldItemMainhand().getItem().equals(ModCombat.titaniumSword)) {                if(player.getHeldItemOffhand().getItem().equals(ModCombat.titaniumShield)) {
                        }
                    }
                }                if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {

if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {                        player.addStat(AchievementHandler.achievementBattleReady);
            }
        }

 

The red brackets are executed if the offhand item is a titaniumShield. The blue brackets are executed if the mainhand item is a titaniumSword. Can you see that both of those brackets have no actual code inside?

Edited by Jay Avery
Posted

Im using this, (code inside the proper brackets) but its still not firing 

Spoiler

		public void onTick(World world, EntityPlayer player, ItemStack itemStack) {
			int TitaniumArmorPeices = 0;
			if(player.getArmorInventoryList() != null) {
				Iterator<ItemStack> iterator = player.getArmorInventoryList().iterator();
				while(iterator.hasNext()) {
					ItemStack stack = iterator.next();
					if(stack != null) {
						if(stack.getItem() instanceof ItemModArmor) {
							ItemModArmor item = (ItemModArmor) stack.getItem();
							if(item.getArmorMaterial() == ModArmor.TitaniumMaterial) {
								TitaniumArmorPeices++;
								continue;
							}
						}
					}
				}
			}
			if(TitaniumArmorPeices == 4) {
				if(player.getHeldItemMainhand().getItem().equals(ModCombat.titaniumSword)) {
					if(player.getHeldItemOffhand().getItem().equals(ModCombat.titaniumShield)) {
					if(player.hasAchievement(AchievementHandler.achievementBulletProof)) {
						if(!player.hasAchievement(AchievementHandler.achievementBattleReady)) {
							player.addStat(AchievementHandler.achievementBattleReady);
							}
						}
					}
				}
			}
		}

 

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.