Jump to content

Recommended Posts

Posted

I'm trying to figure out how to disable the player movement keys when the left and right mouse buttons are being held down at the same time. When the player releases the mouse keys the movement keys will work again.

 

I have been reading the tutorials provided on the website explaining how mouse and keyboard input works.

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

 

I am looking for tips on how to apply this information to a mod. I'm not entirely sure where to start.

 

Thanks in advance to anyone who is able to help me out.

Posted

Hey thanks for the reply guys.

TheGreyGhost, I have read the thread you linked me and I figured I will get confused keys working first and then I will use that as a base to get my mod to work.

I am however having a few problems.

 

 

(In 1.7.10)

I have re-created your three classes ConfusedMovementInput, ClientTickHandler, (my main modding class)

 

- ConfusedMovementInput doesn't seem to have any errors

 

- ClientTickHandler has the following errors:

  -> It's telling me I need to create the interface "ITickHandler"

  -> It's telling me I need to create an interface or Class called "TickType"

 

- (main modding class called Shinobi) doesn't seem to have any errors

 

Here is the code:

package net.shinobi.mod;

import net.shinobi.mod.keyboard.ConfusedMovementInput;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;

@Mod(modid = Shinobi.MODID, version = Shinobi.VERSION)
public class Shinobi
{
    public static final String MODID = "Shinobi";
    public static final String VERSION = "Alpha 1.0";

    public static net.shinobi.mod.Shinobi instance;
    
    public static ConfusedMovementInput confusedMovementInput;
}

package net.shinobi.mod.keyboard;

import net.minecraft.util.MovementInput;

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

package net.shinobi.mod.keyboard;

import java.util.EnumSet;

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.item.ItemStack;
import net.shinobi.mod.Shinobi;

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 {
        Shinobi.confusedMovementInput = new ConfusedMovementInput(player.movementInput);
        player.movementInput = Shinobi.confusedMovementInput;
      }

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



  }

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

  

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

}

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.