Posted March 17, 201312 yr Hello. I got an idea for a mod and want to start with it. I make the whole mod mobile (the writing thing) because i like to look how much i know and how much i do not know. But these informations are not needed here. Now informations what i think they are important: I want to make items and these work with Strings: Like this: String Username = "Null"; String par1 = ""; String par2 = ""; Now the problem: i want to make a String Checking lib like this: if(Username.startsWith("C") { than do this this and this; } else if(Username.startsWith("G") { than do this but not that } else { do nothing } now all letters together are 26 My Problem is i do not want to do 26 if states. How can make a (maybe) enum for ever letter or something which stores the letters and i can say: enumname: 0 = "A", "G", "Z", "K", "D", "I", "Q" if(username.startswith(enumname.0) { than do that } else { do this } So who can help me?
March 17, 201312 yr Are you new to Java? =) Yes with enum you can do that,but if you want the same thing to do when it starts with 'X' letter,then you just make an array,or an arraylist,any collection do it,then loop it through.
March 17, 201312 yr Author I am a little bit new. I want to use minecraft to learn how things work. (The understanding) I know that i can not learn java from minecraft. But now to the answer you mean it like this: public class ItemTest extends Item { String[] letters = new String[5] {"A", "X", "Y", "G", "T"}; String username; String var1; //I will not tell what this parameter do public ItemTest(int id) { super(id); setHasSubtypes(true); } public ItemStack onRightClickItem(ItemStack par1, World par2, EntityPlayer par3) { if(username == null) { username = par3.username; } return par1; } public void onUpdate(ItemStack par1, World par2, Entity par3, int par4, boolean par5) { if(par5) { for(int i = 0; i < 5; i++) { if(var1 == null) { if(username.startsWith(letters) { var1 = "This"; } else { var1 = "That"; } } else { //Do nothing } } } } } Does this work?
March 17, 201312 yr In the loop you aren't using the elements,you should: letters But for understanding from minecraft is a really terrible thing,because of the variable names. You should start making you own games,like a simple top-down shooter games,platform games,pacman any easy game do it. And i recommend you LWJGL and Slick2D
March 17, 201312 yr Author I do not want to make my own games. I want learn how to understand learning things i mean (I use now google): I want to understand how you have to look at the stuff in the programming and understand even what I do. .
March 18, 201312 yr personaly i'd use a case using a char function (void or return type) checkName(String name){ char nameChar[] = name.toLowerCase().toCharArray(); switch nameChar[0] { case 'a' : <function to do here> break; // if void, else return from the above function case 'b' : <function to do here> break; // ect.. case default : System.out.println("you fucked up"); break; } }
March 19, 201312 yr Author Ok now i have to explain what i want to do. I have no name for the mod. But it has something todo with blood: When you are rightclick the item. The player get Hurt (half heart damage) and the item got the username. Then the item checks what letter it starts and choose from that which bloodgroup the player has. and with that you can make potions and whatever
March 19, 201312 yr the general idea is solid, but it sounds like it would be severely limited in a SSP environment
March 19, 201312 yr Guys we're dealing with strings.... public static final String blood_O = "aqtik"; public static final String blood_Opos = "rhnsb"; /**pass the first char of username*/ public void handleBlood(char c){ if(blood_O.contains(c)) //dostuff; else if(blood_Opos.contains(c)) //dostuff; } Fast and legible I think its my java of the variables.
March 19, 201312 yr Author You did understand nothing. here my codeidea: private String dna = "null"; private String username = "null"; public ItemStack onRightClickItem(ItemStack par1, World par2, EntityPlayer par3) { if(username == "null") { username = par3.username; } return par1; } public void onUpdate(....boolean par5) { if(par5) { checkDNA(); } } public void checkDNA(); { if(dna == "null" && !username == "null") { if(username.startsWith("a") { // do stuff; } else { //dostuff } } }
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.