I am trying to muddle my way through creating a type of Item which, when you right click with the 'straw golem' item, will decr your itemstack and spawn a golem (think back to thaumcraft for the general flow). I stripped out the AI so it should just spawn and wander, avoiding water and looking at things.
The Item works correctly - when right clicked on a block it will spawn a golem using my texture and the EntityIronGolem's model - but all it does is... spawn and play sounds.
I am sure I am missing something basic, but it seems like the entity is desynched between the client and server? It seems as if there's no way to interact with it. Further, I do not know if it is related or not, but I get a warning from the mainthread when he's spawned saying "Skipping Entity with id -1" - though I don't really understand this to know if it is related or not.
Appreciate your insight in advance!
(PS: if you also know of a way to adjust the models' size [I thought the this.setSize() call in the constructor would do it] please let me know!)
(PPS: Can anyone explain to me why on earth we're advised to do a commonProxy at all? It seems like one should simply have Client&Server, then anything from common goes in the main class. No?)
(PPS: In general, if I am going about something very much the wrong way, I'd appreciate pointers. This is a family project and I'd love to instill better habits in the fam where I can).
One thing you're doing wrong is that you extended EntityIronGolem which is okay except then you also copy the EntityIronGolem code. You shouldn't do both. For example, in your updateAITasks() method you do all that stuff and then call super.updateAITasks() which will repeat all that code again. In some cases that could cause trouble, for example your home check timer will count down twice as fast as you expect.
Basically, for all the methods you don't want to change from iron golem you shouldn't even have them in your class. You're already extending EntityIronGolem.
I would clean that up first because it could have some weird effects, like the timer counting faster, but also you're currently registering the same data manager thing twice, and so on.
Regarding your question about scaling the model, you need to do that with a GL scale method call in your renderer. The setSize() method sets the size of the bounding box, but doesn't actually scale the model itself.
Hello again, jabelar ! Thank you for your thoughts thus far! I really appreciate the insight, but I'm still stuck - github updated.
I have refactored such that EntitySimpleRancherGolem extends EntityGolem instead of EntityIronGolem, and as such (I think) I have removed the conflicting elements you mentioned above (I had thought @Override would solve that, but /shrug). I had only inherited in the first place to try to re-use it's model - so I simply copied it's model and now we're fully separate. I applied the scaling (I think) in the way you suggested by implementing a protected float of 'scale' and referencing that in my renderer's preRenderCallback. Seems OK...
**edit** I further refactored to make EntitySimpleRancherGolem not abstract, and changed my item's spawn code to instantiate that (instead of EntityStrawGolem (which extends EntitySimpleRancherGolem) - now the behavior is when you spawn the golem from the item, two golems appear - one which is interactable with the client and executes AI - and one which does not interact with the player and does not exhibit AI (though collision appears to work?). I also added natural spawning for EntitySimpleRancherGolem - and those entities appear to work beautifully - so I imagine it's a synch issue between client and server? But I've no idea where except in the item's onUse method? Any thoughts?
**final edit** Turns out that that behavior _IS_ indicative of a confusion somewhere between client and server. I resolved it by adding a check for !worldIn.isRemote around my 'spawn the dude and decr the itemstack' code - and everything is working beautifully! SOLVED!
@Jabelar, thank you for your thoughts - you got me back into the right track when I was lost
(I had thought @Override would solve that, but /shrug)
Actually to get you to the next level of programming, you can't just "shrug" this off. You need to understand it thoroughly.
The problem is that in your @Override you were calling super methods. That is okay (in fact strict class hierarchies should do this) but implies that you are extending the method -- doing everything the parent does plus some extra stuff. But in your case the "extra stuff" was a copy of the parent stuff so it was executing twice.
Modding is a little goofy compared to proper programming because in proper programming each child class should strictly extend (i.e. do everything the parent does but with something extra), but in modding sometimes you want to fully replace. Like you can also @Override without calling super methods at all. However, if you do this make sure you understand everything the super method was doing (especially if it also called super methods in which case you need to follow the functionality all the way to the beginning).
Anyway, make sure you understand @Override thoroughly. It is the most powerful thing for creating custom classes since almost always you will be extending existing classes.
I'll admit to being a touch shamed here. You're 100% right and my shrug was flippant.
I hope you dont mind but I ended up almost verbatum sharing your comment with my family. I know you maintain a blog of tutorials, Jabelar, and I think this post here is worthy of a place in that blog (and if it's there already further shame on me for missing it!). I had used the super calls to try to 'ensure I didn't miss anything crucial' while I was attempting to pare down what our code did. As a result I was inadvertantly duplicating - or even undoing - the changes I was trying to make. Shortcuts evidently don't pay off.
Thank you for your insight - both in the context of modding and in the context of general coding! I hope that - if nothing else - you can be pleased at seeing the quality of question I ask improve, as well as the quality of the github improve as me and mine work on this mod together.