<commit_before>/*
 *    Copyright 2017 <NAME> (darkevilmac)
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.elytradev.teckle.common.tile;

import com.elytradev.teckle.client.gui.GuiFabricator;
import com.elytradev.teckle.common.TeckleMod;
import com.elytradev.teckle.common.TeckleObjects;
import com.elytradev.teckle.common.container.ContainerFabricator;
import com.elytradev.teckle.common.tile.base.IElementProvider;
import com.elytradev.teckle.common.tile.inv.AdvancedItemStackHandler;
import com.elytradev.teckle.common.util.BlueprintUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class TileFabricator extends TileEntity implements ITickable, IElementProvider {

    public AdvancedItemStackHandler stackHandler = new AdvancedItemStackHandler(18);
    public AdvancedItemStackHandler blueprint = new AdvancedItemStackHandler(1).withChangeListener(this::onBlueprintChanged).withSlotLimit(s -> 1).withInsertCheck((integer, stack) -> stack.getItem() == TeckleObjects.itemBlueprint);
    public IRecipe templateRecipe;
    public InventoryCrafting craftingGrid = new InventoryCrafting((Container) getServerElement(null), 3, 3);
    public int cooldown = 5;
    public NonNullList<ItemStack> blueprintTemplate = NonNullList.withSize(9,ItemStack.EMPTY);

    public void onBlueprintChanged(int unused) {
        templateRecipe = BlueprintUtil.getRecipeFromBlueprint(getBlueprint(), getWorld()).orElse(null);
        blueprintTemplate = BlueprintUtil.getListFromBlueprint(getBlueprint());
        generateBlueprintRecipe();
    }

    public ItemStack getBlueprint() {
        return blueprint.getStackInSlot(0);
    }

    @Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        return new SPacketUpdateTileEntity(this.pos, 0, getUpdateTag());
    }

    @Override
    public NBTTagCompound getUpdateTag() {
        return this.writeToNBT(new NBTTagCompound());
    }

    @Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
        this.readFromNBT(pkt.getNbtCompound());
    }

    @Nonnull
    public ItemStack getTemplateSlot(int index) {
        return blueprintTemplate.get(index);
    }

    @Nonnull
    public ItemStack setTemplateSlot(int index, @Nonnull ItemStack stack) {
        if(getBlueprint().isEmpty())
            return ItemStack.EMPTY;
        ItemStack result = blueprintTemplate.set(index, stack);
        BlueprintUtil.setInventoryOfBlueprint(getBlueprint(),blueprintTemplate,getWorld());
        generateBlueprintRecipe();
        return result;
    }

    @Override
    public void update() {
        if (world.isRemote)
            return;<commit_msg>*whoops*<commit_after>/*
 *    Copyright 2017 <NAME> (darkevilmac)
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.elytradev.teckle.common.tile;

import com.elytradev.teckle.client.gui.GuiFabricator;
import com.elytradev.teckle.common.TeckleMod;
import com.elytradev.teckle.common.TeckleObjects;
import com.elytradev.teckle.common.container.ContainerFabricator;
import com.elytradev.teckle.common.tile.base.IElementProvider;
import com.elytradev.teckle.common.tile.inv.AdvancedItemStackHandler;
import com.elytradev.teckle.common.util.BlueprintUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public class TileFabricator extends TileEntity implements ITickable, IElementProvider {

    public AdvancedItemStackHandler stackHandler = new AdvancedItemStackHandler(18);
    public AdvancedItemStackHandler blueprint = new AdvancedItemStackHandler(1).withChangeListener(this::onBlueprintChanged).withSlotLimit(s -> 1).withInsertCheck((integer, stack) -> stack.getItem() == TeckleObjects.itemBlueprint);
    public IRecipe templateRecipe;
    public InventoryCrafting craftingGrid = new InventoryCrafting((Container) getServerElement(null), 3, 3);
    public int cooldown = 5;
    public NonNullList<ItemStack> blueprintTemplate = NonNullList.withSize(9,ItemStack.EMPTY);

    public void onBlueprintChanged(int unused) {
        templateRecipe = BlueprintUtil.getRecipeFromBlueprint(getBlueprint(), getWorld()).orElse(null);
        blueprintTemplate = BlueprintUtil.getListFromBlueprint(getBlueprint());
        generateBlueprintRecipe();
    }

    public ItemStack getBlueprint() {
        return blueprint.getStackInSlot(0);
    }

    @Nullable
    @Override
    public SPacketUpdateTileEntity getUpdatePacket() {
        return new SPacketUpdateTileEntity(this.pos, 0, getUpdateTag());
    }

    @Override
    public NBTTagCompound getUpdateTag() {
        return this.writeToNBT(new NBTTagCompound());
    }

    @Override
    public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) {
        this.readFromNBT(pkt.getNbtCompound());
    }

    @Nonnull
    public ItemStack getTemplateSlot(int index) {
        return blueprintTemplate.get(index);
    }

    @Nonnull
    public ItemStack setTemplateSlot(int index, @Nonnull ItemStack stack) {
        if(getBlueprint().isEmpty())
            return ItemStack.EMPTY;
        stack.setCount(1);
        ItemStack result = blueprintTemplate.set(index, stack);
        BlueprintUtil.setInventoryOfBlueprint(getBlueprint(),blueprintTemplate,getWorld());
        generateBlueprintRecipe();
        return result;
    }

    @Override
    public void update() {
        if (world.isRemote)
            return;
{'fraction_non_alphanumeric': 0.08950169327527818, 'fraction_numerical': 0.004475084663763909, 'mean_word_length': 4.479787939032472, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3436326', 'n_tokens_mistral': 2415, 'n_tokens_neox': 2381, 'n_words': 510}