EnderCookie Posted June 30, 2015 Share Posted June 30, 2015 Hallo allerseits, ich habe aktuell beim modden ein relativ großes Problem Ich will in meinem Mod mittels einer GUI (die mt Itemrechtsclick aufrufbar ist) eine möglichkeit schaffen sich zu seinem Bett tpn zu lassen. Mein Problem ist z.Z das teleportieren. Ich finde keine Methode ohne Crash, um den Spieler zu tp?n. Mit der unten gezeigten Methode funktioniert es nicht, da ich EntityPlayer nicht zu EntityPlayerMP casten kann. Ich hoffe, dass wer helfen kann! LG EnderCookie_ EnderTeleporterItem.class package de.EnderCookie.moreStuff.items; import de.EnderCookie.moreStuff.Main; import de.EnderCookie.moreStuff.handler.EnderTeleporterGUI; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.living.EnderTeleportEvent; public class EnderTeleporterItem extends Item{ public EnderTeleporterItem(String unlocalizedName, CreativeTabs tab) { super(); this.setUnlocalizedName(unlocalizedName); this.setCreativeTab(tab); } @Override public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn){ playerIn.openGui(Main.instance, EnderTeleporterGUI.EnderTeleporterGUIID, worldIn, playerIn.getPosition().getX(), playerIn.getPosition().getY(), playerIn.getPosition().getZ()); return itemStackIn; } } EnderTeleporterGUI.class package de.EnderCookie.moreStuff.handler; import com.mojang.authlib.GameProfile; import de.EnderCookie.moreStuff.Main; import de.EnderCookie.moreStuff.gui.enderteleporter.EnderTeleporterGUIScreen; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.management.ItemInWorldManager; import net.minecraft.util.ChatComponentText; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.IGuiHandler; public class EnderTeleporterGUI implements IGuiHandler{ public static int EnderTeleporterGUIID = 1; @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { if(ID == EnderTeleporterGUIID){ return new EnderTeleporterGUIScreen(player,world); } return null; } } EnderTeleporterGUIScreen.class package de.EnderCookie.moreStuff.gui.enderteleporter; import java.io.IOException; import com.mojang.authlib.GameProfile; import de.EnderCookie.moreStuff.Main; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.Language; import net.minecraft.client.resources.LanguageManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.server.MinecraftServer; import net.minecraft.server.management.ItemInWorldManager; import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import net.minecraftforge.client.MinecraftForgeClient; import net.minecraftforge.common.MinecraftForge; public class EnderTeleporterGUIScreen extends GuiScreen{ private ResourceLocation EnderTeleporterGUIBackground = new ResourceLocation(Main.MODID + ":/textures/gui/enderteleportergui.png"); private int tpbed = 1; private EntityPlayer GUIViewer; private World GUIViewerWorld; public EnderTeleporterGUIScreen(EntityPlayer player, World worldIn) { GUIViewer = player; GUIViewerWorld = worldIn; } @Override public void initGui() { int drawscreenx = (width - 256) / 2; int drawscreeny = (height -128) / 2; this.buttonList.add(new GuiButton(tpbed, drawscreenx + 10, drawscreeny + 25, 236, 20, "Teleportiere zu Bett")); super.initGui(); } @Override protected void actionPerformed(GuiButton button) throws IOException { switch(button.id){ case 1:{ this.mc.thePlayer.closeScreen(); EnderTeleporterAction.tptobed(GUIViewer,GUIViewerWorld); break; } } super.actionPerformed(button); } @Override public void updateScreen() { super.updateScreen(); } @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); int drawscreenx = (width - 256) / 2; int drawscreeny = (height -128) / 2; this.mc.getTextureManager().bindTexture(EnderTeleporterGUIBackground); this.drawModalRectWithCustomSizedTexture(drawscreenx, drawscreeny, 0, 0, 256, 128, 256, 128); this.fontRendererObj.drawString(StatCollector.translateToLocal("gui.enderteleporter.title"), drawscreenx + 10, drawscreeny + 10, 0x000000); super.drawScreen(mouseX, mouseY, partialTicks); } } EnderTeleporterGUIAction.class package de.EnderCookie.moreStuff.gui.enderteleporter; import java.util.EnumSet; import com.mojang.authlib.GameProfile; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.network.play.server.S08PacketPlayerPosLook; import net.minecraft.server.management.ItemInWorldManager; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EnderTeleporterAction { public static void tptobed(EntityPlayer player, World worldIn){ BlockPos loc = player.getBedSpawnLocation(worldIn,player.getBedLocation(), false); if(!worldIn.isRemote){ EntityPlayerMP player2 = (EntityPlayerMP) player; player2.playerNetServerHandler.setPlayerLocation(64, 64, 64, 0, 0);} }} Link to comment Share on other sites More sharing options...
Marktfraid Posted July 1, 2015 Share Posted July 1, 2015 Hallo, so sollte es sowohl im Singleplayer als auch im Multiplayer funktionieren. Schreib bitte ob es funktioniert oder nicht. public static void tptobed(EntityPlayer player, World worldIn) { BlockPos loc = null; EntityPlayerMP playerMP; playerMP = Minecraft.getMinecraft().getIntegratedServer() .getConfigurationManager() .getPlayerByUUID(player.getUniqueID()); if (playerMP.getBedLocation() != null) { loc = playerMP.getBedSpawnLocation(worldIn, playerMP.getBedLocation(), false); } if (!worldIn.isRemote && loc != null) { playerMP.playerNetServerHandler.setPlayerLocation(loc.getX(), loc.getY(), loc.getZ(), 0, 0); } } Link to comment Share on other sites More sharing options...
EnderCookie Posted July 3, 2015 Author Share Posted July 3, 2015 (edited) Schon mal danke, ich kanns leider erst Fr/Sa testen Im SP funkt es leider nicht, da die isRemote() immer true ist. Es geht aber wenn man isRemote weglässt Edited July 3, 2015 by EnderCookie Link to comment Share on other sites More sharing options...
Marktfraid Posted July 3, 2015 Share Posted July 3, 2015 Schön, dass es so funktioniert. Bei mir ging es auch im SP, da ich es in einem anderen Kontext verwendet habe. Aber wenn es von der Gui aufgerufen wird gibt es anscheinend nur die Client-Welt. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now