Minecraft Forge:对setLocationAndAngles使用正确的Join Game侦听器 [英] Minecraft Forge: Using correct Join Game listener for setLocationAndAngles

查看:96
本文介绍了Minecraft Forge:对setLocationAndAngles使用正确的Join Game侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地开发环境中的Eclipse(Mars.1版本(4.5.1))中使用Forge 1.8.9.

Using Forge 1.8.9 in Eclipse (Mars.1 Release (4.5.1)) in local development environment.

目标是每次玩家加入(或重新加入)世界时将其位置设置为预定的xyz.因此,如果他们退出游戏,然后重返世界,他们将在以下代码确定的相同位置开始,而不是停在哪里.基本上,它将像大厅一样运作,每次玩家都从同一位置开始.

The goal is to set a player's location to a predetermined xyz every time they join (or re-join) a world. So if they quit the game, but then come back to the world, they will start in the same location as determined by the code below instead of wherever they left off. Basically, it will work like a lobby, where players start in the same place each time.

该代码可使用聊天组件工作(例如,聊天消息在加入游戏时出现),但目前我已将其注释掉.从上次离开游戏后,玩家仅会出现在他们离开的任何地方.

The code works using the chat component (e.g. the chat message appears upon joining the game) but I've commented it out, for now. The player simply appears wherever they left off after having left the game from last time around.

问题是:1. PlayerLoggedInEvent是最好使用的事件,还是有更好的事件?2.是最好使用setLocationAndAngles,还是应该更好地使用其他设置位置类型的事件(或移动)?

Questions are: 1. is the PlayerLoggedInEvent the best event to use, or is there a better event? 2. is setLocationAndAngles the best to use, or should a different set location type event (or move) better?

先谢谢了.LAMP堆栈有很多经验,但是Java和mod是新的兴趣(obvs).代码在下面.

Thanks in advance. Lots of experience with LAMP stack, but Java and mods are a new interest (obvs). 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);

    }
}

推荐答案

使用实体加入世界和克隆事件

Use the entity join world and the clone event

      @SubscribeEvent
      public void onClonePlayer(PlayerEvent.Clone event) {

      }

      @SubscribeEvent
      public void onEntityJoinWorld(EntityJoinWorldEvent event) {
          if (event.entity != null && event.entity instanceof EntityPlayer && !event.entity.worldObj.isRemote) {
          }
      }

克隆事件是在tp,尺寸更改等情况下触发的...当世界加入时,显然加入世界.我建议你玩这些.

The clone event is triggered upon tp, dimension change, etc... The join world obviously when the world is joined. I suggest you play around with these.

这篇关于Minecraft Forge:对setLocationAndAngles使用正确的Join Game侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆