Fixed hot plate rendering
This commit is contained in:
parent
3156ebd7e8
commit
f84cdfa0c5
|
@ -88,12 +88,14 @@ class TileEngineeringTable extends TileInventory(Material.wood) with IPacketRece
|
||||||
isOpaqueCube(false)
|
isOpaqueCube(false)
|
||||||
itemBlock(classOf[ItemBlockSaved])
|
itemBlock(classOf[ItemBlockSaved])
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def getIcon(side: Int, meta: Int): IIcon =
|
||||||
{
|
{
|
||||||
return if (side == 1) TileEngineeringTable.iconTop else (if (side == meta) TileEngineeringTable.iconFront else TileEngineeringTable.iconSide)
|
return if (side == 1) TileEngineeringTable.iconTop else (if (side == meta) TileEngineeringTable.iconFront else TileEngineeringTable.iconSide)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT) override def registerIcons(iconRegister: IIconRegister)
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def registerIcons(iconRegister: IIconRegister)
|
||||||
{
|
{
|
||||||
TileEngineeringTable.iconTop = iconRegister.registerIcon(getTextureName + "_top")
|
TileEngineeringTable.iconTop = iconRegister.registerIcon(getTextureName + "_top")
|
||||||
TileEngineeringTable.iconFront = iconRegister.registerIcon(getTextureName + "_front")
|
TileEngineeringTable.iconFront = iconRegister.registerIcon(getTextureName + "_front")
|
||||||
|
|
|
@ -11,15 +11,14 @@ import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.item.crafting.FurnaceRecipes
|
import net.minecraft.item.crafting.FurnaceRecipes
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
import net.minecraft.tileentity.TileEntity
|
|
||||||
import net.minecraft.util.IIcon
|
import net.minecraft.util.IIcon
|
||||||
import resonant.content.spatial.block.SpatialBlock
|
import resonant.content.spatial.block.SpatialBlock
|
||||||
import resonant.lib.content.prefab.java.TileInventory
|
import resonant.lib.content.prefab.java.TileInventory
|
||||||
import resonant.lib.network.discriminator.{PacketTile, PacketType}
|
import resonant.lib.network.discriminator.{PacketTile, PacketType}
|
||||||
import resonant.lib.network.handle.IPacketReceiver
|
import resonant.lib.network.handle.IPacketReceiver
|
||||||
import resonantinduction.core.Reference
|
|
||||||
import resonant.lib.transform.region.Cuboid
|
import resonant.lib.transform.region.Cuboid
|
||||||
import resonant.lib.transform.vector.{Vector2, Vector3}
|
import resonant.lib.transform.vector.{Vector2, Vector3}
|
||||||
|
import resonantinduction.core.Reference
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For smelting items.
|
* For smelting items.
|
||||||
|
@ -28,234 +27,232 @@ import resonant.lib.transform.vector.{Vector2, Vector3}
|
||||||
*/
|
*/
|
||||||
object TileHotPlate
|
object TileHotPlate
|
||||||
{
|
{
|
||||||
final val MAX_SMELT_TIME: Int = 200
|
final val MAX_SMELT_TIME: Int = 200
|
||||||
}
|
}
|
||||||
|
|
||||||
class TileHotPlate extends TileInventory(Material.iron) with IPacketReceiver
|
class TileHotPlate extends TileInventory(Material.iron) with IPacketReceiver
|
||||||
{
|
{
|
||||||
final val smeltTime: Array[Int] = Array[Int](0, 0, 0, 0)
|
final val smeltTime: Array[Int] = Array[Int](0, 0, 0, 0)
|
||||||
final val stackSizeCache: Array[Int] = Array[Int](0, 0, 0, 0)
|
final val stackSizeCache: Array[Int] = Array[Int](0, 0, 0, 0)
|
||||||
private final val POWER: Int = 50000
|
private final val POWER: Int = 50000
|
||||||
|
|
||||||
//Constructor
|
//Constructor
|
||||||
setSizeInventory(4)
|
setSizeInventory(4)
|
||||||
bounds(new Cuboid(0, 0, 0, 1, 0.2f, 1))
|
bounds(new Cuboid(0, 0, 0, 1, 0.2f, 1))
|
||||||
normalRender(false)
|
forceItemToRenderAsBlock = true
|
||||||
forceStandardRender(true)
|
isOpaqueCube = false
|
||||||
isOpaqueCube(false)
|
|
||||||
|
|
||||||
override def update
|
override def update()
|
||||||
|
{
|
||||||
|
super.update()
|
||||||
|
|
||||||
|
if (canRun)
|
||||||
{
|
{
|
||||||
if (canRun)
|
var didSmelt = false
|
||||||
{
|
|
||||||
var didSmelt: Boolean = false
|
|
||||||
|
|
||||||
for (i <- 0 to getSizeInventory)
|
for (i <- 0 to getSizeInventory)
|
||||||
{
|
{
|
||||||
if (canSmelt(this.getStackInSlot(i)))
|
if (canSmelt(this.getStackInSlot(i)))
|
||||||
{
|
|
||||||
if (smeltTime(i) <= 0)
|
|
||||||
{
|
|
||||||
stackSizeCache(i) = this.getStackInSlot(i).stackSize
|
|
||||||
smeltTime(i) = TileHotPlate.MAX_SMELT_TIME * stackSizeCache(i)
|
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
|
||||||
}
|
|
||||||
else if (smeltTime(i) > 0)
|
|
||||||
{
|
|
||||||
smeltTime(i) -= 1;
|
|
||||||
if (smeltTime(i) == 0)
|
|
||||||
{
|
|
||||||
if (!worldObj.isRemote)
|
|
||||||
{
|
|
||||||
val outputStack: ItemStack = FurnaceRecipes.smelting.getSmeltingResult(getStackInSlot(i)).copy
|
|
||||||
outputStack.stackSize = stackSizeCache(i)
|
|
||||||
setInventorySlotContents(i, outputStack)
|
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
didSmelt = true
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
smeltTime(i) = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override def onInventoryChanged
|
|
||||||
{
|
|
||||||
for (i <- 0 to getSizeInventory)
|
|
||||||
{
|
|
||||||
if (getStackInSlot(i) != null)
|
|
||||||
{
|
|
||||||
if (stackSizeCache(i) != getStackInSlot(i).stackSize)
|
|
||||||
{
|
|
||||||
if (smeltTime(i) > 0)
|
|
||||||
{
|
|
||||||
smeltTime(i) += (getStackInSlot(i).stackSize - stackSizeCache(i)) * TileHotPlate.MAX_SMELT_TIME
|
|
||||||
}
|
|
||||||
stackSizeCache(i) = getStackInSlot(i).stackSize
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stackSizeCache(i) = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (worldObj != null)
|
|
||||||
{
|
{
|
||||||
|
if (smeltTime(i) <= 0)
|
||||||
|
{
|
||||||
|
stackSizeCache(i) = this.getStackInSlot(i).stackSize
|
||||||
|
smeltTime(i) = TileHotPlate.MAX_SMELT_TIME * stackSizeCache(i)
|
||||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
||||||
}
|
}
|
||||||
}
|
else if (smeltTime(i) > 0)
|
||||||
|
{
|
||||||
def canRun: Boolean =
|
smeltTime(i) -= 1
|
||||||
{
|
if (smeltTime(i) == 0)
|
||||||
val tileEntity: TileEntity = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord)
|
|
||||||
if (tileEntity.isInstanceOf[TileFirebox])
|
|
||||||
{
|
|
||||||
if ((tileEntity.asInstanceOf[TileFirebox]).isBurning)
|
|
||||||
{
|
{
|
||||||
return true
|
if (!worldObj.isRemote)
|
||||||
|
{
|
||||||
|
val outputStack: ItemStack = FurnaceRecipes.smelting.getSmeltingResult(getStackInSlot(i)).copy
|
||||||
|
outputStack.stackSize = stackSizeCache(i)
|
||||||
|
setInventorySlotContents(i, outputStack)
|
||||||
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
didSmelt = true
|
||||||
}
|
}
|
||||||
return false
|
else
|
||||||
}
|
|
||||||
|
|
||||||
def canSmelt(stack: ItemStack): Boolean =
|
|
||||||
{
|
|
||||||
return FurnaceRecipes.smelting.getSmeltingResult(stack) != null
|
|
||||||
}
|
|
||||||
|
|
||||||
def isSmelting: Boolean =
|
|
||||||
{
|
|
||||||
{
|
{
|
||||||
var i: Int = 0
|
smeltTime(i) = 0
|
||||||
while (i < getSizeInventory)
|
|
||||||
{
|
|
||||||
{
|
|
||||||
if (getSmeltTime(i) > 0)
|
|
||||||
{
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
({
|
|
||||||
i += 1;
|
|
||||||
i - 1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
def getSmeltTime(i: Int): Int =
|
override def onInventoryChanged()
|
||||||
|
{
|
||||||
|
for (i <- 0 until getSizeInventory)
|
||||||
{
|
{
|
||||||
return smeltTime(i)
|
if (getStackInSlot(i) != null)
|
||||||
}
|
{
|
||||||
|
if (stackSizeCache(i) != getStackInSlot(i).stackSize)
|
||||||
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
|
|
||||||
{
|
|
||||||
return i < getSizeInventory && canSmelt(itemStack)
|
|
||||||
}
|
|
||||||
|
|
||||||
override def getDescPacket: PacketTile =
|
|
||||||
{
|
|
||||||
return new PacketTile(this, this.getPacketData(0).toArray)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 1 - Description Packet
|
|
||||||
* 2 - Energy Update
|
|
||||||
* 3 - Tesla Beam
|
|
||||||
*/
|
|
||||||
def getPacketData(`type`: Int): List[Any] =
|
|
||||||
{
|
|
||||||
val list: List[Any] = new ArrayList[Any]
|
|
||||||
val nbt: NBTTagCompound = new NBTTagCompound
|
|
||||||
this.writeToNBT(nbt)
|
|
||||||
list.add(nbt)
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
this.readFromNBT(ByteBufUtils.readTag(data))
|
if (smeltTime(i) > 0)
|
||||||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
|
{
|
||||||
|
smeltTime(i) += (getStackInSlot(i).stackSize - stackSizeCache(i)) * TileHotPlate.MAX_SMELT_TIME
|
||||||
|
}
|
||||||
|
stackSizeCache(i) = getStackInSlot(i).stackSize
|
||||||
}
|
}
|
||||||
catch
|
}
|
||||||
{
|
else
|
||||||
case e: Exception =>
|
{
|
||||||
{
|
stackSizeCache(i) = 0
|
||||||
e.printStackTrace
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (worldObj != null)
|
||||||
override def readFromNBT(nbt: NBTTagCompound)
|
|
||||||
{
|
{
|
||||||
super.readFromNBT(nbt)
|
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
|
||||||
for (i <- 0 to getSizeInventory)
|
|
||||||
{
|
|
||||||
smeltTime(i) = nbt.getInteger("smeltTime" + i)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override def writeToNBT(nbt: NBTTagCompound)
|
def canRun: Boolean =
|
||||||
|
{
|
||||||
|
val tileEntity = worldObj.getTileEntity(xCoord, yCoord - 1, zCoord)
|
||||||
|
|
||||||
|
if (tileEntity.isInstanceOf[TileFirebox])
|
||||||
{
|
{
|
||||||
super.writeToNBT(nbt)
|
if ((tileEntity.asInstanceOf[TileFirebox]).isBurning)
|
||||||
|
{
|
||||||
for (i <- 0 to getSizeInventory)
|
|
||||||
{
|
|
||||||
nbt.setInteger("smeltTime" + i, smeltTime(i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT) override def registerIcons(iconReg: IIconRegister)
|
|
||||||
{
|
|
||||||
super.registerIcons(iconReg)
|
|
||||||
SpatialBlock.icon.put("electricHotPlate", iconReg.registerIcon(Reference.prefix + "electricHotPlate"))
|
|
||||||
}
|
|
||||||
|
|
||||||
@SideOnly(Side.CLIENT) override def getIcon(side: Int, meta: Int): IIcon =
|
|
||||||
{
|
|
||||||
return if (meta == 1) SpatialBlock.icon.get("electricHotPlate") else SpatialBlock.icon.get(getTextureName)
|
|
||||||
}
|
|
||||||
|
|
||||||
override def click(player: EntityPlayer)
|
|
||||||
{
|
|
||||||
if (server)
|
|
||||||
{
|
|
||||||
extractItem(this, 0, player)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
|
||||||
{
|
|
||||||
if (server)
|
|
||||||
{
|
|
||||||
val hitVector: Vector2 = new Vector2(hit.x, hit.z)
|
|
||||||
val regionLength: Double = 1d / 2d
|
|
||||||
var j: Int = 0
|
|
||||||
for (j <- 0 to 2)
|
|
||||||
{
|
|
||||||
for (k <- 0 to 2)
|
|
||||||
{
|
|
||||||
val check: Vector2 = new Vector2(j, k).multiply(regionLength)
|
|
||||||
if (check.distance(hitVector) < regionLength)
|
|
||||||
{
|
|
||||||
val slotID: Int = j * 2 + k
|
|
||||||
interactCurrentItem(this, slotID, player)
|
|
||||||
onInventoryChanged
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
def canSmelt(stack: ItemStack): Boolean =
|
||||||
|
{
|
||||||
|
return FurnaceRecipes.smelting.getSmeltingResult(stack) != null
|
||||||
|
}
|
||||||
|
|
||||||
|
def isSmelting: Boolean =
|
||||||
|
{
|
||||||
|
|
||||||
|
for (i <- 0 until getSizeInventory)
|
||||||
|
{
|
||||||
|
if (getSmeltTime(i) > 0)
|
||||||
|
{
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
def getSmeltTime(i: Int): Int =
|
||||||
|
{
|
||||||
|
return smeltTime(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def isItemValidForSlot(i: Int, itemStack: ItemStack): Boolean =
|
||||||
|
{
|
||||||
|
return i < getSizeInventory && canSmelt(itemStack)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def getDescPacket: PacketTile =
|
||||||
|
{
|
||||||
|
return new PacketTile(this, this.getPacketData(0).toArray)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1 - Description Packet
|
||||||
|
* 2 - Energy Update
|
||||||
|
* 3 - Tesla Beam
|
||||||
|
*/
|
||||||
|
def getPacketData(`type`: Int): List[Any] =
|
||||||
|
{
|
||||||
|
val list: List[Any] = new ArrayList[Any]
|
||||||
|
val nbt: NBTTagCompound = new NBTTagCompound
|
||||||
|
this.writeToNBT(nbt)
|
||||||
|
list.add(nbt)
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
def read(data: ByteBuf, player: EntityPlayer, `type`: PacketType)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
this.readFromNBT(ByteBufUtils.readTag(data))
|
||||||
|
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord)
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
case e: Exception =>
|
||||||
|
{
|
||||||
|
e.printStackTrace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def readFromNBT(nbt: NBTTagCompound)
|
||||||
|
{
|
||||||
|
super.readFromNBT(nbt)
|
||||||
|
for (i <- 0 until getSizeInventory)
|
||||||
|
{
|
||||||
|
smeltTime(i) = nbt.getInteger("smeltTime" + i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def writeToNBT(nbt: NBTTagCompound)
|
||||||
|
{
|
||||||
|
super.writeToNBT(nbt)
|
||||||
|
|
||||||
|
for (i <- 0 until getSizeInventory)
|
||||||
|
{
|
||||||
|
nbt.setInteger("smeltTime" + i, smeltTime(i))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def registerIcons(iconReg: IIconRegister)
|
||||||
|
{
|
||||||
|
super.registerIcons(iconReg)
|
||||||
|
SpatialBlock.icon.put("electricHotPlate", iconReg.registerIcon(Reference.prefix + "electricHotPlate"))
|
||||||
|
}
|
||||||
|
|
||||||
|
@SideOnly(Side.CLIENT)
|
||||||
|
override def getIcon(side: Int, meta: Int): IIcon =
|
||||||
|
{
|
||||||
|
return if (meta == 1) SpatialBlock.icon.get("electricHotPlate") else SpatialBlock.icon.get(getTextureName)
|
||||||
|
}
|
||||||
|
|
||||||
|
override def click(player: EntityPlayer)
|
||||||
|
{
|
||||||
|
if (server)
|
||||||
|
{
|
||||||
|
extractItem(this, 0, player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
||||||
|
{
|
||||||
|
if (server)
|
||||||
|
{
|
||||||
|
val hitVector: Vector2 = new Vector2(hit.x, hit.z)
|
||||||
|
val regionLength: Double = 1d / 2d
|
||||||
|
var j: Int = 0
|
||||||
|
for (j <- 0 until 2)
|
||||||
|
{
|
||||||
|
for (k <- 0 until 2)
|
||||||
|
{
|
||||||
|
val check = new Vector2(j, k) * regionLength
|
||||||
|
if (check.distance(hitVector) < regionLength)
|
||||||
|
{
|
||||||
|
val slotID = j * 2 + k
|
||||||
|
interactCurrentItem(this, slotID, player)
|
||||||
|
onInventoryChanged()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue