Jump to content

Recommended Posts

Posted

I have a question, it seems like you cant give a player any motion in this context, it works perfectly with a pig or something like that, but a player doen't want to fly away, thats weird

 

@Override
public void onLeftClick(World world, ItemStack stack, EntityLivingBase player) {
	NBTTagCompound nbt = stack.getTagCompound();
	if(!world.isRemote){
		Entity entity = null;
		if(nbt.getString("EntityID") != ""){
			WorldServer server = (WorldServer) world;
			entity = server.getEntityFromUuid(UUID.fromString(nbt.getString("EntityID")));
		}
		if(nbt.getBoolean("SomethingTaken")){
			if(entity != null){
				if(entity instanceof EntityNotFallingBlock){
					EntityBlock entityBlock = new EntityBlock(world, player, ((EntityNotFallingBlock) entity).getBlock());
					entityBlock.tileEntityData = ((EntityNotFallingBlock) entity).tileEntityData;
					entityBlock.posX = entity.posX;
					entityBlock.posY = entity.posY;
					entityBlock.posZ = entity.posZ;
					world.spawnEntityInWorld(entityBlock);
					stack.setTagCompound(new NBTTagCompound());
					entity.setDead();
				}else{
					stack.setTagCompound(new NBTTagCompound());
					float f = 2;
					if(entity instanceof EntityPlayer){
						double motionX = (double)(-MathHelper.sin(player.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float)Math.PI) * f);
						double motionZ = (double)(MathHelper.cos(player.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float)Math.PI) * f);
						double motionY = (double)(-MathHelper.sin((player.rotationPitch / 180.0F * (float)Math.PI) * f));
						MoreMinecraft.network.sendTo(new MessageToClient(1, motionX, motionY, motionZ), (EntityPlayerMP) player);
					}else{
						entity.motionX = (double)(-MathHelper.sin(player.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float)Math.PI) * f);
						entity.motionZ = (double)(MathHelper.cos(player.rotationYaw / 180.0F * (float)Math.PI) * MathHelper.cos(player.rotationPitch / 180.0F * (float)Math.PI) * f);
						entity.motionY = (double)(-MathHelper.sin((player.rotationPitch / 180.0F * (float)Math.PI) * f));
					}
				}
			}
		}
	}
}

 

And yes the method gets called

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

Posted

Well I did, but it doesn't work

The player just dropps to ground, as I remember correctly, the motion handling is done by client?

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

Posted

Well I didn't find the solution so far, but what I also found out is, that you can't giva a player a potion effect only on server side, so you can only make the player move if the client agrees with that, thats why there can be a NoKnockBack hack, because the client doen't react on the motion change, but that doen't help me, my idea was, to give the player an Item, which makes him move, but that won't work if he has full inventory, so I don't have any idea what to do

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

Posted

Well, I think thats bad code of Mojang, because in a game like CSGO, everything has to be handled by server, otherways player would start hacking, but well, its not the time to dicuss why minecraft is coded bad. Anyone has an idea how to make the player knockback?

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

Posted

Minecraft, and CS:GO in that matter, get input on the client. If you send that to the server, move the player in there, and then notify the player, you get some stuttering on the client. To solve this, they let the client make predictions about the player movement, and then every once in a while the server notifys the client and changes his position the the correct one if the client is wrong. This way, player movement is so smooth, even when there is server lag. So, always do movement on both the client and server.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Here a code from old versions of my mod.. see if this works for you. Used on leftClickEntity of an item...

 

 

    
    public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) 
    {
    	if(entity instanceof EntityLivingBase)
    		((EntityLivingBase) entity).knockBack(player, 30, player.posX - entity.posX, player.posZ - entity.posZ);
    	
    	return false;
    }

// BSc CIS, hardcore gamer and a big fan of Minecraft.

 

TmzOS ::..

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.