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]作爲我的變體之一。 –