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

I would have thought that

this.mc.thePlayer.setGameType(EnumGameType.SURVIVAL);

was the correct way to change a player's game mode, but that doesn't seem to work.

 

How do you do this?

  • Author

Never use the client-side player for stuff like this (Minecraft#thePlayer). You need the serverside player. From where do you want to do this?

 

From a tick handler.

  • Author
What TickType? That matters.

 

I had it set to client. Whops! I want this to be multiplayer.

 

I just tried this.

this.mc.playerController.setGameType(EnumGameType.SURVIVAL);

 

Is that what I'm looking for?

  • Author

You have to realize that there can always be multiple players. So you need to decide how to determine from the TickHandler which player's gamemode to change.

When exactly should the change happen?

 

I knew I would have to do that soon. I was planning on getting an array of all the online players and sorting through them one by one. I have it set to every 20 ticks to get the player's coordinates and compare them with a polygon. If you're inside it, then set the game mode to X.

  • Author

MinecraftServer.getServer()

is the server, yes?

 

How do you select a player? I was expecting a

MinecraftServer.getServer().getPlayer(playerName)

 

FOUND IT

use FMLCommonHandler.instance().getEffectiseSide.isServer() / isClient()  just in case :)

 

or world.isRemote if you have access to a world reference

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Good news! I made it work, and it is working just like I imagined. Although, the player gets spammed constantly with "your game mode has been changed" because of the tick handler. Any ideas how I could make it silent?

 

This is how I change the player's game mode.

MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername("username").setGameType(EnumGameType.SURVIVAL)

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.