iluvpie777 Posted September 25, 2015 Posted September 25, 2015 Hi I've been trying to make an entity spawn next to the player when a specific key is pressed however in the KeyInputEvent there is no world or entity so how do I make it so when I press a certain button an entity spawns, or do I have to use a different event completely. It's not much help but here is my KeyInputEvent code Code: public class KeyHandler { public boolean isAttacking = false; World world; EntityPlayer player; private static Key getPressedKeybinding() { if (KeyBindings.attack.isPressed()) { return Key.ATTACK; } return Key.UKNOWN; } @SubscribeEvent public void handleKeyInputEvent(InputEvent.KeyInputEvent event) { if (KeyBindings.attack.isPressed()) { isAttacking = true; } } } Quote
Ernio Posted September 25, 2015 Posted September 25, 2015 Keys are client-side. Client can't spawn anything. You need to send packet to server telling "this player clicked button". Packet can only contain button id or even noting is button would be static. On server (handler side) you will get player from packet itself (server knows who sent packet) and spawn entity there. http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with Short: http://www.minecraftforge.net/forum/index.php/topic,20135.0.html Quote 1.7.10 is no longer supported by forge, you are on your own.
iluvpie777 Posted September 25, 2015 Author Posted September 25, 2015 So I'm kinda confused on how Simple Network Wrapper works, so basically it sends a string from the client side to server side, and the server takes that string and does stuff with it? Quote
iluvpie777 Posted September 25, 2015 Author Posted September 25, 2015 So I've mannaged to get SimpleNetworkWrapper working but the only place to execute the spawn entity code is here: code: @Override public IMessage onMessage(EMMessage message, MessageContext context) { return null; } So once again there is no world or player so how do I execute the spawn entity code Quote
ItsAMysteriousYT Posted September 25, 2015 Posted September 25, 2015 Everything you need you can get from the MessageContext. It is smart to put the things you wanna make in a new thread like this: IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; mainThread.addScheduledTask(new Runnable() { World world = ctx.getServerHandler().playerEntity.worldObj; @Override public void run() { } }); return null; Quote
iluvpie777 Posted September 25, 2015 Author Posted September 25, 2015 Thank You! Everything is working perfectly now I didn't realize that everything I needed was in conext 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.