Deadlyapples Posted March 23, 2014 Posted March 23, 2014 Hi guys! I am really enjoying learning to mod and some things I can work out for myself and I have been doing so far however I have come to a point in my mod that I just can't work out or get past on my own and I am asking for some assistance if possible! Let me set the scene for you! I have a very nice pickaxe, its all working fine. Crafting recipe, custom items for crafting etc. These custom items drop from skeletons, but they only drop when these skeletons are burning, either in daylight or other sources. The tools function as you would expect. They have durability and material properties similar to iron! Here is where I want to go but I don't know how to get there! When the tool reaches 0 durability, instead of it breaking and being lost forever, it becomes a broken version of the tool. Useless in its current form! In order to fix this you place it in a custom block (I am thinking of maybe a kind of repair station which uses meat as fuel) There is a progress bar which shows how long it is going to take till the tool is repaired. Once the bar fills up the tool is fully repaired and is now usable again. Now I know that this is maybe a lot to ask for but if I can even just get some help with swapping the pick, that is about to break, into another item which would be a broken variation of the tool which is basically just an item with a similar texture. I hope someone can help me with this. At the moment the way of mod is layout out is its just like any other basic tool and gear mod. Each tool has its own class etc. Am I looking at putting code into the Tool's class file or a desperate class which handles the tool to item swapping upon reaching 0 durability? This forum is sort of a last resort as I have asked all over and have had no luck. Either that or I have had an experience programming laughing at me because of my lack of knowledge with java programming. But I most definitely not a complete idiot (Not entirely anyway ). Any help I can get would be appreciated! SUMMARY! How do I check an item / tool / armors durability level? How do I then make an if statement based on that item / tool / armors durability level? How do I replace one item with another? If those 3 questions can be answered in a way which I can process and understand I will love you eternally. Quote
hotrods20 Posted March 23, 2014 Posted March 23, 2014 A good thing to look into is events. One event that may have interest to you is, PlayerDestroyItemEvent. Quote http://www.slothygaming.com/img/ota.png[/img] If your grammar is shit and you blatantly don't know what you're doing, I will not help you.
Deadlyapples Posted March 23, 2014 Author Posted March 23, 2014 Hotrods. I will try that out shortly. Thankyou for the quick reply! Quote
coolAlias Posted March 23, 2014 Posted March 23, 2014 If it's your own Item class, you don't even need to fuss with Events, though that would work, too. It's much more efficient, however, to simply do it in your Item's hitEntity and onBlockDestroyed methods, since those only get called for your Item rather than every single Item that gets destroyed. You can see how I did it for some swords here. Just look for those two methods. If you're coding in 1.7 it's practically exactly the same, but onBlockDestroyed takes a Block instead of int {blockID} as the 3rd parameter. Quote http://i.imgur.com/NdrFdld.png[/img]
hotrods20 Posted March 23, 2014 Posted March 23, 2014 Do what coolAlias says, it's faster and you don't muck around with events. If you wanted to break normal pickaxes and replace them with a broken pickaxe item, then you should use the event. Quote http://www.slothygaming.com/img/ota.png[/img] If your grammar is shit and you blatantly don't know what you're doing, I will not help you.
Deadlyapples Posted March 23, 2014 Author Posted March 23, 2014 I'll give this a go guys! Much appreciated. If you think of anything else I would also appreciate that. I'll give this a go! Quote
Deadlyapples Posted March 23, 2014 Author Posted March 23, 2014 Sorry about this but I just can't get this working. I am still new to the whole programming thing and if someone could just show me a way of getting it to work that would be great. I have tried for several hours with bits of ideas from your code coolAlias but I just can't get it to work. I ended up at the point where my item wasn't doing any damage. I tried also setting up console notifications so I could see the code progress with simple println("Step 1"); kind of stuff but it never triggers. Am I missing something here or what hehe. It must be frustrating trying to help people when they just can get it but if you will bear with me and once I understand they way in which the code needs to be layed out it will be golden! Quote
coolAlias Posted March 23, 2014 Posted March 23, 2014 How about you post your item code and we'll take a peek? Quote http://i.imgur.com/NdrFdld.png[/img]
Deadlyapples Posted March 23, 2014 Author Posted March 23, 2014 package com.aappleyard.evolvinggearmod.tools; import com.aappleyard.evolvinggearmod.EvolvingGearMod; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.PlayerEvent; public class FusedBoneClaymore extends ItemSword { public FusedBoneClaymore(int i, ToolMaterial fusedbone) { super(fusedbone); this.setCreativeTab(CreativeTabs.tabCombat); this.setTextureName("evolvinggearmod:FusedBoneClaymore"); this.setUnlocalizedName("Fused Bone Claymore"); this.setMaxDamage(3); } } That is the basic code. No fancy item on destroy stuff. This next bit is was I am trying but I just can't get my head around it. Help would be appreciated. Tell me what I did wrong and tell me what I did right or what I can do. Examples help too. package com.aappleyard.evolvinggearmod.tools; import com.aappleyard.evolvinggearmod.EvolvingGearMod; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.world.World; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.player.PlayerEvent; public class FusedBoneClaymore extends ItemSword { boolean hitEntityTrue; boolean brokeBlockTrue; boolean itemIsDestroyed; //Basic Info for Fused Bone Claymore public FusedBoneClaymore(int i, ToolMaterial fusedbone) { super(fusedbone); this.setCreativeTab(CreativeTabs.tabCombat); this.setTextureName("evolvinggearmod:FusedBoneClaymore"); this.setUnlocalizedName("Fused Bone Claymore"); this.setMaxDamage(3); } //Is an entity hit? public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker){ return hitEntityTrue; } //Is a block destroyed? public boolean onBlockDestroyed(ItemStack stack, World world, int blockID, int x, int y, int z, EntityLivingBase entity){ return brokeBlockTrue; } // Not sure how to get the durability level of the claymore. // If i get the durability level I would prefer to have the item swap to another item at 1 durability. public int getDamage(ItemStack stack) { return itemIsDestroyed; } // When the item is damaged. If the item was damaged on an entity ir by breaking a block // AND the durability level is 1 or lower - delete item and replace with broken fused bone claymore //Thats one way I can think of doing it. //Other way is just causing an effect when the item is broken due to lack of durability. protected void onStackDamaged(ItemStack stack, EntityLivingBase entity){ if (hitEntityTrue || brokeBlockTrue && /*Item is Destroyed*/ ){ } } } I really am trying and I just lost when I don't know what methods and exist and lack of experience in using the events and methods as well as lack of programming experience in general. I have trained to be a 3D modeler and audio engineer so this stuff is still new. But I find it fascinating and want to learn more by making a mod and learning as I go with the help from kind people like yourselves. Quote
coolboy4531 Posted March 23, 2014 Posted March 23, 2014 Why don't you check for the durability in those methods, instead of returning a boolean? Quote
Deadlyapples Posted March 23, 2014 Author Posted March 23, 2014 I have no idea how to check for durability other than getDamage() But I don't know how to save that as a variable and then if variableOfDurability = 1 or less then give item. I just don't know how to code that. It complained that it needs to be a Boolean. Then says that it doesn't work and needs to be an int. argh headache! The other thing as well is I have added in System.out.println("Block was broken") and others like that so I can track the code as it works and it never prints out the block has been broken or that I hit an entity. Quote
coolAlias Posted March 24, 2014 Posted March 24, 2014 Alright, well first of all you can't store variables directly in your Item class and expect them to function normally, since Items are all declared as static. // No. boolean hitEntityTrue; boolean brokeBlockTrue; boolean itemIsDestroyed; Second of all, if you are putting println's in your methods and never seeing any console output in your Eclipse log (it's not a chat message), then your methods are incorrect or something else is going wrong. Add @Override above all inherited methods to make sure your method signatures are correct. Finally, storing ANY data about the ItemStack is fruitless; you need to get the data directly from the ItemStack EVERY single time a method is called with an ItemStack parameter. I gave you a perfectly valid example earlier and you completely butchered it... just follow the example as closely as possible and only change what is absolutely necessary - meaning only the names of the Items involved. Quote http://i.imgur.com/NdrFdld.png[/img]
Deadlyapples Posted March 24, 2014 Author Posted March 24, 2014 When I use @Override at the public boolean onBlockDestroyed it complains saying : The method onBlockDestroyed(ItemStack, World, int, int, int, int, EntityLivingBase) of type FusedBoneClaymore must override or implement a supertype method I have googled for the past hour and have no better idea as to what that means. Thanks Quote
coolAlias Posted March 24, 2014 Posted March 24, 2014 If you're coding in 1.7 it's practically exactly the same, but onBlockDestroyed takes a Block instead of int {blockID} as the 3rd parameter. There I go again, quoting myself... if you add @Override to a method that you know is from the super-class and you are getting an error, it's because your method is WRONG. See quote above. Quote http://i.imgur.com/NdrFdld.png[/img]
Deadlyapples Posted March 24, 2014 Author Posted March 24, 2014 I apologize. I swear I am loosing my mind or something. Quote
Deadlyapples Posted March 24, 2014 Author Posted March 24, 2014 coolAlias. I want to say thankyou very much for your help with this! I have the code working more or less as I intended and I really appreciate your support! Quote
Deadlyapples Posted March 24, 2014 Author Posted March 24, 2014 Since making my code work how I want I have made quite a bit of progress! I have a question about variables. Is it possible to have an item retain a variable to be used later on? I have a claymore weapon which as it kills mobs, needs to retain the number of kills it has. I have a variable declared at the start of the class and it works for the most part. But when I shut down the client and reload it the variables are lost. Do I need to make a sort of player.dat file which contains information of the weapons. My only thought is that having a file to save the data might start getting more and more full as more weapons are made and used which would not be desirable. Any thoughts? I have seen in your code you do something similar but is there an easier way for me to understand what you are doing? Quote
coolAlias Posted March 24, 2014 Posted March 24, 2014 ItemStack NBT. Only way, and it's fairly simple when you get used to it. Quote http://i.imgur.com/NdrFdld.png[/img]
Deadlyapples Posted March 24, 2014 Author Posted March 24, 2014 coolAlias. Is there any way of sending information out to the game chat. For example. Instead of System.out.println("Chatty chat chat"); Which is console bound. Is there a way to display text in the chat area that is in the game? Quote
coolAlias Posted March 24, 2014 Posted March 24, 2014 Use your IDE and search in EntityPlayer, I'm sure you'll find something. Quote http://i.imgur.com/NdrFdld.png[/img]
Deadlyapples Posted March 24, 2014 Author Posted March 24, 2014 What are your opinions on setting out a separate class file for the detection of when my mod items damage entities they store NBT data. That way each of my tools doesn't need 20+ lines of code. It just refers to the separate class file? Any ideas or tips? Quote
sequituri Posted March 25, 2014 Posted March 25, 2014 That would sure complicate the whole business, but you are right that you can do most anything with a class if you want to. It just isn't always the best way. Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
coolAlias Posted March 25, 2014 Posted March 25, 2014 First, do all of your tools really need to be in different classes of their own, or could they share a single class? If they can't share a class for whatever reason, could they not share a prior class that implements all the NBT functionality for you, similar to how ItemAxe, ItemShovel, etc. all extend ItemTool, make your own "ItemCustomTool" that all of your other tools extend. Done, with those 20+ lines written only once but working for every single tool. That's a far cry from what I would call complex, but to each their own. Quote http://i.imgur.com/NdrFdld.png[/img]
The_SlayerMC Posted March 25, 2014 Posted March 25, 2014 You can check the durability of the tool by going: int i = ((ItemPickaxe)Items.diamond_pickaxe).getMaxDamage(); That can be used for the armour/weapons/item just change the cast you can make an if statement for the weapon durability by going if(i < 1000) (that will check if 1000 is greater than the current tools durability) if you want to replace a broken tool with a new one go if(i < 0){ player.inventory.addStackToInventory(new ItemStack(Items.diamond)) } Quote Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
sequituri Posted March 25, 2014 Posted March 25, 2014 What are your opinions on setting out a separate class file for the detection of when my mod items damage entities they store NBT data. That way each of my tools doesn't need 20+ lines of code. It just refers to the separate class file? Any ideas or tips? I was saying earlier that a separate class is not the way to go. However, as CoolAlias was so kind as to point out, if you can refactor most of the guts and hard stuff into a common base class, then your weapons and such could just be declared as subclasses and gain all of the functionality that you don't override. This is good old everyday java programming, so I hesitated to mention it. Check out how ItemTool works for Axes, pickaxes, Shovels, etc. Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
Recommended Posts
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.