Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to sub forum page

General forum

Non-course related subjects

3. Programming help

PlayerName moved wrongly!

  • 2014-03-23 18:50:37
    Hallo, I'm working on a Item for my mod that's basically flashed the player through a 1 block thick wall or just flashes the player a bit forward. This works fine in creativemode but when I go into survival and try to flash through a wall, I get flashed through like intended but just for a quarter of a second I get teleported back to my original position. The console prints out; "PlayerName" moved wrongly! Its like minecraft has this inbuild thing to make it harder for people to glitch through walls. How do I get the Minecraft to ignore this when I'm in survival and this item is getting used?

    here my codes:

    package Clockwork.Items.Item;

    import net.minecraft.client.renderer.texture.IconRegister;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.server.MinecraftServer;
    import net.minecraft.util.Icon;
    import net.minecraft.util.MathHelper;
    import net.minecraft.world.World;
    import net.minecraftforge.event.Cancelable;
    import Clockwork.Items.Techincal.ItemInfo;
    import Clockwork.Main.CWCreativeTabs;
    import cpw.mods.fml.relauncher.Side;
    import cpw.mods.fml.relauncher.SideOnly;

    public class Clock extends Item
    {
        public Clock(int id)
        {
            super(id);
            setCreativeTab(CWCreativeTabs.ClockworkTab);
            setMaxStackSize(1);
            setUnlocalizedName(ItemInfo.ClockUnlocalized);
        }
        
        @Override
        @SideOnly(Side.CLIENT)
        public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase target)
        {    
            if (!target.worldObj.isRemote)
            {
                target.motionX = (target.posX - player.posX / 1);
                target.motionZ = (target.posZ - player.posZ / 1);
                target.motionY = (target.posY - player.posY / 1);
            }
            
            return false;
        }
        
        @Override
        @SideOnly(Side.CLIENT)
        public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hit)
        {
            player.addChatMessage("§3§lFlash §3§5Activated");
            player.inventory.consumeInventoryItem(Item.enderPearl.itemID);
            
            double X = player.posX;
    double Z = player.posZ;

    int test = MathHelper.floor_double((double)((player.rotationYaw * 4F) / 360F) + 0.5D) & 3;
    if (test == 1) {
    X = X - 2.0;
    }
    if (test == 3) {
    X = X + 2.0;
    }
    if (test == 2) {
    Z = Z - 2.0;
    }
    if (test == 0) {
    Z = Z + 2.0;
    }
    player.moveEntity(X, 0.0, Z);
    player.setPosition(X, player.posY, Z);

            if (player.onGround = true)
                {
                    player.fallDistance = 0;
                }
                return true;
        }
        
        @SideOnly(Side.CLIENT)
        private Icon ClockIcons;
        
        @Override
        @SideOnly(Side.CLIENT)
        public void registerIcons(IconRegister register)
        {
            ClockIcons = register.registerIcon(ItemInfo.Texture_Location + ":" + ItemInfo.ClockTexture);
        }
        
        @Override
        @SideOnly(Side.CLIENT)
        public Icon getIconFromDamage (int dmg)
        {
            return ClockIcons;
        }
    }
  • 2014-03-25 22:39:44
    SHORT ANSWER: remove some of those @SideOnly(Side.CLIENT) because movement is handled by the server and this way you are creating illegal client only movements.

    LONG ANSWER: the way a network/multiplayer game works is that all the movement/physics is handled by the (one) server and not by the (lots of) clients, but a game would be terrible if every time you (or any other moving thing/player) wanted to move you had to send a "I want to move" request to the server and get back a "Ok! You are now there" response, because it takes time to do this. So what happens is that the client makes guesses about how stuff will move based on their current and previous position and speed. Then every now and then the server and the client will synchronize and you'll end up in the right position that is more or less the position the client had guessed, so everything runs smooth (unless you have a bad connection). If a client for some reason has some weird values of the position, that are completely different from what the server sent you, you'll get an error.
    What happens in your case is this: you are using plenty of "@SideOnly(Side.CLIENT)" this means that all the instructions will be only executed by the client. When you move the player you change the position value in a way that is not expected by the server and thus you get the "Player moved wrongly" error. This doesn't happen in creative because those errors are not checked if a player is in creative mode. You should change your code removing all the unnecessary SideOnly annotation (but leave them where they are needed) and make sure you only move the player on the server side.
  • Log in or sign up to reply to this thread