<commit_before>package rtk.common;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class CNBT {
    public static NBTTagCompound ensureCompound(ItemStack stack){
        if(!stack.hasTagCompound())
            stack.setTagCompound(new NBTTagCompound());
        return stack.getTagCompound();
    }

    public static int ensureInt(NBTTagCompound nbt, String name, int defaultValue){
        if(!nbt.hasKey(name))
            nbt.setInteger(name, defaultValue);
        return nbt.getInteger(name);
    }

    public static int ensureInt(NBTTagCompound nbt, String name){
        return ensureInt(nbt, name, 0);
    }

    public static NBTTagCompound NBTFromBlock(World world, BlockPos pos){
        NBTTagCompound NBT = new NBTTagCompound();

        NBT.setInteger("stateID", Block.getStateId(world.getBlockState(pos)));

        TileEntity tile = world.getTileEntity(pos);
        if(tile != null){
            NBTTagCompound tileNBT = new NBTTagCompound();
            tile.writeToNBT(tileNBT);
            NBT.setTag("tileEntity", tileNBT);
        }

        return NBT;
    }

    public static void placeBlockFromNBT(World world, BlockPos pos, NBTTagCompound NBT){
        IBlockState bs = Block.getStateById(NBT.getInteger("stateID"));

        world.setBlockState(pos, bs, 3);

        if(NBT.hasKey("tileEntity")){
            TileEntity tile = TileEntity.create(world, (NBTTagCompound)NBT.getTag("tileEntity"));
            world.setTileEntity(pos, tile);
        }
    }

    public static <T extends NBTBase> T ensure(NBTTagCompound nbt, String name, T defaultValue){
        if(!nbt.hasKey(name))
            nbt.setTag(name, defaultValue);
        return (T)nbt.getTag(name);
    }

}<commit_msg>Fixed tents breaking some items like doors on placement.<commit_after>package rtk.common;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class CNBT {
    public static NBTTagCompound ensureCompound(ItemStack stack){
        if(!stack.hasTagCompound())
            stack.setTagCompound(new NBTTagCompound());
        return stack.getTagCompound();
    }

    public static int ensureInt(NBTTagCompound nbt, String name, int defaultValue){
        if(!nbt.hasKey(name))
            nbt.setInteger(name, defaultValue);
        return nbt.getInteger(name);
    }

    public static int ensureInt(NBTTagCompound nbt, String name){
        return ensureInt(nbt, name, 0);
    }

    public static NBTTagCompound NBTFromBlock(World world, BlockPos pos){
        NBTTagCompound NBT = new NBTTagCompound();

        NBT.setInteger("stateID", Block.getStateId(world.getBlockState(pos)));

        TileEntity tile = world.getTileEntity(pos);
        if(tile != null){
            NBTTagCompound tileNBT = new NBTTagCompound();
            tile.writeToNBT(tileNBT);
            NBT.setTag("tileEntity", tileNBT);
        }

        return NBT;
    }

    public static void placeBlockFromNBT(World world, BlockPos pos, NBTTagCompound NBT){
        IBlockState bs = Block.getStateById(NBT.getInteger("stateID"));

        world.setBlockState(pos, bs, 2);

        if(NBT.hasKey("tileEntity")){
            TileEntity tile = TileEntity.create(world, (NBTTagCompound)NBT.getTag("tileEntity"));
            world.setTileEntity(pos, tile);
        }
    }

    public static <T extends NBTBase> T ensure(NBTTagCompound nbt, String name, T defaultValue){
        if(!nbt.hasKey(name))
            nbt.setTag(name, defaultValue);
        return (T)nbt.getTag(name);
    }

}
{'fraction_non_alphanumeric': 0.10740094692250186, 'fraction_numerical': 0.00099676052828308, 'mean_word_length': 3.146694214876033, 'pattern_counts': {'":': 0, '<': 5, '<?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': '504552', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1253, 'n_words': 252}