Using Forge 1.8.9 in Eclipse (Mars.1 release (4.5.1)) in the local development environment.
The goal is to set the playerโs location to a predefined xyz each time they join (or re-join) the world. Therefore, if they leave the game, but then return to the world, they will begin in the same place as the code below, and not wherever they stop. Basically, it will function as a lobby where players start at the same place every time.
The code works using the chat component (for example, a chat message appears when you enter the game), but now I commented on it. The player simply appears wherever they left off after leaving the game for the last time.
Questions: 1. Is PlayerLoggedInEvent the best event to use, or is there a better event? 2. is setLocationAndAngles best used or is it better to use another location type event (or move)?
Thanks in advance. A lot of experience with the LAMP stack, but Java and mods are of new interest (obvs). The code is below.
import net.minecraftforge.client.event.RenderPlayerEvent; //import net.minecraft.util.ChatComponentText; //import net.minecraft.util.EnumChatFormatting; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; //import cpw.mods.fml.common.eventhandler.SubscribeEvent; public class JoinGameLocation { @SubscribeEvent public void SpawningLocation(PlayerLoggedInEvent event){ event.player.setLocationAndAngles(145, 72, 145, 0, 0); //-----This works when uncommented //event.player //.addChatMessage( // new ChatComponentText( // EnumChatFormatting.RED + "You joined the game")); //event.world.setWorldTime(0); int ticks = 0; double good_x = 145; double good_y = 72; double good_z = 145; event.player.setLocationAndAngles(good_x, good_y, good_z, 0, 0); } }
source share