1
在本地开发环境中在Eclipse中使用Forge 1.8.9(Mars.1 Release(4.5.1))。Minecraft Forge:使用setLocationAndAngles的正确加入游戏监听器
目标是在每次参加(或重新加入)世界时将玩家的位置设置为预定的xyz。因此,如果他们退出游戏,但后来回到世界,他们将从下面的代码确定的相同位置开始,而不是他们离开的任何地方。基本上,它会像大堂一样工作,每次球员都在同一个地方开始比赛。
该代码使用聊天组件(例如,在加入游戏时出现聊天消息),但我现在已经评论了它。在上次离开游戏后,玩家只会出现在他们离开的任何地方。
问题是: 1.是PlayerLoggedInEvent使用的最佳事件,还是有更好的事件? 2.是setLocationAndAngles最好用,还是应该不同的设置位置类型事件(或移动)更好?
在此先感谢。有很多LAMP堆栈的经验,但是Java和mods是一个新兴趣(obvs)。代码如下。
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);
}
}
好的,我会检查出来的。我有一个不同的变化,世界渲染将失败,但搬迁将工作。我会告诉你。 :) –
不幸的是,位置的持久性不是问题,重新设置新鲜的位置,所以我不认为克隆是它。我曾尝试过EntityJoinWorldEvent,它导致世界返回一个“错误的位置!”错误。我做了一些阅读,但没有结果。控制台:' [21:12:44] [服务器线程/信息]:Player534加入游戏 [21:12:45] [服务器线程/警告]:错误的位置! (9,9)应该是(8,6),EntityPlayerMP ['Player534'/ 828,l ='world',x = 145.00,y = 72.00,z = 145.00] [21:12:55] [Server thread/INFO]:保存并暂停游戏... [21:12:55] [服务器线程/信息]:保存块为lev ...' –
交叉发布此与[http://stackoverflow.com/questions/35503721/minecraft-forge-entityjoinworldevent-returns-wrong-location-error]作为我的变体之一。 –