Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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;

	}
}
}

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.

  • Author

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?

  • Author

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

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;

  • Author

Thank You! Everything is working perfectly now :D I didn't realize that everything I needed was in conext

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.