<commit_before>package com.kylantraynor.mangostructures.structures;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

public class Kiln extends Structure implements InventoryHolder{
	
	static public Map<Material, Integer> cookingTimes = new HashMap<Material, Integer>();
	static public Map<Material, Integer> ingotWorth = new HashMap<Material, Integer>();
	static public Map<Material, Material> ingotKind = new HashMap<Material, Material>();
	
	
	public static void register(Material m, Material result, int amount){
		ingotWorth.put(m, amount);
		ingotKind.put(m, result);
	}
	
	private String shape;
	private Chimney chimney;
	private int speed = 2;
	
	
	public Kiln(Location l){
		super(l);
		loadShape();
	}
	
	public void update(){
		if(!isValidShape()) return;
		if(chimney == null){
			chimney = new Chimney(getChimneyStartLocation());
		}
		if(isActive()){
			chimney.updateConduit();
			chimney.puff(3);
		}
		if(tryConsumeFuel()){
			getNetherrackLocation().getBlock().getRelative(BlockFace.UP).setType(Material.FIRE);
			tryMelt();
		} else {
			getNetherrackLocation().getBlock().getRelative(BlockFace.UP).setType(Material.AIR);
		}
	}
	
	private void tryMelt() {
		List<Integer> ilist = getMeltableSlots();
		int i = (int) Math.floor((Math.random() * ilist.size()));
		if(isMeltable(getInventory().getItem(ilist.get(i)))){
			tryTransform(ilist.get(i));
		}
	}

	private boolean isActive() {
		return getNetherrackLocation().getBlock().getRelative(BlockFace.UP).getType() == Material.FIRE;
	}

	public boolean isInside(Location l){
		int minX = getLocation().getBlockX() - 1;
		int minY = getLocation().getBlockY() - 5;
		int minZ = getLocation().getBlockZ() - 1;
		int maxX = getLocation().getBlockX() + 1;
		int maxY = getLocation().getBlockY() + 1;
		int maxZ = getLocation().getBlockZ() + 1;
		return(l.getBlockX() <= maxX && l.getBlockX() >= minX &&
				l.getBlockY() <= maxY && l.getBlockY() >= minY &&
				l.getBlockZ() <= maxZ && l.getBlockZ() >= minZ);
	}
	
	public Location getChimneyStartLocation(){
		return getLocation().clone().add(0,1,0);
	}
	
	public Location getNetherrackLocation(){
		return getLocation().clone().add(0,-4,0);
	}<commit_msg>Fixed index out of bounds.<commit_after>package com.kylantraynor.mangostructures.structures;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;

public class Kiln extends Structure implements InventoryHolder{
	
	static public Map<Material, Integer> cookingTimes = new HashMap<Material, Integer>();
	static public Map<Material, Integer> ingotWorth = new HashMap<Material, Integer>();
	static public Map<Material, Material> ingotKind = new HashMap<Material, Material>();
	
	
	public static void register(Material m, Material result, int amount){
		ingotWorth.put(m, amount);
		ingotKind.put(m, result);
	}
	
	private String shape;
	private Chimney chimney;
	private int speed = 2;
	
	
	public Kiln(Location l){
		super(l);
		loadShape();
	}
	
	public void update(){
		if(!isValidShape()) return;
		if(chimney == null){
			chimney = new Chimney(getChimneyStartLocation());
		}
		if(isActive()){
			chimney.updateConduit();
			chimney.puff(3);
		}
		if(tryConsumeFuel()){
			getNetherrackLocation().getBlock().getRelative(BlockFace.UP).setType(Material.FIRE);
			tryMelt();
		} else {
			getNetherrackLocation().getBlock().getRelative(BlockFace.UP).setType(Material.AIR);
		}
	}
	
	private void tryMelt() {
		List<Integer> ilist = getMeltableSlots();
		if(ilist.size() == 0){
			return;
		}
		int i = (int) Math.floor((Math.random() * ilist.size()));
		if(isMeltable(getInventory().getItem(ilist.get(i)))){
			tryTransform(ilist.get(i));
		}
	}

	private boolean isActive() {
		return getNetherrackLocation().getBlock().getRelative(BlockFace.UP).getType() == Material.FIRE;
	}

	public boolean isInside(Location l){
		int minX = getLocation().getBlockX() - 1;
		int minY = getLocation().getBlockY() - 5;
		int minZ = getLocation().getBlockZ() - 1;
		int maxX = getLocation().getBlockX() + 1;
		int maxY = getLocation().getBlockY() + 1;
		int maxZ = getLocation().getBlockZ() + 1;
		return(l.getBlockX() <= maxX && l.getBlockX() >= minX &&
				l.getBlockY() <= maxY && l.getBlockY() >= minY &&
				l.getBlockZ() <= maxZ && l.getBlockZ() >= minZ);
	}
	
	public Location getChimneyStartLocation(){
		return getLocation().clone().add(0,1,0);
	}
	
	public Location getNetherrackLocation(){
		return getLocation().clone().add(0,-4,0);
	}
{'fraction_non_alphanumeric': 0.15045270660759005, 'fraction_numerical': 0.00558659217877095, 'mean_word_length': 4.827160493827161, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '2657438', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1756, 'n_words': 359}