Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.11.2] Server won't let me update my teleport position
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 2
Triphion

[1.11.2] Server won't let me update my teleport position

By Triphion, September 29, 2018 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 29, 2018 (edited)

So to get rid of a misunderstanding here, i can use the item, and it does teleport me if i click on the ground or something like 5 blocks away. However if i click beyond that then i will teleport to the position im looking at but right after the server will teleport me straight back to my beginning-position. It works on singleplayer, and the raytrace is further away than 5 blocks, it's actually a raytrace distance of 22 blocks. Any help would be much appreciated. 

	@Override
	public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
	{
		if(!playerIn.world.isRemote)
		{
			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
			double x = pos.getBlockPos().getX();
			double y = pos.getBlockPos().getY() + 1.0D;
			double z = pos.getBlockPos().getZ();
			playerIn.setPositionAndUpdate(x, y, z);
			worldIn.updateEntities();
			playerIn.getHeldItem(handIn).damageItem(1, playerIn);
			
			return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
		}
		
		else if(playerIn.world.isRemote)
		{
			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
			double x = pos.getBlockPos().getX();
			double y = pos.getBlockPos().getY() + 1.0D;
			double z = pos.getBlockPos().getZ();
			playerIn.setPositionAndUpdate(x, y, z);
			worldIn.updateEntities();
			playerIn.getHeldItem(handIn).damageItem(1, playerIn);
			
			return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
		}
		
		return new ActionResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
	}

 

Edited September 29, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 14011 posts
Posted September 29, 2018

Because you never told the server what you were doing.

 

Remember:

The client is always a lying, cheating bastard.

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 29, 2018 (edited)

But i don't understand that part, i can still teleport if i look into the ground like 5 blocks forward, but not any more than that. Why is that? As you can see, my raytrace is far more than 5 blocks. 

Edited September 29, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2090

Draco18s

Draco18s    2090

  • Reality Controller
  • Draco18s
  • Members
  • 2090
  • 14011 posts
Posted September 29, 2018

Because the onItemRightClick method is only called when the player has their mouse over a block and that only happens when the block is within their reach.

  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    677

Animefan8888

Animefan8888    677

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 677
  • 5746 posts
Posted September 29, 2018
Just now, Draco18s said:

Because the onItemRightClick method is only called when the player has their mouse over a block and that only happens when the block is within their reach.

I believe you are thinking of onItemUse instead here Draco.

 

58 minutes ago, Triphion said:

worldIn.updateEntities();

You shouldn't be calling this.

59 minutes ago, Triphion said:

if(!playerIn.world.isRemote)

Try only having this section.

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 29, 2018 (edited)
	@Override
	public ActionResult onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
	{
		if(!playerIn.world.isRemote)
		{
			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
			double x = pos.getBlockPos().getX();
			double y = pos.getBlockPos().getY() + 1.0D;
			double z = pos.getBlockPos().getZ();
			playerIn.setPositionAndUpdate(x, y, z);
			playerIn.getHeldItem(handIn).damageItem(1, playerIn);
			
			return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
		}
		
		return new ActionResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
	}

I tried this, but now it doesn't work at all in server. Also tried with only checking if(!worldIn.isremote) but doesn't work in servers either. 

Edited September 29, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Animefan8888    677

Animefan8888

Animefan8888    677

  • Reality Controller
  • Animefan8888
  • Forge Modder
  • 677
  • 5746 posts
Posted September 29, 2018
4 minutes ago, Triphion said:

I tried this, but now it doesn't work at all in server. 

Change the method Entity#setPositionAndUpdate to setPosition and use World#updateEntityWithOptionalForce wth the boolean parameter being true.

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 29, 2018
5 minutes ago, Animefan8888 said:

Change the method Entity#setPositionAndUpdate to setPosition and use World#updateEntityWithOptionalForce wth the boolean parameter being true.

Tried it, but server won't activate my item. And if i add the "else if(worldIn.isRemote)" i'm back where i started.

This is a gyazo gif of what happens: 

https://gyazo.com/789d6fcf8c9f3c05c3fcdfc191aa96a7

  • Quote

Share this post


Link to post
Share on other sites

Cadiboo    275

Cadiboo

Cadiboo    275

  • Reality Controller
  • Cadiboo
  • Members
  • 275
  • 3303 posts
Posted September 30, 2018 (edited)

Look at the vanilla Chorus Fruit code

Edited September 30, 2018 by Cadiboo
  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 30, 2018 (edited)
37 minutes ago, Cadiboo said:

Look at the corcusfruit code

What is that? I have no idea what that is. Could you explain it to me? 

EDIT: Oh, i realized that you meant the Minecraft item, sorry about that. I'll take a look. 

Edited September 30, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 30, 2018 (edited)

So i tried with console-printing and when im on the server it doesn't get called after the if(!worldIn.isRemote) check for some reason. 

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
	{
		scala.Console.print("Gets called. ");
		if (!worldIn.isRemote)
		{
			scala.Console.print("worki. ");
			
			RayTraceResult pos = playerIn.rayTrace(22.0D, 0.0F);
			double x = pos.getBlockPos().getX();
			double y = pos.getBlockPos().getY() + 1.0D;
			double z = pos.getBlockPos().getZ();
			
			if (playerIn.attemptTeleport(x, y, z)) 
			{
				scala.Console.print("Teleported. ");
				playerIn.getHeldItem(handIn).damageItem(1, playerIn);
			}
		}
		else{
		    return new ActionResult(EnumActionResult.FAIL, playerIn.getHeldItem(handIn));
		}
		
		return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
	}

Anything that seems to doesn't work on server here? 

 

EDIT: I got a message from the server window that there's a problem with my raytracing apparently? Doesn't that get called correctly on server side, am i missing some important raytracing check for serverside? 

Edited September 30, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Cadiboo    275

Cadiboo

Cadiboo    275

  • Reality Controller
  • Cadiboo
  • Members
  • 275
  • 3303 posts
Posted September 30, 2018 (edited)

...scala.Console????

Please set up and use a logger for your mod (An example of this is included in the example code that ships with every forge install). Try stepping through your code with the debugger

Edited September 30, 2018 by Cadiboo
  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 30, 2018 (edited)

Yes, that is the one. But now i realize the if(!worldIn.isRemote) but the raytracing isn't working serverside. Anything i'm missing? 

Quote

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
    {
        if (!worldIn.isRemote)
        {
            scala.Console.print("worki. ");
            
            EntityLivingBase player = ((EntityLivingBase)playerIn);
                
            RayTraceResult pos = player.rayTrace(22.0D, 20.0F);
            double x = pos.getBlockPos().getX();
            double y = pos.getBlockPos().getY() + 1.0D;
            double z = pos.getBlockPos().getZ();
                
                if (player.attemptTeleport(x, y, z)) 
                {
                    scala.Console.print("Teleported. ");
                    player.getHeldItem(handIn).damageItem(1, playerIn);
                }
            }
        else{
            return new ActionResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
        }
        
        return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
    }

Also, i added added a cast to the player saying it's an entitylivingbase, although the player class does extend entitylivingbase but i thought it could help just being even more specific. 

Edited September 30, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

Cadiboo    275

Cadiboo

Cadiboo    275

  • Reality Controller
  • Cadiboo
  • Members
  • 275
  • 3303 posts
Posted September 30, 2018
8 minutes ago, Cadiboo said:

Please set up and use a logger for your mod (An example of this is included in the example code that ships with every forge install). Try stepping through your code with the debugger

Find out why (you think that) it’s not working

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 30, 2018
49 minutes ago, Cadiboo said:

Find out why (you think that) it’s not working

Found it. 

java.util.concurrent.ExecutionException: java.lang.NoSuchMethodError: net.minecraft.entity.EntityLivingBase.rayTrace(DF)Lnet/minecraft/util/math/RayTraceResult;
	at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_151]
	at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_151]
	at net.minecraft.util.Util.runTask(Util.java:30) [Util.class:?]
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:754) [MinecraftServer.class:?]
	at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:402) [DedicatedServer.class:?]
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:699) [MinecraftServer.class:?]
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548) [MinecraftServer.class:?]
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
Caused by: java.lang.NoSuchMethodError: net.minecraft.entity.EntityLivingBase.rayTrace(DF)Lnet/minecraft/util/math/RayTraceResult;
	at com.triphion.ancient.items.ItemTheCosmician.onItemRightClick(ItemTheCosmician.java:45) ~[ItemTheCosmician.class:?]
	at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:213) ~[ItemStack.class:?]
	at net.minecraft.server.management.PlayerInteractionManager.processRightClick(PlayerInteractionManager.java:387) ~[PlayerInteractionManager.class:?]
	at net.minecraft.network.NetHandlerPlayServer.processTryUseItem(NetHandlerPlayServer.java:739) ~[NetHandlerPlayServer.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:43) ~[CPacketPlayerTryUseItem.class:?]
	at net.minecraft.network.play.client.CPacketPlayerTryUseItem.processPacket(CPacketPlayerTryUseItem.java:9) ~[CPacketPlayerTryUseItem.class:?]
	at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_151]
	at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_151]
	at net.minecraft.util.Util.runTask(Util.java:29) ~[Util.class:?]
	... 5 more
[14:11:24] [Server thread/FATAL]: Error executing task

This is the error and i have no idea how to fix it. The line that is the problem is the raytracing line that i talked about but i don't know more than this. 

This is line 45:

			RayTraceResult pos = player.rayTrace(22.0D, 20.0F);

Any ideas? 

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted September 30, 2018 (edited)

I do have a logger function, but only one that gets called preinit. If i want the logger function to get called, this way of doing it does work when im on singleplayer, however in server window, the log function never gets mentioned? 

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
	{
		if (!worldIn.isRemote)
		{
			EntityLivingBase player = ((EntityLivingBase)playerIn);
			
			RayTraceResult pos = player.rayTrace(22.0D, 20.0F);
			double x = pos.getBlockPos().getX();
			double y = pos.getBlockPos().getY() + 1.0D;
			double z = pos.getBlockPos().getZ();
			Utils.getLogger().info("Raytrace: " + pos.toString().substring(5));
				
				if (player.attemptTeleport(x, y, z)) 
				{
					player.getHeldItem(handIn).damageItem(1, playerIn);
				}
			}
		else{
		    return new ActionResult(EnumActionResult.PASS, playerIn.getHeldItem(handIn));
		}
		
        return new ActionResult(EnumActionResult.SUCCESS, playerIn.getHeldItem(handIn));
	}

 

Edited September 30, 2018 by Triphion
  • Quote

Share this post


Link to post
Share on other sites

DefectiveProgram    2

DefectiveProgram

DefectiveProgram    2

  • Tree Puncher
  • DefectiveProgram
  • Members
  • 2
  • 8 posts
Posted September 30, 2018

You're trying to call a client only function on the server.

 

@Nullable
@SideOnly(Side.CLIENT)
public RayTraceResult rayTrace(double blockReachDistance, float partialTicks)
{
    Vec3d vec3d = this.getPositionEyes(partialTicks);
    Vec3d vec3d1 = this.getLook(partialTicks);
    Vec3d vec3d2 = vec3d.addVector(vec3d1.xCoord * blockReachDistance, vec3d1.yCoord * blockReachDistance, vec3d1.zCoord * blockReachDistance);
    return this.world.rayTraceBlocks(vec3d, vec3d2, false, false, true);
}

 

  • Quote

Share this post


Link to post
Share on other sites

jabelar    591

jabelar

jabelar    591

  • Reality Controller
  • jabelar
  • Members
  • 591
  • 3266 posts
Posted September 30, 2018

As mentioned you are trying to call a client method. Just copy the code (and any further client-only code involved) into your own method. You'll also need to modify the part regarding the reach distance. Overall ray-tracing is pretty simple concept so you should be able to implement your own version.

  • Quote

Share this post


Link to post
Share on other sites

Triphion    0

Triphion

Triphion    0

  • Stone Miner
  • Triphion
  • Members
  • 0
  • 95 posts
Posted October 1, 2018
21 hours ago, DefectiveProgram said:

You're trying to call a client only function on the server.

 


@Nullable
@SideOnly(Side.CLIENT)
public RayTraceResult rayTrace(double blockReachDistance, float partialTicks)
{
    Vec3d vec3d = this.getPositionEyes(partialTicks);
    Vec3d vec3d1 = this.getLook(partialTicks);
    Vec3d vec3d2 = vec3d.addVector(vec3d1.xCoord * blockReachDistance, vec3d1.yCoord * blockReachDistance, vec3d1.zCoord * blockReachDistance);
    return this.world.rayTraceBlocks(vec3d, vec3d2, false, false, true);
}

 

 

14 hours ago, jabelar said:

As mentioned you are trying to call a client method. Just copy the code (and any further client-only code involved) into your own method. You'll also need to modify the part regarding the reach distance. Overall ray-tracing is pretty simple concept so you should be able to implement your own version.

Worked for me. A massive thanks to everyone who helped me! :D

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • BitNet_
      [1.12.2] Exception loading model

      By BitNet_ · Posted 10 minutes ago

      That hasn't worked for me, I still get the model registering error even when adding the code to my build.gradle
    • JMAS
      Recompile mod with newer version of Java?

      By JMAS · Posted 13 minutes ago

      Thank you for your quick and direct response.   After making the changes directed, I now receive the following error: Execution failed for task ':runClient'. > Process 'command 'C:\Program Files\Java\jdk1.8.0_231\bin\java.exe'' finished with non-zero exit value 1    No new debug.log was generated in run/logs. 😕
    • Lea9ue
      .setRepairItem not work

      By Lea9ue · Posted 27 minutes ago

      In your item class you should have something like...   @Override public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { if (toRepair.getItem().equals("YOUR ITEM") && repair.getItem().equals("WHAT REPAIRS IT")) { return true; } else { return false; } }  
    • Electrodynamite12
      .setRepairItem not work

      By Electrodynamite12 · Posted 34 minutes ago

      I made the ToolMaterial, and i add the .setRepairItem method, announced the ItemStack, where indicated the target item. Maybe i made something wrong? public static Item.ToolMaterial HLOMINITE = EnumHelper.addToolMaterial("another_test:hlominite", 5, 1000, 50.0F, 16.0F, 76).setRepairItem(new ItemStack(ItemsRegister.HLOMINGOT));
    • diesieben07
      [1.12.2] Exception loading model

      By diesieben07 · Posted 1 hour ago

  • Topics

    • BitNet_
      2
      [1.12.2] Exception loading model

      By BitNet_
      Started 8 hours ago

    • JMAS
      6
      Recompile mod with newer version of Java?

      By JMAS
      Started 10 hours ago

    • Electrodynamite12
      1
      .setRepairItem not work

      By Electrodynamite12
      Started 34 minutes ago

    • Hemeroahz
      5
      1.12.2 Crashing Upon Running Forge

      By Hemeroahz
      Started November 27, 2017

    • zhubwat
      9
      Forge not creating version .jar files?

      By zhubwat
      Started January 25, 2016

  • Who's Online (See full list)

    • JMAS
    • imacatlolol
    • saxon564
    • BitNet_
    • AJGingy
    • Lordyammer
    • ItzGenes
    • Nuparu00
    • M1ntcraft3r
    • fcelon
    • KolonilGamer
    • Choonster
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.11.2] Server won't let me update my teleport position
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community