Jump to content

Recommended Posts

Posted

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;

	}
}
}

Posted

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

1.7.10 is no longer supported by forge, you are on your own.

Posted

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

Posted

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;

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.