<commit_before>package com.awesomesauce.minecraft.forge.openautomation.common.oc.baubles.item

import java.util

import baubles.api.{BaubleType, IBauble}
import cofh.api.energy.ItemEnergyContainer
import li.cil.oc.api.Driver
import li.cil.oc.api.machine.MachineHost
import li.cil.oc.api.network.{Connector, ManagedEnvironment, Node}
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
import net.minecraftforge.common.util.Constants


class MachineBaubleHost(stack: ItemStack, player: EntityLivingBase) extends MachineHost {
  lazy final val machine = li.cil.oc.api.Machine.create(this)
  val nbt = stack.getTagCompound
  val itemNBT = nbt.getTagList("items", Constants.NBT.TAG_COMPOUND)
  val inventory = new util.ArrayList[ItemStack](itemNBT.tagCount())
  val components = new util.ArrayList[ManagedEnvironment](inventory.size)
  val updatingComponents = new util.ArrayList[ManagedEnvironment](inventory.size)
  init()

  def init() = {
    for (i <- Range(0, itemNBT.tagCount())) {
      val in = i
      // Inventory loading.
      val stackNbt = itemNBT.getCompoundTagAt(in)
      val stack = ItemStack.loadItemStackFromNBT(stackNbt)
      inventory.add(stack)
      createComponent(in, stack)
    }
    if (nbt.hasKey("machine")) {
      machine.load(nbt.getCompoundTag("machine"))
    }
  }

  def createComponent(slot:Int, stack:ItemStack) {
    // This check is just needed to make it simpler to use in onConnect.
    if (stack == null || components.get(slot) != null) return

    // Get the driver for the component, so we can create an environment.
    // You don't have to pass the host class here, but it's the preferred
    // way, since that allows for component blacklisting by host.
    val driver = Driver.driverFor(stack, getClass)
    if (driver != null) {
      val environment = driver.createEnvironment(stack, this)
      if (environment != null) {
        environment.load(driver.dataTag(stack))
        components.add(environment)
        if (components.get(slot).canUpdate) {
          updatingComponents.add(components.get(slot))
        }
      }
    }
  }

  def markChanged() = {
    val itemsNbt = new NBTTagList
    for (i <- 0 until inventory.size()) {
      val stack = inventory.get(i)

      // Save components to items, first, so the info gets saved with the items.
      val environment = components.get(i)
      val driver = Driver.driverFor(stack, getClass)<commit_msg>Bauble Computer should work now. - Part 6.<commit_after>package com.awesomesauce.minecraft.forge.openautomation.common.oc.baubles.item

import java.util

import baubles.api.{BaubleType, IBauble}
import cofh.api.energy.ItemEnergyContainer
import li.cil.oc.api.Driver
import li.cil.oc.api.machine.MachineHost
import li.cil.oc.api.network.{Connector, ManagedEnvironment, Node}
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
import net.minecraftforge.common.util.Constants


class MachineBaubleHost(stack: ItemStack, player: EntityLivingBase) extends MachineHost {
  lazy final val machine = li.cil.oc.api.Machine.create(this)
  val nbt = stack.getTagCompound
  val itemNBT = nbt.getTagList("items", Constants.NBT.TAG_COMPOUND)
  val inventory = new util.ArrayList[ItemStack](itemNBT.tagCount())
  val components = new util.ArrayList[ManagedEnvironment](inventory.size)
  val updatingComponents = new util.ArrayList[ManagedEnvironment](inventory.size)
  init()

  def init() = {
    for (i <- Range(0, itemNBT.tagCount())) {
      val in = i
      // Inventory loading.
      val stackNbt = itemNBT.getCompoundTagAt(in)
      val stack = ItemStack.loadItemStackFromNBT(stackNbt)
      inventory.add(stack)
      createComponent(in, stack)
    }
    if (nbt.hasKey("machine")) {
      machine.load(nbt.getCompoundTag("machine"))
    }
  }

  def createComponent(slot:Int, stack:ItemStack) {
    // This check is just needed to make it simpler to use in onConnect.
    if (stack == null) return

    // Get the driver for the component, so we can create an environment.
    // You don't have to pass the host class here, but it's the preferred
    // way, since that allows for component blacklisting by host.
    val driver = Driver.driverFor(stack, getClass)
    if (driver != null) {
      val environment = driver.createEnvironment(stack, this)
      if (environment != null) {
        environment.load(driver.dataTag(stack))
        components.add(environment)
        if (components.get(slot).canUpdate) {
          updatingComponents.add(components.get(slot))
        }
      }
    }
  }

  def markChanged() = {
    val itemsNbt = new NBTTagList
    for (i <- 0 until inventory.size()) {
      val stack = inventory.get(i)

      // Save components to items, first, so the info gets saved with the items.
      val environment = components.get(i)
      val driver = Driver.driverFor(stack, getClass)
{'fraction_non_alphanumeric': 0.10557415796730353, 'fraction_numerical': 0.0009848335631278313, 'mean_word_length': 3.566546762589928, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '382437', 'n_tokens_mistral': 1566, 'n_tokens_neox': 1529, 'n_words': 387}