Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I'm going to write a potion that perform like confusion. That I want to swap the client's keybindings that when he press "w" and want to move forward and then he actually press "s" that he move backward.

I'm searching for the code in the src but get confusion :'( :-[....

Could someone point out the code I'm looking for? Or some simple idea about that?

Hi

 

This is some background info that might be useful...

http://greyminecraftcoder.blogspot.com.au/2013/10/user-input.html

 

EntityPlayerSP.movementInput uses the method MovementInputFromOptions.updatePlayerMoveState(), so if you create your own class ConfusedMovementInput extends MovementInputFromOptions, and store it in EntityPlayerSP.movementInput, you can turn confusion on or off

 

eg

 

public class ConfusedMovementInput extends MovementInputFromOptions {

public ConfusedMovementInput(MovementInput interceptedMovementInput) {
underlyingMovementInput = interceptedMovementInput;
}

@Override
public void updatePlayerMoveState() {
  underlyingMovementInput.updatedPlayerMoveState();

        this.jump = underlyingMovementInput.jump;
        this.sneak = underlyingMovementInput.sneak;

        if (!confused) {
          this.moveStrafe = underlyingMovementInput.moveStrafe;
          this.moveForward = underlyingMovementInput.moveForward;
        } else {
            // swap moveStrafe, moveForward, or make them negative, etc
        }

}

public void setConfusion(boolean newConfused) {
  confused = newConfused;
}

protected MovementInput underlyingMovementInput;
private boolean confused = false;

}

 

And somewhere else in your code you execute

 

ConfusedMovementInput myInput = new ConfusedMovementInput(entityPlayerSP.movementInput);

entityPlayerSP.movementInput =myInput;

 

and then myInput.setConfusion(true/false) to turn confusion on or off.

 

You can access entityPlayerSP from

Minecraft.getMinecraft().thePlayer

 

I haven't tried to execute this code, but you get the idea?  The mix of composition and inheritance is a bit clumsy because of the private GameSettings but it should still work.  I have used something very similar for other keybindings (https://gist.github.com/TheGreyGhost/7033821) and it worked great.

 

-TGG

 

 

 

  • Author

I've tried your code. But it seems not working.

I try to replace the movement input while the player join the world. And as the log I see that I replace it successfully. But the updatePlayerMoveState() of the new class did not invoke. dont know why.

I make a small change the it inhert from MovementInput, not MovementInputFromOptions. dont know if that is related.

Hi

 

Interesting.  I tried it in my mod and it works fine.  When I'm holding an item, left and right are swapped.  When I'm not holding an item, left and right are normal.

 

-TGG

 

/**
* User: The Grey Ghost
* Date: 10/11/13
*/
public class ConfusedMovementInput extends MovementInput
{
  public ConfusedMovementInput(MovementInput interceptedMovementInput)
  {
    underlyingMovementInput = interceptedMovementInput;
  }

  @Override
  public void updatePlayerMoveState() {
    underlyingMovementInput.updatePlayerMoveState();

    this.jump = underlyingMovementInput.jump;
    this.sneak = underlyingMovementInput.sneak;

    if (!confused) {
      this.moveStrafe = underlyingMovementInput.moveStrafe;
      this.moveForward = underlyingMovementInput.moveForward;
    } else {
      this.moveStrafe = -underlyingMovementInput.moveStrafe;           //swap left and right
      this.moveForward = underlyingMovementInput.moveForward;
    }
  }

  public void setConfusion(boolean newConfused) {
    confused = newConfused;
  }

  protected MovementInput underlyingMovementInput;
  private boolean confused = false;
}

/**
* User: The Grey Ghost
* Date: 2/11/13
*/
public class ClientTickHandler implements ITickHandler {

  public EnumSet<TickType> ticks()
  {
    return EnumSet.of(TickType.CLIENT);
  }

  public void tickStart(EnumSet<TickType> type, Object... tickData)
  {
    if (!type.contains(TickType.CLIENT)) return;

    EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
    if (player != null) {
      if (player.movementInput instanceof ConfusedMovementInput) {
      } else {
        SpeedyToolsMod.confusedMovementInput = new ConfusedMovementInput(player.movementInput);
        player.movementInput = SpeedyToolsMod.confusedMovementInput;
      }

      ItemStack heldItem = player.getHeldItem();
      if (heldItem != null) {
        SpeedyToolsMod.confusedMovementInput.setConfusion(true);
      } else {
        SpeedyToolsMod.confusedMovementInput.setConfusion(false);
      }
    }



  }

  public void tickEnd(EnumSet<TickType> type, Object... tickData)
  {
    }

  }

  public String getLabel()
  {
    return "ClientTickHandler";
  }

}

@Mod(modid="SpeedyToolsMod", name="Speedy Tools Mod", version="0.0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=true, channels={"SpeedyTools"}, packetHandler = PacketHandler.class)
public class SpeedyToolsMod {

  // The instance of your mod that Forge uses.
  @Mod.Instance("SpeedyToolsMod")
  public static speedytools.SpeedyToolsMod instance;


  public static ConfusedMovementInput confusedMovementInput;

 

}

  • Author

Hi.

I've try you code and it works.

I replace it in the event EntityJoinWorldEvent. May be it's before the initialization of the player's movementInput. It seems that I should go to see how MC runs.

Anyway it works, thx.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.