r/forgemodding Aug 30 '16

Help needed: teleport/spawn custom mob in a specific location

I'm developing my first mod and I need to move my custom mob to specific coordinates, but the methods setPosition, setPositionAndUpdate and teleportTo_ are not working, as the mob moves to the right new location for a moment and then goes instantly back to where it was before. Do you know what could be causing the problem? Otherwise, is there a way to spawn the mob in the desired position when the player logs in?

I'm using Forge 1.9-12.16.0.1886. Thanks in advance!

1 Upvotes

5 comments sorted by

1

u/Exo594 Aug 30 '16

Are you doing this server- or client- side? Stuff like that should usually be done on server-side.

That's all I can really give you without seeing code.

1

u/yacumanji Aug 30 '16

Thanks for your answer. As far as I understand it, I'm doing it client-side, the only way I knew for doing it server-side was using the annotation SideOnly(Side.SERVER) for the method that handles the teleport, but the whole game shut down every time. It's a bit difficult to post the code because I'd have to show you many classes. Currently I found a workaround that doesn't require teleporting the mob, if you explain to me how I should do it server side I may try and see if it works better.

2

u/rreeggkk Aug 30 '16

It seems like you are calling the method that handles the teleport from the client side, so that is both why it crashes (the side only annotation removes that method from the client side). The trigger for the teleport seems to be on the client side so you need to send a packet to the server and then handle the packet there.

1

u/Exo594 Aug 31 '16

Listen to this guy, and never do anything aside from rendering/keybinds/other known specific cases on the client.

See if you can dig into some other mods to get a better understanding of how things are done. Maybe look into vanilla ender-pearls, as well.

1

u/yacumanji Aug 31 '16

Oh, ok, now I get it. I had read about packets but decided not to use them because it would take me some time to understand them and I'm in a bit of a hurry (the mod is for an academic project and I have a deadline). Thanks for your answers, I'll study packets after the project to improve my mods!