<commit_before>/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package net.wurstclient.features.mods;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiInventory;
import net.minecraft.init.Items;
import net.minecraft.init.MobEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketHeldItemChange;
import net.minecraft.network.play.client.CPacketPlayer;
import net.minecraft.network.play.client.CPacketPlayerTryUseItem;
import net.minecraft.potion.PotionEffect;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.EnumHand;
import net.wurstclient.compatibility.WConnection;
import net.wurstclient.compatibility.WMinecraft;
import net.wurstclient.compatibility.WPlayerController;
import net.wurstclient.events.listeners.UpdateListener;
import net.wurstclient.features.HelpPage;
import net.wurstclient.features.Mod;
import net.wurstclient.features.SearchTags;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;

@SearchTags({"AutoPotion", "auto potion", "auto splash potion"})
@HelpPage("Mods/AutoSplashPot")
@Mod.Bypasses
public final class AutoSplashPotMod extends Mod implements UpdateListener
{
	public float health = 18F;
	
	public AutoSplashPotMod()
	{
		super("AutoSplashPot",
			"Automatically throws splash healing potions if your health is below the set value.");
	}
	
	@Override
	public void initSettings()
	{
		settings.add(
			new SliderSetting("Health", health, 2, 20, 1, ValueDisplay.INTEGER)
			{
				@Override
				public void update()
				{
					health = (float)getValue();
				}
			});
	}
	
	@Override
	public void onEnable()
	{
		wurst.events.add(UpdateListener.class, this);
	}
	
	@Override
	public void onUpdate()
	{
		// update timer
		updateMS();
		
		// check if no container is open
		if(mc.currentScreen instanceof GuiContainer
			&& !(mc.currentScreen instanceof GuiInventory))
			return;
		
		// check if health is low
		if(WMinecraft.getPlayer().getHealth() >= health)
			return;
		
		// find health potions
		int potionInInventory = findPotion(9, 36);
		int potionInHotbar = findPotion(36, 45);
		
		// check if any potion was found
		if(potionInInventory == -1 && potionInHotbar == -1)
			return;
		
		if(hasTimePassedM(500))
			if(potionInHotbar != -1)
			{
				// throw potion in hotbar
				int oldSlot = WMinecraft.getPlayer().inventory.currentItem;
				WConnection.sendPacket(new CPacketPlayer.Rotation(
					WMinecraft.getPlayer().rotationYaw, 90.0F,
					WMinecraft.getPlayer().onGround));
				WConnection
					.sendPacket(new CPacketHeldItemChange(potionInHotbar - 36));
				mc.playerController.updateController();
				WConnection.sendPacket(
					new CPacketPlayerTryUseItem(EnumHand.MAIN_HAND));
				WConnection.sendPacket(new CPacketHeldItemChange(oldSlot));
				WConnection.sendPacket(new CPacketPlayer.Rotation(
					WMinecraft.getPlayer().rotationYaw,
					WMinecraft.getPlayer().rotationPitch,
					WMinecraft.getPlayer().onGround));
				
				// reset timer
				updateLastMS();
			}else
				// move potion in inventory to hotbar
				WPlayerController.windowClick_QUICK_MOVE(potionInInventory);
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
	}
	
	private int findPotion(int startSlot, int endSlot)
	{
		for(int i = startSlot; i < endSlot; i++)
		{
			ItemStack stack =
				WMinecraft.getPlayer().inventoryContainer.getSlot(i).getStack();
			if(stack != null && stack.getItem() == Items.SPLASH_POTION)
				for(PotionEffect effect : PotionUtils
					.getEffectsFromStack(stack))
					if(effect.getPotion() == MobEffects.INSTANT_HEALTH)
						return i;
		}
		return -1;
	}
}<commit_msg>Update AutoSplashPotMod<commit_after>/*
 * Copyright  2014 - 2017 | Wurst-Imperium | All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package net.wurstclient.features.mods;

import net.minecraft.item.ItemStack;
import net.minecraft.network.play.client.CPacketPlayer;
import net.wurstclient.compatibility.WPotionEffects;
import net.wurstclient.compatibility.WConnection;
import net.wurstclient.compatibility.WMinecraft;
import net.wurstclient.compatibility.WPlayerController;
import net.wurstclient.events.listeners.UpdateListener;
import net.wurstclient.features.Feature;
import net.wurstclient.features.HelpPage;
import net.wurstclient.features.Mod;
import net.wurstclient.features.SearchTags;
import net.wurstclient.features.special_features.YesCheatSpf.BypassLevel;
import net.wurstclient.settings.CheckboxSetting;
import net.wurstclient.settings.SliderSetting;
import net.wurstclient.settings.SliderSetting.ValueDisplay;
import net.wurstclient.utils.InventoryUtils;

@SearchTags({"AutoPotion", "auto potion", "auto splash potion"})
@HelpPage("Mods/AutoSplashPot")
@Mod.Bypasses
public final class AutoSplashPotMod extends Mod implements UpdateListener
{
	public final SliderSetting health =
		new SliderSetting("Health", 6, 0.5, 9.5, 0.5, ValueDisplay.DECIMAL);
	public CheckboxSetting ignoreScreen =
		new CheckboxSetting("Ignore screen", true);
	
	private int timer;
	
	public AutoSplashPotMod()
	{
		super("AutoSplashPot",
			"Automatically throws instant health splash potions if your health is lower than or equal to\n"
				+ "the set value.");
	}
	
	@Override
	public void initSettings()
	{
		settings.add(health);
		settings.add(ignoreScreen);
	}
	
	@Override
	public Feature[] getSeeAlso()
	{
		return new Feature[]{wurst.mods.potionSaverMod, wurst.mods.autoSoupMod};
	}
	
	@Override
	public void onEnable()
	{
		wurst.events.add(UpdateListener.class, this);
	}
	
	@Override
	public void onDisable()
	{
		wurst.events.remove(UpdateListener.class, this);
		timer = 0;
	}
	
	@Override
	public void onUpdate()
	{
		// search potion in hotbar
		int potionInHotbar = findPotion(0, 9);
		
		// check if any potion was found
		if(potionInHotbar != -1)
		{
			// check timer
			if(timer > 0)
			{
				timer--;
				return;
			}
			
			// check health
			if(WMinecraft.getPlayer().getHealth() > health.getValueF() * 2F)
				return;
			
			// check screen
			if(!ignoreScreen.isChecked() && mc.currentScreen != null)
				return;
			
			// save old slot
			int oldSlot = WMinecraft.getPlayer().inventory.currentItem;
			
			// throw potion in hotbar
			WMinecraft.getPlayer().inventory.currentItem = potionInHotbar;
			WConnection.sendPacket(
				new CPacketPlayer.Rotation(WMinecraft.getPlayer().rotationYaw,
					90.0F, WMinecraft.getPlayer().onGround));
			WPlayerController.processRightClick();
			
			// reset slot and rotation
			WMinecraft.getPlayer().inventory.currentItem = oldSlot;
			WConnection.sendPacket(
				new CPacketPlayer.Rotation(WMinecraft.getPlayer().rotationYaw,
					WMinecraft.getPlayer().rotationPitch,
					WMinecraft.getPlayer().onGround));
			
			// reset timer
			timer = 10;
			
			return;
		}
		
		// search potion in inventory
		int potionInInventory = findPotion(9, 36);
		
		// move potion in inventory to hotbar
		if(potionInInventory != -1)
			WPlayerController.windowClick_QUICK_MOVE(potionInInventory);
	}
	
	@Override
	public void onYesCheatUpdate(BypassLevel bypassLevel)
	{
		switch(bypassLevel)
		{
			case GHOST_MODE:
			ignoreScreen.lock(() -> false);
			break;
			
			default:
			ignoreScreen.unlock();
			break;
		}
	}
	
	private int findPotion(int startSlot, int endSlot)
	{
		for(int i = startSlot; i < endSlot; i++)
		{
			ItemStack stack =
				WMinecraft.getPlayer().inventory.getStackInSlot(i);
			
			// filter out non-splash potion items
			if(!InventoryUtils.isSplashPotion(stack))
				continue;
			
			// search for instant health effects
			if(InventoryUtils.hasEffect(stack, WPotionEffects.INSTANT_HEALTH))
				return i;
		}
		
		return -1;
	}
}
{'fraction_non_alphanumeric': 0.10824742268041238, 'fraction_numerical': 0.008836524300441826, 'mean_word_length': 4.061490683229814, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6739980', 'n_tokens_mistral': 3046, 'n_tokens_neox': 2642, 'n_words': 569}