zacharyjaiden Posted May 11, 2014 Posted May 11, 2014 ok so im making it so that my custom entities (and maybe some vanilla entities) can only spawn when condition is met, i have browsed through the forge events and found the event living spawn event, is that suited for this? i am not quite sure how to properly use this event can anybody help out with this? in sudo ive kinda thought of this way @SubscribeEvent public void LivingSpawnEvent(LivingSpawnEvent event) { EntityPlayer player = (EntityPlayer)event.getPlayer(); if(event.entity == EntityCutstomMob && StorageLevel.getPlayer().GetMasterLevel() < 5) { setCanceled{True} } } i know this event or a part of this event is cancelable but im not 100% sure how to properly set canceled so if anyone knows that aswell please let me know, but basically i need to know how to do this in the way that ive displayed but obviously not sudo properly with the correct terms and such thanks in advance +1 karma for any answers (that arent just for sake of getting karma) Quote
TheGreyGhost Posted May 11, 2014 Posted May 11, 2014 Hi the code you posted is close, I reckon it will work if you modify it slightly to use the following event: /** * Fires before mob spawn events. * * Result is significant: * DEFAULT: use vanilla spawn rules * ALLOW: allow the spawn * DENY: deny the spawn * */ @HasResult public static class CheckSpawn extends LivingSpawnEvent In your handler you should call event.setResult(your result here); -TGG Quote
zacharyjaiden Posted May 11, 2014 Author Posted May 11, 2014 thanks, but how would i appropriately reference the entity? i tried if(event.entity == EntityBunny.class); but that errors the whole line, i tried just if(event.entity == EntityBunny); that errors on entity bunny, idk how to refer to the mob Quote
GotoLink Posted May 11, 2014 Posted May 11, 2014 LivingSpawnEvent event) { EntityPlayer player = (EntityPlayer)event.getPlayer(); if(event.entity == EntityCutstomMob && StorageLevel.getPlayer().GetMasterLevel() < 5) } You can't get a EntityPlayer instance from those event. They are for mobs. Your entity check could be if(event.entity.getClass().equals(EntityCustomMob.class)) Quote
zacharyjaiden Posted May 11, 2014 Author Posted May 11, 2014 thank you for your amusing arrogance diesieben but i do know basic java. you dont have to try and belittle everyone on this forum i look at quite a few posts on this forum and a great percentage of them have at least one post from you using that little phrase of yours, i have used instanceof before with items and blocks but didnt know that it would apply to an entity since the way i came about that term implied that it was something used for "things" not entities so i never looked into it too much, obviously i was wrong but i and everyone else on this forum dont need comments like those, it may very well hinder peoples ability to learn and progress their skills as you probably make a lot of people uncomfortable and or embarrassed which im sure youre quite aware of... i dont appreciate it. my attempt in thinking if the entity == entityWHATEVER isnt that far fetched.. at least gotoLink can provide help without trying to downgrade others (appreciate your help gotolink +1 karma) and its not like i was asking anyone to code the thing for me i had a general idea of what i was doing from the start Quote
zacharyjaiden Posted May 11, 2014 Author Posted May 11, 2014 you do need to get off your high horse, just because somebody doesnt understand java yet to the extent that you do does not mean that they dont know "basic java", i learn the java associated with minecraft modding because im using it to MOD MINECRAFT, i learn what i can from tutorials (which im sure you read tutorials when you were starting out too) also from minecraft source code, i dont know all of the applications of the code ive learnt but i know how to use it pretty widely, what i dont know i come to this forum for help, (which is the very purpose of this forum) not for criticism on my knowledge of the language... your contribution consisted of a single word, which i already knew just didnt think to apply it and you find it necessary to downgrade my knowledge and skills when in comparison to you obviously high opinions and views on your own, i am fairly new to java and minecraft modding hence why i seek out support. again get off your high horse mate come to this forum to help people not throw out negative comments. that one word "instanceof" was all i needed not my code written for me as you seem to think Quote
coolAlias Posted May 12, 2014 Posted May 12, 2014 Zachary, Most of the time when someone around here encourages you to learn more about Java, we are doing so in an effort to help you, and getting upset about it is not very conducive to learning. As we've discussed before, learning Java is a process, and claiming that you already 'know basic Java', while it certainly contains some truth, is also far enough from reality that believing this is simply going to prevent you from taking the steps necessary to expand your knowledge. I've been coding in Java for almost a year now, and while I have a pretty good grasp of most of the fundamentals, I am still always learning new things, even things that most Java programmers would consider extremely basic (such as the difference between 'instanceof' and 'isAssignableFrom(Class)', which I learned about only a month or two ago). So when you ask a question and someone responds with 'please learn basic Java, what you want is {fill in the blank}', instead of getting upset at that person, take the opportunity to do a search for the Java documentation of whatever they said you needed (e.g. instanceof), and you will not only have shown yourself to be a mature and proactive individual, but you will also have learned valuable information that will make modding much easier, especially if you make it a habit to look things up. On the other hand, if you don't care about learning Java except just enough to make a mod, then you can hardly expect people to take you seriously on a forum such as this. Sorry for the rant, but please understand that help comes in many forms, and the best kind of help is the kind that helps you help yourself. As the saying goes, 'Give a man a fish, you feed him for a day; teach a man to fish, you feed him for a lifetime.' Regards, coolAlias Quote http://i.imgur.com/NdrFdld.png[/img]
zacharyjaiden Posted May 14, 2014 Author Posted May 14, 2014 Zachary, Most of the time when someone around here encourages you to learn more about Java, we are doing so in an effort to help you, and getting upset about it is not very conducive to learning. As we've discussed before, learning Java is a process, and claiming that you already 'know basic Java', while it certainly contains some truth, is also far enough from reality that believing this is simply going to prevent you from taking the steps necessary to expand your knowledge. I've been coding in Java for almost a year now, and while I have a pretty good grasp of most of the fundamentals, I am still always learning new things, even things that most Java programmers would consider extremely basic (such as the difference between 'instanceof' and 'isAssignableFrom(Class)', which I learned about only a month or two ago). So when you ask a question and someone responds with 'please learn basic Java, what you want is {fill in the blank}', instead of getting upset at that person, take the opportunity to do a search for the Java documentation of whatever they said you needed (e.g. instanceof), and you will not only have shown yourself to be a mature and proactive individual, but you will also have learned valuable information that will make modding much easier, especially if you make it a habit to look things up. On the other hand, if you don't care about learning Java except just enough to make a mod, then you can hardly expect people to take you seriously on a forum such as this. Sorry for the rant, but please understand that help comes in many forms, and the best kind of help is the kind that helps you help yourself. As the saying goes, 'Give a man a fish, you feed him for a day; teach a man to fish, you feed him for a lifetime.' Regards, coolAlias Ok, i get what youre saying cool alias and i guess youre right, its just im dedicating hours of my time to read java documentation, minecraft tutorials and browsing the forums, when im getting responses of "Learn basic java" its really annoying me BIG time as i am very new to this and i am like i said dedicating quite a large portion of my time to learning all the fundamentals of java and learning the way minecraft is coded, i feel like those comments shot straight out of nowhere get to me. i owe you a bit of an apology diesie, i shouldnt of gotten angry at you, i do in fact appreciate your help, ive known the basics of java and modding minecraft for quite a while although havent done it for a couple years so i have forgotten quite a few things... i never needed to expand my knowledge of java cause i didnt need to know anything new but ive been trying to venture into new territories in modding and faced a lot of java problems and in doing so, ive spent hours recapping over the java i already knew, and have spent hours reading up on new java information when relevant issue arise, i may ask some dumb questions but like i said im new, i absolutely do not want anybody to write the mod for me but i do appreciate helpful information something like "google switch statements mate that might help" rather than "Learn basic java. use (this word) instead of (thatword)" helps a lot more and would be appreciated 100 times more if im asking a question on here its because i probably dont know what area of java to look up for the class im trying to create Quote
jabelar Posted May 14, 2014 Posted May 14, 2014 While diesenben's comments are often terse you shouldn't take them as being on a high horse or belittling. He spends time to correct a lot of us, and being corrected can feel like being criticized but diesenben is usually right on the mark with his comments. Confusion about ==, .equals() and instanceof is a failure to understand basic java. (I'm also new to Java and have similar failures all the time, for example I'm always trying to compare strings with == which is a no-no). You can see that GoToLink (another highly respected commenter here) suggested .equals() and diesenben even had improvement over that in understanding the performance impact of instanceof. I would treat diesenben like a tough martial arts instructor. Just the fact that he is commenting on your thread shows that he cares about you and his comments have a point you should consider carefully. It's tough love. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/
zacharyjaiden Posted May 15, 2014 Author Posted May 15, 2014 thanks for the help and sorry for snapping mate Quote
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.