Refactored engine package to core

This commit is contained in:
Calclavia 2015-01-22 10:30:51 +08:00
parent e95550621a
commit 31e46db791
6 changed files with 247 additions and 247 deletions

View File

@ -19,7 +19,7 @@ import net.minecraft.network.Packet
import net.minecraft.util.IIcon
import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonant.engine.ResonantEngine
import resonant.core.ResonantEngine
import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketReceiver
import resonant.lib.prefab.tile.spatial.{SpatialBlock, SpatialTile}
@ -97,23 +97,6 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor
* sections).
*/
def setInventorySlotContents(slot: Int, itemStack: ItemStack)
{
if (slot < this.getSizeInventory)
{
inventory(slot) = itemStack
}
}
def getSizeInventory: Int =
{
return this.inventory.length
}
/**
* Inventory methods.
*/
@ -177,6 +160,28 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory
}
}
/**
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor
* sections).
*/
def setInventorySlotContents(slot: Int, itemStack: ItemStack)
{
if (slot < this.getSizeInventory)
{
inventory(slot) = itemStack
}
}
def getSizeInventory: Int =
{
return this.inventory.length
}
def getStackInSlot(slot: Int): ItemStack =
{
return this.inventory(slot)
}
def openInventory
{
this.onInventoryChanged
@ -187,6 +192,64 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory
this.onInventoryChanged
}
/**
* Updates all the output slots. Call this to update the Imprinter.
*/
def onInventoryChanged
{
if (!this.worldObj.isRemote)
{
val fitlerStack: ItemStack = this.inventory(9)
if (fitlerStack != null && fitlerStack.getItem.isInstanceOf[ItemImprint])
{
val outputStack: ItemStack = fitlerStack.copy
val filters: java.util.List[ItemStack] = ItemImprint.getFilters(outputStack)
val toAdd: Set[ItemStack] = new HashSet[ItemStack]
val toBeImprinted: Set[ItemStack] = new HashSet[ItemStack]
var i: Int = 0
while (i < 9)
{
val stackInInventory: ItemStack = inventory(i)
if (stackInInventory != null)
{
for (check <- toBeImprinted)
{
if (check.isItemEqual(stackInInventory))
{
i = 10
}
}
toBeImprinted.add(stackInInventory)
}
i += 1;
}
for (stackInInventory <- toBeImprinted)
{
val it: Iterator[ItemStack] = filters.iterator
var removed: Boolean = false
while (it.hasNext)
{
val filteredStack: ItemStack = it.next
if (filteredStack.isItemEqual(stackInInventory))
{
it.remove
removed = true
}
}
if (!removed)
{
toAdd.add(stackInInventory)
}
}
filters.addAll(toAdd)
ItemImprint.setFilters(outputStack, filters)
this.inventory(9) = outputStack
}
}
}
def getInventoryStackLimit: Int =
{
return 64
@ -225,11 +288,6 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory
GL11.glPopMatrix
}
def getStackInSlot(slot: Int): ItemStack =
{
return this.inventory(slot)
}
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
{
super.registerIcons(iconReg)
@ -346,62 +404,4 @@ class TileImprinter extends SpatialTile(Material.circuits) with ISidedInventory
onInventoryChanged
}
}
/**
* Updates all the output slots. Call this to update the Imprinter.
*/
def onInventoryChanged
{
if (!this.worldObj.isRemote)
{
val fitlerStack: ItemStack = this.inventory(9)
if (fitlerStack != null && fitlerStack.getItem.isInstanceOf[ItemImprint])
{
val outputStack: ItemStack = fitlerStack.copy
val filters: java.util.List[ItemStack] = ItemImprint.getFilters(outputStack)
val toAdd: Set[ItemStack] = new HashSet[ItemStack]
val toBeImprinted: Set[ItemStack] = new HashSet[ItemStack]
var i: Int = 0
while (i < 9)
{
val stackInInventory: ItemStack = inventory(i)
if (stackInInventory != null)
{
for (check <- toBeImprinted)
{
if (check.isItemEqual(stackInInventory))
{
i = 10
}
}
toBeImprinted.add(stackInInventory)
}
i += 1;
}
for (stackInInventory <- toBeImprinted)
{
val it: Iterator[ItemStack] = filters.iterator
var removed: Boolean = false
while (it.hasNext)
{
val filteredStack: ItemStack = it.next
if (filteredStack.isItemEqual(stackInInventory))
{
it.remove
removed = true
}
}
if (!removed)
{
toAdd.add(stackInInventory)
}
}
filters.addAll(toAdd)
ItemImprint.setFilters(outputStack, filters)
this.inventory(9) = outputStack
}
}
}
}

View File

@ -27,7 +27,7 @@ import org.lwjgl.opengl.GL11
import resonant.api.gui.ISlotPickResult
import resonant.api.recipe.{MachineRecipes, RecipeResource, RecipeType}
import resonant.api.tile.IRotatable
import resonant.engine.ResonantEngine
import resonant.core.ResonantEngine
import resonant.lib.collection.Pair
import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketReceiver
@ -129,6 +129,167 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece
}
}
override def getSizeInventory: Int =
{
return 10 + (if (this.invPlayer != null) this.invPlayer.getSizeInventory else 0)
}
override def setInventorySlotContents(slot: Int, itemStack: ItemStack)
{
if (slot < TileEngineeringTable.CRAFTING_MATRIX_END)
{
craftingMatrix(slot) = itemStack
}
else if (slot < TileEngineeringTable.CRAFTING_OUTPUT_END)
{
outputInventory(slot - TileEngineeringTable.CRAFTING_MATRIX_END) = itemStack
}
else if (slot < TileEngineeringTable.PLAYER_OUTPUT_END && this.invPlayer != null)
{
this.invPlayer.setInventorySlotContents(slot - TileEngineeringTable.CRAFTING_OUTPUT_END, itemStack)
val player: EntityPlayer = this.invPlayer.player
if (player.isInstanceOf[EntityPlayerMP])
{
(player.asInstanceOf[EntityPlayerMP]).sendContainerToPlayer(player.inventoryContainer)
}
}
else if (searchInventories)
{
var idDisplacement: Int = TileEngineeringTable.PLAYER_OUTPUT_END
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
val tile: TileEntity = toVectorWorld.add(dir).getTileEntity
if (tile.isInstanceOf[IInventory])
{
val inventory: IInventory = tile.asInstanceOf[IInventory]
val slotID: Int = slot - idDisplacement
if (slotID >= 0 && slotID < inventory.getSizeInventory)
{
inventory.setInventorySlotContents(slotID, itemStack)
}
idDisplacement += inventory.getSizeInventory
}
}
}
onInventoryChanged
}
/**
* Updates all the output slots. Call this to update the Engineering Table.
*/
override def onInventoryChanged
{
if (worldObj != null)
{
if (!worldObj.isRemote)
{
this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = null
var didCraft: Boolean = false
val inventoryCrafting: InventoryCrafting = this.getCraftingMatrix
val matrixOutput: ItemStack = CraftingManager.getInstance.findMatchingRecipe(inventoryCrafting, this.worldObj)
if (matrixOutput != null && this.getCraftingManager.getIdealRecipe(matrixOutput) != null)
{
this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = matrixOutput
didCraft = true
}
if (!didCraft)
{
val filterStack: ItemStack = craftingMatrix(TileEngineeringTable.CENTER_SLOT)
if (filterStack != null && filterStack.getItem.isInstanceOf[ItemImprint])
{
val filters: java.util.List[ItemStack] = ItemImprint.getFilters(filterStack)
for (o <- filters)
{
val outputStack: ItemStack = o
if (outputStack != null)
{
val idealRecipe: Pair[ItemStack, Array[ItemStack]] = this.getCraftingManager.getIdealRecipe(outputStack)
if (idealRecipe != null)
{
val recipeOutput: ItemStack = idealRecipe.left
if (recipeOutput != null & recipeOutput.stackSize > 0)
{
this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = recipeOutput
didCraft = true
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
return
}
}
}
}
}
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
}
/**
* Gets the AutoCraftingManager that does all the crafting results
*/
def getCraftingManager: AutoCraftingManager =
{
if (craftManager == null)
{
craftManager = new AutoCraftingManager(this)
}
return craftManager
}
/**
* Construct an InventoryCrafting Matrix on the fly.
*
* @return
*/
def getCraftingMatrix: InventoryCrafting =
{
val inventoryCrafting: InventoryCrafting = new InventoryCrafting(new ContainerDummy(this), 3, 3)
for (i <- 0 until this.craftingMatrix.length)
{
inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix(i))
}
return inventoryCrafting
}
/**
* DO NOT USE THIS INTERNALLY. FOR EXTERNAL USE ONLY!
*/
override def getStackInSlot(slot: Int): ItemStack =
{
if (slot < TileEngineeringTable.CRAFTING_MATRIX_END)
{
return this.craftingMatrix(slot)
}
else if (slot < TileEngineeringTable.CRAFTING_OUTPUT_END)
{
return outputInventory(slot - TileEngineeringTable.CRAFTING_MATRIX_END)
}
else if (slot < TileEngineeringTable.PLAYER_OUTPUT_END && invPlayer != null)
{
return this.invPlayer.getStackInSlot(slot - TileEngineeringTable.CRAFTING_OUTPUT_END)
}
else if (searchInventories)
{
var idDisplacement: Int = TileEngineeringTable.PLAYER_OUTPUT_END
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
val tile: TileEntity = toVectorWorld.add(dir).getTileEntity
if (tile.isInstanceOf[IInventory])
{
val inventory: IInventory = tile.asInstanceOf[IInventory]
val slotID: Int = slot - idDisplacement
if (slotID >= 0 && slotID < inventory.getSizeInventory)
{
return inventory.getStackInSlot(slotID)
}
idDisplacement += inventory.getSizeInventory
}
}
}
return null
}
override def use(player: EntityPlayer, hitSide: Int, hit: Vector3): Boolean =
{
if (player.getCurrentEquippedItem != null && player.getCurrentEquippedItem.getItem.isInstanceOf[ItemHammer])
@ -330,11 +491,6 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece
nbt.setBoolean("searchInventories", this.searchInventories)
}
override def getSizeInventory: Int =
{
return 10 + (if (this.invPlayer != null) this.invPlayer.getSizeInventory else 0)
}
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
{
try
@ -418,162 +574,6 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece
}
}
override def setInventorySlotContents(slot: Int, itemStack: ItemStack)
{
if (slot < TileEngineeringTable.CRAFTING_MATRIX_END)
{
craftingMatrix(slot) = itemStack
}
else if (slot < TileEngineeringTable.CRAFTING_OUTPUT_END)
{
outputInventory(slot - TileEngineeringTable.CRAFTING_MATRIX_END) = itemStack
}
else if (slot < TileEngineeringTable.PLAYER_OUTPUT_END && this.invPlayer != null)
{
this.invPlayer.setInventorySlotContents(slot - TileEngineeringTable.CRAFTING_OUTPUT_END, itemStack)
val player: EntityPlayer = this.invPlayer.player
if (player.isInstanceOf[EntityPlayerMP])
{
(player.asInstanceOf[EntityPlayerMP]).sendContainerToPlayer(player.inventoryContainer)
}
}
else if (searchInventories)
{
var idDisplacement: Int = TileEngineeringTable.PLAYER_OUTPUT_END
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
val tile: TileEntity = toVectorWorld.add(dir).getTileEntity
if (tile.isInstanceOf[IInventory])
{
val inventory: IInventory = tile.asInstanceOf[IInventory]
val slotID: Int = slot - idDisplacement
if (slotID >= 0 && slotID < inventory.getSizeInventory)
{
inventory.setInventorySlotContents(slotID, itemStack)
}
idDisplacement += inventory.getSizeInventory
}
}
}
onInventoryChanged
}
/**
* Updates all the output slots. Call this to update the Engineering Table.
*/
override def onInventoryChanged
{
if (worldObj != null)
{
if (!worldObj.isRemote)
{
this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = null
var didCraft: Boolean = false
val inventoryCrafting: InventoryCrafting = this.getCraftingMatrix
val matrixOutput: ItemStack = CraftingManager.getInstance.findMatchingRecipe(inventoryCrafting, this.worldObj)
if (matrixOutput != null && this.getCraftingManager.getIdealRecipe(matrixOutput) != null)
{
this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = matrixOutput
didCraft = true
}
if (!didCraft)
{
val filterStack: ItemStack = craftingMatrix(TileEngineeringTable.CENTER_SLOT)
if (filterStack != null && filterStack.getItem.isInstanceOf[ItemImprint])
{
val filters: java.util.List[ItemStack] = ItemImprint.getFilters(filterStack)
for (o <- filters)
{
val outputStack: ItemStack = o
if (outputStack != null)
{
val idealRecipe: Pair[ItemStack, Array[ItemStack]] = this.getCraftingManager.getIdealRecipe(outputStack)
if (idealRecipe != null)
{
val recipeOutput: ItemStack = idealRecipe.left
if (recipeOutput != null & recipeOutput.stackSize > 0)
{
this.outputInventory(TileEngineeringTable.CRAFTING_OUTPUT_SLOT) = recipeOutput
didCraft = true
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
return
}
}
}
}
}
}
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
}
}
/**
* Gets the AutoCraftingManager that does all the crafting results
*/
def getCraftingManager: AutoCraftingManager =
{
if (craftManager == null)
{
craftManager = new AutoCraftingManager(this)
}
return craftManager
}
/**
* Construct an InventoryCrafting Matrix on the fly.
*
* @return
*/
def getCraftingMatrix: InventoryCrafting =
{
val inventoryCrafting: InventoryCrafting = new InventoryCrafting(new ContainerDummy(this), 3, 3)
for (i <- 0 until this.craftingMatrix.length)
{
inventoryCrafting.setInventorySlotContents(i, this.craftingMatrix(i))
}
return inventoryCrafting
}
/**
* DO NOT USE THIS INTERNALLY. FOR EXTERNAL USE ONLY!
*/
override def getStackInSlot(slot: Int): ItemStack =
{
if (slot < TileEngineeringTable.CRAFTING_MATRIX_END)
{
return this.craftingMatrix(slot)
}
else if (slot < TileEngineeringTable.CRAFTING_OUTPUT_END)
{
return outputInventory(slot - TileEngineeringTable.CRAFTING_MATRIX_END)
}
else if (slot < TileEngineeringTable.PLAYER_OUTPUT_END && invPlayer != null)
{
return this.invPlayer.getStackInSlot(slot - TileEngineeringTable.CRAFTING_OUTPUT_END)
}
else if (searchInventories)
{
var idDisplacement: Int = TileEngineeringTable.PLAYER_OUTPUT_END
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
val tile: TileEntity = toVectorWorld.add(dir).getTileEntity
if (tile.isInstanceOf[IInventory])
{
val inventory: IInventory = tile.asInstanceOf[IInventory]
val slotID: Int = slot - idDisplacement
if (slotID >= 0 && slotID < inventory.getSizeInventory)
{
return inventory.getStackInSlot(slotID)
}
idDisplacement += inventory.getSizeInventory
}
}
}
return null
}
override def isItemValidForSlot(i: Int, itemstack: ItemStack): Boolean =
{
return true

View File

@ -13,7 +13,7 @@ import edx.quantum.QuantumContent
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.common.config.Configuration
import org.modstats.{ModstatInfo, Modstats}
import resonant.engine.ResonantEngine
import resonant.core.ResonantEngine
import resonant.lib.mod.config.ConfigHandler
import resonant.lib.mod.loadable.LoadableHandler

View File

@ -18,7 +18,7 @@ import net.minecraft.tileentity.TileEntity
import net.minecraft.util.{AxisAlignedBB, IIcon}
import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection
import resonant.engine.ResonantEngine
import resonant.core.ResonantEngine
import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketIDReceiver
import resonant.lib.prefab.tile.spatial.SpatialBlock

View File

@ -10,7 +10,7 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.network.Packet
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.engine.ResonantEngine
import resonant.core.ResonantEngine
import resonant.lib.content.prefab.TIO
import resonant.lib.grid.energy.EnergyStorage
import resonant.lib.network.discriminator.{PacketTile, PacketType}

View File

@ -11,7 +11,7 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.network.Packet
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
import resonant.engine.ResonantEngine
import resonant.core.ResonantEngine
import resonant.lib.grid.energy.EnergyStorage
import resonant.lib.mod.config.Config
import resonant.lib.network.discriminator.{PacketTile, PacketType}