Jump to content

How to toggle off a function on unequip


Robosphinx

Recommended Posts

How might I toggle off my night vision when the player unequips my helm? I've currently got a keybind that only toggles the night vision on and off when the helmet is equipped but when the player unequips the helm the night vision stays toggled on, which could be used as an exploit :(

 

Anyway, here's the code I'm using in the helmet class:

 

private float regBrightness;
public boolean nightVisionToggle;

@Override
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) {
	if(player.getCurrentItemOrArmor(4) !=null) {
		ItemStack helmet = player.getCurrentItemOrArmor(4);

		if(helmet.getItem() == RoboEye.diamondEyeHelm && VisionKeyBind.keyPressed) {
			nightVisionToggle = !nightVisionToggle;
			this.mc.sndManager.playSoundFX("random.click", 1.0F, 1.0F);
			VisionKeyBind.keyPressed = false;
			if (nightVisionToggle) {
				regBrightness = mc.gameSettings.gammaSetting;
				mc.gameSettings.gammaSetting = 1500.0F;
			} else if (!nightVisionToggle) {
				mc.gameSettings.gammaSetting = regBrightness;
			}
		}
	}
}

 

 

And here's the relevant part of my keybind handler:

 

 

public boolean keyHasBeenPressed = false;
public static boolean keyPressed = false;

@Override
    public void keyDown(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd, boolean isRepeat)
    {
        keyHasBeenPressed = true;
    }
    @Override
    public void keyUp(EnumSet<TickType> types, KeyBinding kb, boolean tickEnd)
    {
            if (keyHasBeenPressed) {
            	keyHasBeenPressed = false;
            	keyPressed = true;
            }

 

The further a society drifts from the truth, the more it hates those who speak it.

Link to comment
Share on other sites

onUpdate is called for ALL inventory items.

onEntityItemUpdate is called for dropped items.

 

You'll need to use both to insure that the effect is removed.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hey draco, thanks for your reply. I think what you're referencing is if the item itself has an effect if I'm not mistaken. However, I've got a night vision mode that is only toggle-able when the helmet is equipped. What I had in mind was when the player takes off the helmet the toggle is turned off as well. If this is what you were pointing me to, please explain just a tad so I can get this sucker exploit free :P

 

Cheers!

Robosphinx

The further a society drifts from the truth, the more it hates those who speak it.

Link to comment
Share on other sites

When the helmet comes off, the player can only do one of two things with it:

a) add it to their regular inventory

b) drop it on the ground

 

If they add it to their regular inventory, the item will receive an onUpdate call every tick.

If they drop it on the ground, the item will receive an onEntityItemUpdate call every tick (or so; I have a vague recollection that it was more like once every 4, but you only need a once-off so it doesn't matter).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Works perfectly for what I need it to do, thanks. Draco, I feel like a noob now you say that, overrode those functions and everything works perfectly now.

 

Here's what I did in the codemabobs:

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5){
	nightVisionToggle = false;
	VisionKeyBind.keyPressed = false;
	mc.gameSettings.gammaSetting = regBrightness;		
}

@Override
public boolean onEntityItemUpdate(EntityItem entityItem){
	nightVisionToggle = false;
	VisionKeyBind.keyPressed = false;
	mc.gameSettings.gammaSetting = regBrightness;
	return false;
}

The further a society drifts from the truth, the more it hates those who speak it.

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.