Jump to content

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


Recommended Posts

Posted (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 by Triphion
Posted

Because you never told the server what you were doing.

 

Remember:

The client is always a lying, cheating bastard.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (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 by Triphion
Posted

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.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
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.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (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 by Triphion
Posted
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.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

Look at the vanilla Chorus Fruit code

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (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 by Triphion
Posted (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 by Triphion
Posted (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 by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (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 by Triphion
Posted
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

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
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? 

Posted (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 by Triphion
Posted

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);
}

 

Posted

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.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Announcements



×
×
  • Create New...

Important Information

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