Removed crates

This commit is contained in:
Calclavia 2015-01-14 19:20:18 +08:00
parent b87895d313
commit 3e7e126a92
9 changed files with 0 additions and 1099 deletions

View file

@ -1,337 +0,0 @@
package edx.basic.crate
import java.util.List
import codechicken.multipart.ControlKeyModifer
import cpw.mods.fml.relauncher.{Side, SideOnly}
import edx.basic.BasicContent
import edx.core.Reference
import net.minecraft.block.material.Material
import net.minecraft.client.renderer.texture.IIconRegister
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP}
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.IIcon
import net.minecraft.world.World
import net.minecraftforge.oredict.OreDictionary
import resonant.lib.prefab.tile.spatial.SpatialBlock
import resonant.lib.wrapper.WrapList._
import scala.collection.JavaConversions._
import scala.util.control.Breaks._
/** A block that allows the placement of mass amount of a specific item within it. It will be allowed
* to go on Conveyor Belts.
*
* NOTE: Crates should be upgraded with an item.
*
* @author DarkGuardsman */
object BlockCrate
{
/** Puts an itemStack into the crate.
*
* @param tileEntity
* @param itemStack*/
def addStackToCrate(tileEntity: TileCrate, itemStack: ItemStack): ItemStack =
{
if (itemStack == null || itemStack.getItem.isDamageable && itemStack.getItem.getDamage(itemStack) > 0)
{
return itemStack
}
val containingStack: ItemStack = tileEntity.getSampleStack
if (containingStack == null || (containingStack.isItemEqual(itemStack) || (tileEntity.oreFilterEnabled && OreDictionary.getOreID(containingStack) == OreDictionary.getOreID(itemStack))))
{
val room: Int = Math.max((tileEntity.getInventory.getSizeInventory * 64) - (if (containingStack != null) containingStack.stackSize else 0), 0)
if (itemStack.stackSize <= room)
{
tileEntity.addToStack(itemStack)
return null
}
else
{
tileEntity.addToStack(itemStack, room)
itemStack.stackSize -= room
}
return itemStack
}
if (itemStack.stackSize <= 0)
{
return null
}
return itemStack
}
}
class BlockCrate extends SpatialBlock(Material.iron)
{
private[crate] var blockIcon: IIcon = null
private[crate] var advanced: IIcon = null
private[crate] var elite: IIcon = null
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
{
this.blockIcon = iconReg.registerIcon(Reference.prefix + "crate_wood")
this.advanced = iconReg.registerIcon(Reference.prefix + "crate_iron")
this.elite = iconReg.registerIcon(Reference.prefix + "crate_steel")
}
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
{
if (meta == 1)
{
return advanced
}
else if (meta == 2)
{
return elite
}
return this.blockIcon
}
def onBlockClicked(world: World, x: Int, y: Int, z: Int, player: EntityPlayer)
{
if (!world.isRemote && world.getTileEntity(x, y, z).isInstanceOf[TileCrate])
{
val tileEntity: TileCrate = world.getTileEntity(x, y, z).asInstanceOf[TileCrate]
this.tryEject(tileEntity, player, (System.currentTimeMillis - tileEntity.prevClickTime) < 200)
tileEntity.prevClickTime = System.currentTimeMillis
}
}
def tryEject(tileEntity: TileCrate, player: EntityPlayer, allMode: Boolean)
{
if (tileEntity.getSampleStack == null)
{
return
}
if (allMode && !player.isSneaking)
{
this.ejectItems(tileEntity, player, tileEntity.getSlotCount * 64)
}
else
{
if (player.isSneaking)
{
this.ejectItems(tileEntity, player, 64)
}
else
{
this.ejectItems(tileEntity, player, tileEntity.getSampleStack.getMaxStackSize)
}
}
}
/** Ejects and item out of the crate and spawn it under the player entity.
*
* @param tileEntity
* @param player
* @param requestSize - The maximum stack size to take out. Default should be 64.
* @return True on success */
def ejectItems(tileEntity: TileCrate, player: EntityPlayer, requestSize: Int): Boolean =
{
val world: World = tileEntity.getWorldObj
if (!world.isRemote)
{
val sampleStack: ItemStack = tileEntity.getSampleStack
var ammountEjected: Int = 0
if (sampleStack != null && requestSize > 0)
{
for (slot <- 0 until tileEntity.getInventory.getSizeInventory)
{
{
val slotStack: ItemStack = tileEntity.getInventory.getStackInSlot(slot)
if (slotStack != null && slotStack.stackSize > 0)
{
val amountToTake: Int = Math.min(slotStack.stackSize, requestSize)
val dropStack: ItemStack = slotStack.copy
dropStack.stackSize = amountToTake
if (!player.inventory.addItemStackToInventory(dropStack))
{
tileEntity.getInventory.setInventorySlotContents(slot, slotStack)
ammountEjected += amountToTake - slotStack.stackSize
break
}
else
{
tileEntity.getInventory.setInventorySlotContents(slot, null)
ammountEjected += amountToTake
}
}
if (ammountEjected >= requestSize)
{
return true
}
}
}
player.inventoryContainer.detectAndSendChanges()
tileEntity.onInventoryChanged
return true
}
}
return false
}
def onMachineActivated(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean =
{
if (!world.isRemote && world.getTileEntity(x, y, z).isInstanceOf[TileCrate])
{
val tile: TileCrate = world.getTileEntity(x, y, z).asInstanceOf[TileCrate]
if (ControlKeyModifer.isControlDown(player))
{
if (player.getCurrentEquippedItem != null && (!player.getCurrentEquippedItem.getItem.isDamageable || player.getCurrentEquippedItem.getItem.getDamage(player.getCurrentEquippedItem) > 0))
{
val filter: ItemStack = player.getCurrentEquippedItem.copy
filter.stackSize = 0
tile.setFilter(filter)
}
else
{
tile.setFilter(null)
}
}
else
{
val current: ItemStack = player.inventory.getCurrentItem
if (player.capabilities.isCreativeMode)
{
if (side == 1)
{
if (current != null && tile.getSampleStack == null)
{
val cStack: ItemStack = current.copy
cStack.stackSize = TileCrate.getSlotCount(world.getBlockMetadata(x, y, z)) * 64
BlockCrate.addStackToCrate(tile, cStack)
}
}
else if (hitY <= 0.5)
{
tryEject(tile, player, System.currentTimeMillis - tile.prevClickTime < 250)
}
else
{
tryInsert(tile, player, System.currentTimeMillis - tile.prevClickTime < 250)
}
}
else
{
tryInsert(tile, player, System.currentTimeMillis - tile.prevClickTime < 250)
}
}
tile.prevClickTime = System.currentTimeMillis
}
return true
}
/** Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
* in. */
def tryInsert(tileEntity: TileCrate, player: EntityPlayer, allMode: Boolean, doSearch: Boolean)
{
val success: Boolean = if (allMode) insertAllItems(tileEntity, player) else insertCurrentItem(tileEntity, player)
val pathfinder: PathfinderCrate = new PathfinderCrate().init(tileEntity)
for (checkTile <- pathfinder.iteratedNodes)
{
if (checkTile.isInstanceOf[TileCrate])
{
this.tryInsert((checkTile.asInstanceOf[TileCrate]), player, allMode, false)
}
}
}
def tryInsert(tileEntity: TileCrate, player: EntityPlayer, allMode: Boolean)
{
tryInsert(tileEntity, player, allMode, true)
}
/** Inserts a the itemStack the player is holding into the crate. */
def insertCurrentItem(tileEntity: TileCrate, player: EntityPlayer): Boolean =
{
val currentStack: ItemStack = player.getCurrentEquippedItem
if (currentStack != null)
{
if (currentStack.getItem() == Item.getItemFromBlock(BasicContent.blockCrate))
{
val containedStack: ItemStack = ItemBlockCrate.getContainingItemStack(currentStack)
val crateStack: ItemStack = tileEntity.getSampleStack
if (containedStack != null && (crateStack == null || ItemStack.areItemStacksEqual(containedStack, crateStack)))
{
val returned: ItemStack = BlockCrate.addStackToCrate(tileEntity, containedStack)
ItemBlockCrate.setContainingItemStack(currentStack, returned)
return true
}
}
else
{
if (tileEntity.getSampleStack != null)
{
if (!(tileEntity.getSampleStack.isItemEqual(currentStack) || (tileEntity.oreFilterEnabled && !(OreDictionary.getOreName(OreDictionary.getOreID(tileEntity.getSampleStack)) == "Unknown") && OreDictionary.getOreID(tileEntity.getSampleStack) == OreDictionary.getOreID(currentStack))))
{
return false
}
}
player.inventory.setInventorySlotContents(player.inventory.currentItem, BlockCrate.addStackToCrate(tileEntity, currentStack))
return true
}
}
return false
}
/** Inserts all items of the same type this player has into the crate.
*
* @return True on success */
def insertAllItems(tileEntity: TileCrate, player: EntityPlayer): Boolean =
{
var requestStack: ItemStack = null
if (tileEntity.getSampleStack != null)
{
requestStack = tileEntity.getSampleStack.copy
}
if (requestStack == null)
{
requestStack = player.getCurrentEquippedItem
}
if (requestStack != null && requestStack.getItem != Item.getItemFromBlock(BasicContent.blockCrate))
{
var success: Boolean = false
for (i <- 0 until player.inventory.getSizeInventory)
{
val currentStack: ItemStack = player.inventory.getStackInSlot(i)
if (currentStack != null)
{
if (requestStack.isItemEqual(currentStack))
{
player.inventory.setInventorySlotContents(i, BlockCrate.addStackToCrate(tileEntity, currentStack))
if (player.isInstanceOf[EntityPlayerMP])
{
(player.asInstanceOf[EntityPlayerMP]).sendContainerToPlayer(player.inventoryContainer)
}
success = true
}
}
}
return success
}
return false
}
def damageDropped(metadata: Int): Int =
{
return metadata
}
def createNewTileEntity(var1: World): TileEntity =
{
return new TileCrate
}
override def getSubBlocks(item: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
{
par3List.add(new ItemStack(item, 1, 0))
par3List.add(new ItemStack(item, 1, 1))
par3List.add(new ItemStack(item, 1, 2))
}
}

View file

@ -1,44 +0,0 @@
package edx.basic.crate
import edx.basic.BasicContent
import net.minecraft.block.Block
import net.minecraft.inventory.InventoryCrafting
import net.minecraft.item.{Item, ItemStack}
import net.minecraftforge.oredict.ShapedOreRecipe
/**
* Crafting handler for crates
*
* @author Darkguardsman
*/
class CrateRecipe(result: ItemStack, recipe: AnyRef*) extends ShapedOreRecipe(result, recipe)
{
def this(result: Block, recipe: AnyRef*)
{
this(new ItemStack(result), recipe)
}
def this(result: Item, recipe: AnyRef*)
{
this(new ItemStack(result), recipe)
}
override def getCraftingResult(grid: InventoryCrafting): ItemStack =
{
val result: ItemStack = super.getCraftingResult(grid)
val crateItem: Item = Item.getItemFromBlock(BasicContent.blockCrate)
if (result != null && result.getItem == crateItem)
{
val centerStack: ItemStack = grid.getStackInSlot(4)
if (centerStack != null && centerStack.getItem == crateItem)
{
val containedStack: ItemStack = ItemBlockCrate.getContainingItemStack(centerStack)
if (centerStack != null)
{
ItemBlockCrate.setContainingItemStack(result, containedStack)
}
}
}
return result
}
}

View file

@ -1,59 +0,0 @@
package edx.basic.crate
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import resonant.api.tile.IInventoryProvider
import resonant.lib.utility.inventory.ExternalInventory
import scala.util.control.Breaks._
class InventoryCrate(crate: IInventoryProvider) extends ExternalInventory(crate: IInventoryProvider, 512)
{
/** Clones the single stack into an inventory format for automation interaction */
def buildInventory(sampleStack: ItemStack)
{
this.containedItems = new Array[ItemStack](this.getSizeInventory)
if (sampleStack != null && sampleStack.getItem != null)
{
var baseStack: ItemStack = sampleStack.copy
var itemsLeft: Int = baseStack.stackSize
for (slot <- 0 until this.getContainedItems.length)
{
val stackL: Int = Math.min(Math.min(itemsLeft, baseStack.getMaxStackSize), this.getInventoryStackLimit)
var st = baseStack.copy
st.stackSize = stackL
this.setInventorySlotContents(slot, st)
itemsLeft -= stackL
if (baseStack.stackSize <= 0)
{
baseStack = null
break
}
}
}
}
override def getSizeInventory: Int =
{
if (this.host.isInstanceOf[TileCrate])
{
return (this.host.asInstanceOf[TileCrate]).getSlotCount
}
return 512
}
override def save(nbt: NBTTagCompound)
{
}
override def load(nbt: NBTTagCompound)
{
if (nbt.hasKey("Items"))
{
super.load(nbt)
}
}
}

View file

@ -1,134 +0,0 @@
package edx.basic.crate
import java.util.List
import net.minecraft.block.Block
import net.minecraft.entity.Entity
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.{ItemBlock, ItemStack}
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.potion.{Potion, PotionEffect}
import net.minecraft.world.World
import resonant.lib.utility.LanguageUtility
import resonant.lib.wrapper.WrapList._
import scala.util.control.Breaks._
object ItemBlockCrate
{
def setContainingItemStack(itemStack: ItemStack, containingStack: ItemStack)
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound)
}
if (containingStack != null)
{
val itemTagCompound: NBTTagCompound = new NBTTagCompound
containingStack.stackSize = Math.abs(containingStack.stackSize)
containingStack.writeToNBT(itemTagCompound)
itemStack.getTagCompound.setTag("Item", itemTagCompound)
itemStack.getTagCompound.setInteger("Count", containingStack.stackSize)
}
else
{
itemStack.getTagCompound.setTag("Item", new NBTTagCompound)
itemStack.getTagCompound.setInteger("Count", 0)
}
}
def getContainingItemStack(itemStack: ItemStack): ItemStack =
{
if (itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound)
return null
}
val itemTagCompound: NBTTagCompound = itemStack.getTagCompound.getCompoundTag("Item")
val containingStack: ItemStack = ItemStack.loadItemStackFromNBT(itemTagCompound)
if (containingStack != null)
{
containingStack.stackSize = itemStack.getTagCompound.getInteger("Count")
}
return containingStack
}
}
class ItemBlockCrate(block: Block) extends ItemBlock(block: Block)
{
this.setHasSubtypes(true)
override def getUnlocalizedName(itemStack: ItemStack): String =
{
return getUnlocalizedName() + "." + itemStack.getItemDamage
}
override def addInformation(itemStack: ItemStack, par2EntityPlayer: EntityPlayer, list: List[_], par4: Boolean)
{
super.addInformation(itemStack, par2EntityPlayer, list, par4)
val containingStack: ItemStack = ItemBlockCrate.getContainingItemStack(itemStack)
if (containingStack != null)
{
val s = LanguageUtility.getLocal("crate.tooltip.amount") + " " + containingStack.stackSize
list.add(containingStack.getDisplayName)
list.add(s)
}
}
override def getItemStackLimit(stack: ItemStack): Int =
{
val containingStack: ItemStack = ItemBlockCrate.getContainingItemStack(stack)
if (containingStack != null)
{
return 1
}
return this.maxStackSize
}
override def onUpdate(itemStack: ItemStack, par2World: World, entity: Entity, par4: Int, par5: Boolean)
{
if (entity.isInstanceOf[EntityPlayer])
{
val player: EntityPlayer = entity.asInstanceOf[EntityPlayer]
val containingStack: ItemStack = ItemBlockCrate.getContainingItemStack(itemStack)
if (containingStack != null && !player.capabilities.isCreativeMode)
{
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (containingStack.stackSize.asInstanceOf[Float] / TileCrate.getSlotCount(itemStack.getItemDamage).asInstanceOf[Float]).asInstanceOf[Int] * 5))
}
}
}
override def getMetadata(metadata: Int): Int =
{
return metadata
}
override def placeBlockAt(stack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, side: Int, hitX: Float, hitY: Float, hitZ: Float, metadata: Int): Boolean =
{
if (super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
{
var containingItem: ItemStack = ItemBlockCrate.getContainingItemStack(stack)
if (world.getTileEntity(x, y, z) != null && containingItem != null)
{
if (containingItem.stackSize > 0)
{
val tileEntity: TileCrate = world.getTileEntity(x, y, z).asInstanceOf[TileCrate]
var count: Int = containingItem.stackSize
for (slot <- 0 until tileEntity.getInventory.getSizeInventory)
{
val stackSize: Int = Math.min(64, count)
tileEntity.getInventory.setInventorySlotContents(slot, new ItemStack(containingItem.getItem, stackSize, containingItem.getItemDamage))
count -= stackSize
if (count <= 0)
{
containingItem = null
break
}
}
tileEntity.buildSampleStack
}
}
}
return true
}
}

View file

@ -1,114 +0,0 @@
package edx.basic.crate
import java.util.{ArrayList, List}
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.transform.vector.VectorWorld
/**
* A class that allows flexible path finding in Minecraft Blocks. Back Ported from UE 1.3.0.
* <p/>
* TODO: Will need to change when MC 1.5 comes out.
*
* @author Calclavia
*/
object PathfinderCrate
{
abstract trait IPathCallBack
{
/**
* Is this a valid node to search for?
*
* @return
*/
def isValidNode(finder: PathfinderCrate, direction: ForgeDirection, provider: TileEntity, node: TileEntity): Boolean
/**
* Called when looping through nodes.
*
* @param finder
* @param provider
* @return True to stop the path finding operation.
*/
def onSearch(finder: PathfinderCrate, provider: TileEntity): Boolean
}
}
class PathfinderCrate
{
/**
* A pathfinding call back interface used to call back on paths.
*/
var callBackCheck: PathfinderCrate.IPathCallBack = null
/**
* A list of nodes that the pathfinder went through.
*/
var iteratedNodes: List[TileEntity] = null
/**
* The results and findings found by the pathfinder.
*/
var results: List[Any] = null
this.callBackCheck = new PathfinderCrate.IPathCallBack
{
def isValidNode(finder: PathfinderCrate, direction: ForgeDirection, provider: TileEntity, node: TileEntity): Boolean =
{
return node.isInstanceOf[TileCrate]
}
def onSearch(finder: PathfinderCrate, provider: TileEntity): Boolean =
{
return false
}
}
this.clear
def findNodes(provider: TileEntity): Boolean =
{
if (provider != null)
{
this.iteratedNodes.add(provider)
if (this.callBackCheck.onSearch(this, provider))
{
return false
}
for (i <- 0 to 6)
{
val vec: VectorWorld = new VectorWorld(provider)
vec.addEquals(ForgeDirection.getOrientation(i))
val connectedTile: TileEntity = vec.getTileEntity
if (!iteratedNodes.contains(connectedTile))
{
if (this.callBackCheck.isValidNode(this, ForgeDirection.getOrientation(i), provider, connectedTile))
{
if (!this.findNodes(connectedTile))
{
return false
}
}
}
}
}
return true
}
/**
* Called to execute the pathfinding operation.
*/
def init(provider: TileEntity): PathfinderCrate =
{
this.findNodes(provider)
return this
}
def clear: PathfinderCrate =
{
this.iteratedNodes = new ArrayList[TileEntity]
this.results = new ArrayList[Any]
return this
}
}

View file

@ -1,22 +0,0 @@
package edx.basic.crate
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import org.lwjgl.opengl.GL11
import resonant.lib.render.RenderItemOverlayUtility
import resonant.lib.utility.LanguageUtility
@SideOnly(Side.CLIENT) class RenderCrate extends TileEntitySpecialRenderer
{
def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, var8: Float)
{
if (tileEntity.isInstanceOf[TileCrate])
{
GL11.glPushMatrix
val tile: TileCrate = tileEntity.asInstanceOf[TileCrate]
RenderItemOverlayUtility.renderItemOnSides(tileEntity, tile.getSampleStack, x, y, z, LanguageUtility.getLocal("tooltip.empty"))
GL11.glPopMatrix
}
}
}

View file

@ -1,335 +0,0 @@
package edx.basic.crate
import java.util
import java.util.List
import edx.basic.BasicContent
import io.netty.buffer.ByteBuf
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.oredict.OreDictionary
import resonant.api.tile.IFilterable
import resonant.api.tile.IRemovable.ISneakPickup
import resonant.lib.network.discriminator.PacketType
import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
import resonant.lib.prefab.tile.TileInventory
import resonant.lib.wrapper.ByteBufWrapper._
/** Basic single stack inventory.
* <p/>
* TODO: Add filter-locking feature. Put filter in, locks the crate to only use that item.
*
* @author DarkGuardsman */
object TileCrate
{
/** max meta size of the crate */
final val maxSize: Int = 2
/** Gets the slot count for the crate meta */
def getSlotCount(metadata: Int): Int =
{
if (metadata >= 2)
{
return 256
}
else if (metadata >= 1)
{
return 64
}
return 32
}
}
class TileCrate extends TileInventory(Material.rock) with TPacketReceiver with TPacketSender with IFilterable with ISneakPickup
{
override protected lazy val inventory = new InventoryCrate(this)
/** delay from last click */
var prevClickTime: Long = -1000
/** Check to see if oreName items can be force stacked */
var oreFilterEnabled: Boolean = false
/** Collective total stack of all inv slots */
private var sampleStack: ItemStack = null
private var filterStack: ItemStack = null
private var updateTick: Long = 1
private var doUpdate: Boolean = false
override def update()
{
super.update()
if (!worldObj.isRemote)
{
this.writeToNBT(new NBTTagCompound)
if (ticks % updateTick == 0)
{
updateTick = 5 + worldObj.rand.nextInt(50)
doUpdate = true
}
if (doUpdate)
{
doUpdate = false
sendDescPacket()
}
}
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
this.buildSampleStack(false)
val stack: ItemStack = this.getSampleStack
if (stack != null)
{
nbt.setInteger("Count", stack.stackSize)
nbt.setTag("stack", stack.writeToNBT(new NBTTagCompound))
}
nbt.setBoolean("oreFilter", this.oreFilterEnabled)
if (this.filterStack != null)
{
nbt.setTag("filter", filterStack.writeToNBT(new NBTTagCompound))
}
}
def addStackToStorage(stack: ItemStack): ItemStack =
{
return BlockCrate.addStackToCrate(this, stack)
}
/** Adds an item to the stack */
def addToStack(stack: ItemStack, amount: Int)
{
if (stack != null)
{
val newStack: ItemStack = stack.copy
newStack.stackSize = amount
this.addToStack(newStack)
}
}
/** Adds the stack to the sample stack */
def addToStack(stack: ItemStack)
{
if (stack != null && stack.stackSize > 0)
{
if (this.getSampleStack == null)
{
this.sampleStack = stack
getInventory.asInstanceOf[InventoryCrate].buildInventory(getSampleStack)
}
else if (this.getSampleStack.isItemEqual(stack) || (this.oreFilterEnabled && OreDictionary.getOreID(getSampleStack) == OreDictionary.getOreID(stack)))
{
getSampleStack.stackSize += stack.stackSize
getInventory.asInstanceOf[InventoryCrate].buildInventory(getSampleStack)
}
}
}
override def decrStackSize(slot: Int, amount: Int): ItemStack =
{
if (sampleStack != null)
{
var var3: ItemStack = null
if (sampleStack.stackSize <= amount)
{
var3 = sampleStack
sampleStack = null
this.onInventoryChanged
getInventory.asInstanceOf[InventoryCrate].buildInventory(getSampleStack)
return var3
}
else
{
var3 = sampleStack.splitStack(amount)
if (sampleStack.stackSize == 0)
{
sampleStack = null
}
getInventory.asInstanceOf[InventoryCrate].buildInventory(getSampleStack)
onInventoryChanged
return var3
}
}
else
{
return null
}
}
override def onInventoryChanged
{
if (worldObj != null && !worldObj.isRemote) doUpdate = true
}
override def canStore(stack: ItemStack, slot: Int, side: ForgeDirection): Boolean =
{
return getSampleStack == null || stack != null && (stack.isItemEqual(getSampleStack) || (this.oreFilterEnabled && OreDictionary.getOreID(getSampleStack) == OreDictionary.getOreID(stack)))
}
/** Gets the sample stack that represent the total inventory */
def getSampleStack: ItemStack =
{
if (this.sampleStack == null)
{
this.buildSampleStack()
}
return this.sampleStack
}
/** Builds the sample stack using the inventory as a point of reference. Assumes all items match
* each other, and only takes into account stack sizes */
def buildSampleStack()
{
buildSampleStack(true)
}
def buildSampleStack(buildInv: Boolean)
{
if (worldObj == null || !worldObj.isRemote)
{
var newSampleStack: ItemStack = null
var rebuildBase: Boolean = false
for (slot <- 0 until getSizeInventory)
{
val slotStack: ItemStack = this.getInventory.getStackInSlot(slot)
if (slotStack != null && slotStack.getItem != null && slotStack.stackSize > 0)
{
if (newSampleStack == null)
{
newSampleStack = slotStack.copy
}
else
{
newSampleStack.stackSize += slotStack.stackSize
}
if (slotStack.stackSize > slotStack.getMaxStackSize)
{
rebuildBase = true
}
}
}
if (newSampleStack == null || newSampleStack.getItem == null || newSampleStack.stackSize <= 0)
{
this.sampleStack = if (this.getFilter != null) this.getFilter.copy else null
}
else
{
this.sampleStack = newSampleStack.copy
}
if (buildInv && this.sampleStack != null && (rebuildBase || this.getInventory.getContainedItems.length > this.getSizeInventory))
{
this.getInventory.asInstanceOf[InventoryCrate].buildInventory(this.sampleStack)
}
}
}
override def getSizeInventory: Int = TileCrate.getSlotCount(getBlockMetadata)
def getFilter: ItemStack =
{
return this.filterStack
}
def setFilter(filter: ItemStack)
{
this.filterStack = filter
this.onInventoryChanged
}
/** Gets the current slot count for the crate */
def getSlotCount: Int =
{
if (this.worldObj == null)
{
return TileCrate.getSlotCount(TileCrate.maxSize)
}
return TileCrate.getSlotCount(this.getBlockMetadata)
}
override def read(data: ByteBuf, player: EntityPlayer, packet: PacketType)
{
if (this.worldObj.isRemote)
{
if (data.readBoolean)
{
this.sampleStack = ItemStack.loadItemStackFromNBT(data.readTag())
this.sampleStack.stackSize = data.readInt
}
else
{
this.sampleStack = null
}
}
}
/**
* Override this method
* Be sure to super this method or manually write the id into the packet when sending
*/
override def write(buf: ByteBuf, id: Int)
{
this.buildSampleStack()
val stack = this.getSampleStack
if (stack != null)
{
buf <<< true
buf <<< stack
buf <<< stack.stackSize
}
else
{
buf <<< false
}
}
/** NBT Data */
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
var stack: ItemStack = null
val count: Int = nbt.getInteger("Count")
if (nbt.hasKey("itemID"))
{
stack = new ItemStack(Item.getItemById(nbt.getInteger("itemID")), count, nbt.getInteger("itemMeta"))
}
else
{
stack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("stack"))
if (stack != null)
{
stack.stackSize = count
}
}
if (stack != null && stack.getItem != null && stack.stackSize > 0)
{
this.sampleStack = stack
this.getInventory.asInstanceOf[InventoryCrate].buildInventory(this.sampleStack)
}
this.oreFilterEnabled = nbt.getBoolean("oreFilter")
if (nbt.hasKey("filter"))
{
filterStack = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag("filter"))
}
}
def getRemovedItems(entity: EntityPlayer): List[ItemStack] =
{
val list = new util.ArrayList[ItemStack]()
val sampleStack: ItemStack = getSampleStack
val drop: ItemStack = new ItemStack(Item.getItemFromBlock(BasicContent.blockCrate), 1, this.getBlockMetadata)
if (sampleStack != null && sampleStack.stackSize > 0)
{
ItemBlockCrate.setContainingItemStack(drop, sampleStack)
}
list.add(drop)
return list
}
}

View file

@ -1,52 +0,0 @@
package edx.basic.waila
import java.util.List
import edx.basic.crate.TileCrate
import mcp.mobius.waila.api.{IWailaConfigHandler, IWailaDataAccessor, IWailaDataProvider}
import net.minecraft.item.ItemStack
import net.minecraft.tileentity.TileEntity
import resonant.lib.utility.LanguageUtility
/**
* Waila support for crates
*
* @author Darkguardsman
*/
class WailaCrate extends IWailaDataProvider
{
override def getWailaBody(itemStack: ItemStack, currenttip: List[String], accessor: IWailaDataAccessor, config: IWailaConfigHandler): List[String] =
{
val tile: TileEntity = accessor.getTileEntity
if (tile.isInstanceOf[TileCrate])
{
val stored: ItemStack = (tile.asInstanceOf[TileCrate]).getSampleStack
val cap: Int = (tile.asInstanceOf[TileCrate]).getSlotCount * 64
if (stored != null)
{
currenttip.add(LanguageUtility.getLocal("info.waila.crate.stack") + " " + stored.getDisplayName)
currenttip.add(LanguageUtility.getLocal("info.waila.crate.stored") + " " + stored.stackSize + " / " + cap)
}
else
{
currenttip.add(LanguageUtility.getLocal("info.waila.crate.empty"))
}
}
return currenttip
}
override def getWailaHead(itemStack: ItemStack, currenttip: List[String], accessor: IWailaDataAccessor, config: IWailaConfigHandler): List[String] =
{
return currenttip
}
override def getWailaStack(accessor: IWailaDataAccessor, config: IWailaConfigHandler): ItemStack =
{
return null
}
override def getWailaTail(itemStack: ItemStack, currenttip: List[String], accessor: IWailaDataAccessor, config: IWailaConfigHandler): List[String] =
{
return currenttip
}
}

View file

@ -1,6 +1,5 @@
package edx.basic.waila package edx.basic.waila
import edx.basic.crate.TileCrate
import edx.basic.fluid.tank.TileTank import edx.basic.fluid.tank.TileTank
import mcp.mobius.waila.api.IWailaRegistrar import mcp.mobius.waila.api.IWailaRegistrar
@ -8,7 +7,6 @@ object WailaRegistrar
{ {
def wailaCallBack(registrar: IWailaRegistrar) def wailaCallBack(registrar: IWailaRegistrar)
{ {
registrar.registerBodyProvider(new WailaCrate, classOf[TileCrate])
registrar.registerBodyProvider(new WailaFluidTank, classOf[TileTank]) registrar.registerBodyProvider(new WailaFluidTank, classOf[TileTank])
} }
} }