Jump to content

cheesecake441

Members
  • Posts

    2
  • Joined

  • Last visited

cheesecake441's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Thanks for the response - I've tried implementing player.setPositionAndUpdate (having changed my coord variables to doubles) as per the below but its not actually doing anything if(!event.getPlayer().getEntityWorld().isRemote()) { player.sendMessage(new StringTextComponent("Have a nice trip"), player.getUniqueID()); try { player.setPositionAndUpdate(px, py, pz); HelloWorld.LOGGER.info("The player has been teleported"); } catch (Exception e) { HelloWorld.LOGGER.info("Could not teleport the player"); } } I've tried it with player as a LivingEntity and a PlayerEntity but neither works
  2. Hi folks, Very new to game-dev work so my apologies if I'm just a n00b but I've been combing the forums for hours and my head is sore from banging it against the wall: I'm trying to add an event listener on the "PlayerWakeUpEvent" that will send a message in chat and throw the player across the world using the "/teleport" command. It worked absolutely perfectly when I used the "PlayerSleepInBedEvent" but for the wake-up event I seem to get stuck in a loop whereby my chat message and the error stack is verbose'd indefinitely until the game crashes (I was going to post the full error logs but there are 569773 lines so I just took what looked important) Logs: https://pastebin.com/5gFYL6Y4 package com.cheesecake.helloworld.events; import com.cheesecake.helloworld.HelloWorld; import com.cheesecake.helloworld.util.RegistryHandler; import net.minecraft.client.Minecraft; import net.minecraft.command.CommandSource; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.World; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent; import net.minecraftforge.event.entity.player.PlayerWakeUpEvent; import net.minecraftforge.eventbus.api.Event; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = HelloWorld.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ModClientEvents { @SubscribeEvent public static void onPlayerWakeUp(PlayerWakeUpEvent event){ PlayerEntity player = event.getPlayer(); World world = player.getEntityWorld(); MinecraftServer server = world.getServer(); CommandSource source = player.getCommandSource(); //Static X Y Z Values until we can find biomes int px = 4226; int py = 67; // Above sea level but below clouds int pz = -79; if(!event.getPlayer().getEntityWorld().isRemote()) { player.sendMessage(new StringTextComponent("Have a nice trip"), player.getUniqueID()); try { server.getCommandManager().handleCommand(source, "/teleport " + player.getUniqueID() + " " + px + " " + py + " " + pz); } catch (Exception e) { HelloWorld.LOGGER.info("Could not teleport the player"); } } } } For reference here is the PlayerSleepInBedEvent I was using earlier (I disabled it when running the above in case of conflicts) @SubscribeEvent public static void MagicalDreamBed(PlayerSleepInBedEvent event){ LivingEntity player = event.getPlayer(); World world = player.getEntityWorld(); MinecraftServer server = world.getServer(); CommandSource commandsource = server.getCommandSource(); // Static X Y Z Values until we can find biomes int px = 4226; int py = 67; // Above sea level but below clouds int pz = -79; if(!event.getPlayer().getEntityWorld().isRemote()){ server.getCommandManager().handleCommand(commandsource, "/tp " + player.getUniqueID() + " " + px + " " + py + " " + pz); player.sendMessage(new StringTextComponent("Have a nice trip"), player.getUniqueID()); } } I'm pretty sure its the server.getCommandManager().handleCommand part thats the problem but I have no idea as to why Thanks in advance folks
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.