Jump to content

Server Client Synchro Strange Problem with entity


Kloonder

Recommended Posts

So I am here in my Item Class:

 

Entity entity;
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ) {
	if(entity == null){
		System.out.println(FMLCommonHandler.instance().getEffectiveSide() + "Take");
		takeBlock(world, pos, hitX, hitY, hitZ, 3);
	}else{
		if(entity instanceof EntityNotFallingBlock){
			System.out.println(FMLCommonHandler.instance().getEffectiveSide() + "Place");
			world.setBlockState(new BlockPos(entity), ((EntityNotFallingBlock) entity).theBlock);
			entity.setDead();
			entity = null;
		}
	}
	return true;

}

@Override
public void onUpdate(ItemStack stack, World world, Entity player, int itemSlot, boolean isSelected) {
//		if(blockPlaced){
//			entity = null;
//			blockPlaced = false;
//		}
	if(!stack.hasTagCompound()){
		stack.setTagCompound(new NBTTagCompound());
	}
	NBTTagCompound nbt = stack.getTagCompound();
	if(player instanceof EntityPlayer){
		if(((EntityPlayer) player).getCurrentEquippedItem() == stack){
			if(entity != null){
				boolean flag = true;
				if(entity instanceof EntityNotFallingBlock){
					if(((EntityNotFallingBlock) entity).getAllowFall()){
						flag = false;
					}
				}
				if(flag){
					int far = 5;
					if(player.rayTrace(far, 1) != null){
						if(player.rayTrace(far, 1).hitVec != null){
							MovingObjectPosition mop = player.rayTrace(far, 1);
							Vec3 hit = mop.hitVec;
							int side = mop.sideHit.getIndex();	
							switch(side){
							case 0:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord - 1, (int)hit.zCoord - 0.5);
								break;
							case 1:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 2:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 3:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord + 0.5);
								break;
							case 4:
								entity.setPositionAndUpdate((int)hit.xCoord - 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							case 5:
								entity.setPositionAndUpdate((int)hit.xCoord + 0.5, (int)hit.yCoord, (int)hit.zCoord - 0.5);
								break;
							}
						}
					}
				}
			}
		}
	}
}

 

I know the Entity entity is not the best solution, if this is the problem I'm sorry, but the problem is, when I use my item on a block, it takes it on client(or the other way around), and places it on server, if I delete the code which should place the block, it works, but thats not a solution :/

 

Should I try with network, but I mean the onItemUsed is called the exact same way on both server and client, so it makes no sense to me

Creator of Extra Shoes

 

Watch out, I'm total jerk, and I'll troll anybody if it feels like its necessary. Pls report me then

Link to comment
Share on other sites

Why not read what people told you in the first post on this?

 

Someone chimed in and told you to add a check for side in it  'if (!world.isRemote()).

 

Go delete entity.  Its not that is a bad way to do it, it is flat wrong.  Entity will always be wrong the way you are using it.

Long time Bukkit & Forge Programmer

Happy to try and help

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



×
×
  • Create New...

Important Information

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