<commit_before>package iguanaman.iguanatweaks.config;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.registry.GameRegistry;
import iguanaman.iguanatweaks.IguanaTweaks;
import iguanaman.iguanatweaks.util.IguanaJsonReader;

public class IguanaWeightsConfig {

    private static HashMap<String, Double> weights;

    public static void init(File file) {
        if(file.exists()) {
            weights = IguanaJsonReader.readWeightsJson(file);
        } else {
            try {
                if(file.createNewFile()) {
                    PrintWriter writer = new PrintWriter(file);
                    writer.println("[");
                    writer.println("]");
                    writer.close();
                }
            } catch(IOException e) {
                IguanaTweaks.log.error("There was an error in creating the weights.json file");
                e.printStackTrace();
            }
        }
    }

    /**
     * Obtains the weight of a given block or item, either specified in the <I>weights.json</I> file, or by using it's default value if a different one is not specified in the <I>weights.json</I> file.<br/>
     * Blocks' default value are based on their material, while all Items are one constant value.
     * @param stack The ItemStack to get the weight for
     * @return The weight of the block as a double
     */
    public static double getWeight(ItemStack stack) {
        if(weights != null && weights.containsKey(GameRegistry.findUniqueIdentifierFor(stack.getItem()).toString())) {
            return weights.get(GameRegistry.findUniqueIdentifierFor(stack.getItem()).toString());
        } else {
            return getDefaultWeight(stack);
        }
    }

    private static double getDefaultWeight(ItemStack stack) {
        if(!(stack.getItem() instanceof ItemBlock)) {
            return 1D / 64D;
        }

        Block block = Block.getBlockFromItem(stack.getItem());
        Material blockMaterial = block.getMaterial();

        if(blockMaterial == Material.iron || blockMaterial == Material.anvil) {
            return 1.5D;
        } else if(blockMaterial == Material.rock) {<commit_msg>Potentially fixes #42.<commit_after>package iguanaman.iguanatweaks.config;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.registry.GameRegistry;
import iguanaman.iguanatweaks.IguanaTweaks;
import iguanaman.iguanatweaks.util.IguanaJsonReader;

public class IguanaWeightsConfig {

    private static HashMap<String, Double> weights;

    public static void init(File file) {
        if(file.exists()) {
            weights = IguanaJsonReader.readWeightsJson(file);
        } else {
            try {
                if(file.createNewFile()) {
                    PrintWriter writer = new PrintWriter(file);
                    writer.println("[");
                    writer.println("]");
                    writer.close();
                }
            } catch(IOException e) {
                IguanaTweaks.log.error("There was an error in creating the weights.json file");
                e.printStackTrace();
            }
        }
    }

    /**
     * Obtains the weight of a given block or item, either specified in the <I>weights.json</I> file, or by using it's default value if a different one is not specified in the <I>weights.json</I> file.<br/>
     * Blocks' default value are based on their material, while all Items are one constant value.
     * @param stack The ItemStack to get the weight for
     * @return The weight of the block as a double
     */
    public static double getWeight(ItemStack stack) {
        if(weights != null && weights.containsKey(Item.itemRegistry.getNameForObject(stack.getItem()))) {
            return weights.get(GameRegistry.findUniqueIdentifierFor(stack.getItem()).toString());
        } else {
            return getDefaultWeight(stack);
        }
    }

    private static double getDefaultWeight(ItemStack stack) {
        if(!(stack.getItem() instanceof ItemBlock)) {
            return 1D / 64D;
        }

        Block block = Block.getBlockFromItem(stack.getItem());
        Material blockMaterial = block.getMaterial();

        if(blockMaterial == Material.iron || blockMaterial == Material.anvil) {
            return 1.5D;
        } else if(blockMaterial == Material.rock) {
{'fraction_non_alphanumeric': 0.10150375939849623, 'fraction_numerical': 0.002506265664160401, 'mean_word_length': 2.5239146431199413, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '7660972', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1291, 'n_words': 336}