81 lines
2.5 KiB
Scala
81 lines
2.5 KiB
Scala
package edx.quantum.machine.thermometer
|
|
|
|
import java.util.List
|
|
|
|
import net.minecraft.block.Block
|
|
import net.minecraft.entity.player.EntityPlayer
|
|
import net.minecraft.item.ItemStack
|
|
import net.minecraft.nbt.NBTTagCompound
|
|
import net.minecraft.util.ChatComponentText
|
|
import net.minecraft.world.World
|
|
import resonantengine.lib.transform.vector.Vector3
|
|
import resonantengine.lib.utility.LanguageUtility
|
|
import resonantengine.lib.utility.nbt.NBTUtility
|
|
import resonantengine.lib.wrapper.CollectionWrapper._
|
|
import resonantengine.prefab.block.itemblock.ItemBlockSaved
|
|
|
|
class ItemBlockThermometer(block: Block) extends ItemBlockSaved(block: Block)
|
|
{
|
|
override def addInformation(itemStack: ItemStack, player: EntityPlayer, par3List: List[_], par4: Boolean)
|
|
{
|
|
super.addInformation(itemStack, player, par3List, par4)
|
|
|
|
val coord: Vector3 = getSavedCoord(itemStack)
|
|
if (coord != null)
|
|
{
|
|
par3List.add("\uaa74" + LanguageUtility.getLocal("tooltip.trackingTemperature"))
|
|
par3List.add("X: " + coord.xi + ", Y: " + coord.yi + ", Z: " + coord.zi)
|
|
}
|
|
else
|
|
{
|
|
par3List.add("\u00a74" + LanguageUtility.getLocal("tooltip.notTrackingTemperature"))
|
|
}
|
|
}
|
|
|
|
def getSavedCoord(itemStack: ItemStack): Vector3 =
|
|
{
|
|
val nbt: NBTTagCompound = NBTUtility.getNBTTagCompound(itemStack)
|
|
if (nbt.hasKey("trackCoordinate"))
|
|
{
|
|
return new Vector3(nbt.getCompoundTag("trackCoordinate"))
|
|
}
|
|
return null
|
|
}
|
|
|
|
override def onItemRightClick(itemStack: ItemStack, world: World, player: EntityPlayer): ItemStack =
|
|
{
|
|
setSavedCoords(itemStack, null)
|
|
if (!world.isRemote)
|
|
{
|
|
player.addChatMessage(new ChatComponentText("Cleared tracking coordinate."))
|
|
}
|
|
return itemStack
|
|
}
|
|
|
|
override def onItemUse(itemStack: ItemStack, player: EntityPlayer, world: World, x: Int, y: Int, z: Int, par7: Int, par8: Float, par9: Float, par10: Float): Boolean =
|
|
{
|
|
if (player.isSneaking)
|
|
{
|
|
if (!world.isRemote)
|
|
{
|
|
setSavedCoords(itemStack, new Vector3(x, y, z))
|
|
player.addChatMessage(new ChatComponentText("Tracking coordinate: " + x + ", " + y + ", " + z))
|
|
}
|
|
return true
|
|
}
|
|
return super.onItemUse(itemStack, player, world, x, y, z, par7, par8, par9, par10)
|
|
}
|
|
|
|
def setSavedCoords(itemStack: ItemStack, position: Vector3)
|
|
{
|
|
val nbt: NBTTagCompound = NBTUtility.getNBTTagCompound(itemStack)
|
|
if (position != null)
|
|
{
|
|
nbt.setTag("trackCoordinate", position.writeNBT(new NBTTagCompound))
|
|
}
|
|
else
|
|
{
|
|
nbt.removeTag("trackCoordinate")
|
|
}
|
|
}
|
|
} |