Jump to content

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


Triphion

Recommended Posts

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

	@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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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? 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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

Link to comment
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.
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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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