<commit_before>package com.creativemd.littletiles.client.gui.controls;

import com.creativemd.creativecore.common.gui.GuiControl;
import com.creativemd.creativecore.common.gui.controls.container.SlotControl;
import com.creativemd.littletiles.common.items.ItemBlockIngredient;
import com.creativemd.littletiles.common.utils.ingredients.BlockIngredientEntry;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class SlotControlBlockIngredient extends SlotControl {
	
	public SlotControlBlockIngredient(Slot slot) {
		super(slot);
	}
	
	public BlockIngredientEntry getIngredient() {
		return ItemBlockIngredient.loadIngredient(slot.getStack());
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public GuiControl createGuiControl() {
		GuiControl control = new GuiSlotControlBlockIngredient(slot.xPos, slot.yPos, this);
		return control;
	}
	
	@Override
	public boolean canMergeIntoInventory(Slot mergeSlot) {
		return super.canMergeIntoInventory(mergeSlot) && !mergeSlot.inventory.getName().equals("input");
	}
	
	public boolean isEntireBlock() {
		BlockIngredientEntry entry = getIngredient();
		if (entry != null && entry.value >= 1)
			return true;
		return false;
	}
	
	@Override
	public void transferIntoOtherInventory(int amount) {
		if (!isEntireBlock())
			super.transferIntoOtherInventory(amount);
		
		BlockIngredientEntry entry = getIngredient();
		ItemStack stack = entry.getItemStack();
		amount = Math.min(amount, (int) entry.value);
		stack.setCount(amount);
		
		mergeToOtherInventory(stack, false);
		if (!stack.isEmpty())
			mergeToOtherInventory(stack, true);
		
		if (!stack.isEmpty())
			amount -= stack.getCount();
		
		entry.value -= amount;
		ItemBlockIngredient.saveIngredient(slot.getStack(), entry);
	}
	
	@Override
	public void takeStack(boolean leftClick, InventoryPlayer inventoryplayer) {
		if (!isEntireBlock()) {
			super.takeStack(leftClick, inventoryplayer);
			return;
		}
		
		ItemStack hand = getPlayer().inventory.getItemStack();
		
		BlockIngredientEntry entry = getIngredient();
		ItemStack slotItem = entry.getItemStack();<commit_msg>Fixed crash when using shift right click in bag<commit_after>package com.creativemd.littletiles.client.gui.controls;

import com.creativemd.creativecore.common.gui.GuiControl;
import com.creativemd.creativecore.common.gui.controls.container.SlotControl;
import com.creativemd.littletiles.common.items.ItemBlockIngredient;
import com.creativemd.littletiles.common.utils.ingredients.BlockIngredientEntry;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class SlotControlBlockIngredient extends SlotControl {
	
	public SlotControlBlockIngredient(Slot slot) {
		super(slot);
	}
	
	public BlockIngredientEntry getIngredient() {
		return ItemBlockIngredient.loadIngredient(slot.getStack());
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public GuiControl createGuiControl() {
		GuiControl control = new GuiSlotControlBlockIngredient(slot.xPos, slot.yPos, this);
		return control;
	}
	
	@Override
	public boolean canMergeIntoInventory(Slot mergeSlot) {
		return super.canMergeIntoInventory(mergeSlot) && !mergeSlot.inventory.getName().equals("input");
	}
	
	public boolean isEntireBlock() {
		BlockIngredientEntry entry = getIngredient();
		if (entry != null && entry.value >= 1)
			return true;
		return false;
	}
	
	@Override
	public void transferIntoOtherInventory(int amount) {
		if (!isEntireBlock())
			super.transferIntoOtherInventory(amount);
		
		BlockIngredientEntry entry = getIngredient();
		if (entry == null)
			return;
		
		ItemStack stack = entry.getItemStack();
		amount = Math.min(amount, (int) entry.value);
		stack.setCount(amount);
		
		mergeToOtherInventory(stack, false);
		if (!stack.isEmpty())
			mergeToOtherInventory(stack, true);
		
		if (!stack.isEmpty())
			amount -= stack.getCount();
		
		entry.value -= amount;
		ItemBlockIngredient.saveIngredient(slot.getStack(), entry);
	}
	
	@Override
	public void takeStack(boolean leftClick, InventoryPlayer inventoryplayer) {
		if (!isEntireBlock()) {
			super.takeStack(leftClick, inventoryplayer);
			return;
		}
		
		ItemStack hand = getPlayer().inventory.getItemStack();
		
		BlockIngredientEntry entry = getIngredient();
		ItemStack slotItem = entry.getItemStack();
{'fraction_non_alphanumeric': 0.10848126232741617, 'fraction_numerical': 0.00043830813061582295, 'mean_word_length': 5.446327683615819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3877786', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1448, 'n_words': 259}